Revize d6451c0a
Přidáno uživatelem Jakub Šmíd před téměř 3 roky(ů)
backend/src/main/java/cz/zcu/kiv/backendapi/alternativename/AlternativeName.java | ||
---|---|---|
1 | 1 |
package cz.zcu.kiv.backendapi.alternativename; |
2 | 2 |
|
3 | 3 |
import cz.zcu.kiv.backendapi.catalog.CatalogItem; |
4 |
import lombok.*; |
|
4 |
import lombok.AllArgsConstructor; |
|
5 |
import lombok.Getter; |
|
6 |
import lombok.NoArgsConstructor; |
|
7 |
import lombok.Setter; |
|
5 | 8 |
|
6 | 9 |
import javax.persistence.*; |
7 |
import java.io.Serializable; |
|
8 | 10 |
|
9 | 11 |
/** |
10 | 12 |
* Alternative name entity representing alternative name of catalog item |
11 | 13 |
*/ |
12 |
@Data |
|
13 |
@EqualsAndHashCode(exclude = "catalogItem") |
|
14 |
@ToString(exclude = "catalogItem") |
|
14 |
@Getter |
|
15 |
@Setter |
|
15 | 16 |
@NoArgsConstructor |
16 | 17 |
@AllArgsConstructor |
17 | 18 |
@Entity |
18 | 19 |
@Table(name = "alternative_names") |
19 |
@IdClass(AlternativeName.class) |
|
20 |
public class AlternativeName implements Serializable {
|
|
20 |
@IdClass(AlternativeNamePK.class)
|
|
21 |
public class AlternativeName { |
|
21 | 22 |
/** |
22 | 23 |
* Name, serves as ID |
23 | 24 |
*/ |
... | ... | |
27 | 28 |
/** |
28 | 29 |
* Catalog entity |
29 | 30 |
*/ |
30 |
@ManyToOne |
|
31 |
@JoinColumn(name = "catalog_item_id") |
|
31 |
@ManyToOne(fetch = FetchType.LAZY) |
|
32 | 32 |
@Id |
33 |
@JoinColumn(name = "catalog_item_id") |
|
33 | 34 |
private CatalogItem catalogItem; |
34 | 35 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/alternativename/AlternativeNamePK.java | ||
---|---|---|
1 |
package cz.zcu.kiv.backendapi.alternativename; |
|
2 |
|
|
3 |
import lombok.AllArgsConstructor; |
|
4 |
import lombok.EqualsAndHashCode; |
|
5 |
import lombok.NoArgsConstructor; |
|
6 |
|
|
7 |
import java.io.Serializable; |
|
8 |
import java.util.UUID; |
|
9 |
|
|
10 |
/** |
|
11 |
* Class representing alternative name primary key |
|
12 |
*/ |
|
13 |
@EqualsAndHashCode |
|
14 |
@AllArgsConstructor |
|
15 |
@NoArgsConstructor |
|
16 |
public class AlternativeNamePK implements Serializable { |
|
17 |
/** |
|
18 |
* Name |
|
19 |
*/ |
|
20 |
private String name; |
|
21 |
|
|
22 |
/** |
|
23 |
* ID of catalog item |
|
24 |
*/ |
|
25 |
private UUID catalogItem; |
|
26 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/bibliography/Bibliography.java | ||
---|---|---|
1 | 1 |
package cz.zcu.kiv.backendapi.bibliography; |
2 | 2 |
|
3 | 3 |
import cz.zcu.kiv.backendapi.catalog.CatalogItem; |
4 |
import lombok.*; |
|
4 |
import lombok.AllArgsConstructor; |
|
5 |
import lombok.Getter; |
|
6 |
import lombok.NoArgsConstructor; |
|
7 |
import lombok.Setter; |
|
5 | 8 |
|
6 | 9 |
import javax.persistence.*; |
7 |
import java.io.Serializable; |
|
8 | 10 |
|
9 | 11 |
/** |
10 | 12 |
* Bibliography entity representing bibliography |
11 | 13 |
*/ |
12 |
@Data |
|
13 |
@EqualsAndHashCode(exclude = "catalogItem") |
|
14 |
@ToString(exclude = "catalogItem") |
|
14 |
@Getter |
|
15 |
@Setter |
|
15 | 16 |
@NoArgsConstructor |
16 | 17 |
@AllArgsConstructor |
17 | 18 |
@Entity |
18 | 19 |
@Table(name = "bibliography") |
19 |
@IdClass(Bibliography.class) |
|
20 |
public class Bibliography implements Serializable {
|
|
20 |
@IdClass(BibliographyPK.class)
|
|
21 |
public class Bibliography { |
|
21 | 22 |
/** |
22 | 23 |
* Source, serves as ID |
23 | 24 |
*/ |
24 | 25 |
@Id |
25 | 26 |
private String source; |
26 | 27 |
|
27 |
@ManyToOne |
|
28 |
@ManyToOne(fetch = FetchType.LAZY) |
|
29 |
@Id |
|
28 | 30 |
@JoinColumn(name = "catalog_item_id") |
29 | 31 |
private CatalogItem catalogItem; |
30 | 32 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/bibliography/BibliographyPK.java | ||
---|---|---|
1 |
package cz.zcu.kiv.backendapi.bibliography; |
|
2 |
|
|
3 |
import lombok.AllArgsConstructor; |
|
4 |
import lombok.EqualsAndHashCode; |
|
5 |
import lombok.NoArgsConstructor; |
|
6 |
|
|
7 |
import java.io.Serializable; |
|
8 |
import java.util.UUID; |
|
9 |
|
|
10 |
/** |
|
11 |
* Class representing bibliography primary key |
|
12 |
*/ |
|
13 |
@EqualsAndHashCode |
|
14 |
@AllArgsConstructor |
|
15 |
@NoArgsConstructor |
|
16 |
public class BibliographyPK implements Serializable { |
|
17 |
/** |
|
18 |
* Source |
|
19 |
*/ |
|
20 |
private String source; |
|
21 |
|
|
22 |
/** |
|
23 |
* ID of catalog item |
|
24 |
*/ |
|
25 |
private UUID catalogItem; |
|
26 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogController.java | ||
---|---|---|
43 | 43 |
*/ |
44 | 44 |
@GetMapping("") |
45 | 45 |
@Operation(summary = "returns catalog items based on filter") |
46 |
public ResponseEntity<List<CatalogItemDto>> getCatalog(@RequestParam(defaultValue = "") String name, @RequestParam(defaultValue = "") String country, @RequestParam(defaultValue = "") String type) { |
|
47 |
return new ResponseEntity<>(catalogService.getCatalog(name, country, type), HttpStatus.OK); |
|
46 |
public ResponseEntity<List<CatalogItemDto>> getCatalog(@RequestParam(defaultValue = "") String name, @RequestParam(defaultValue = "") String country, @RequestParam(defaultValue = "") String type, @RequestParam(defaultValue = "") String writtenForm) {
|
|
47 |
return new ResponseEntity<>(catalogService.getCatalog(name, country, type, writtenForm), HttpStatus.OK);
|
|
48 | 48 |
} |
49 | 49 |
|
50 | 50 |
/** |
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItem.java | ||
---|---|---|
5 | 5 |
import cz.zcu.kiv.backendapi.country.Country; |
6 | 6 |
import cz.zcu.kiv.backendapi.type.Type; |
7 | 7 |
import cz.zcu.kiv.backendapi.writtenform.WrittenForm; |
8 |
import lombok.Data; |
|
8 |
import lombok.EqualsAndHashCode; |
|
9 |
import lombok.Getter; |
|
9 | 10 |
import lombok.NoArgsConstructor; |
11 |
import lombok.Setter; |
|
10 | 12 |
import org.hibernate.annotations.Fetch; |
11 | 13 |
import org.hibernate.annotations.FetchMode; |
12 | 14 |
import org.hibernate.annotations.LazyCollection; |
... | ... | |
21 | 23 |
/** |
22 | 24 |
* Catalog entity representing catalog item |
23 | 25 |
*/ |
24 |
@Data |
|
26 |
@Getter |
|
27 |
@Setter |
|
28 |
@EqualsAndHashCode(onlyExplicitlyIncluded = true) |
|
25 | 29 |
@NoArgsConstructor |
26 | 30 |
@Entity |
27 | 31 |
@Table(name = "catalog_item") |
... | ... | |
33 | 37 |
* Catalog item id |
34 | 38 |
*/ |
35 | 39 |
@Id |
36 |
@GeneratedValue |
|
37 |
private UUID id; |
|
40 |
// @GeneratedValue |
|
41 |
@EqualsAndHashCode.Include |
|
42 |
private UUID id = UUID.randomUUID(); |
|
38 | 43 |
|
39 | 44 |
/** |
40 | 45 |
* Name of geographic item |
... | ... | |
68 | 73 |
@OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL) |
69 | 74 |
@LazyCollection(LazyCollectionOption.FALSE) |
70 | 75 |
@Fetch(FetchMode.SUBSELECT) |
71 |
private Set<Bibliography> bibliography = Collections.emptySet();
|
|
76 |
private Set<Bibliography> bibliography = new HashSet<>();
|
|
72 | 77 |
|
73 | 78 |
/** |
74 | 79 |
* Countries |
... | ... | |
76 | 81 |
@OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL) |
77 | 82 |
@LazyCollection(LazyCollectionOption.FALSE) |
78 | 83 |
@Fetch(FetchMode.SUBSELECT) |
79 |
private Set<Country> countries = Collections.emptySet();
|
|
84 |
private Set<Country> countries = new HashSet<>();
|
|
80 | 85 |
|
81 | 86 |
/** |
82 | 87 |
* Written forms |
... | ... | |
84 | 89 |
@OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL) |
85 | 90 |
@LazyCollection(LazyCollectionOption.FALSE) |
86 | 91 |
@Fetch(FetchMode.SUBSELECT) |
87 |
private Set<WrittenForm> writtenForms = Collections.emptySet();
|
|
92 |
private Set<WrittenForm> writtenForms = new HashSet<>();
|
|
88 | 93 |
|
89 | 94 |
/** |
90 | 95 |
* Alternative names |
... | ... | |
92 | 97 |
@OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL) |
93 | 98 |
@LazyCollection(LazyCollectionOption.FALSE) |
94 | 99 |
@Fetch(FetchMode.SUBSELECT) |
95 |
private Set<AlternativeName> alternativeNames = Collections.emptySet();
|
|
100 |
private Set<AlternativeName> alternativeNames = new HashSet<>();
|
|
96 | 101 |
|
97 | 102 |
/** |
98 | 103 |
* Set of user roles - many-to-many relationship |
... | ... | |
108 | 113 |
@JoinColumn(name = "type", referencedColumnName = "type") |
109 | 114 |
} |
110 | 115 |
) |
111 |
private Set<Type> types = Collections.emptySet();
|
|
116 |
private Set<Type> types = new HashSet<>();
|
|
112 | 117 |
|
113 | 118 |
public CatalogItem(final List<String> csvFields) { |
114 | 119 |
|
115 | 120 |
this.name = csvFields.get(1); |
116 |
List<String> stringList = processListField(csvFields.get(2));
|
|
121 |
Set<String> stringList = processListField(csvFields.get(2));
|
|
117 | 122 |
this.alternativeNames = stringList.stream().map(s -> new AlternativeName(s, this)).collect(Collectors.toSet()); |
118 | 123 |
|
119 | 124 |
this.certainty = processIntField(csvFields.get(3)); |
... | ... | |
151 | 156 |
} |
152 | 157 |
} |
153 | 158 |
|
154 |
private List<String> processListField(String field) {
|
|
159 |
private Set<String> processListField(String field) {
|
|
155 | 160 |
if (field.isEmpty() || field.equals(EMPTY_ENTRY)) { |
156 |
return new ArrayList<>();
|
|
161 |
return new HashSet<>();
|
|
157 | 162 |
} |
158 |
return Arrays.stream(field.split(",")).map(String::trim).filter(item -> !item.isEmpty()).collect(Collectors.toList());
|
|
163 |
return Arrays.stream(field.split(",")).map(String::trim).filter(item -> !item.isEmpty()).collect(Collectors.toSet());
|
|
159 | 164 |
} |
160 | 165 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItemRepository.java | ||
---|---|---|
5 | 5 |
import org.springframework.stereotype.Repository; |
6 | 6 |
|
7 | 7 |
import java.util.List; |
8 |
import java.util.Set; |
|
9 | 8 |
import java.util.UUID; |
10 | 9 |
|
11 | 10 |
/** |
... | ... | |
14 | 13 |
@Repository |
15 | 14 |
public interface CatalogItemRepository extends JpaRepository<CatalogItem, UUID> { |
16 | 15 |
|
17 |
/** |
|
18 |
* Returns all catalog items containing specific values |
|
19 |
* |
|
20 |
* @param name name - optional |
|
21 |
* @param country country - optional |
|
22 |
* @param type type - optional |
|
23 |
* @return set of catalog items satisfying filter conditions |
|
24 |
*/ |
|
25 |
@Query("SELECT DISTINCT e FROM CatalogItem e " + |
|
26 |
"LEFT JOIN FETCH AlternativeName a ON e = a.catalogItem " + |
|
27 |
"LEFT JOIN FETCH Country c ON e = c.catalogItem " + |
|
28 |
"LEFT JOIN FETCH e.types t " + |
|
29 |
"WHERE (?1 = '' OR UPPER(e.name) LIKE UPPER(?1) OR UPPER(a.name) LIKE UPPER(?1)) " + |
|
30 |
"AND (?2 = '' OR UPPER(c.name) LIKE UPPER(?2)) " + |
|
31 |
"AND (?3 = '' OR UPPER(t.type) LIKE UPPER(?3))") |
|
32 |
Set<CatalogItem> filterCatalog(String name, String country, String type); |
|
33 |
|
|
34 | 16 |
/** |
35 | 17 |
* Selects catalog items with given name (alternative name) |
36 | 18 |
* |
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItemServiceImpl.java | ||
---|---|---|
14 | 14 |
import org.springframework.stereotype.Service; |
15 | 15 |
import org.springframework.transaction.annotation.Transactional; |
16 | 16 |
|
17 |
import java.util.ArrayList; |
|
18 |
import java.util.List; |
|
19 |
import java.util.Set; |
|
20 |
import java.util.UUID; |
|
17 |
import java.util.*; |
|
18 |
import java.util.function.Predicate; |
|
21 | 19 |
import java.util.regex.Matcher; |
22 | 20 |
import java.util.regex.Pattern; |
23 | 21 |
import java.util.stream.Collectors; |
... | ... | |
36 | 34 |
private static final String WILDCARD_CHARACTER_REGEX = "\\?"; |
37 | 35 |
|
38 | 36 |
/** |
39 |
* Regex for one arbitrary character in string used in SQL language
|
|
37 |
* Regex for one arbitrary character in string used in Java
|
|
40 | 38 |
*/ |
41 |
private static final String WILDCARD_CHARACTER_REGEX_SQL = "_";
|
|
39 |
private static final String WILDCARD_CHARACTER_REGEX_JAVA = ".";
|
|
42 | 40 |
|
43 | 41 |
/** |
44 | 42 |
* Regex for any number of arbitrary characters in string |
45 | 43 |
*/ |
46 | 44 |
private static final String WILDCARD_CHARACTERS_REGEX = "\\*"; |
47 | 45 |
|
46 |
/** |
|
47 |
* Regex for any number of arbitrary characters in string used in Java |
|
48 |
*/ |
|
49 |
private static final String WILDCARD_CHARACTERS_REGEX_JAVA = ".*"; |
|
50 |
|
|
48 | 51 |
/** |
49 | 52 |
* Regex for finding punctuation at the start of word |
50 | 53 |
*/ |
... | ... | |
65 | 68 |
*/ |
66 | 69 |
private static final Pattern END_PUNCTUATION_PATTERN = Pattern.compile(END_PUNCTUATION_REGEX); |
67 | 70 |
|
68 |
/** |
|
69 |
* Regex for any number of arbitrary characters in string used in SQL language |
|
70 |
*/ |
|
71 |
private static final String WILDCARD_CHARACTERS_REGEX_SQL = "%"; |
|
72 |
|
|
73 | 71 |
/** |
74 | 72 |
* Message for exception when catalog item is not found by id |
75 | 73 |
*/ |
... | ... | |
125 | 123 |
log.info("Catalog item deleted"); |
126 | 124 |
} |
127 | 125 |
|
128 |
@Override |
|
129 |
public List<CatalogItemDto> getCatalog(String name, String country, String type) { |
|
130 |
log.info("Retrieving catalog"); |
|
131 |
name = name.replaceAll(WILDCARD_CHARACTER_REGEX, WILDCARD_CHARACTER_REGEX_SQL); |
|
132 |
name = name.replaceAll(WILDCARD_CHARACTERS_REGEX, WILDCARD_CHARACTERS_REGEX_SQL); |
|
133 |
country = country.replaceAll(WILDCARD_CHARACTER_REGEX, WILDCARD_CHARACTER_REGEX_SQL); |
|
134 |
country = country.replaceAll(WILDCARD_CHARACTERS_REGEX, WILDCARD_CHARACTERS_REGEX_SQL); |
|
135 |
type = type.replaceAll(WILDCARD_CHARACTER_REGEX, WILDCARD_CHARACTER_REGEX_SQL); |
|
136 |
type = type.replaceAll(WILDCARD_CHARACTERS_REGEX, WILDCARD_CHARACTERS_REGEX_SQL); |
|
137 |
Set<CatalogItem> entities = catalogItemRepository.filterCatalog(name, country, type); |
|
138 |
return entities.stream().map(this::convertEntityToDto).collect(Collectors.toList()); |
|
139 |
} |
|
126 |
private final Map<String, AlternativeName> map = new HashMap<>(); |
|
140 | 127 |
|
141 | 128 |
@Override |
142 | 129 |
public CatalogItemDto getCatalogItem(UUID id) { |
... | ... | |
201 | 188 |
return pathDto; |
202 | 189 |
} |
203 | 190 |
|
191 |
@Override |
|
192 |
public List<CatalogItemDto> getCatalog(String name, String country, String type, String writtenForm) { |
|
193 |
log.info("Retrieving catalog"); |
|
194 |
|
|
195 |
String finalName = name.replaceAll(WILDCARD_CHARACTER_REGEX, WILDCARD_CHARACTER_REGEX_JAVA).replaceAll(WILDCARD_CHARACTERS_REGEX, WILDCARD_CHARACTERS_REGEX_JAVA); |
|
196 |
String finalCountry = country.replaceAll(WILDCARD_CHARACTER_REGEX, WILDCARD_CHARACTER_REGEX_JAVA).replaceAll(WILDCARD_CHARACTERS_REGEX, WILDCARD_CHARACTERS_REGEX_JAVA); |
|
197 |
String finalType = type.replaceAll(WILDCARD_CHARACTER_REGEX, WILDCARD_CHARACTER_REGEX_JAVA).replaceAll(WILDCARD_CHARACTERS_REGEX, WILDCARD_CHARACTERS_REGEX_JAVA); |
|
198 |
String finalWrittenForm = writtenForm.replaceAll(WILDCARD_CHARACTER_REGEX, WILDCARD_CHARACTER_REGEX_JAVA).replaceAll(WILDCARD_CHARACTERS_REGEX, WILDCARD_CHARACTERS_REGEX_JAVA); |
|
199 |
|
|
200 |
Pattern patternName = Pattern.compile(finalName, Pattern.CASE_INSENSITIVE); |
|
201 |
Pattern patternCountry = Pattern.compile(finalCountry, Pattern.CASE_INSENSITIVE); |
|
202 |
Pattern patternType = Pattern.compile(finalType, Pattern.CASE_INSENSITIVE); |
|
203 |
Pattern patternWrittenForm = Pattern.compile(finalWrittenForm, Pattern.CASE_INSENSITIVE); |
|
204 |
|
|
205 |
List<CatalogItem> catalogItems = catalogItemRepository.findAll(); |
|
206 |
|
|
207 |
Predicate<CatalogItem> predicateType = i -> finalType.equals("") || i.getTypes().stream().anyMatch(t -> patternType.matcher(t.getType()).matches()); |
|
208 |
Predicate<CatalogItem> predicateCountry = i -> finalCountry.equals("") || i.getCountries().stream().anyMatch(t -> patternCountry.matcher(t.getName()).matches()); |
|
209 |
Predicate<CatalogItem> predicateName = i -> finalName.equals("") || patternName.matcher(i.getName()).matches() || i.getAlternativeNames().stream().anyMatch(t -> patternName.matcher(t.getName()).matches()); |
|
210 |
Predicate<CatalogItem> predicateWrittenForm = i -> finalWrittenForm.equals("") || i.getWrittenForms().stream().anyMatch(t -> patternWrittenForm.matcher(t.getForm()).matches()); |
|
211 |
|
|
212 |
catalogItems = catalogItems.stream().filter(predicateName.and(predicateCountry).and(predicateType).and(predicateWrittenForm)).collect(Collectors.toList()); |
|
213 |
|
|
214 |
return catalogItems.stream().map(this::convertEntityToDto).collect(Collectors.toList()); |
|
215 |
} |
|
216 |
|
|
204 | 217 |
/** |
205 | 218 |
* Saves catalog entity to database |
206 | 219 |
* |
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/ICatalogItemService.java | ||
---|---|---|
41 | 41 |
/** |
42 | 42 |
* Returns catalog items satisfying given filter |
43 | 43 |
* |
44 |
* @param name name - optional |
|
45 |
* @param country country - optional |
|
46 |
* @param type type - optional |
|
44 |
* @param name name - optional |
|
45 |
* @param country country - optional |
|
46 |
* @param type type - optional |
|
47 |
* @param writtenForm written form - optional |
|
47 | 48 |
* @return list of catalog items satisfying given filter |
48 | 49 |
*/ |
49 |
List<CatalogItemDto> getCatalog(String name, String country, String type); |
|
50 |
List<CatalogItemDto> getCatalog(String name, String country, String type, String writtenForm);
|
|
50 | 51 |
|
51 | 52 |
/** |
52 | 53 |
* Returns catalog item with given ID |
backend/src/main/java/cz/zcu/kiv/backendapi/country/Country.java | ||
---|---|---|
1 | 1 |
package cz.zcu.kiv.backendapi.country; |
2 | 2 |
|
3 | 3 |
import cz.zcu.kiv.backendapi.catalog.CatalogItem; |
4 |
import lombok.*; |
|
4 |
import lombok.AllArgsConstructor; |
|
5 |
import lombok.Getter; |
|
6 |
import lombok.NoArgsConstructor; |
|
7 |
import lombok.Setter; |
|
5 | 8 |
|
6 | 9 |
import javax.persistence.*; |
7 |
import java.io.Serializable; |
|
8 | 10 |
|
9 | 11 |
/** |
10 | 12 |
* Country entity representing country of catalog item |
11 | 13 |
*/ |
12 |
@Data |
|
13 |
@EqualsAndHashCode(exclude = "catalogItem") |
|
14 |
@ToString(exclude = "catalogItem") |
|
14 |
@Getter |
|
15 |
@Setter |
|
15 | 16 |
@NoArgsConstructor |
16 | 17 |
@AllArgsConstructor |
17 | 18 |
@Entity |
18 | 19 |
@Table(name = "countries") |
19 |
@IdClass(Country.class) |
|
20 |
public class Country implements Serializable {
|
|
20 |
@IdClass(CountryPK.class)
|
|
21 |
public class Country { |
|
21 | 22 |
/** |
22 | 23 |
* Name of country, serves as ID |
23 | 24 |
*/ |
24 | 25 |
@Id |
25 | 26 |
private String name; |
26 | 27 |
|
27 |
@ManyToOne |
|
28 |
@JoinColumn(name = "catalog_item_id") |
|
28 |
@ManyToOne(fetch = FetchType.LAZY) |
|
29 | 29 |
@Id |
30 |
@JoinColumn(name = "catalog_item_id") |
|
30 | 31 |
private CatalogItem catalogItem; |
31 | 32 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/country/CountryPK.java | ||
---|---|---|
1 |
package cz.zcu.kiv.backendapi.country; |
|
2 |
|
|
3 |
import lombok.AllArgsConstructor; |
|
4 |
import lombok.EqualsAndHashCode; |
|
5 |
import lombok.NoArgsConstructor; |
|
6 |
|
|
7 |
import java.io.Serializable; |
|
8 |
import java.util.UUID; |
|
9 |
|
|
10 |
/** |
|
11 |
* Class representing country primary key |
|
12 |
*/ |
|
13 |
@EqualsAndHashCode |
|
14 |
@AllArgsConstructor |
|
15 |
@NoArgsConstructor |
|
16 |
public class CountryPK implements Serializable { |
|
17 |
/** |
|
18 |
* Name |
|
19 |
*/ |
|
20 |
private String name; |
|
21 |
|
|
22 |
/** |
|
23 |
* ID of catalog item |
|
24 |
*/ |
|
25 |
private UUID catalogItem; |
|
26 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/writtenform/WrittenForm.java | ||
---|---|---|
1 | 1 |
package cz.zcu.kiv.backendapi.writtenform; |
2 | 2 |
|
3 | 3 |
import cz.zcu.kiv.backendapi.catalog.CatalogItem; |
4 |
import lombok.*; |
|
4 |
import lombok.AllArgsConstructor; |
|
5 |
import lombok.Getter; |
|
6 |
import lombok.NoArgsConstructor; |
|
7 |
import lombok.Setter; |
|
5 | 8 |
|
6 | 9 |
import javax.persistence.*; |
7 |
import java.io.Serializable; |
|
8 | 10 |
|
9 | 11 |
/** |
10 | 12 |
* Written form entity representing written form of catalog item |
11 | 13 |
*/ |
12 |
@Data |
|
13 |
@EqualsAndHashCode(exclude = "catalogItem") |
|
14 |
@ToString(exclude = "catalogItem") |
|
14 |
@Getter |
|
15 |
@Setter |
|
15 | 16 |
@NoArgsConstructor |
16 | 17 |
@AllArgsConstructor |
17 | 18 |
@Entity |
18 | 19 |
@Table(name = "written_forms") |
19 |
@IdClass(WrittenForm.class) |
|
20 |
public class WrittenForm implements Serializable {
|
|
20 |
@IdClass(WrittenFormPK.class)
|
|
21 |
public class WrittenForm { |
|
21 | 22 |
/** |
22 | 23 |
* Written form, serves as ID |
23 | 24 |
*/ |
24 | 25 |
@Id |
25 | 26 |
private String form; |
26 | 27 |
|
27 |
@ManyToOne |
|
28 |
@JoinColumn(name = "catalog_item_id") |
|
28 |
@ManyToOne(fetch = FetchType.LAZY) |
|
29 | 29 |
@Id |
30 |
@JoinColumn(name = "catalog_item_id") |
|
30 | 31 |
private CatalogItem catalogItem; |
31 | 32 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/writtenform/WrittenFormPK.java | ||
---|---|---|
1 |
package cz.zcu.kiv.backendapi.writtenform; |
|
2 |
|
|
3 |
import lombok.AllArgsConstructor; |
|
4 |
import lombok.EqualsAndHashCode; |
|
5 |
import lombok.NoArgsConstructor; |
|
6 |
|
|
7 |
import java.io.Serializable; |
|
8 |
import java.util.UUID; |
|
9 |
|
|
10 |
/** |
|
11 |
* Class representing written form primary key |
|
12 |
*/ |
|
13 |
@EqualsAndHashCode |
|
14 |
@AllArgsConstructor |
|
15 |
@NoArgsConstructor |
|
16 |
public class WrittenFormPK implements Serializable { |
|
17 |
/** |
|
18 |
* Form |
|
19 |
*/ |
|
20 |
private String form; |
|
21 |
|
|
22 |
/** |
|
23 |
* ID of catalog item |
|
24 |
*/ |
|
25 |
private UUID catalogItem; |
|
26 |
} |
backend/src/test/java/cz/zcu/kiv/backendapi/catalog/CatalogItemRepositoryTest.java | ||
---|---|---|
1 | 1 |
package cz.zcu.kiv.backendapi.catalog; |
2 | 2 |
|
3 | 3 |
import cz.zcu.kiv.backendapi.alternativename.AlternativeName; |
4 |
import cz.zcu.kiv.backendapi.country.Country; |
|
5 |
import cz.zcu.kiv.backendapi.type.Type; |
|
6 |
import cz.zcu.kiv.backendapi.type.TypeRepository; |
|
7 | 4 |
import org.junit.jupiter.api.AfterEach; |
8 | 5 |
import org.junit.jupiter.api.BeforeEach; |
9 | 6 |
import org.junit.jupiter.api.Test; |
... | ... | |
22 | 19 |
@Autowired |
23 | 20 |
private CatalogItemRepository underTest; |
24 | 21 |
|
25 |
@Autowired |
|
26 |
private TypeRepository typeRepository; |
|
27 |
|
|
28 | 22 |
private CatalogItem catalogItem1; |
29 | 23 |
private CatalogItem catalogItem2; |
30 | 24 |
private CatalogItem catalogItem3; |
... | ... | |
33 | 27 |
|
34 | 28 |
@BeforeEach |
35 | 29 |
void setUp() { |
36 |
Type typeCountry = new Type("country"); |
|
37 |
Type typeCity = new Type("city"); |
|
38 |
Type typeCapitalCity = new Type("capital city new"); |
|
39 |
Type typeCityUpper = new Type("City"); |
|
40 |
Type typeCountri = new Type("countri"); |
|
41 |
typeRepository.saveAll(List.of(typeCountry, typeCity, typeCapitalCity, typeCityUpper, typeCountri)); |
|
42 |
|
|
43 | 30 |
String nameFirst = "first"; |
44 | 31 |
String nameFirstUpper = "First"; |
45 | 32 |
String nameSecond = "second"; |
... | ... | |
48 | 35 |
String nameTwelve = "twelve"; |
49 | 36 |
String nameTwentyUpper = "TWENTY"; |
50 | 37 |
|
51 |
String countryAaa = "aaa"; |
|
52 |
String countryAaaUpper = "AAA"; |
|
53 |
String countryBbb = "bbb"; |
|
54 |
String countryBccb = "bccb"; |
|
55 |
String countryCcc = "ccc"; |
|
56 |
String countryDdd = "ddd"; |
|
57 |
String countryDcd = "dcd"; |
|
58 |
|
|
59 | 38 |
catalogItem1 = new CatalogItem(); |
60 | 39 |
catalogItem2 = new CatalogItem(); |
61 | 40 |
catalogItem3 = new CatalogItem(); |
... | ... | |
63 | 42 |
catalogItem5 = new CatalogItem(); |
64 | 43 |
|
65 | 44 |
catalogItem1.setName(nameFirst); |
66 |
catalogItem1.setTypes(Set.of(typeCountry, typeCity)); |
|
67 |
catalogItem1.setCountries(Set.of(new Country(countryAaa, catalogItem1), new Country(countryDcd, catalogItem1))); |
|
68 | 45 |
|
69 | 46 |
catalogItem2.setName(nameSecond); |
70 | 47 |
catalogItem2.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem2), new AlternativeName(nameThird, catalogItem2))); |
71 |
catalogItem2.setTypes(Set.of(typeCountry, typeCityUpper)); |
|
72 |
catalogItem2.setCountries(Set.of(new Country(countryAaa, catalogItem2), new Country(countryBbb, catalogItem2))); |
|
73 | 48 |
|
74 | 49 |
catalogItem3.setName(nameThird); |
75 | 50 |
catalogItem3.setAlternativeNames(Set.of(new AlternativeName(nameTwentyUpper, catalogItem3), new AlternativeName(nameSedond, catalogItem3))); |
76 |
catalogItem3.setTypes(Set.of(typeCountri, typeCapitalCity)); |
|
77 |
catalogItem3.setCountries(Set.of(new Country(countryAaaUpper, catalogItem3), new Country(countryCcc, catalogItem3))); |
|
78 |
|
|
79 | 51 |
|
80 | 52 |
catalogItem4.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem4), new AlternativeName(nameFirstUpper, catalogItem4))); |
81 |
catalogItem4.setTypes(Set.of(typeCountri, typeCountry)); |
|
82 |
catalogItem4.setCountries(Set.of(new Country(countryBccb, catalogItem4), new Country(countryDdd, catalogItem4))); |
|
83 |
|
|
84 | 53 |
|
85 | 54 |
catalogItem5.setName(nameSedond); |
86 | 55 |
catalogItem5.setAlternativeNames(Set.of(new AlternativeName(nameThird, catalogItem5))); |
87 |
catalogItem5.setTypes(Set.of(typeCountri)); |
|
88 | 56 |
|
89 | 57 |
underTest.saveAll(List.of(catalogItem1, catalogItem2, catalogItem3, catalogItem4, catalogItem5)); |
90 | 58 |
|
... | ... | |
96 | 64 |
underTest.deleteAll(); |
97 | 65 |
} |
98 | 66 |
|
99 |
@Test |
|
100 |
void itShouldReturnAll() { |
|
101 |
// given |
|
102 |
String name = ""; |
|
103 |
String country = ""; |
|
104 |
String type = ""; |
|
105 |
|
|
106 |
// when |
|
107 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
108 |
|
|
109 |
// then |
|
110 |
assertThat(filterResult.size()).isEqualTo(5); |
|
111 |
} |
|
112 |
|
|
113 |
@Test |
|
114 |
void testName() { |
|
115 |
// given |
|
116 |
String name = "first"; |
|
117 |
String country = ""; |
|
118 |
String type = ""; |
|
119 |
|
|
120 |
// when |
|
121 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
122 |
|
|
123 |
// then |
|
124 |
assertThat(filterResult.size()).isEqualTo(2); |
|
125 |
assertTrue(filterResult.contains(catalogItem1)); |
|
126 |
assertTrue(filterResult.contains(catalogItem4)); |
|
127 |
} |
|
128 |
|
|
129 |
@Test |
|
130 |
void testWildcardCharacterName() { |
|
131 |
// given |
|
132 |
String name = "se_ond"; |
|
133 |
String country = ""; |
|
134 |
String type = ""; |
|
135 |
|
|
136 |
// when |
|
137 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
138 |
|
|
139 |
// then |
|
140 |
assertThat(filterResult.size()).isEqualTo(3); |
|
141 |
assertTrue(filterResult.contains(catalogItem2)); |
|
142 |
assertTrue(filterResult.contains(catalogItem3)); |
|
143 |
assertTrue(filterResult.contains(catalogItem5)); |
|
144 |
} |
|
145 |
|
|
146 |
@Test |
|
147 |
void testWildcardCharactersName() { |
|
148 |
// given |
|
149 |
String name = "twe%"; |
|
150 |
String country = ""; |
|
151 |
String type = ""; |
|
152 |
|
|
153 |
// when |
|
154 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
155 |
|
|
156 |
// then |
|
157 |
assertThat(filterResult.size()).isEqualTo(3); |
|
158 |
assertTrue(filterResult.contains(catalogItem2)); |
|
159 |
assertTrue(filterResult.contains(catalogItem3)); |
|
160 |
assertTrue(filterResult.contains(catalogItem4)); |
|
161 |
} |
|
162 |
|
|
163 |
@Test |
|
164 |
void testCountry() { |
|
165 |
// given |
|
166 |
String name = ""; |
|
167 |
String country = "aaa"; |
|
168 |
String type = ""; |
|
169 |
|
|
170 |
// when |
|
171 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
172 |
|
|
173 |
// then |
|
174 |
assertThat(filterResult.size()).isEqualTo(3); |
|
175 |
assertTrue(filterResult.contains(catalogItem1)); |
|
176 |
assertTrue(filterResult.contains(catalogItem2)); |
|
177 |
assertTrue(filterResult.contains(catalogItem3)); |
|
178 |
} |
|
179 |
|
|
180 |
@Test |
|
181 |
void testWildcardCharacterCountry() { |
|
182 |
// given |
|
183 |
String name = ""; |
|
184 |
String country = "d_d"; |
|
185 |
String type = ""; |
|
186 |
|
|
187 |
// when |
|
188 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
189 |
|
|
190 |
// then |
|
191 |
assertThat(filterResult.size()).isEqualTo(2); |
|
192 |
assertTrue(filterResult.contains(catalogItem1)); |
|
193 |
assertTrue(filterResult.contains(catalogItem4)); |
|
194 |
} |
|
195 |
|
|
196 |
@Test |
|
197 |
void testWildcardCharactersCountry() { |
|
198 |
// given |
|
199 |
String name = ""; |
|
200 |
String country = "b%b"; |
|
201 |
String type = ""; |
|
202 |
|
|
203 |
// when |
|
204 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
205 |
|
|
206 |
// then |
|
207 |
assertThat(filterResult.size()).isEqualTo(2); |
|
208 |
assertTrue(filterResult.contains(catalogItem2)); |
|
209 |
assertTrue(filterResult.contains(catalogItem4)); |
|
210 |
} |
|
211 |
|
|
212 |
|
|
213 |
@Test |
|
214 |
void testType() { |
|
215 |
// given |
|
216 |
String name = ""; |
|
217 |
String country = ""; |
|
218 |
String type = "city"; |
|
219 |
|
|
220 |
// when |
|
221 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
222 |
|
|
223 |
// then |
|
224 |
assertThat(filterResult.size()).isEqualTo(2); |
|
225 |
assertTrue(filterResult.contains(catalogItem1)); |
|
226 |
assertTrue(filterResult.contains(catalogItem2)); |
|
227 |
} |
|
228 |
|
|
229 |
@Test |
|
230 |
void testWildcardCharacterType() { |
|
231 |
// given |
|
232 |
String name = ""; |
|
233 |
String country = ""; |
|
234 |
String type = "countr_"; |
|
235 |
|
|
236 |
// when |
|
237 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
238 |
|
|
239 |
// then |
|
240 |
assertThat(filterResult.size()).isEqualTo(5); |
|
241 |
assertTrue(filterResult.contains(catalogItem1)); |
|
242 |
assertTrue(filterResult.contains(catalogItem2)); |
|
243 |
assertTrue(filterResult.contains(catalogItem3)); |
|
244 |
assertTrue(filterResult.contains(catalogItem4)); |
|
245 |
assertTrue(filterResult.contains(catalogItem5)); |
|
246 |
} |
|
247 |
|
|
248 |
@Test |
|
249 |
void testWildcardCharactersType() { |
|
250 |
// given |
|
251 |
String name = ""; |
|
252 |
String country = ""; |
|
253 |
String type = "%city%"; |
|
254 |
|
|
255 |
// when |
|
256 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
257 |
|
|
258 |
// then |
|
259 |
assertThat(filterResult.size()).isEqualTo(3); |
|
260 |
assertTrue(filterResult.contains(catalogItem1)); |
|
261 |
assertTrue(filterResult.contains(catalogItem2)); |
|
262 |
assertTrue(filterResult.contains(catalogItem3)); |
|
263 |
} |
|
264 |
|
|
265 |
@Test |
|
266 |
void testNameAndCountry() { |
|
267 |
// given |
|
268 |
String name = "third"; |
|
269 |
String country = "aaa"; |
|
270 |
String type = ""; |
|
271 |
|
|
272 |
// when |
|
273 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
274 |
|
|
275 |
// then |
|
276 |
assertThat(filterResult.size()).isEqualTo(2); |
|
277 |
assertTrue(filterResult.contains(catalogItem2)); |
|
278 |
assertTrue(filterResult.contains(catalogItem3)); |
|
279 |
} |
|
280 |
|
|
281 |
@Test |
|
282 |
void testNameAndType() { |
|
283 |
// given |
|
284 |
String name = "third"; |
|
285 |
String country = ""; |
|
286 |
String type = "countri"; |
|
287 |
|
|
288 |
// when |
|
289 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
290 |
|
|
291 |
// then |
|
292 |
assertThat(filterResult.size()).isEqualTo(2); |
|
293 |
assertTrue(filterResult.contains(catalogItem3)); |
|
294 |
assertTrue(filterResult.contains(catalogItem5)); |
|
295 |
} |
|
296 |
|
|
297 |
@Test |
|
298 |
void testCountryAndType() { |
|
299 |
// given |
|
300 |
String name = ""; |
|
301 |
String country = "ddd"; |
|
302 |
String type = "country"; |
|
303 |
|
|
304 |
// when |
|
305 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
306 |
|
|
307 |
// then |
|
308 |
assertThat(filterResult.size()).isEqualTo(1); |
|
309 |
assertTrue(filterResult.contains(catalogItem4)); |
|
310 |
} |
|
311 |
|
|
312 |
@Test |
|
313 |
void testAll() { |
|
314 |
// given |
|
315 |
String name = "third"; |
|
316 |
String country = "AAA"; |
|
317 |
String type = "countri"; |
|
318 |
|
|
319 |
// when |
|
320 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type); |
|
321 |
|
|
322 |
// then |
|
323 |
assertThat(filterResult.size()).isEqualTo(1); |
|
324 |
assertTrue(filterResult.contains(catalogItem3)); |
|
325 |
} |
|
326 |
|
|
327 | 67 |
@Test |
328 | 68 |
void testItemsByName() { |
329 | 69 |
// given |
backend/src/test/java/cz/zcu/kiv/backendapi/catalog/CatalogItemServiceImplTest.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
23 | 23 |
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; |
24 |
import static org.junit.jupiter.api.Assertions.assertTrue; |
|
25 | 24 |
import static org.mockito.ArgumentMatchers.any; |
26 | 25 |
import static org.mockito.ArgumentMatchers.anyString; |
27 | 26 |
import static org.mockito.BDDMockito.given; |
... | ... | |
37 | 36 |
@Mock |
38 | 37 |
private TypeServiceImpl typeService; |
39 | 38 |
|
40 |
|
|
41 | 39 |
private CatalogItemServiceImpl underTest; |
42 | 40 |
|
43 | 41 |
@BeforeEach |
... | ... | |
127 | 125 |
|
128 | 126 |
CatalogItem capturedItem = argumentCaptor.getValue(); |
129 | 127 |
|
130 |
assertThat(capturedItem).isEqualTo(catalogItem); |
|
128 |
assertThat(capturedItem.getName()).isEqualTo(catalogItem.getName()); |
|
129 |
assertThat(capturedItem.getLongitude()).isEqualTo(catalogItem.getLongitude()); |
|
130 |
assertThat(capturedItem.getLatitude()).isEqualTo(catalogItem.getLatitude()); |
|
131 |
assertThat(capturedItem.getCertainty()).isEqualTo(catalogItem.getCertainty()); |
|
132 |
assertThat(capturedItem.getAlternativeNames().size()).isEqualTo(catalogItem.getAlternativeNames().size()); |
|
133 |
assertThat(capturedItem.getBibliography().size()).isEqualTo(catalogItem.getBibliography().size()); |
|
134 |
assertThat(capturedItem.getCountries().size()).isEqualTo(catalogItem.getCountries().size()); |
|
135 |
assertThat(capturedItem.getWrittenForms().size()).isEqualTo(catalogItem.getWrittenForms().size()); |
|
136 |
assertThat(capturedItem.getTypes().size()).isEqualTo(catalogItem.getTypes().size()); |
|
137 |
assertThat(capturedItem.getDescription()).isEqualTo(catalogItem.getDescription()); |
|
131 | 138 |
|
132 | 139 |
} |
133 | 140 |
|
... | ... | |
184 | 191 |
Type typeOld = new Type("old"); |
185 | 192 |
|
186 | 193 |
CatalogItem catalogItem = new CatalogItem(); |
194 |
catalogItem.setId(id); |
|
187 | 195 |
catalogItem.setName("name"); |
188 | 196 |
catalogItem.setBibliography(Set.of(new Bibliography("bibl", catalogItem))); |
189 | 197 |
catalogItem.setTypes(Set.of(type)); |
... | ... | |
196 | 204 |
catalogItem.setDescription("description"); |
197 | 205 |
|
198 | 206 |
CatalogItem oldCatalogItem = new CatalogItem(); |
207 |
oldCatalogItem.setId(id); |
|
199 | 208 |
oldCatalogItem.setName("old"); |
200 | 209 |
oldCatalogItem.setBibliography(Set.of(new Bibliography("old", oldCatalogItem))); |
201 | 210 |
oldCatalogItem.setTypes(Set.of(typeOld)); |
... | ... | |
279 | 288 |
verify(catalogItemRepository, never()).deleteById(any()); |
280 | 289 |
} |
281 | 290 |
|
282 |
@Test |
|
283 |
void getCatalog() { |
|
284 |
// given |
|
285 |
String name = "aaa?bb*aa"; |
|
286 |
String country = "aaa?bb*aa"; |
|
287 |
String type = "aaa?bb*aa"; |
|
288 |
String nameChanged = "aaa_bb%aa"; |
|
289 |
String countryChanged = "aaa_bb%aa"; |
|
290 |
String typeChanged = "aaa_bb%aa"; |
|
291 |
|
|
292 |
Type typeEntity = new Type(type); |
|
293 |
|
|
294 |
CatalogItem catalogItem = new CatalogItem(); |
|
295 |
catalogItem.setName("aaacbbbbbbbaa"); |
|
296 |
catalogItem.setBibliography(Set.of(new Bibliography("bibl", catalogItem))); |
|
297 |
catalogItem.setTypes(Set.of(typeEntity)); |
|
298 |
catalogItem.setAlternativeNames(Set.of(new AlternativeName("altName", catalogItem))); |
|
299 |
catalogItem.setCountries(Set.of(new Country("aaaabbaa", catalogItem))); |
|
300 |
catalogItem.setWrittenForms(Set.of(new WrittenForm("written", catalogItem))); |
|
301 |
catalogItem.setCertainty(0); |
|
302 |
catalogItem.setLatitude(0.1); |
|
303 |
catalogItem.setLongitude(0.2); |
|
304 |
|
|
305 |
CatalogItem catalogItem2 = new CatalogItem(); |
|
306 |
catalogItem2.setName("name"); |
|
307 |
catalogItem2.setBibliography(Set.of(new Bibliography("bibl", catalogItem2))); |
|
308 |
catalogItem2.setTypes(Set.of(typeEntity)); |
|
309 |
catalogItem2.setAlternativeNames(Set.of(new AlternativeName("aaaabbbbbbaa", catalogItem2))); |
|
310 |
catalogItem2.setCountries(Set.of(new Country("aaaabbcccefaa", catalogItem2))); |
|
311 |
catalogItem2.setWrittenForms(Set.of(new WrittenForm("written", catalogItem2))); |
|
312 |
catalogItem2.setCertainty(1); |
|
313 |
catalogItem2.setLatitude(1.1); |
|
314 |
catalogItem2.setLongitude(1.2); |
|
315 |
|
|
316 |
CatalogItemDto catalogItemDto = new CatalogItemDto(); |
|
317 |
catalogItemDto.setName("aaacbbbbbbbaa"); |
|
318 |
catalogItemDto.setBibliography(Set.of("bibl")); |
|
319 |
catalogItemDto.setTypes(Set.of("aaa?bb*aa")); |
|
320 |
catalogItemDto.setAlternativeNames(Set.of("altName")); |
|
321 |
catalogItemDto.setCountries(Set.of("aaaabbaa")); |
|
322 |
catalogItemDto.setWrittenForms(Set.of("written")); |
|
323 |
catalogItemDto.setCertainty(0); |
|
324 |
catalogItemDto.setLatitude(0.1); |
|
325 |
catalogItemDto.setLongitude(0.2); |
|
326 |
|
|
327 |
CatalogItemDto catalogItemDto2 = new CatalogItemDto(); |
|
328 |
catalogItemDto2.setName("name"); |
|
329 |
catalogItemDto2.setBibliography(Set.of("bibl")); |
|
330 |
catalogItemDto2.setTypes(Set.of("aaa?bb*aa")); |
|
331 |
catalogItemDto2.setAlternativeNames(Set.of("aaaabbbbbbaa")); |
|
332 |
catalogItemDto2.setCountries(Set.of("aaaabbcccefaa")); |
|
333 |
catalogItemDto2.setWrittenForms(Set.of("written")); |
|
334 |
catalogItemDto2.setCertainty(1); |
|
335 |
catalogItemDto2.setLatitude(1.1); |
|
336 |
catalogItemDto2.setLongitude(1.2); |
|
337 |
|
|
338 |
given(catalogItemRepository.filterCatalog(nameChanged, countryChanged, typeChanged)).willReturn(Set.of(catalogItem, catalogItem2)); |
|
339 |
|
|
340 |
// when |
|
341 |
List<CatalogItemDto> results = underTest.getCatalog(name, country, type); |
|
342 | 291 |
|
343 |
// then |
|
344 |
assertThat(results.size()).isEqualTo(2); |
|
345 |
assertTrue(results.contains(catalogItemDto)); |
|
346 |
assertTrue(results.contains(catalogItemDto2)); |
|
347 |
|
|
348 |
verify(catalogItemRepository).filterCatalog(nameChanged, countryChanged, typeChanged); |
|
349 |
} |
|
350 | 292 |
|
351 | 293 |
@Test |
352 | 294 |
void testSearchedTest() { |
... | ... | |
389 | 331 |
catalogItem6.setLongitude(0.0); |
390 | 332 |
|
391 | 333 |
CatalogItemDto catalogItemDto1 = new CatalogItemDto(); |
334 |
catalogItemDto1.setId(catalogItem1.getId()); |
|
392 | 335 |
catalogItemDto1.setAlternativeNames(Stream.of("Azbar").collect(Collectors.toSet())); |
393 | 336 |
catalogItemDto1.setLatitude(5); |
394 | 337 |
catalogItemDto1.setLongitude(5); |
395 | 338 |
|
396 | 339 |
CatalogItemDto catalogItemDto2 = new CatalogItemDto(); |
340 |
catalogItemDto2.setId(catalogItem2.getId()); |
|
397 | 341 |
catalogItemDto2.setAlternativeNames(Stream.of("Azbar", "Azbarasdf").collect(Collectors.toSet())); |
398 | 342 |
catalogItemDto2.setLatitude(0.0); |
399 | 343 |
catalogItemDto2.setLongitude(0.0); |
400 | 344 |
|
401 | 345 |
CatalogItemDto catalogItemDto3 = new CatalogItemDto(); |
346 |
catalogItemDto3.setId(catalogItem3.getId()); |
|
402 | 347 |
catalogItemDto3.setAlternativeNames(Stream.of("U-re-me-re").collect(Collectors.toSet())); |
403 | 348 |
catalogItemDto3.setLatitude(55); |
404 | 349 |
catalogItemDto3.setLongitude(68); |
405 | 350 |
|
406 | 351 |
CatalogItemDto catalogItemDto4 = new CatalogItemDto(); |
352 |
catalogItemDto4.setId(catalogItem4.getId()); |
|
407 | 353 |
catalogItemDto4.setAlternativeNames(Stream.of("Huga").collect(Collectors.toSet())); |
408 | 354 |
catalogItemDto4.setLatitude(0.0); |
409 | 355 |
catalogItemDto4.setLongitude(0.0); |
410 | 356 |
|
411 | 357 |
CatalogItemDto catalogItemDto5 = new CatalogItemDto(); |
358 |
catalogItemDto5.setId(catalogItem5.getId()); |
|
412 | 359 |
catalogItemDto5.setAlternativeNames(Stream.of("Huga", "Hugaa").collect(Collectors.toSet())); |
413 | 360 |
catalogItemDto5.setLatitude(0.0); |
414 | 361 |
catalogItemDto5.setLongitude(0.0); |
415 | 362 |
|
416 | 363 |
CatalogItemDto catalogItemDto6 = new CatalogItemDto(); |
364 |
catalogItemDto6.setId(catalogItem6.getId()); |
|
417 | 365 |
catalogItemDto6.setAlternativeNames(Stream.of("Duga").collect(Collectors.toSet())); |
418 | 366 |
catalogItemDto6.setLatitude(0.0); |
419 | 367 |
catalogItemDto6.setLongitude(0.0); |
backend/src/test/java/cz/zcu/kiv/backendapi/catalog/CatalogItemServiceImplTest2.java | ||
---|---|---|
1 |
package cz.zcu.kiv.backendapi.catalog; |
|
2 |
|
|
3 |
import cz.zcu.kiv.backendapi.alternativename.AlternativeName; |
|
4 |
import cz.zcu.kiv.backendapi.country.Country; |
|
5 |
import cz.zcu.kiv.backendapi.type.Type; |
|
6 |
import cz.zcu.kiv.backendapi.type.TypeServiceImpl; |
|
7 |
import cz.zcu.kiv.backendapi.writtenform.WrittenForm; |
|
8 |
import org.junit.jupiter.api.BeforeEach; |
|
9 |
import org.junit.jupiter.api.Test; |
|
10 |
import org.junit.jupiter.api.extension.ExtendWith; |
|
11 |
import org.mockito.Mock; |
|
12 |
import org.mockito.junit.jupiter.MockitoExtension; |
|
13 |
|
|
14 |
import java.util.Collections; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Set; |
|
17 |
import java.util.UUID; |
|
18 |
|
|
19 |
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
|
20 |
import static org.junit.jupiter.api.Assertions.assertTrue; |
|
21 |
import static org.mockito.BDDMockito.given; |
|
22 |
import static org.mockito.Mockito.verify; |
|
23 |
|
|
24 |
@ExtendWith(MockitoExtension.class) |
|
25 |
class CatalogItemServiceImplTest2 { |
|
26 |
@Mock |
|
27 |
private CatalogItemRepository catalogItemRepository; |
|
28 |
|
|
29 |
@Mock |
|
30 |
private TypeServiceImpl typeService; |
|
31 |
|
|
32 |
private CatalogItemServiceImpl underTest; |
|
33 |
|
|
34 |
private CatalogItemDto catalogItemDto1; |
|
35 |
private CatalogItemDto catalogItemDto2; |
|
36 |
private CatalogItemDto catalogItemDto3; |
|
37 |
private CatalogItemDto catalogItemDto4; |
|
38 |
private CatalogItemDto catalogItemDto5; |
|
39 |
|
|
40 |
@BeforeEach |
|
41 |
void setUp() { |
|
42 |
underTest = new CatalogItemServiceImpl(catalogItemRepository, typeService); |
|
43 |
// given |
|
44 |
String country = "country"; |
|
45 |
String city = "city"; |
|
46 |
String capitalCityNew = "capital city new"; |
|
47 |
String cityUpper = "City"; |
|
48 |
String countri = "countri"; |
|
49 |
|
|
50 |
Type typeCountry = new Type(country); |
|
51 |
Type typeCity = new Type(city); |
|
52 |
Type typeCapitalCity = new Type(capitalCityNew); |
|
53 |
Type typeCityUpper = new Type(cityUpper); |
|
54 |
Type typeCountri = new Type(countri); |
|
55 |
|
|
56 |
String nameFirst = "first"; |
|
57 |
String nameFirstUpper = "First"; |
|
58 |
String nameSecond = "second"; |
|
59 |
String nameSedond = "sedond"; |
|
60 |
String nameThird = "third"; |
|
61 |
String nameTwelve = "twelve"; |
|
62 |
String nameTwentyUpper = "TWENTY"; |
|
63 |
|
|
64 |
String countryAaa = "aaa"; |
|
65 |
String countryAaaUpper = "AAA"; |
|
66 |
String countryBbb = "bbb"; |
|
67 |
String countryBccb = "bccb"; |
|
68 |
String countryCcc = "ccc"; |
|
69 |
String countryDdd = "ddd"; |
|
70 |
String countryDcd = "dcd"; |
|
71 |
|
|
72 |
String writtenForm = "written"; |
|
73 |
String writtenFormUpper = "WRITTEN"; |
|
74 |
String writtenFormForOr = "wratten"; |
|
75 |
|
|
76 |
CatalogItem catalogItem1 = new CatalogItem(); |
|
77 |
CatalogItem catalogItem2 = new CatalogItem(); |
|
78 |
CatalogItem catalogItem3 = new CatalogItem(); |
|
79 |
CatalogItem catalogItem4 = new CatalogItem(); |
|
80 |
CatalogItem catalogItem5 = new CatalogItem(); |
|
81 |
|
|
82 |
UUID catalogItemId1 = UUID.randomUUID(); |
|
83 |
UUID catalogItemId2 = UUID.randomUUID(); |
|
84 |
UUID catalogItemId3 = UUID.randomUUID(); |
|
85 |
UUID catalogItemId4 = UUID.randomUUID(); |
|
86 |
UUID catalogItemId5 = UUID.randomUUID(); |
|
87 |
|
|
88 |
catalogItem1.setId(catalogItemId1); |
|
89 |
catalogItem2.setId(catalogItemId2); |
|
90 |
catalogItem3.setId(catalogItemId3); |
|
91 |
catalogItem4.setId(catalogItemId4); |
|
92 |
catalogItem5.setId(catalogItemId5); |
|
93 |
|
|
94 |
catalogItem1.setName(nameFirst); |
|
95 |
catalogItem1.setTypes(Set.of(typeCountry, typeCity)); |
|
96 |
catalogItem1.setCountries(Set.of(new Country(countryAaa, catalogItem1), new Country(countryDcd, catalogItem1))); |
|
97 |
catalogItem1.setWrittenForms(Set.of(new WrittenForm(writtenForm, catalogItem1))); |
|
98 |
|
|
99 |
catalogItemDto1 = new CatalogItemDto(catalogItemId1, nameFirst, Collections.emptySet(), Set.of(writtenForm), Set.of(country, city), Set.of(countryAaa, countryDcd), Collections.emptySet(), 0.0, 0.0, 0, ""); |
|
100 |
|
|
101 |
catalogItem2.setName(nameSecond); |
|
102 |
catalogItem2.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem2), new AlternativeName(nameThird, catalogItem2))); |
|
103 |
catalogItem2.setTypes(Set.of(typeCountry, typeCityUpper)); |
|
104 |
catalogItem2.setCountries(Set.of(new Country(countryAaa, catalogItem2), new Country(countryBbb, catalogItem2))); |
|
105 |
catalogItem2.setWrittenForms(Set.of(new WrittenForm(writtenFormUpper, catalogItem2))); |
|
106 |
|
|
107 |
catalogItemDto2 = new CatalogItemDto(catalogItemId2, nameSecond, Set.of(nameTwelve, nameThird), Set.of(writtenFormUpper), Set.of(country, cityUpper), Set.of(countryAaa, countryBbb), Collections.emptySet(), 0.0, 0.0, 0, ""); |
|
108 |
|
|
109 |
catalogItem3.setName(nameThird); |
|
110 |
catalogItem3.setAlternativeNames(Set.of(new AlternativeName(nameTwentyUpper, catalogItem3), new AlternativeName(nameSedond, catalogItem3))); |
|
111 |
catalogItem3.setTypes(Set.of(typeCountri, typeCapitalCity)); |
|
112 |
catalogItem3.setCountries(Set.of(new Country(countryAaaUpper, catalogItem3), new Country(countryCcc, catalogItem3))); |
|
113 |
catalogItem3.setWrittenForms(Set.of(new WrittenForm(writtenFormForOr, catalogItem3))); |
|
114 |
|
|
115 |
catalogItemDto3 = new CatalogItemDto(catalogItemId3, nameThird, Set.of(nameTwentyUpper, nameSedond), Set.of(writtenFormForOr), Set.of(countri, capitalCityNew), Set.of(countryAaaUpper, countryCcc), Collections.emptySet(), 0.0, 0.0, 0, ""); |
|
116 |
|
|
117 |
catalogItem4.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem4), new AlternativeName(nameFirstUpper, catalogItem4))); |
|
118 |
catalogItem4.setTypes(Set.of(typeCountri, typeCountry)); |
|
119 |
catalogItem4.setCountries(Set.of(new Country(countryBccb, catalogItem4), new Country(countryDdd, catalogItem4))); |
|
120 |
catalogItem4.setWrittenForms(Set.of(new WrittenForm(writtenForm, catalogItem4), new WrittenForm(writtenFormForOr, catalogItem4))); |
|
121 |
|
|
122 |
catalogItemDto4 = new CatalogItemDto(catalogItemId4, "", Set.of(nameTwelve, nameFirstUpper), Set.of(writtenForm, writtenFormForOr), Set.of(countri, country), Set.of(countryBccb, countryDdd), Collections.emptySet(), 0.0, 0.0, 0, ""); |
|
123 |
|
|
124 |
catalogItem5.setName(nameSedond); |
|
125 |
catalogItem5.setAlternativeNames(Set.of(new AlternativeName(nameThird, catalogItem5))); |
|
126 |
catalogItem5.setTypes(Set.of(typeCountri)); |
|
127 |
|
|
128 |
catalogItemDto5 = new CatalogItemDto(catalogItemId5, nameSedond, Set.of(nameThird), Collections.emptySet(), Set.of(countri), Collections.emptySet(), Collections.emptySet(), 0.0, 0.0, 0, ""); |
|
129 |
|
|
130 |
given(catalogItemRepository.findAll()).willReturn(List.of(catalogItem1, catalogItem2, catalogItem3, catalogItem4, catalogItem5)); |
|
131 |
} |
|
132 |
|
|
133 |
@Test |
|
134 |
void itShouldReturnAll() { |
|
135 |
// given |
|
136 |
String name = ""; |
|
137 |
String country = ""; |
|
138 |
String type = ""; |
|
139 |
String writtenForm = ""; |
|
140 |
|
|
141 |
// when |
|
142 |
List<CatalogItemDto> results = underTest.getCatalog(name, country, type, writtenForm); |
|
143 |
|
|
144 |
// then |
|
145 |
assertThat(results.size()).isEqualTo(5); |
|
146 |
assertTrue(results.contains(catalogItemDto1)); |
|
147 |
assertTrue(results.contains(catalogItemDto2)); |
|
148 |
assertTrue(results.contains(catalogItemDto3)); |
|
149 |
assertTrue(results.contains(catalogItemDto4)); |
|
150 |
assertTrue(results.contains(catalogItemDto5)); |
|
151 |
|
|
152 |
verify(catalogItemRepository).findAll(); |
|
153 |
} |
|
154 |
|
|
155 |
@Test |
|
156 |
void testName() { |
|
157 |
// given |
|
158 |
String name = "first"; |
|
159 |
String country = ""; |
|
160 |
String type = ""; |
|
161 |
String writtenForm = ""; |
|
162 |
|
|
163 |
// when |
|
164 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
165 |
|
|
166 |
// then |
|
167 |
assertThat(filterResult.size()).isEqualTo(2); |
|
168 |
assertTrue(filterResult.contains(catalogItemDto1)); |
|
169 |
assertTrue(filterResult.contains(catalogItemDto4)); |
|
170 |
} |
|
171 |
|
|
172 |
@Test |
|
173 |
void testWildcardCharacterName() { |
|
174 |
// given |
|
175 |
String name = "se?ond"; |
|
176 |
String country = ""; |
|
177 |
String type = ""; |
|
178 |
String writtenForm = ""; |
|
179 |
|
|
180 |
// when |
|
181 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
182 |
|
|
183 |
// then |
|
184 |
assertThat(filterResult.size()).isEqualTo(3); |
|
185 |
assertTrue(filterResult.contains(catalogItemDto2)); |
|
186 |
assertTrue(filterResult.contains(catalogItemDto3)); |
|
187 |
assertTrue(filterResult.contains(catalogItemDto5)); |
|
188 |
} |
|
189 |
|
|
190 |
@Test |
|
191 |
void testWildcardCharactersName() { |
|
192 |
// given |
|
193 |
String name = "twe*"; |
|
194 |
String country = ""; |
|
195 |
String type = ""; |
|
196 |
String writtenForm = ""; |
|
197 |
|
|
198 |
|
|
199 |
// when |
|
200 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
201 |
|
|
202 |
// then |
|
203 |
assertThat(filterResult.size()).isEqualTo(3); |
|
204 |
assertTrue(filterResult.contains(catalogItemDto2)); |
|
205 |
assertTrue(filterResult.contains(catalogItemDto3)); |
|
206 |
assertTrue(filterResult.contains(catalogItemDto4)); |
|
207 |
} |
|
208 |
|
|
209 |
@Test |
|
210 |
void testCountry() { |
|
211 |
// given |
|
212 |
String name = ""; |
|
213 |
String country = "aaa"; |
|
214 |
String type = ""; |
|
215 |
String writtenForm = ""; |
|
216 |
|
|
217 |
|
|
218 |
// when |
|
219 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
220 |
|
|
221 |
// then |
|
222 |
assertThat(filterResult.size()).isEqualTo(3); |
|
223 |
assertTrue(filterResult.contains(catalogItemDto1)); |
|
224 |
assertTrue(filterResult.contains(catalogItemDto2)); |
|
225 |
assertTrue(filterResult.contains(catalogItemDto3)); |
|
226 |
} |
|
227 |
|
|
228 |
@Test |
|
229 |
void testWildcardCharacterCountry() { |
|
230 |
// given |
|
231 |
String name = ""; |
|
232 |
String country = "d?d"; |
|
233 |
String type = ""; |
|
234 |
String writtenForm = ""; |
|
235 |
|
|
236 |
// when |
|
237 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
238 |
|
|
239 |
// then |
|
240 |
assertThat(filterResult.size()).isEqualTo(2); |
|
241 |
assertTrue(filterResult.contains(catalogItemDto1)); |
|
242 |
assertTrue(filterResult.contains(catalogItemDto4)); |
|
243 |
} |
|
244 |
|
|
245 |
@Test |
|
246 |
void testWildcardCharactersCountry() { |
|
247 |
// given |
|
248 |
String name = ""; |
|
249 |
String country = "b*b"; |
|
250 |
String type = ""; |
|
251 |
String writtenForm = ""; |
|
252 |
|
|
253 |
// when |
|
254 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
255 |
|
|
256 |
// then |
|
257 |
assertThat(filterResult.size()).isEqualTo(2); |
|
258 |
assertTrue(filterResult.contains(catalogItemDto2)); |
|
259 |
assertTrue(filterResult.contains(catalogItemDto4)); |
|
260 |
} |
|
261 |
|
|
262 |
|
|
263 |
@Test |
|
264 |
void testType() { |
|
265 |
// given |
|
266 |
String name = ""; |
|
267 |
String country = ""; |
|
268 |
String type = "city"; |
|
269 |
String writtenForm = ""; |
|
270 |
|
|
271 |
// when |
|
272 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
273 |
|
|
274 |
// then |
|
275 |
assertThat(filterResult.size()).isEqualTo(2); |
|
276 |
assertTrue(filterResult.contains(catalogItemDto1)); |
|
277 |
assertTrue(filterResult.contains(catalogItemDto2)); |
|
278 |
} |
|
279 |
|
|
280 |
@Test |
|
281 |
void testWildcardCharacterType() { |
|
282 |
// given |
|
283 |
String name = ""; |
|
284 |
String country = ""; |
|
285 |
String type = "countr?"; |
|
286 |
String writtenForm = ""; |
|
287 |
|
|
288 |
// when |
|
289 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
290 |
|
|
291 |
// then |
|
292 |
assertThat(filterResult.size()).isEqualTo(5); |
|
293 |
assertTrue(filterResult.contains(catalogItemDto1)); |
|
294 |
assertTrue(filterResult.contains(catalogItemDto2)); |
|
295 |
assertTrue(filterResult.contains(catalogItemDto3)); |
|
296 |
assertTrue(filterResult.contains(catalogItemDto4)); |
|
297 |
assertTrue(filterResult.contains(catalogItemDto5)); |
|
298 |
} |
|
299 |
|
|
300 |
@Test |
|
301 |
void testWildcardCharactersType() { |
|
302 |
// given |
|
303 |
String name = ""; |
|
304 |
String country = ""; |
|
305 |
String type = "*city*"; |
|
306 |
String writtenForm = ""; |
|
307 |
|
|
308 |
// when |
|
309 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
310 |
|
|
311 |
// then |
|
312 |
assertThat(filterResult.size()).isEqualTo(3); |
|
313 |
assertTrue(filterResult.contains(catalogItemDto1)); |
|
314 |
assertTrue(filterResult.contains(catalogItemDto2)); |
|
315 |
assertTrue(filterResult.contains(catalogItemDto3)); |
|
316 |
} |
|
317 |
|
|
318 |
@Test |
|
319 |
void testWrittenForm() { |
|
320 |
// given |
|
321 |
String name = ""; |
|
322 |
String country = ""; |
|
323 |
String type = ""; |
|
324 |
String writtenForm = "written"; |
|
325 |
|
|
326 |
// when |
|
327 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
328 |
|
|
329 |
// then |
|
330 |
assertThat(filterResult.size()).isEqualTo(3); |
|
331 |
assertTrue(filterResult.contains(catalogItemDto1)); |
|
332 |
assertTrue(filterResult.contains(catalogItemDto2)); |
|
333 |
assertTrue(filterResult.contains(catalogItemDto4)); |
|
334 |
} |
|
335 |
|
|
336 |
@Test |
|
337 |
void testWrittenFormWildcardCharacter() { |
|
338 |
// given |
|
339 |
String name = ""; |
|
340 |
String country = ""; |
|
341 |
String type = ""; |
|
342 |
String writtenForm = "wr?tten"; |
|
343 |
|
|
344 |
// when |
|
345 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
346 |
|
|
347 |
// then |
|
348 |
assertThat(filterResult.size()).isEqualTo(4); |
|
349 |
assertTrue(filterResult.contains(catalogItemDto1)); |
|
350 |
assertTrue(filterResult.contains(catalogItemDto2)); |
|
351 |
assertTrue(filterResult.contains(catalogItemDto3)); |
|
352 |
assertTrue(filterResult.contains(catalogItemDto4)); |
|
353 |
} |
|
354 |
|
|
355 |
@Test |
|
356 |
void testWrittenFormWildcardCharacters() { |
|
357 |
// given |
|
358 |
String name = ""; |
|
359 |
String country = ""; |
|
360 |
String type = ""; |
|
361 |
String writtenForm = "wri*tten"; |
|
362 |
|
|
363 |
// when |
|
364 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
365 |
|
|
366 |
// then |
|
367 |
assertThat(filterResult.size()).isEqualTo(3); |
|
368 |
assertTrue(filterResult.contains(catalogItemDto1)); |
|
369 |
assertTrue(filterResult.contains(catalogItemDto2)); |
|
370 |
assertTrue(filterResult.contains(catalogItemDto4)); |
|
371 |
} |
|
372 |
|
|
373 |
@Test |
|
374 |
void testWrittenFormOr() { |
|
375 |
// given |
|
376 |
String name = ""; |
|
377 |
String country = ""; |
|
378 |
String type = ""; |
|
379 |
String writtenForm = "wr(i|a)tten"; |
|
380 |
|
|
381 |
// when |
|
382 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
383 |
|
|
384 |
// then |
|
385 |
assertThat(filterResult.size()).isEqualTo(4); |
|
386 |
assertTrue(filterResult.contains(catalogItemDto1)); |
|
387 |
assertTrue(filterResult.contains(catalogItemDto2)); |
|
388 |
assertTrue(filterResult.contains(catalogItemDto3)); |
|
389 |
assertTrue(filterResult.contains(catalogItemDto4)); |
|
390 |
} |
|
391 |
|
|
392 |
@Test |
|
393 |
void testNameAndCountry() { |
|
394 |
// given |
|
395 |
String name = "third"; |
|
396 |
String country = "aaa"; |
|
397 |
String type = ""; |
|
398 |
String writtenForm = ""; |
|
399 |
|
|
400 |
// when |
|
401 |
List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm); |
|
402 |
|
|
403 |
// then |
|
404 |
assertThat(filterResult.size()).isEqualTo(2); |
|
405 |
assertTrue(filterResult.contains(catalogItemDto2)); |
|
406 |
assertTrue(filterResult.contains(catalogItemDto3)); |
|
407 |
} |
|
408 |
|
Také k dispozici: Unified diff
Added filter for written forms and some tests
re #9492