1
|
package cz.zcu.kiv.backendapi.catalog;
|
2
|
|
3
|
import cz.zcu.kiv.backendapi.alternativename.AlternativeName;
|
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.List;
|
9
|
import java.util.Set;
|
10
|
|
11
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
12
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
13
|
|
14
|
@DataJpaTest
|
15
|
class CatalogItemRepositoryTest {
|
16
|
|
17
|
@Autowired
|
18
|
private CatalogItemRepository underTest;
|
19
|
|
20
|
@Test
|
21
|
void testItemsByName() {
|
22
|
// given
|
23
|
String nameFirst = "first";
|
24
|
String nameFirstUpper = "First";
|
25
|
String nameSecond = "second";
|
26
|
String nameSedond = "sedond";
|
27
|
String nameThird = "third";
|
28
|
String nameTwelve = "twelve";
|
29
|
String nameTwentyUpper = "TWENTY";
|
30
|
|
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();
|
36
|
|
37
|
catalogItem1.setName(nameFirst);
|
38
|
|
39
|
catalogItem2.setName(nameSecond);
|
40
|
catalogItem2.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem2), new AlternativeName(nameThird, catalogItem2)));
|
41
|
|
42
|
catalogItem3.setName(nameThird);
|
43
|
catalogItem3.setAlternativeNames(Set.of(new AlternativeName(nameTwentyUpper, catalogItem3), new AlternativeName(nameSedond, catalogItem3)));
|
44
|
|
45
|
catalogItem4.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem4), new AlternativeName(nameFirstUpper, catalogItem4)));
|
46
|
|
47
|
catalogItem5.setName(nameSedond);
|
48
|
catalogItem5.setAlternativeNames(Set.of(new AlternativeName(nameThird, catalogItem5)));
|
49
|
|
50
|
underTest.saveAll(List.of(catalogItem1, catalogItem2, catalogItem3, catalogItem4, catalogItem5));
|
51
|
|
52
|
|
53
|
String name = "twelve";
|
54
|
|
55
|
// when
|
56
|
List<CatalogItem> res = underTest.getItemsByName(name);
|
57
|
|
58
|
// then
|
59
|
assertThat(res.size()).isEqualTo(2);
|
60
|
assertTrue(res.contains(catalogItem2));
|
61
|
assertTrue(res.contains(catalogItem4));
|
62
|
}
|
63
|
}
|