Projekt

Obecné

Profil

Stáhnout (25 KB) Statistiky
| Větev: | Tag: | Revize:
1
package cz.zcu.kiv.backendapi.catalog;
2

    
3
import cz.zcu.kiv.backendapi.alternativename.CatalogItemName;
4
import cz.zcu.kiv.backendapi.bibliography.Bibliography;
5
import cz.zcu.kiv.backendapi.country.Country;
6
import cz.zcu.kiv.backendapi.exception.ApiRequestException;
7
import cz.zcu.kiv.backendapi.path.PathDto;
8
import cz.zcu.kiv.backendapi.type.Type;
9
import cz.zcu.kiv.backendapi.type.TypeServiceImpl;
10
import cz.zcu.kiv.backendapi.writtenform.WrittenForm;
11
import org.junit.jupiter.api.BeforeEach;
12
import org.junit.jupiter.api.Test;
13
import org.junit.jupiter.api.extension.ExtendWith;
14
import org.mockito.ArgumentCaptor;
15
import org.mockito.Mock;
16
import org.mockito.junit.jupiter.MockitoExtension;
17

    
18
import java.util.*;
19
import java.util.stream.Collectors;
20
import java.util.stream.Stream;
21

    
22
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
23
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
24
import static org.mockito.ArgumentMatchers.any;
25
import static org.mockito.ArgumentMatchers.anyString;
26
import static org.mockito.BDDMockito.given;
27
import static org.mockito.Mockito.never;
28
import static org.mockito.Mockito.verify;
29

    
30
@ExtendWith(MockitoExtension.class)
31
class CatalogItemServiceImplTest {
32

    
33
    @Mock
34
    private CatalogItemRepository catalogItemRepository;
35

    
36
    @Mock
37
    private TypeServiceImpl typeService;
38

    
39
    private CatalogItemServiceImpl underTest;
40

    
41
    @BeforeEach
42
    void setUp() {
43
        underTest = new CatalogItemServiceImpl(catalogItemRepository, typeService);
44
    }
45

    
46
    @Test
47
    void saveCatalog() {
48
        // given
49
        Type type = new Type("type");
50

    
51
        CatalogItem catalogItem = new CatalogItem();
52
        catalogItem.setName("aaacbbbbbbbaa");
53
        catalogItem.setBibliography(Stream.of(new Bibliography("bibl", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
54
        catalogItem.setTypes(Stream.of(type).collect(Collectors.toCollection(LinkedHashSet::new)));
55
        catalogItem.setAllNames(Stream.of(new CatalogItemName("altName", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
56
        catalogItem.setCountries(Stream.of(new Country("aaaabbaa", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
57
        catalogItem.setWrittenForms(Stream.of(new WrittenForm("written", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
58
        catalogItem.setCertainty(0);
59
        catalogItem.setLatitude(0.1);
60
        catalogItem.setLongitude(0.2);
61

    
62
        CatalogItemDto catalogItemDto = new CatalogItemDto();
63
        catalogItemDto.setId(catalogItem.getId());
64
        catalogItemDto.setName("aaacbbbbbbbaa");
65
        catalogItemDto.setBibliography(Stream.of("bibl").collect(Collectors.toCollection(LinkedHashSet::new)));
66
        catalogItemDto.setTypes(Stream.of(type.getType()).collect(Collectors.toCollection(LinkedHashSet::new)));
67
        catalogItemDto.setAllNames(Stream.of("altName").collect(Collectors.toCollection(LinkedHashSet::new)));
68
        catalogItemDto.setCountries(Stream.of("aaaabbaa").collect(Collectors.toCollection(LinkedHashSet::new)));
69
        catalogItemDto.setWrittenForms(Stream.of("written").collect(Collectors.toCollection(LinkedHashSet::new)));
70
        catalogItemDto.setCertainty(0);
71
        catalogItemDto.setLatitude(0.1);
72
        catalogItemDto.setLongitude(0.2);
73

    
74
        CatalogItem catalogItem2 = new CatalogItem();
75
        catalogItem2.setName("name");
76
        catalogItem2.setBibliography(Stream.of(new Bibliography("bibl", catalogItem2, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
77
        catalogItem2.setTypes(Stream.of(type).collect(Collectors.toCollection(LinkedHashSet::new)));
78
        catalogItem2.setAllNames(Stream.of(new CatalogItemName("aaaabbbbbbaa", catalogItem2, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
79
        catalogItem2.setCountries(Stream.of(new Country("aaaabbcccefaa", catalogItem2, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
80
        catalogItem2.setWrittenForms(Stream.of(new WrittenForm("written", catalogItem2, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
81
        catalogItem2.setCertainty(1);
82
        catalogItem2.setLatitude(1.1);
83
        catalogItem2.setLongitude(1.2);
84

    
85
        CatalogItemDto catalogItemDto2 = new CatalogItemDto();
86
        catalogItemDto2.setId(catalogItem2.getId());
87
        catalogItemDto2.setName("name");
88
        catalogItemDto2.setBibliography(Stream.of("bibl").collect(Collectors.toCollection(LinkedHashSet::new)));
89
        catalogItemDto2.setTypes(Stream.of(type.getType()).collect(Collectors.toCollection(LinkedHashSet::new)));
90
        catalogItemDto2.setAllNames(Stream.of("aaaabbbbbbaa").collect(Collectors.toCollection(LinkedHashSet::new)));
91
        catalogItemDto2.setCountries(Stream.of("aaaabbcccefaa").collect(Collectors.toCollection(LinkedHashSet::new)));
92
        catalogItemDto2.setWrittenForms(Stream.of("written").collect(Collectors.toCollection(LinkedHashSet::new)));
93
        catalogItemDto2.setCertainty(1);
94
        catalogItemDto2.setLatitude(1.1);
95
        catalogItemDto2.setLongitude(1.2);
96

    
97
        List<CatalogItemDto> catalog = List.of(catalogItemDto, catalogItemDto2);
98

    
99
        given(typeService.getTypeByName(anyString())).willReturn(Optional.of(type));
100
        given(catalogItemRepository.findById(catalogItemDto.getId())).willReturn(Optional.of(catalogItem));
101
        given(catalogItemRepository.findById(catalogItemDto2.getId())).willReturn(Optional.of(catalogItem2));
102

    
103
        // when
104
        underTest.saveCatalogItems(catalog);
105

    
106
        // then
107
        verify(typeService, never()).saveType(type);
108
        verify(catalogItemRepository).save(catalogItem);
109
        verify(catalogItemRepository).save(catalogItem2);
110
    }
111

    
112
    @Test
113
    void testSaveCatalogItem() {
114
        // given
115
        CatalogItemDto catalogItemDto = new CatalogItemDto();
116
        catalogItemDto.setName("name");
117
        catalogItemDto.setBibliography(Stream.of("bibl").collect(Collectors.toCollection(LinkedHashSet::new)));
118
        catalogItemDto.setTypes(Stream.of("type").collect(Collectors.toCollection(LinkedHashSet::new)));
119
        catalogItemDto.setAllNames(Stream.of("altName").collect(Collectors.toCollection(LinkedHashSet::new)));
120
        catalogItemDto.setCountries(Stream.of("country").collect(Collectors.toCollection(LinkedHashSet::new)));
121
        catalogItemDto.setWrittenForms(Stream.of("written").collect(Collectors.toCollection(LinkedHashSet::new)));
122
        catalogItemDto.setCertainty(0);
123
        catalogItemDto.setLatitude(0.1);
124
        catalogItemDto.setLongitude(0.2);
125
        catalogItemDto.setDescription("description");
126

    
127
        Type type = new Type("type");
128

    
129
        CatalogItem catalogItem = new CatalogItem();
130
        catalogItem.setName("name");
131
        catalogItem.setBibliography(Stream.of(new Bibliography("bibl", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
132
        catalogItem.setTypes(Stream.of(type).collect(Collectors.toCollection(LinkedHashSet::new)));
133
        catalogItem.setAllNames(Stream.of(new CatalogItemName("altName", catalogItem, 1), new CatalogItemName("name", catalogItem, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
134
        catalogItem.setCountries(Stream.of(new Country("country", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
135
        catalogItem.setWrittenForms(Stream.of(new WrittenForm("written", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
136
        catalogItem.setCertainty(0);
137
        catalogItem.setLatitude(0.1);
138
        catalogItem.setLongitude(0.2);
139
        catalogItem.setDescription("description");
140

    
141
        given(typeService.getTypeByName(anyString())).willReturn(Optional.of(type));
142

    
143
        // when
144
        underTest.saveCatalogItem(catalogItemDto);
145

    
146
        // then
147
        ArgumentCaptor<CatalogItem> argumentCaptor = ArgumentCaptor.forClass(CatalogItem.class);
148

    
149
        verify(catalogItemRepository).save(argumentCaptor.capture());
150
        verify(typeService, never()).saveType(type);
151

    
152
        CatalogItem capturedItem = argumentCaptor.getValue();
153

    
154
        assertThat(capturedItem.getId()).isNotEqualTo(catalogItemDto.getId());
155
        assertThat(capturedItem.getName()).isEqualTo(catalogItem.getName());
156
        assertThat(capturedItem.getLongitude()).isEqualTo(catalogItem.getLongitude());
157
        assertThat(capturedItem.getLatitude()).isEqualTo(catalogItem.getLatitude());
158
        assertThat(capturedItem.getCertainty()).isEqualTo(catalogItem.getCertainty());
159
        assertThat(capturedItem.getAllNames().size()).isEqualTo(catalogItem.getAllNames().size());
160
        assertThat(capturedItem.getBibliography().size()).isEqualTo(catalogItem.getBibliography().size());
161
        assertThat(capturedItem.getCountries().size()).isEqualTo(catalogItem.getCountries().size());
162
        assertThat(capturedItem.getWrittenForms().size()).isEqualTo(catalogItem.getWrittenForms().size());
163
        assertThat(capturedItem.getTypes().size()).isEqualTo(catalogItem.getTypes().size());
164
        assertThat(capturedItem.getDescription()).isEqualTo(catalogItem.getDescription());
165

    
166
    }
167

    
168
    @Test
169
    void testSaveCatalogItemIdNotPresent() {
170
        // given
171
        CatalogItemDto catalogItemDto = new CatalogItemDto();
172
        catalogItemDto.setId(UUID.randomUUID());
173
        catalogItemDto.setName("name");
174
        catalogItemDto.setBibliography(Stream.of("bibl").collect(Collectors.toCollection(LinkedHashSet::new)));
175
        catalogItemDto.setTypes(Stream.of("type").collect(Collectors.toCollection(LinkedHashSet::new)));
176
        catalogItemDto.setAllNames(Stream.of("altName").collect(Collectors.toCollection(LinkedHashSet::new)));
177
        catalogItemDto.setCountries(Stream.of("country").collect(Collectors.toCollection(LinkedHashSet::new)));
178
        catalogItemDto.setWrittenForms(Stream.of("written").collect(Collectors.toCollection(LinkedHashSet::new)));
179
        catalogItemDto.setCertainty(0);
180
        catalogItemDto.setLatitude(0.1);
181
        catalogItemDto.setLongitude(0.2);
182
        catalogItemDto.setDescription("description");
183

    
184
        Type type = new Type("type");
185

    
186
        CatalogItem catalogItem = new CatalogItem();
187
        catalogItem.setName("name");
188
        catalogItem.setBibliography(Stream.of(new Bibliography("bibl", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
189
        catalogItem.setTypes(Stream.of(type).collect(Collectors.toCollection(LinkedHashSet::new)));
190
        catalogItem.setAllNames(Stream.of(new CatalogItemName("altName", catalogItem, 1), new CatalogItemName("name", catalogItem, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
191
        catalogItem.setCountries(Stream.of(new Country("country", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
192
        catalogItem.setWrittenForms(Stream.of(new WrittenForm("written", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
193
        catalogItem.setCertainty(0);
194
        catalogItem.setLatitude(0.1);
195
        catalogItem.setLongitude(0.2);
196
        catalogItem.setDescription("description");
197

    
198
        given(typeService.getTypeByName(anyString())).willReturn(Optional.of(type));
199
        given(catalogItemRepository.findById(catalogItemDto.getId())).willReturn(Optional.empty());
200

    
201
        // when
202
        underTest.saveCatalogItem(catalogItemDto);
203

    
204
        // then
205
        ArgumentCaptor<CatalogItem> argumentCaptor = ArgumentCaptor.forClass(CatalogItem.class);
206

    
207
        verify(catalogItemRepository).save(argumentCaptor.capture());
208
        verify(typeService, never()).saveType(type);
209

    
210
        CatalogItem capturedItem = argumentCaptor.getValue();
211

    
212
        assertThat(capturedItem.getId()).isNotEqualTo(catalogItemDto.getId());
213
        assertThat(capturedItem.getName()).isEqualTo(catalogItem.getName());
214
        assertThat(capturedItem.getLongitude()).isEqualTo(catalogItem.getLongitude());
215
        assertThat(capturedItem.getLatitude()).isEqualTo(catalogItem.getLatitude());
216
        assertThat(capturedItem.getCertainty()).isEqualTo(catalogItem.getCertainty());
217
        assertThat(capturedItem.getAllNames().size()).isEqualTo(catalogItem.getAllNames().size());
218
        assertThat(capturedItem.getBibliography().size()).isEqualTo(catalogItem.getBibliography().size());
219
        assertThat(capturedItem.getCountries().size()).isEqualTo(catalogItem.getCountries().size());
220
        assertThat(capturedItem.getWrittenForms().size()).isEqualTo(catalogItem.getWrittenForms().size());
221
        assertThat(capturedItem.getTypes().size()).isEqualTo(catalogItem.getTypes().size());
222
        assertThat(capturedItem.getDescription()).isEqualTo(catalogItem.getDescription());
223

    
224
    }
225

    
226
    @Test
227
    void testSaveCatalogItemIdPresent() {
228
        // given
229
        UUID id = UUID.randomUUID();
230

    
231
        CatalogItemDto catalogItemDto = new CatalogItemDto();
232
        catalogItemDto.setId(id);
233
        catalogItemDto.setName("name");
234
        catalogItemDto.setBibliography(Stream.of("bibl").collect(Collectors.toCollection(LinkedHashSet::new)));
235
        catalogItemDto.setTypes(Stream.of("type").collect(Collectors.toCollection(LinkedHashSet::new)));
236
        catalogItemDto.setAllNames(Stream.of("altName").collect(Collectors.toCollection(LinkedHashSet::new)));
237
        catalogItemDto.setCountries(Stream.of("country").collect(Collectors.toCollection(LinkedHashSet::new)));
238
        catalogItemDto.setWrittenForms(Stream.of("written").collect(Collectors.toCollection(LinkedHashSet::new)));
239
        catalogItemDto.setCertainty(0);
240
        catalogItemDto.setLatitude(0.1);
241
        catalogItemDto.setLongitude(0.2);
242
        catalogItemDto.setDescription("description");
243

    
244
        Type type = new Type("type");
245
        Type typeOld = new Type("old");
246

    
247
        CatalogItem catalogItem = new CatalogItem();
248
        catalogItem.setId(id);
249
        catalogItem.setName("name");
250
        catalogItem.setBibliography(Stream.of(new Bibliography("bibl", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
251
        catalogItem.setTypes(Stream.of(type).collect(Collectors.toCollection(LinkedHashSet::new)));
252
        catalogItem.setAllNames(Stream.of(new CatalogItemName("altName", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
253
        catalogItem.setCountries(Stream.of(new Country("country", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
254
        catalogItem.setWrittenForms(Stream.of(new WrittenForm("written", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
255
        catalogItem.setCertainty(0);
256
        catalogItem.setLatitude(0.1);
257
        catalogItem.setLongitude(0.2);
258
        catalogItem.setDescription("description");
259

    
260
        CatalogItem oldCatalogItem = new CatalogItem();
261
        oldCatalogItem.setId(id);
262
        oldCatalogItem.setName("old");
263
        oldCatalogItem.setBibliography(Stream.of(new Bibliography("old", oldCatalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
264
        oldCatalogItem.setTypes(Stream.of(typeOld).collect(Collectors.toCollection(LinkedHashSet::new)));
265
        oldCatalogItem.setAllNames(Stream.of(new CatalogItemName("old", oldCatalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
266
        oldCatalogItem.setCountries(Stream.of(new Country("old", oldCatalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
267
        oldCatalogItem.setWrittenForms(Stream.of(new WrittenForm("old", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
268
        oldCatalogItem.setCertainty(10);
269
        oldCatalogItem.setLatitude(10.1);
270
        oldCatalogItem.setLongitude(10.2);
271

    
272
        given(catalogItemRepository.findById(id)).willReturn(Optional.of(oldCatalogItem));
273
        given(typeService.getTypeByName(anyString())).willReturn(Optional.empty());
274

    
275
        // when
276

    
277
        underTest.saveCatalogItem(catalogItemDto);
278

    
279
        // then
280
        verify(typeService).saveType(type);
281

    
282
        ArgumentCaptor<CatalogItem> argumentCaptor = ArgumentCaptor.forClass(CatalogItem.class);
283

    
284
        verify(catalogItemRepository).save(argumentCaptor.capture());
285

    
286
        CatalogItem capturedCatalogItem = argumentCaptor.getValue();
287

    
288
        assertThat(capturedCatalogItem).isEqualTo(catalogItem);
289
        assertThat(capturedCatalogItem.getCertainty()).isEqualTo(catalogItem.getCertainty());
290
        assertThat(capturedCatalogItem.getLatitude()).isEqualTo(catalogItem.getLatitude());
291
        assertThat(capturedCatalogItem.getLongitude()).isEqualTo(catalogItem.getLongitude());
292
        assertThat(capturedCatalogItem.getDescription()).isEqualTo(catalogItem.getDescription());
293
        assertThat(capturedCatalogItem.getTypes().stream().map(Type::getType).collect(Collectors.toSet())).isEqualTo(catalogItem.getTypes().stream().map(Type::getType).collect(Collectors.toCollection(LinkedHashSet::new)));
294
        Set<String> alternativeNamesEntity = catalogItem.getAllNames().stream().map(CatalogItemName::getName).collect(Collectors.toCollection(LinkedHashSet::new));
295
        alternativeNamesEntity.add(catalogItem.getName());
296
        assertThat(capturedCatalogItem.getAllNames().stream().map(CatalogItemName::getName).collect(Collectors.toSet())).isEqualTo(alternativeNamesEntity);
297
        assertThat(capturedCatalogItem.getCountries().stream().map(Country::getName).collect(Collectors.toSet())).isEqualTo(catalogItem.getCountries().stream().map(Country::getName).collect(Collectors.toCollection(LinkedHashSet::new)));
298
        assertThat(capturedCatalogItem.getBibliography().stream().map(Bibliography::getSource).collect(Collectors.toSet())).isEqualTo(catalogItem.getBibliography().stream().map(Bibliography::getSource).collect(Collectors.toCollection(LinkedHashSet::new)));
299
        assertThat(capturedCatalogItem.getWrittenForms().stream().map(WrittenForm::getForm).collect(Collectors.toSet())).isEqualTo(catalogItem.getWrittenForms().stream().map(WrittenForm::getForm).collect(Collectors.toCollection(LinkedHashSet::new)));
300
    }
301

    
302

    
303

    
304
    @Test
305
    void testCanGetCatalogItem() {
306
        // given
307
        UUID id = UUID.randomUUID();
308
        CatalogItem catalogItem = new CatalogItem();
309
        catalogItem.setId(id);
310
        CatalogItemDto catalogItemDto = new CatalogItemDto();
311
        catalogItemDto.setId(id);
312
        given(catalogItemRepository.findById(id)).willReturn(Optional.of(catalogItem));
313

    
314
        // when
315
        CatalogItemDto retrievedItemDto = underTest.getCatalogItem(id);
316

    
317
        // then
318
        verify(catalogItemRepository).findById(id);
319
        assertThat(retrievedItemDto).isEqualTo(catalogItemDto);
320
    }
321

    
322
    @Test
323
    void testCanNotGetCatalogItem() {
324
        // given
325
        UUID id = UUID.randomUUID();
326

    
327
        // when
328
        // then
329
        assertThatThrownBy(() -> underTest.getCatalogItem(id))
330
                .isInstanceOf(ApiRequestException.class)
331
                .hasMessageContaining("Catalog item not found");
332

    
333
        verify(catalogItemRepository).findById(id);
334
    }
335

    
336
    @Test
337
    void testCanDeleteCatalogItem() {
338
        // given
339
        UUID id = UUID.randomUUID();
340
        given(catalogItemRepository.existsById(id)).willReturn(true);
341

    
342
        // when
343
        underTest.deleteCatalogItem(id);
344

    
345
        // then
346
        verify(catalogItemRepository).deleteById(id);
347
    }
348

    
349
    @Test
350
    void testCanNotDeleteCatalogItem() {
351
        // given
352
        UUID id = UUID.randomUUID();
353
        given(catalogItemRepository.existsById(id)).willReturn(false);
354

    
355
        // when
356
        // then
357
        assertThatThrownBy(() -> underTest.deleteCatalogItem(id))
358
                .isInstanceOf(ApiRequestException.class)
359
                .hasMessageContaining("Catalog item not found");
360

    
361
        verify(catalogItemRepository, never()).deleteById(any());
362
    }
363

    
364

    
365
    @Test
366
    void testSearchedTest() {
367
        // given
368
        String text = "The city of Azbar was found in first century near the ocean.  " +
369
                "⌈U-re-me-re⌉, another town , was found " +
370
                "in 1956.\nThe location of Huga and Duga is not known, but it was probably near Puga.";
371
        String highlightedText = "The <b>city</b> of <span style='color:green'>Azbar</span> was found in first century near the <b>ocean</b>.  " +
372
                "⌈<span style='color:green'>U-re-me-re</span>⌉, another town , was found " +
373
                "in 1956.\nThe location of <span style='color:red'>Huga</span> and <span style='color:red'>Duga</span> is not known, but it was probably near Puga.";
374

    
375
        CatalogItem catalogItem1 = new CatalogItem();
376
        catalogItem1.setAllNames(Stream.of(new CatalogItemName("Azbar", catalogItem1, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
377
        catalogItem1.setLatitude(5.0);
378
        catalogItem1.setLongitude(5.0);
379

    
380
        CatalogItem catalogItem2 = new CatalogItem();
381
        catalogItem2.setAllNames(Stream.of(new CatalogItemName("Azbar", catalogItem2, 1), new CatalogItemName("Azbarasdf", catalogItem2, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
382
        catalogItem2.setLatitude(null);
383
        catalogItem2.setLongitude(null);
384

    
385
        CatalogItem catalogItem3 = new CatalogItem();
386
        catalogItem3.setAllNames(Stream.of(new CatalogItemName("U-re-me-re", catalogItem3, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
387
        catalogItem3.setLatitude(55.0);
388
        catalogItem3.setLongitude(68.0);
389

    
390
        CatalogItem catalogItem4 = new CatalogItem();
391
        catalogItem4.setAllNames(Stream.of(new CatalogItemName("Huga", catalogItem4, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
392
        catalogItem4.setLatitude(null);
393
        catalogItem4.setLongitude(null);
394

    
395
        CatalogItem catalogItem5 = new CatalogItem();
396
        catalogItem5.setAllNames(Stream.of(new CatalogItemName("Huga", catalogItem5, 1), new CatalogItemName("Hugaa", catalogItem5, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
397
        catalogItem5.setLatitude(null);
398
        catalogItem5.setLongitude(null);
399

    
400
        CatalogItem catalogItem6 = new CatalogItem();
401
        catalogItem6.setAllNames(Stream.of(new CatalogItemName("Duga", catalogItem6, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
402
        catalogItem6.setLatitude(null);
403
        catalogItem6.setLongitude(null);
404

    
405
        CatalogItemDto catalogItemDto1 = new CatalogItemDto();
406
        catalogItemDto1.setId(catalogItem1.getId());
407
        catalogItemDto1.setAllNames(Stream.of("Azbar").collect(Collectors.toCollection(LinkedHashSet::new)));
408
        catalogItemDto1.setLatitude(5.0);
409
        catalogItemDto1.setLongitude(5.0);
410

    
411
        CatalogItemDto catalogItemDto2 = new CatalogItemDto();
412
        catalogItemDto2.setId(catalogItem2.getId());
413
        catalogItemDto2.setAllNames(Stream.of("Azbar", "Azbarasdf").collect(Collectors.toCollection(LinkedHashSet::new)));
414
        catalogItemDto2.setLatitude(null);
415
        catalogItemDto2.setLongitude(null);
416

    
417
        CatalogItemDto catalogItemDto3 = new CatalogItemDto();
418
        catalogItemDto3.setId(catalogItem3.getId());
419
        catalogItemDto3.setAllNames(Stream.of("U-re-me-re").collect(Collectors.toCollection(LinkedHashSet::new)));
420
        catalogItemDto3.setLatitude(55.0);
421
        catalogItemDto3.setLongitude(68.0);
422

    
423
        CatalogItemDto catalogItemDto4 = new CatalogItemDto();
424
        catalogItemDto4.setId(catalogItem4.getId());
425
        catalogItemDto4.setAllNames(Stream.of("Huga").collect(Collectors.toCollection(LinkedHashSet::new)));
426
        catalogItemDto4.setLatitude(null);
427
        catalogItemDto4.setLongitude(null);
428

    
429
        CatalogItemDto catalogItemDto5 = new CatalogItemDto();
430
        catalogItemDto5.setId(catalogItem5.getId());
431
        catalogItemDto5.setAllNames(Stream.of("Huga", "Hugaa").collect(Collectors.toCollection(LinkedHashSet::new)));
432
        catalogItemDto5.setLatitude(null);
433
        catalogItemDto5.setLongitude(null);
434

    
435
        CatalogItemDto catalogItemDto6 = new CatalogItemDto();
436
        catalogItemDto6.setId(catalogItem6.getId());
437
        catalogItemDto6.setAllNames(Stream.of("Duga").collect(Collectors.toCollection(LinkedHashSet::new)));
438
        catalogItemDto6.setLatitude(null);
439
        catalogItemDto6.setLongitude(null);
440

    
441

    
442
        given(typeService.getAllTypesAsString()).willReturn(Stream.of("city", "ocean").collect(Collectors.toCollection(LinkedHashSet::new)));
443
        given(catalogItemRepository.findAll()).willReturn(List.of(catalogItem1, catalogItem2, catalogItem3, catalogItem4, catalogItem5, catalogItem6));
444

    
445
        // when
446
        PathDto pathDto = underTest.getPath(text);
447

    
448
        // then
449
        verify(catalogItemRepository).findAll();
450

    
451
        assertThat(pathDto.getText()).isEqualTo(highlightedText);
452

    
453
        assertThat(pathDto.getFoundCatalogItems().size()).isEqualTo(4);
454

    
455
        assertThat(pathDto.getFoundCatalogItems().get(0).size()).isEqualTo(2);
456
        assertThat(pathDto.getFoundCatalogItems().get(0).get(0)).isEqualTo(catalogItemDto1);
457
        assertThat(pathDto.getFoundCatalogItems().get(0).get(1)).isEqualTo(catalogItemDto2);
458

    
459
        assertThat(pathDto.getFoundCatalogItems().get(1).size()).isEqualTo(1);
460
        assertThat(pathDto.getFoundCatalogItems().get(1).get(0)).isEqualTo(catalogItemDto3);
461

    
462
        assertThat(pathDto.getFoundCatalogItems().get(2).size()).isEqualTo(2);
463
        assertThat(pathDto.getFoundCatalogItems().get(2).get(0)).isEqualTo(catalogItemDto4);
464
        assertThat(pathDto.getFoundCatalogItems().get(2).get(1)).isEqualTo(catalogItemDto5);
465

    
466
        assertThat(pathDto.getFoundCatalogItems().get(3).size()).isEqualTo(1);
467
        assertThat(pathDto.getFoundCatalogItems().get(3).get(0)).isEqualTo(catalogItemDto6);
468
    }
469
}
(2-2/2)