Projekt

Obecné

Profil

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

    
3
import cz.zcu.kiv.backendapi.alternativename.CatalogItemName;
4
import org.junit.jupiter.api.Test;
5
import org.springframework.beans.factory.annotation.Autowired;
6
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
7

    
8
import java.util.LinkedHashSet;
9
import java.util.List;
10
import java.util.stream.Collectors;
11
import java.util.stream.Stream;
12

    
13
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
14
import static org.junit.jupiter.api.Assertions.assertTrue;
15

    
16
@DataJpaTest
17
class CatalogItemRepositoryTest {
18

    
19
    @Autowired
20
    private CatalogItemRepository underTest;
21

    
22
    @Test
23
    void testItemsByName() {
24
        // given
25
        String nameFirst = "first";
26
        String nameFirstUpper = "First";
27
        String nameSecond = "second";
28
        String nameSedond = "sedond";
29
        String nameThird = "third";
30
        String nameTwelve = "twelve";
31
        String nameTwentyUpper = "TWENTY";
32

    
33
        CatalogItem catalogItem1 = new CatalogItem();
34
        CatalogItem catalogItem2 = new CatalogItem();
35
        CatalogItem catalogItem3 = new CatalogItem();
36
        CatalogItem catalogItem4 = new CatalogItem();
37
        CatalogItem catalogItem5 = new CatalogItem();
38

    
39
        catalogItem1.setName(nameFirst);
40

    
41
        catalogItem2.setName(nameSecond);
42
        catalogItem2.setAllNames(Stream.of(new CatalogItemName(nameTwelve, catalogItem2, 1), new CatalogItemName(nameThird, catalogItem2, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
43

    
44
        catalogItem3.setName(nameThird);
45
        catalogItem3.setAllNames(Stream.of(new CatalogItemName(nameTwentyUpper, catalogItem3, 1), new CatalogItemName(nameSedond, catalogItem3, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
46

    
47
        catalogItem4.setAllNames(Stream.of(new CatalogItemName(nameTwelve, catalogItem4, 1), new CatalogItemName(nameFirstUpper, catalogItem4, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
48

    
49
        catalogItem5.setName(nameSedond);
50
        catalogItem5.setAllNames(Stream.of(new CatalogItemName(nameThird, catalogItem5, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
51

    
52
        underTest.saveAll(List.of(catalogItem1, catalogItem2, catalogItem3, catalogItem4, catalogItem5));
53

    
54

    
55
        String name = "twelve";
56

    
57
        // when
58
        List<CatalogItem> res = underTest.getItemsByName(name);
59

    
60
        // then
61
        assertThat(res.size()).isEqualTo(2);
62
        assertTrue(res.contains(catalogItem2));
63
        assertTrue(res.contains(catalogItem4));
64
    }
65
}
(1-1/3)