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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
@ActiveProfiles("default")
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class AdminServiceAddress_default_ITest extends AdminServiceAddressITestBase {
class AdminServiceAddress_default_ITest extends AdminServiceAddressITestBase {

@Test
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@ActiveProfiles({"default", "mocked"})
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
properties = "cds.remote.services.'[API_BUSINESS_PARTNER]'.destination.name=myself-AdminServiceAddressITest")
public class AdminServiceAddress_mocked_ITest extends AdminServiceAddressITestBase {
class AdminServiceAddress_mocked_ITest extends AdminServiceAddressITestBase {

@Test
@Override
Expand Down
12 changes: 6 additions & 6 deletions srv/src/test/java/my/bookshop/AdminServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
import cds.gen.adminservice.Orders;

@SpringBootTest
public class AdminServiceTest {
class AdminServiceTest {

@Autowired
private AdminService.Draft adminService;

@Test
@WithMockUser(username = "user")
public void testUnauthorizedAccess() {
void unauthorizedAccess() {
assertThrows(ServiceException.class, () -> {
adminService.newDraft(Insert.into(AUTHORS).entry(Collections.emptyMap()));
});
}

@Test
@WithMockUser(username = "admin")
public void testInvalidAuthorName() {
void invalidAuthorName() {
assertThrows(ServiceException.class, () -> {
Authors author = Authors.create();
author.setName("little Joey");
Expand All @@ -49,7 +49,7 @@ public void testInvalidAuthorName() {

@Test
@WithMockUser(username = "admin")
public void testValidAuthorName() {
void validAuthorName() {
Authors author = Authors.create();
author.setName("Big Joey");
Result result = adminService.run(Insert.into(AUTHORS).entry(author));
Expand All @@ -58,7 +58,7 @@ public void testValidAuthorName() {

@Test
@WithMockUser(username = "admin")
void testCreateOrderWithoutBook() {
void createOrderWithoutBook() {
Orders order = Orders.create();
order.setOrderNo("324");
order.setShippingAddressId("100");
Expand All @@ -75,7 +75,7 @@ void testCreateOrderWithoutBook() {

@Test
@WithMockUser(username = "admin")
void testCreateOrderWithNonExistingBook() {
void createOrderWithNonExistingBook() {
Orders order = Orders.create();
order.setOrderNo("324");
order.setShippingAddressId("100");
Expand Down
14 changes: 7 additions & 7 deletions srv/src/test/java/my/bookshop/CatalogServiceITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@SpringBootTest
@AutoConfigureMockMvc
public class CatalogServiceITest {
class CatalogServiceITest {

private static final String booksURI = "/api/browse/Books";
private static final String addReviewURI = "%s(ID=%s)/CatalogService.addReview".formatted(booksURI, "f846b0b9-01d4-4f6d-82a4-d79204f62278");
Expand All @@ -39,34 +39,34 @@ public class CatalogServiceITest {
private PersistenceService db;

@AfterEach
public void cleanup() {
void cleanup() {
db.run(Delete.from(REVIEWS));
}

@Test
public void testDiscountApplied() throws Exception {
void discountApplied() throws Exception {
mockMvc.perform(get(booksURI + "?$filter=stock gt 200&top=1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.value[0].title").value(containsString("11% discount")));
}

@Test
public void testDiscountNotApplied() throws Exception {
void discountNotApplied() throws Exception {
mockMvc.perform(get(booksURI + "?$filter=stock lt 100&top=1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.value[0].title").value(not(containsString("11% discount"))));
}

@Test
public void testCreateReviewNotAuthenticated() throws Exception {
void createReviewNotAuthenticated() throws Exception {
String payload = createTestReview().toJson();
mockMvc.perform(post(addReviewURI).contentType(MediaType.APPLICATION_JSON).content(payload))
.andExpect(status().isUnauthorized());
}

@Test
@WithMockUser(USER_USER_STRING)
public void testCreateReviewByUser() throws Exception {
void createReviewByUser() throws Exception {
String payload = createTestReview().toJson();
mockMvc.perform(post(addReviewURI).contentType(MediaType.APPLICATION_JSON).content(payload))
.andExpect(status().isOk())
Expand All @@ -75,7 +75,7 @@ public void testCreateReviewByUser() throws Exception {

@Test
@WithMockUser(ADMIN_USER_STRING)
public void testCreateReviewByAdmin() throws Exception {
void createReviewByAdmin() throws Exception {
String payload = createTestReview().toJson();
mockMvc.perform(post(addReviewURI).contentType(MediaType.APPLICATION_JSON).content(payload))
.andExpect(status().isOk())
Expand Down
12 changes: 6 additions & 6 deletions srv/src/test/java/my/bookshop/CatalogServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import cds.gen.catalogservice.Reviews;

@SpringBootTest
public class CatalogServiceTest {
class CatalogServiceTest {

@Autowired
private CatalogService catalogService;
Expand All @@ -33,13 +33,13 @@ public class CatalogServiceTest {
private PersistenceService db;

@AfterEach
public void cleanup() {
void cleanup() {
db.run(Delete.from(REVIEWS));
}

@Test
@WithMockUser(username = "user")
public void testCreateReviewHandler() {
void createReviewHandler() {
Stream<Reviews> bookReviews = Stream.of(
createReview("f846b0b9-01d4-4f6d-82a4-d79204f62278", 1, "quite bad", "disappointing..."),
createReview("aebdfc8a-0dfa-4468-bd36-48aabd65e663", 5, "great read", "just amazing..."));
Expand All @@ -58,7 +58,7 @@ public void testCreateReviewHandler() {

@Test
@WithMockUser(username = "user")
public void testAddReviewWithInvalidRating() {
void addReviewWithInvalidRating() {
Stream<Reviews> bookReviews = Stream.of(
// lt 1 is invalid
createReview("f846b0b9-01d4-4f6d-82a4-d79204f62278", 0, "quite bad", "disappointing..."),
Expand All @@ -76,7 +76,7 @@ public void testAddReviewWithInvalidRating() {

@Test
@WithMockUser(username = "user")
public void testAddReviewForNonExistingBook() {
void addReviewForNonExistingBook() {

String nonExistingBookId = "non-existing";
String exMessage1 = "You have to specify the book to review";
Expand All @@ -98,7 +98,7 @@ public void testAddReviewForNonExistingBook() {

@Test
@WithMockUser(username = "user")
public void testAddReviewSameBookMoreThanOnceBySameUser() {
void addReviewSameBookMoreThanOnceBySameUser() {

String bookId = "4a519e61-3c3a-4bd9-ab12-d7e0c5329933";
Books_ ref = CQL.entity(BOOKS).filter(b -> b.ID().eq(bookId));
Expand Down
24 changes: 12 additions & 12 deletions srv/src/test/java/my/bookshop/GenreHierarchyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@SpringBootTest
@AutoConfigureMockMvc
public class GenreHierarchyTest {
class GenreHierarchyTest {

@Autowired
private MockMvc client;
Expand All @@ -25,21 +25,21 @@ public class GenreHierarchyTest {

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

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

@Test
@WithMockUser(username = "admin")
void testStartOneLevel() throws Exception {
void startOneLevel() throws Exception {
client.perform(get(genresURI
+ "?$select=DrillState,ID,name,DistanceFromRoot"
+ "&$apply=orderby(name)/"
Expand All @@ -59,7 +59,7 @@ void testStartOneLevel() throws Exception {

@Test
@WithMockUser(username = "admin")
void testStartTwoLevels() throws Exception {
void startTwoLevels() throws Exception {
client.perform(get(genresURI
+ "?$select=DrillState,ID,name,DistanceFromRoot"
+ "&$apply=orderby(name)/"
Expand All @@ -80,7 +80,7 @@ void testStartTwoLevels() throws Exception {

@Test
@WithMockUser(username = "admin")
void testExpandNonFiction() throws Exception {
void expandNonFiction() throws Exception {
client.perform(get(genresURI
+ "?$select=DrillState,ID,name"
+ "&$apply=descendants($root/GenreHierarchy,GenreHierarchy,ID,filter(ID eq 8bbf14c6-b378-4e35-9b4f-05a9c8878021),1)"
Expand All @@ -93,7 +93,7 @@ void testExpandNonFiction() throws Exception {

@Test
@WithMockUser(username = "admin")
void testCollapseAll() throws Exception {
void collapseAll() throws Exception {
client.perform(get(genresURI
+ "?$select=DrillState,ID,name"
+ "&$apply=orderby(name)/com.sap.vocabularies.Hierarchy.v1.TopLevels(HierarchyNodes=$root/GenreHierarchy,HierarchyQualifier='GenreHierarchy',NodeProperty='ID',Levels=1)"
Expand All @@ -108,7 +108,7 @@ void testCollapseAll() throws Exception {

@Test
@WithMockUser(username = "admin")
void testExpandAllTop100() throws Exception {
void expandAllTop100() throws Exception {
String url = genresURI
+ "?$select=DistanceFromRoot,DrillState,ID,LimitedDescendantCount,name"
+ "&$apply=orderby(name)/com.sap.vocabularies.Hierarchy.v1.TopLevels(HierarchyNodes=$root/GenreHierarchy,HierarchyQualifier='GenreHierarchy',NodeProperty='ID')"
Expand All @@ -126,7 +126,7 @@ void testExpandAllTop100() throws Exception {

@Test
@WithMockUser(username = "admin")
void testSearch() throws Exception {
void search() throws Exception {
client.perform(get(genresURI
+ "?$select=DistanceFromRoot,DrillState,ID,LimitedDescendantCount,name"
+ "&$apply=ancestors($root/GenreHierarchy,GenreHierarchy,ID,search(\"true\"),keep start)"
Expand Down Expand Up @@ -154,7 +154,7 @@ void testSearch() throws Exception {

@Test
@WithMockUser(username = "admin")
void testFilterNotExpanded() throws Exception {
void filterNotExpanded() throws Exception {
client.perform(get(genresURI
+ "?$select=DrillState,ID,name,DistanceFromRoot"
+ "&$apply=ancestors($root/GenreHierarchy,GenreHierarchy,ID,filter(name eq 'Autobiography'),keep start)/orderby(name)"
Expand All @@ -168,7 +168,7 @@ void testFilterNotExpanded() throws Exception {

@Test
@WithMockUser(username = "admin")
void testFilterExpandLevels() throws Exception {
void filterExpandLevels() throws Exception {
String expandLevelsJson = """
[{"NodeID":"8bbf14c6-b378-4e35-9b4f-05a9c8878002","Levels":1},{"NodeID":"8bbf14c6-b378-4e35-9b4f-05a9c8878031","Levels":1}]\
""";
Expand All @@ -188,7 +188,7 @@ void testFilterExpandLevels() throws Exception {

@Test
@WithMockUser(username = "admin")
void testStartTwoLevelsOrderByDesc() throws Exception {
void startTwoLevelsOrderByDesc() throws Exception {
client.perform(get(genresURI
+ "?$select=DrillState,ID,name,DistanceFromRoot"
+ "&$apply=orderby(name desc)/"
Expand Down
20 changes: 10 additions & 10 deletions srv/src/test/java/my/bookshop/NotesServiceITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
properties = "cds.remote.services.'[API_BUSINESS_PARTNER]'.destination.name=myself-NotesServiceITest")
@ActiveProfiles({"default", "mocked"})
public class NotesServiceITest {
class NotesServiceITest {

private static final String notesURI = "/api/notes/Notes";
private static final String addressesURI = "/api/notes/Addresses";
Expand All @@ -20,7 +20,7 @@ public class NotesServiceITest {
private WebTestClient client;

@Test
public void testGetNotes() throws Exception {
void getNotes() {
client.get().uri(notesURI).headers(this::authenticatedCredentials).exchange()
.expectStatus().isOk()
.expectBody()
Expand All @@ -40,7 +40,7 @@ public void testGetNotes() throws Exception {
}

@Test
public void testGetAddresses() throws Exception {
void getAddresses() {
client.get().uri(addressesURI + "?$filter=businessPartner eq '10401010'").headers(this::authenticatedCredentials).exchange()
.expectStatus().isOk()
.expectBody()
Expand All @@ -54,7 +54,7 @@ public void testGetAddresses() throws Exception {
}

@Test
public void testGetNoteWithAddress() throws Exception {
void getNoteWithAddress() {
client.get().uri(notesURI + "?$expand=address").headers(this::authenticatedCredentials).exchange()
.expectStatus().isOk()
.expectBody()
Expand Down Expand Up @@ -83,7 +83,7 @@ public void testGetNoteWithAddress() throws Exception {
}

@Test
public void testGetSuppliersWithNotes() throws Exception {
void getSuppliersWithNotes() {
client.get().uri(addressesURI + "?$expand=notes($orderby=ID)&$filter=businessPartner eq '10401010'").headers(this::authenticatedCredentials).exchange()
.expectStatus().isOk()
.expectBody()
Expand All @@ -108,7 +108,7 @@ public void testGetSuppliersWithNotes() throws Exception {
}

@Test
public void testGetNotesToSupplier() throws Exception {
void getNotesToSupplier() {
client.get().uri(notesURI + "(ID=5efc842c-c70d-4ee2-af1d-81c7d257aff7,IsActiveEntity=true)/address").headers(this::authenticatedCredentials).exchange()
.expectStatus().isOk()
.expectBody()
Expand All @@ -119,7 +119,7 @@ public void testGetNotesToSupplier() throws Exception {
}

@Test
public void testGetSupplierToNotes() throws Exception {
void getSupplierToNotes() {
client.get().uri(addressesURI + "(businessPartner='10401010',ID='100')/notes").headers(this::authenticatedCredentials).exchange()
.expectStatus().isOk()
.expectBody()
Expand All @@ -135,7 +135,7 @@ public void testGetSupplierToNotes() throws Exception {
}

@Test
public void testGetSupplierToSpecificNote() throws Exception {
void getSupplierToSpecificNote() {
client.get().uri(addressesURI + "(businessPartner='10401010',ID='100')/notes(ID=83e2643b-aecc-47d3-9f85-a8ba14eff07d,IsActiveEntity=true)")
.headers(this::authenticatedCredentials)
.exchange()
Expand All @@ -148,7 +148,7 @@ public void testGetSupplierToSpecificNote() throws Exception {
}

@Test
public void testGetNotesWithNestedExpands() throws Exception {
void getNotesWithNestedExpands() {
client.get().uri(notesURI + "?$select=note&$expand=address($select=postalCode;$expand=notes($select=note))&$top=1").headers(this::authenticatedCredentials).exchange()
.expectStatus().isOk()
.expectBody()
Expand All @@ -164,7 +164,7 @@ public void testGetNotesWithNestedExpands() throws Exception {
}

@Test
public void testGetAddressesWithNestedExpands() throws Exception {
void getAddressesWithNestedExpands() {
client.get().uri(addressesURI + "?$select=postalCode&$expand=notes($select=note;$expand=address($select=postalCode))&$filter=businessPartner eq '1000020'")
.headers(this::authenticatedCredentials)
.exchange()
Expand Down
Loading