Revize d6451c0a
Přidáno uživatelem Jakub Šmíd před asi 2 roky(ů)
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 |
Také k dispozici: Unified diff
Added filter for written forms and some tests
re #9492