Skip to content

Commit 7e2153e

Browse files
committed
added tests for GenreHierarchy
1 parent a8ea2f2 commit 7e2153e

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package my.bookshop;
2+
3+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
4+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
5+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
6+
7+
8+
import org.junit.jupiter.api.Test;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
11+
import org.springframework.boot.test.context.SpringBootTest;
12+
import org.springframework.security.test.context.support.WithMockUser;
13+
import org.springframework.test.context.ActiveProfiles;
14+
import org.springframework.test.web.servlet.MockMvc;
15+
16+
@SpringBootTest
17+
@AutoConfigureMockMvc
18+
@ActiveProfiles({"hybrid","default"})
19+
public class GenreHierarchyTest {
20+
21+
@Autowired
22+
private MockMvc client;
23+
24+
private static final String genresURI = "/api/admin/GenreHierarchy";
25+
26+
@Test
27+
@WithMockUser(username = "admin")
28+
void testGetAll() throws Exception {
29+
client.perform(get(genresURI)).andExpect(status().isOk());
30+
}
31+
32+
@Test
33+
@WithMockUser(username = "admin")
34+
void testCountAll() throws Exception {
35+
client.perform(get(genresURI + "/$count"))
36+
.andExpect(status().isOk())
37+
.andExpect(jsonPath("$").value(15));
38+
}
39+
40+
@Test
41+
@WithMockUser(username = "admin")
42+
void testStartOneLevel() throws Exception {
43+
client.perform(get(genresURI
44+
+ "?$select=DrillState,ID,name"
45+
+ "&$apply=com.sap.vocabularies.Hierarchy.v1.TopLevels(HierarchyNodes=$root/GenreHierarchy,HierarchyQualifier='GenreHierarchy',NodeProperty='ID',Levels=1)"
46+
+ "&$count=true&$skip=218&$top=20"))
47+
.andExpect(status().isOk())
48+
.andExpect(jsonPath("$.value[0].ID").value(10))
49+
.andExpect(jsonPath("$.value[0].name").value("Fiction"))
50+
.andExpect(jsonPath("$.value[0].DistanceFromRoot").value(0))
51+
.andExpect(jsonPath("$.value[0].DrillState").value("collapsed"))
52+
.andExpect(jsonPath("$.value[0].parnt_ID").isEmpty())
53+
.andExpect(jsonPath("$.value[1].ID").value(20))
54+
.andExpect(jsonPath("$.value[1].name").value("Non-Fiction"))
55+
.andExpect(jsonPath("$.value[1].DistanceFromRoot").value(0))
56+
.andExpect(jsonPath("$.value[1].DrillState").value("collapsed"))
57+
.andExpect(jsonPath("$.value[1].parnt_ID").isEmpty())
58+
.andExpect(jsonPath("$.value[2]").doesNotExist());
59+
60+
}
61+
62+
@Test
63+
@WithMockUser(username = "admin")
64+
void testExpandNonFiction() throws Exception {
65+
client.perform(get(genresURI
66+
+ "?$select=DrillState,ID,name"
67+
+ "&$apply=descendants($root/GenreHierarchy,GenreHierarchy,ID,filter(ID eq 20),1)"
68+
+ "&$count=true&$skip=0&$top=218"))
69+
.andExpect(status().isOk())
70+
.andExpect(jsonPath("$.value[0].ID").value(21))
71+
.andExpect(jsonPath("$.value[0].name").value("Biography"))
72+
// DistanceFromRoot: fix me?
73+
.andExpect(jsonPath("$.value[0].DistanceFromRoot").value(0))
74+
.andExpect(jsonPath("$.value[0].DrillState").value("collapsed"))
75+
.andExpect(jsonPath("$.value[0].parnt_ID").value(20))
76+
.andExpect(jsonPath("$.value[1].ID").value(23))
77+
.andExpect(jsonPath("$.value[1].name").value("Essay"))
78+
.andExpect(jsonPath("$.value[1].DistanceFromRoot").value(0))
79+
.andExpect(jsonPath("$.value[1].DrillState").value("leaf"))
80+
.andExpect(jsonPath("$.value[1].parnt_ID").value(20))
81+
.andExpect(jsonPath("$.value[2].ID").value(24))
82+
.andExpect(jsonPath("$.value[2].name").value("Speech"))
83+
.andExpect(jsonPath("$.value[2].DistanceFromRoot").value(0))
84+
.andExpect(jsonPath("$.value[2].DrillState").value("leaf"))
85+
.andExpect(jsonPath("$.value[2].parnt_ID").value(20))
86+
.andExpect(jsonPath("$.value[3]").doesNotExist());
87+
}
88+
89+
@Test
90+
@WithMockUser(username = "admin")
91+
void testCollapseAll() throws Exception {
92+
client.perform(get(genresURI
93+
+ "?$select=DrillState,ID,name"
94+
+ "&$apply=com.sap.vocabularies.Hierarchy.v1.TopLevels(HierarchyNodes=$root/GenreHierarchy,HierarchyQualifier='GenreHierarchy',NodeProperty='ID',Levels=1)"
95+
+ "&$count=true&$skip=0&$top=238"))
96+
.andExpect(status().isOk())
97+
.andExpect(jsonPath("$.value[0].name").value("Fiction"))
98+
.andExpect(jsonPath("$.value[0].DrillState").value("collapsed"))
99+
.andExpect(jsonPath("$.value[1].name").value("Non-Fiction"))
100+
.andExpect(jsonPath("$.value[1].DrillState").value("collapsed"))
101+
.andExpect(jsonPath("$.value[2]").doesNotExist());
102+
}
103+
104+
@Test
105+
@WithMockUser(username = "admin")
106+
void testExpandAll() throws Exception {
107+
client.perform(get(genresURI
108+
+ "?$select=DistanceFromRoot,DrillState,ID,LimitedDescendantCount,name"
109+
+ "&$apply=com.sap.vocabularies.Hierarchy.v1.TopLevels(HierarchyNodes=$root/GenreHierarchy,HierarchyQualifier='GenreHierarchy',NodeProperty='ID')"
110+
+ "&$count=true&$skip=0&$top=238"))
111+
.andExpect(status().isOk())
112+
.andExpect(jsonPath("$.value[0].name").value("Fiction"))
113+
.andExpect(jsonPath("$.value[0].DrillState").value("expanded"))
114+
.andExpect(jsonPath("$.value[14].name").value("Speech"))
115+
.andExpect(jsonPath("$.value[14].DrillState").value("leaf"))
116+
.andExpect(jsonPath("$.value[15]").doesNotExist());
117+
}
118+
}

0 commit comments

Comments
 (0)