Skip to content

Commit

Permalink
chore(core): add integration test for custom springwolf path
Browse files Browse the repository at this point in the history
Co-authored-by: Timon Back <[email protected]>
  • Loading branch information
sam0r040 and timonback committed Jun 7, 2024
1 parent e865bc0 commit 6cdc677
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.web.WebProperties;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties;
import org.springframework.context.annotation.Configuration;
Expand All @@ -15,6 +16,7 @@
import java.util.Arrays;
import java.util.List;

@Slf4j
@Configuration
@RequiredArgsConstructor
@Order(value = Ordered.HIGHEST_PRECEDENCE) // Highest so that all others will replace this configuration
Expand All @@ -26,8 +28,11 @@ public class SpringwolfUiResourceConfigurer implements WebMvcConfigurer {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler(
springwolfConfigProperties.getPath().getBase() + "/**", webMvcProperties.getStaticPathPattern())
String springwolfBasePath = springwolfConfigProperties.getPath().getBase();

log.debug("Serving Springwolf with base-path: {}", springwolfBasePath);

registry.addResourceHandler(springwolfBasePath + "/**", webMvcProperties.getStaticPathPattern())
.addResourceLocations(buildStaticLocation());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class AsyncApiController {
path = {
"${springwolf.paths.docs:/springwolf/docs}",
"${springwolf.paths.docs:/springwolf/docs}.json",
"${springwolf.path.base:/springwolf}/${springwolf.path.docs:/docs}",
"${springwolf.path.base:/springwolf}/${springwolf.path.docs:/docs}.json"
"${springwolf.path.base:/springwolf}${springwolf.path.docs:/docs}",
"${springwolf.path.base:/springwolf}${springwolf.path.docs:/docs}.json"
},
produces = MediaType.APPLICATION_JSON_VALUE)
public String asyncApiJson() throws JsonProcessingException {
Expand All @@ -36,7 +36,7 @@ public String asyncApiJson() throws JsonProcessingException {
@GetMapping(
path = {
"${springwolf.paths.docs:/springwolf/docs}.yaml",
"${springwolf.path.base:/springwolf}/${springwolf.path.docs:/docs}.yaml"
"${springwolf.path.base:/springwolf}${springwolf.path.docs:/docs}.yaml"
},
produces = "application/yaml")
public String asyncApiYaml() throws JsonProcessingException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.springwolf.examples.sqs;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.TestPropertySource;

import static org.junit.jupiter.api.Assertions.assertEquals;

@SpringBootTest(
classes = {SpringwolfSqsExampleApplication.class},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ExtendWith({SqsTestContainerExtension.class})
@TestPropertySource(
properties = {"springwolf.path.base=/my-custom/springwolf/endpoint/test", "springwolf.path.docs=/apispec"})
class CustomPathConfigurationIntegrationTest {

@DynamicPropertySource
static void setUpTestContainers(DynamicPropertyRegistry registry) {
SqsTestContainerExtension.overrideConfiguration(registry);
}

@Autowired
private TestRestTemplate restTemplate;

@Test
void getSpec() {
String url = "/my-custom/springwolf/endpoint/test/apispec";
ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);

assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
}

@Test
void canPublish() {
String url = "/my-custom/springwolf/endpoint/test/sqs/publish";
ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);

assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
}

@Test
void asyncapiDocsShouldReturnTheCorrectJsonResponse() {
String url = "/my-custom/springwolf/endpoint/test/asyncapi-ui.html";
ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);

assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
}
}

0 comments on commit 6cdc677

Please sign in to comment.