Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ User Interface related Features:
- [Model Localization](https://cap.cloud.sap/docs/guides/i18n) for [English](app/_i18n/i18n.properties) and [German](app/_i18n/i18n_de.properties) language for static texts
- [Custom File Upload extension](app/admin/webapp/extension/Upload.js) which provides a button for uploading `CSV` files
- A simple Swagger UI for the CatalogService API at <http://localhost:8080/swagger/index.html>
- UI5 Tree Table

CDS Maven Plugin Features:

Expand Down Expand Up @@ -138,6 +139,14 @@ are defined for local development:
- User: `user`, password: `user` to browse books
- User: `admin`, password: `admin` to manage books and orders

### Testing in hybrid mode

You can test the `GenreHierarchyTest` on H2 using the profile `default` as well as on HANA using the profile `hybrid`

```
cds bind --exec -- mvn clean install -Dspring.profiles.active=hybrid
```

## Using VS Code

VS Code supports the project out-of-the-box, when using the [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack).
Expand Down
112 changes: 112 additions & 0 deletions srv/src/test/java/my/bookshop/GenreHierarchyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package my.bookshop;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;

@SpringBootTest
@AutoConfigureMockMvc
//@ActiveProfiles({"hybrid"})
public class GenreHierarchyTest {

@Autowired
private MockMvc client;

private static final String genresURI = "/api/admin/GenreHierarchy";

@Test
@WithMockUser(username = "admin")
void testGetAll() throws Exception {
client.perform(get(genresURI)).andExpect(status().isOk());
}

@Test
@WithMockUser(username = "admin")
void testCountAll() throws Exception {
client.perform(get(genresURI + "/$count"))
.andExpect(status().isOk())
.andExpect(jsonPath("$").value(15));
}

@Test
@WithMockUser(username = "admin")
void testStartOneLevel() throws Exception {
client.perform(get(genresURI
+ "?$select=DrillState,ID,name,DistanceFromRoot"
+ "&$apply=orderby(name)/"
+ "com.sap.vocabularies.Hierarchy.v1.TopLevels(HierarchyNodes=$root/GenreHierarchy,HierarchyQualifier='GenreHierarchy',NodeProperty='ID',Levels=1)"
+ "&$count=true"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.value[0].ID").value(10))
.andExpect(jsonPath("$.value[0].name").value("Fiction"))
.andExpect(jsonPath("$.value[0].DistanceFromRoot").value(0))
.andExpect(jsonPath("$.value[0].DrillState").value("collapsed"))
.andExpect(jsonPath("$.value[1].ID").value(20))
.andExpect(jsonPath("$.value[1].name").value("Non-Fiction"))
.andExpect(jsonPath("$.value[1].DistanceFromRoot").value(0))
.andExpect(jsonPath("$.value[1].DrillState").value("collapsed"))
.andExpect(jsonPath("$.value[2]").doesNotExist());

}

@Test
@WithMockUser(username = "admin")
void testExpandNonFiction() throws Exception {
client.perform(get(genresURI
+ "?$select=DrillState,ID,name"
+ "&$apply=descendants($root/GenreHierarchy,GenreHierarchy,ID,filter(ID eq 20),1)"
+ "/orderby(ID)"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.value[0].ID").value(21))
.andExpect(jsonPath("$.value[0].name").value("Biography"))
.andExpect(jsonPath("$.value[0].DrillState").value("collapsed"))
.andExpect(jsonPath("$.value[1].ID").value(23))
.andExpect(jsonPath("$.value[1].name").value("Essay"))
.andExpect(jsonPath("$.value[1].DrillState").value("leaf"))
.andExpect(jsonPath("$.value[2].ID").value(24))
.andExpect(jsonPath("$.value[2].name").value("Speech"))
.andExpect(jsonPath("$.value[2].DrillState").value("leaf"))
.andExpect(jsonPath("$.value[3]").doesNotExist());
}

@Test
@WithMockUser(username = "admin")
void testCollapseAll() throws Exception {
client.perform(get(genresURI
+ "?$select=DrillState,ID,name"
+ "&$apply=com.sap.vocabularies.Hierarchy.v1.TopLevels(HierarchyNodes=$root/GenreHierarchy,HierarchyQualifier='GenreHierarchy',NodeProperty='ID',Levels=1)"
+ "&$count=true&$skip=0&$top=238"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.value[0].name").value("Fiction"))
.andExpect(jsonPath("$.value[0].DrillState").value("collapsed"))
.andExpect(jsonPath("$.value[1].name").value("Non-Fiction"))
.andExpect(jsonPath("$.value[1].DrillState").value("collapsed"))
.andExpect(jsonPath("$.value[2]").doesNotExist());
}

@Test
@WithMockUser(username = "admin")
void testExpandAll() throws Exception {
client.perform(get(genresURI
+ "?$select=DistanceFromRoot,DrillState,ID,LimitedDescendantCount,name"
+ "&$apply=com.sap.vocabularies.Hierarchy.v1.TopLevels(HierarchyNodes=$root/GenreHierarchy,HierarchyQualifier='GenreHierarchy',NodeProperty='ID')"
+ "&$count=true&$skip=0&$top=238"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.value[0].ID").value(10))
.andExpect(jsonPath("$.value[0].name").value("Fiction"))
.andExpect(jsonPath("$.value[0].DrillState").value("expanded"))
.andExpect(jsonPath("$.value[0].DistanceFromRoot").value(0))
.andExpect(jsonPath("$.value[0].LimitedDescendantCount").value(9))
.andExpect(jsonPath("$.value[14].name").value("Speech"))
.andExpect(jsonPath("$.value[14].DrillState").value("leaf"))
.andExpect(jsonPath("$.value[15]").doesNotExist());
}
}