+ This is your SAP Business Technology Platform Cloud Foundry Spring application + powered by the SAP Cloud SDK. +
+application/ directory and execute
+ mvn spring-boot:run.
+ application/src/main/java/.
+ application/src/main/resources/static/.
+ + Further help and examples are available in the SAP Cloud SDK documentation. +
+ + + diff --git a/archetypes/spring-boot4/src/main/resources/archetype-resources/application/src/test/java/__packageInPathFormat__/HelloWorldControllerTest.java b/archetypes/spring-boot4/src/main/resources/archetype-resources/application/src/test/java/__packageInPathFormat__/HelloWorldControllerTest.java new file mode 100644 index 0000000000..2f6b6614e0 --- /dev/null +++ b/archetypes/spring-boot4/src/main/resources/archetype-resources/application/src/test/java/__packageInPathFormat__/HelloWorldControllerTest.java @@ -0,0 +1,74 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}; + +import static java.lang.Thread.currentThread; + +import com.sap.cloud.sdk.cloudplatform.thread.ThreadContextExecutor; +// import com.sap.cloud.security.config.Service; +// import com.sap.cloud.security.test.api.SecurityTestContext; +// import com.sap.cloud.security.test.extension.SecurityTestExtension; +// import com.sap.cloud.security.token.TokenClaims; +import org.apache.commons.io.IOUtils; +// import org.apache.http.HttpHeaders; +import org.junit.jupiter.api.Test; +// import org.junit.jupiter.api.extension.RegisterExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@SpringBootTest +@AutoConfigureMockMvc +@TestPropertySource( + properties = { + "sap.security.services.xsuaa.uaadomain=http://localhost:9001", + "sap.security.services.xsuaa.xsappname=xsapp!t0815", + "sap.security.services.xsuaa.clientid=sb-clientId!t0815" } ) +class HelloWorldControllerTest +{ + @Autowired + private MockMvc mvc; + + /* + @RegisterExtension + static SecurityTestExtension extension = SecurityTestExtension.forService(Service.XSUAA) // or Service.IAS + .setPort(9001); + + private String jwt; + */ + + @Test + void test(/*SecurityTestContext context*/) + { + /* + jwt = context.getPreconfiguredJwtGenerator() + .withLocalScopes("Display") + .withClaimValue(TokenClaims.XSUAA.ORIGIN, "sap-default") // optional + .withClaimValue(TokenClaims.USER_NAME, "John") // optional + .createToken() + .getTokenValue(); + jwt = "Bearer " + jwt; + */ + + final InputStream inputStream = currentThread().getContextClassLoader().getResourceAsStream("expected.json"); + + ThreadContextExecutor.fromNewContext().execute(() -> { + mvc + .perform(MockMvcRequestBuilders.get("/hello") + // .header(HttpHeaders.AUTHORIZATION, jwt) + ) + .andExpect(status().isOk()) + .andExpect(content().json(IOUtils.toString(inputStream, StandardCharsets.UTF_8))); + }); + } +} diff --git a/archetypes/spring-boot4/src/main/resources/archetype-resources/application/src/test/java/__packageInPathFormat__/UnitTest.java b/archetypes/spring-boot4/src/main/resources/archetype-resources/application/src/test/java/__packageInPathFormat__/UnitTest.java new file mode 100644 index 0000000000..edd25390a1 --- /dev/null +++ b/archetypes/spring-boot4/src/main/resources/archetype-resources/application/src/test/java/__packageInPathFormat__/UnitTest.java @@ -0,0 +1,17 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class UnitTest +{ + @Test + void test() + { + assertTrue(true); + } +} diff --git a/archetypes/spring-boot4/src/main/resources/archetype-resources/application/src/test/resources/expected.json b/archetypes/spring-boot4/src/main/resources/archetype-resources/application/src/test/resources/expected.json new file mode 100644 index 0000000000..f2a886f39d --- /dev/null +++ b/archetypes/spring-boot4/src/main/resources/archetype-resources/application/src/test/resources/expected.json @@ -0,0 +1,3 @@ +{ + "hello": "world" +} diff --git a/archetypes/spring-boot4/src/main/resources/archetype-resources/manifest.yml b/archetypes/spring-boot4/src/main/resources/archetype-resources/manifest.yml new file mode 100644 index 0000000000..fe2543ba75 --- /dev/null +++ b/archetypes/spring-boot4/src/main/resources/archetype-resources/manifest.yml @@ -0,0 +1,19 @@ +--- +applications: + +- name: ${artifactId} + memory: 1500M + timeout: 300 + random-route: true + path: application/target/${artifactId}-application.jar + env: + TARGET_RUNTIME: main + SPRING_PROFILES_ACTIVE: 'cloud' + JBP_CONFIG_SAPJVM_MEMORY_SIZES: 'metaspace:128m..' + JBP_CONFIG_COMPONENTS: 'jres: [''com.sap.xs.java.buildpack.jre.SAPMachineJRE'']' + JBP_CONFIG_SAP_MACHINE_JRE: '{ use_offline_repository: false, version: 17.+ }' +# services: +# - my-application-logs +# - my-xsuaa +# - my-destination +# - my-connectivity diff --git a/archetypes/spring-boot4/src/main/resources/archetype-resources/pom.xml b/archetypes/spring-boot4/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000000..6fb939e111 --- /dev/null +++ b/archetypes/spring-boot4/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,98 @@ + +