Projekt

Obecné

Profil

« Předchozí | Další » 

Revize a8335530

Přidáno uživatelem Jakub Šmíd před asi 2 roky(ů)

Test cases added

re #9492

Zobrazit rozdíly:

backend/src/main/java/cz/zcu/kiv/backendapi/alternativename/AlternativeNameRepository.java
1
package cz.zcu.kiv.backendapi.alternativename;
2

  
3
import org.springframework.data.jpa.repository.JpaRepository;
4
import org.springframework.stereotype.Repository;
5

  
6
/**
7
 * Alternative name repository
8
 */
9
@Repository
10
public interface AlternativeNameRepository extends JpaRepository<AlternativeName, AlternativeName> {
11
}
backend/src/main/java/cz/zcu/kiv/backendapi/bibliography/BibliographyRepository.java
1
package cz.zcu.kiv.backendapi.bibliography;
2

  
3
import org.springframework.data.jpa.repository.JpaRepository;
4
import org.springframework.stereotype.Repository;
5

  
6
/**
7
 * Bibliography repository
8
 */
9
@Repository
10
public interface BibliographyRepository extends JpaRepository<Bibliography, Bibliography> {
11
}
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItem.java
28 28
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
29 29
@NoArgsConstructor
30 30
@Entity
31
@Table(name = "catalog_item")
31
@Table(name = "catalog_items")
32 32
public class CatalogItem {
33 33
    private static final String INTEGER_PATTERN = "\\d+";
34 34
    private static final String DOUBLE_PATTERN = "(\\d+[.]\\d+)|(\\d+)";
35 35
    private static final String EMPTY_ENTRY = "–";
36

  
36 37
    /**
37 38
     * Catalog item id
38 39
     */
39 40
    @Id
40
//    @GeneratedValue
41 41
    @EqualsAndHashCode.Include
42 42
    private UUID id = UUID.randomUUID();
43 43

  
......
70 70
    /**
71 71
     * Bibliography
72 72
     */
73
    @OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL)
73
    @OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL, orphanRemoval = true)
74 74
    @LazyCollection(LazyCollectionOption.FALSE)
75 75
    @Fetch(FetchMode.SUBSELECT)
76 76
    private Set<Bibliography> bibliography = new HashSet<>();
......
78 78
    /**
79 79
     * Countries
80 80
     */
81
    @OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL)
81
    @OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL, orphanRemoval = true)
82 82
    @LazyCollection(LazyCollectionOption.FALSE)
83 83
    @Fetch(FetchMode.SUBSELECT)
84 84
    private Set<Country> countries = new HashSet<>();
......
86 86
    /**
87 87
     * Written forms
88 88
     */
89
    @OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL)
89
    @OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL, orphanRemoval = true)
90 90
    @LazyCollection(LazyCollectionOption.FALSE)
91 91
    @Fetch(FetchMode.SUBSELECT)
92 92
    private Set<WrittenForm> writtenForms = new HashSet<>();
......
94 94
    /**
95 95
     * Alternative names
96 96
     */
97
    @OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL)
97
    @OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL, orphanRemoval = true)
98 98
    @LazyCollection(LazyCollectionOption.FALSE)
99 99
    @Fetch(FetchMode.SUBSELECT)
100 100
    private Set<AlternativeName> alternativeNames = new HashSet<>();
backend/src/main/java/cz/zcu/kiv/backendapi/country/CountryRepository.java
1
package cz.zcu.kiv.backendapi.country;
2

  
3
import org.springframework.data.jpa.repository.JpaRepository;
4
import org.springframework.stereotype.Repository;
5

  
6
/**
7
 * Country repository
8
 */
