Skip to content
Open
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: 7 additions & 2 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

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.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.14</version>
<version>4.1.0</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
Expand All @@ -28,9 +28,9 @@

<!-- DEPENDENCIES VERSION -->
<jdk.version>25</jdk.version>
<cds.services.version>4.9.0</cds.services.version>
<cds.services.version>5.0.0-m2624</cds.services.version>
<cloud.sdk.version>5.30.0</cloud.sdk.version>
<xsuaa.version>3.7.3</xsuaa.version>
<xsuaa.version>4.0.0</xsuaa.version>
<cf-java-logging-support.version>4.2.0</cf-java-logging-support.version>
<cds-feature-attachments.version>1.5.0</cds-feature-attachments.version>
</properties>
Expand Down
23 changes: 20 additions & 3 deletions srv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security-oauth2-resource-server</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
Expand All @@ -122,14 +127,26 @@
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webclient</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-webtestclient</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<artifactId>spring-boot-starter-webmvc-test</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package my.bookshop.health;

import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.health.autoconfigure.contributor.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.health.contributor.Health;
import org.springframework.boot.health.contributor.HealthIndicator;
import org.springframework.stereotype.Component;

/** Custom health indicator implementation. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.webtestclient.autoconfigure.AutoConfigureWebTestClient;
import org.springframework.test.context.ActiveProfiles;

/**
Expand All @@ -12,6 +13,7 @@
*/
@ActiveProfiles("default")
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient
class AdminServiceAddress_default_ITest extends AdminServiceAddressITestBase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.webtestclient.autoconfigure.AutoConfigureWebTestClient;
import org.springframework.test.context.ActiveProfiles;

/**
Expand All @@ -16,6 +17,7 @@
webEnvironment = WebEnvironment.RANDOM_PORT,
properties =
"cds.remote.services.'[API_BUSINESS_PARTNER]'.destination.name=myself-AdminServiceAddressITest")
@AutoConfigureWebTestClient
class AdminServiceAddress_mocked_ITest extends AdminServiceAddressITestBase {

@Test
Expand Down
92 changes: 58 additions & 34 deletions srv/src/test/java/my/bookshop/CatalogServiceITest.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package my.bookshop;

import static cds.gen.catalogservice.CatalogService_.REVIEWS;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.assertj.core.api.Assertions.assertThat;

import cds.gen.catalogservice.Reviews;
import com.sap.cds.ql.Delete;
import com.sap.cds.services.persistence.PersistenceService;
import org.junit.jupiter.api.AfterEach;
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.resttestclient.autoconfigure.AutoConfigureRestTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.client.RestTestClient;

@SpringBootTest
@AutoConfigureMockMvc
@AutoConfigureRestTestClient
class CatalogServiceITest {

private static final String booksURI = "/api/browse/Books";
Expand All @@ -32,7 +27,7 @@ class CatalogServiceITest {
private static final String USER_USER_STRING = "user";
private static final String ADMIN_USER_STRING = "admin";

@Autowired private MockMvc mockMvc;
@Autowired private RestTestClient client;

@Autowired private PersistenceService db;

Expand All @@ -42,47 +37,76 @@ void cleanup() {
}

@Test
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")));
void discountApplied() {
client
.get()
.uri(booksURI + "?$filter=stock gt 200&top=1")
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$.value[0].title")
.value(String.class, title -> assertThat(title).contains("11% discount"));
}

@Test
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"))));
void discountNotApplied() {
client
.get()
.uri(booksURI + "?$filter=stock lt 100&top=1")
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$.value[0].title")
.value(String.class, title -> assertThat(title).doesNotContain("11% discount"));
}

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

@Test
@WithMockUser(USER_USER_STRING)
void createReviewByUser() throws Exception {
void createReviewByUser() {
String payload = createTestReview().toJson();
mockMvc
.perform(post(addReviewURI).contentType(MediaType.APPLICATION_JSON).content(payload))
.andExpect(status().isOk())
.andExpect(jsonPath("$.createdBy").value(USER_USER_STRING));
client
.post()
.uri(addReviewURI)
.contentType(MediaType.APPLICATION_JSON)
.body(payload)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$.createdBy")
.isEqualTo(USER_USER_STRING);
}

@Test
@WithMockUser(ADMIN_USER_STRING)
void createReviewByAdmin() throws Exception {
void createReviewByAdmin() {
String payload = createTestReview().toJson();
mockMvc
.perform(post(addReviewURI).contentType(MediaType.APPLICATION_JSON).content(payload))
.andExpect(status().isOk())
.andExpect(jsonPath("$.createdBy").value(ADMIN_USER_STRING));
client
.post()
.uri(addReviewURI)
.contentType(MediaType.APPLICATION_JSON)
.body(payload)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$.createdBy")
.isEqualTo(ADMIN_USER_STRING);
}

private Reviews createTestReview() {
Expand Down
2 changes: 1 addition & 1 deletion srv/src/test/java/my/bookshop/GenreHierarchyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import java.net.URI;
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.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.util.UriComponentsBuilder;
Expand Down
2 changes: 2 additions & 0 deletions srv/src/test/java/my/bookshop/NotesServiceITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.webtestclient.autoconfigure.AutoConfigureWebTestClient;
import org.springframework.http.HttpHeaders;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.reactive.server.WebTestClient;
Expand All @@ -12,6 +13,7 @@
webEnvironment = WebEnvironment.RANDOM_PORT,
properties =
"cds.remote.services.'[API_BUSINESS_PARTNER]'.destination.name=myself-NotesServiceITest")
@AutoConfigureWebTestClient
@ActiveProfiles({"default", "mocked"})
class NotesServiceITest {

Expand Down
Loading