9
@Repository
10
public interface CountryRepository extends JpaRepository<Country, Country> {
11
}
backend/src/main/java/cz/zcu/kiv/backendapi/security/jwt/JwtUsernameAndPasswordAuthenticationFilter.java
53 53
        try {
54 54
            UsernameAndPasswordAuthenticationRequest authenticationRequest = new ObjectMapper()
55 55
                    .readValue(request.getInputStream(), UsernameAndPasswordAuthenticationRequest.class);
56
            log.info("Username is: " + authenticationRequest.getUsername());
57
            log.info("Password is: " + authenticationRequest.getPassword());
58 56
            Authentication authentication = new UsernamePasswordAuthenticationToken(
59 57
                    authenticationRequest.getUsername(),
60 58
                    authenticationRequest.getPassword()
backend/src/main/java/cz/zcu/kiv/backendapi/writtenform/WrittenFormRepository.java
1
package cz.zcu.kiv.backendapi.writtenform;
2

  
3
import org.springframework.data.jpa.repository.JpaRepository;
4
import org.springframework.stereotype.Repository;
5

  
6
/**
7
 * Written form repository
8
 */
9
@Repository
10
public interface WrittenFormRepository extends JpaRepository<WrittenForm, WrittenForm> {
11
}
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 org.junit.jupiter.api.AfterEach;
5
import org.junit.jupiter.api.BeforeEach;
6 4
import org.junit.jupiter.api.Test;
7 5
import org.springframework.beans.factory.annotation.Autowired;
8 6
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
......
19 17
    @Autowired
20 18
    private CatalogItemRepository underTest;
21 19

  
22
    private CatalogItem catalogItem1;
23
    private CatalogItem catalogItem2;
24
    private CatalogItem catalogItem3;
25
    private CatalogItem catalogItem4;
26
    private CatalogItem catalogItem5;
27

  
28
    @BeforeEach
29
    void setUp() {
20
    @Test
21
    void testItemsByName() {
22
        // given
30 23
        String nameFirst = "first";
31 24
        String nameFirstUpper = "First";
32 25
        String nameSecond = "second";
......
35 28
        String nameTwelve = "twelve";
36 29
        String nameTwentyUpper = "TWENTY";
37 30

  
38
        catalogItem1 = new CatalogItem();
39
        catalogItem2 = new CatalogItem();
40
        catalogItem3 = new CatalogItem();
41
        catalogItem4 = new CatalogItem();
42
        catalogItem5 = new CatalogItem();
31
        CatalogItem catalogItem1 = new CatalogItem();
32
        CatalogItem catalogItem2 = new CatalogItem();
33
        CatalogItem catalogItem3 = new CatalogItem();
34
        CatalogItem catalogItem4 = new CatalogItem();
35
        CatalogItem catalogItem5 = new CatalogItem();
43 36

  
44 37
        catalogItem1.setName(nameFirst);
45 38

  
......
57 50
        underTest.saveAll(List.of(catalogItem1, catalogItem2, catalogItem3, catalogItem4, catalogItem5));
58 51

  
59 52

  
60
    }
61

  
62
    @AfterEach
63
    void tearDown() {
64
        underTest.deleteAll();
65
    }
66

  
67
    @Test
68
    void testItemsByName() {
69
        // given
70 53
        String name = "twelve";
71 54

  
72 55
        // when
backend/src/test/java/cz/zcu/kiv/backendapi/catalog/CatalogItemServiceImplFilterTest.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 CatalogItemServiceImplFilterTest {
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

  
409
    @Test
410
    void testNameAndType() {
411
        // given
412
        String name = "third";
413
        String country = "";
414
        String type = "countri";
415
        String writtenForm = "";
416

  
417
        // when
418
        List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm);
419

  
420
        // then
421
        assertThat(filterResult.size()).isEqualTo(2);
422
        assertTrue(filterResult.contains(catalogItemDto3));
423
        assertTrue(filterResult.contains(catalogItemDto5));
424
    }
425

  
426
    @Test
427
    void testNameAndWrittenForm() {
428
        // given
429
        String name = "first";
430
        String country = "";
431
        String type = "";
432
        String writtenForm = "written";
433

  
434
        // when
435
        List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm);
436

  
437
        // then
438
        assertThat(filterResult.size()).isEqualTo(2);
439
        assertTrue(filterResult.contains(catalogItemDto1));
440
        assertTrue(filterResult.contains(catalogItemDto4));
441
    }
442

  
443
    @Test
444
    void testCountryAndType() {
445
        // given
446
        String name = "";
447
        String country = "ddd";
448
        String type = "country";
449
        String writtenForm = "";
450

  
451
        // when
452
        List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm);
453

  
454
        // then
455
        assertThat(filterResult.size()).isEqualTo(1);
456
        assertTrue(filterResult.contains(catalogItemDto4));
457
    }
458

  
459
    @Test
460
    void testAll() {
461
        // given
462
        String name = "third";
463
        String country = "AAA";
464
        String type = "countri";
465
        String writtenForm = "wratten";
466

  
467
        // when
468
        List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm);
469

  
470
        // then
471
        assertThat(filterResult.size()).isEqualTo(1);
472
        assertTrue(filterResult.contains(catalogItemDto3));
473
    }
474
}
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

  
409
    @Test
410
    void testNameAndType() {
411
        // given
412
        String name = "third";
413
        String country = "";
414
        String type = "countri";
415
        String writtenForm = "";
416

  
417
        // when
418
        List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm);
419

  
420
        // then
421
        assertThat(filterResult.size()).isEqualTo(2);
422
        assertTrue(filterResult.contains(catalogItemDto3));
423
        assertTrue(filterResult.contains(catalogItemDto5));
424
    }
425

  
426
    @Test
427
    void testNameAndWrittenForm() {
428
        // given
429
        String name = "first";
430
        String country = "";
431
        String type = "";
432
        String writtenForm = "written";
433

  
434
        // when
435
        List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm);
436

  
437
        // then
438
        assertThat(filterResult.size()).isEqualTo(2);
439
        assertTrue(filterResult.contains(catalogItemDto1));
440
        assertTrue(filterResult.contains(catalogItemDto4));
441
    }
442

  
443
    @Test
444
    void testCountryAndType() {
445
        // given
446
        String name = "";
447
        String country = "ddd";
448
        String type = "country";
449
        String writtenForm = "";
450

  
451
        // when
452
        List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm);
453

  
454
        // then
455
        assertThat(filterResult.size()).isEqualTo(1);
456
        assertTrue(filterResult.contains(catalogItemDto4));
457
    }
458

  
459
    @Test
460
    void testAll() {
461
        // given
462
        String name = "third";
463
        String country = "AAA";
464
        String type = "countri";
465
        String writtenForm = "wratten";
466

  
467
        // when
468
        List<CatalogItemDto> filterResult = underTest.getCatalog(name, country, type, writtenForm);
469

  
470
        // then
471
        assertThat(filterResult.size()).isEqualTo(1);
472
        assertTrue(filterResult.contains(catalogItemDto3));
473
    }
474
}

Také k dispozici: Unified diff