Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelmoez-guetat committed Jan 20, 2025
1 parent 3a15bcd commit bb0405c
Show file tree
Hide file tree
Showing 38 changed files with 90 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.springdoc.core.utils.Constants;
import org.springdoc.webflux.core.configuration.SpringDocWebFluxConfiguration;
import org.springdoc.webflux.ui.SwaggerConfig;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
import org.springframework.test.context.ContextConfiguration;
Expand All @@ -44,7 +43,7 @@
SwaggerConfig.class, SwaggerUiOAuthProperties.class, SpringDocUIConfiguration.class })
public abstract class AbstractSpringDocTest extends AbstractCommonTest {

private static final String DEFAULT_SWAGGER_INITIALIZER_URL = Constants.DEFAULT_WEB_JARS_PREFIX_URL + Constants.SWAGGER_INITIALIZER_URL;
private static final String DEFAULT_SWAGGER_INITIALIZER_URL = Constants.SWAGGER_INITIALIZER_URL;

@Autowired
protected WebTestClient webTestClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import test.org.springdoc.ui.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.reactive.server.WebTestClient;
import test.org.springdoc.ui.AbstractSpringDocTest;


@TestPropertySource(properties = "springdoc.swagger-ui.filter=false")
Expand All @@ -36,7 +35,7 @@ void shouldRedirectWithConfigUrlIgnoringQueryParams() {
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
.expectStatus().isFound();
responseSpec.expectHeader()
.value("Location", Matchers.is("/webjars/swagger-ui/index.html"));
.value("Location", Matchers.is("/swagger-ui/index.html"));
super.checkJS("index1-filter");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import test.org.springdoc.ui.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.reactive.server.WebTestClient;
import test.org.springdoc.ui.AbstractSpringDocTest;


@TestPropertySource(properties = {
Expand All @@ -39,7 +38,7 @@ void shouldRedirectWithConfigUrlIgnoringQueryParams() {
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
.expectStatus().isFound();
responseSpec.expectHeader()
.value("Location", Matchers.is("/webjars/swagger-ui/index.html"));
.value("Location", Matchers.is("/swagger-ui/index.html"));

super.checkJS("index1-configurl");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import test.org.springdoc.ui.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.test.web.reactive.server.WebTestClient;
import test.org.springdoc.ui.AbstractSpringDocTest;


public class SpringDocApp1RedirectDefaultTest extends AbstractSpringDocTest {
Expand All @@ -33,7 +32,7 @@ void shouldRedirectWithDefaultQueryParams() {
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
.expectStatus().isFound();
responseSpec.expectHeader()
.value("Location", Matchers.is("/webjars/swagger-ui/index.html"));
.value("Location", Matchers.is("/swagger-ui/index.html"));

webTestClient.get().uri("/v3/api-docs/swagger-config").exchange()
.expectStatus().isOk().expectBody().jsonPath("$.validatorUrl").isEqualTo("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import test.org.springdoc.ui.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.reactive.server.WebTestClient;
import test.org.springdoc.ui.AbstractSpringDocTest;


@TestPropertySource(properties = "springdoc.swagger-ui.layout=BaseLayout")
Expand All @@ -36,7 +35,7 @@ void shouldRedirectWithConfigUrlIgnoringQueryParams() {
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
.expectStatus().isFound();
responseSpec.expectHeader()
.value("Location", Matchers.is("/webjars/swagger-ui/index.html"));
.value("Location", Matchers.is("/swagger-ui/index.html"));

super.checkJS("index1-layout");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import test.org.springdoc.ui.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.reactive.server.WebTestClient;
import test.org.springdoc.ui.AbstractSpringDocTest;

@TestPropertySource(properties = {
"springdoc.swagger-ui.validatorUrl=/foo/validate",
Expand All @@ -38,7 +37,7 @@ void shouldRedirectWithConfiguredParams() {
.expectStatus().isFound();

responseSpec.expectHeader()
.value("Location", Matchers.is("/webjars/swagger-ui/index.html"));
.value("Location", Matchers.is("/swagger-ui/index.html"));

webTestClient.get().uri("/baf/batz/swagger-config").exchange()
.expectStatus().isOk().expectBody().jsonPath("$.validatorUrl").isEqualTo("/foo/validate");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
package test.org.springdoc.ui.app13;

import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractSpringDocActuatorTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.test.web.reactive.server.EntityExchangeResult;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractSpringDocActuatorTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
Expand All @@ -47,7 +46,7 @@ class SpringDocApp13Test extends AbstractSpringDocActuatorTest {

@Test
void testIndex() {
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri("/application/webjars/swagger-ui/index.html")
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri("/application/swagger-ui/index.html")
.exchange()
.expectStatus().isOk()
.expectBody().returnResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
package test.org.springdoc.ui.app14;

import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractSpringDocActuatorTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.test.web.reactive.server.EntityExchangeResult;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractSpringDocActuatorTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
Expand All @@ -45,7 +44,7 @@ class SpringDocApp14Test extends AbstractSpringDocActuatorTest {

@Test
void testIndex() {
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri("/application/webjars/swagger-ui/index.html")
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri("/application/swagger-ui/index.html")
.exchange()
.expectStatus().isOk()
.expectBody().returnResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
package test.org.springdoc.ui.app15;

import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractSpringDocActuatorTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.test.web.reactive.server.EntityExchangeResult;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractSpringDocActuatorTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
Expand All @@ -48,7 +47,7 @@ class SpringDocApp15Test extends AbstractSpringDocActuatorTest {

@Test
void testIndex() {
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri("/application/webjars/swagger-ui/index.html")
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri("/application/swagger-ui/index.html")
.exchange()
.expectStatus().isOk()
.expectBody().returnResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
package test.org.springdoc.ui.app16;

import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractSpringDocActuatorTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.test.web.reactive.server.EntityExchangeResult;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractSpringDocActuatorTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
Expand All @@ -48,7 +47,7 @@ class SpringDocApp16Test extends AbstractSpringDocActuatorTest {

@Test
void testIndex() {
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri("/application/webjars/swagger-ui/index.html")
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri("/application/swagger-ui/index.html")
.exchange()
.expectStatus().isOk()
.expectBody().returnResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
package test.org.springdoc.ui.app17;

import org.junit.jupiter.api.Test;
import test.org.springdoc.ui.AbstractSpringDocActuatorTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.reactive.server.EntityExchangeResult;
import test.org.springdoc.ui.AbstractSpringDocActuatorTest;

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

Expand All @@ -38,7 +37,7 @@ class SpringDocApp17Test extends AbstractSpringDocActuatorTest {

@Test
void testIndex() {
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri("/webjars/swagger-ui/index.html")
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri("/swagger-ui/index.html")
.exchange()
.expectStatus().isOk()
.expectBody().returnResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@

import jakarta.annotation.PostConstruct;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractCommonTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractCommonTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
Expand All @@ -45,8 +44,7 @@
properties = { "spring.webflux.base-path=/test",
"server.port=9218",
"springdoc.swagger-ui.path=/documentation/swagger-ui.html",
"springdoc.api-docs.path=/documentation/v3/api-docs",
"springdoc.webjars.prefix= /webjars-pref" })
"springdoc.api-docs.path=/documentation/v3/api-docs"})
class SpringDocApp18Test extends AbstractCommonTest {

@LocalServerPort
Expand All @@ -66,7 +64,7 @@ void testIndex() throws Exception {
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
assertThat(httpStatusMono).isEqualTo(HttpStatus.FOUND);

httpStatusMono = webClient.get().uri("/test/documentation/webjars-pref/swagger-ui/index.html")
httpStatusMono = webClient.get().uri("/test/documentation/swagger-ui/index.html")
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
assertThat(httpStatusMono).isEqualTo(HttpStatus.OK);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@

import jakarta.annotation.PostConstruct;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractCommonTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractCommonTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
Expand Down Expand Up @@ -63,7 +62,7 @@ void testIndex() throws Exception {
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
assertThat(httpStatusMono).isEqualTo(HttpStatus.FOUND);

httpStatusMono = webClient.get().uri("/webjars/swagger-ui/index.html")
httpStatusMono = webClient.get().uri("/swagger-ui/index.html")
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
assertThat(httpStatusMono).isEqualTo(HttpStatus.OK);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@

import jakarta.annotation.PostConstruct;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractCommonTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import test.org.springdoc.ui.AbstractCommonTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
Expand All @@ -63,7 +62,7 @@ void testIndex() throws Exception {
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
assertThat(httpStatusMono).isEqualTo(HttpStatus.FOUND);

httpStatusMono = webClient.get().uri("/webjars/swagger-ui/index.html")
httpStatusMono = webClient.get().uri("/swagger-ui/index.html")
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
assertThat(httpStatusMono).isEqualTo(HttpStatus.OK);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
package test.org.springdoc.ui.app24;

import org.junit.jupiter.api.Test;
import test.org.springdoc.ui.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.TestPropertySource;
import test.org.springdoc.ui.AbstractSpringDocTest;

@TestPropertySource(properties = {
"springdoc.api-docs.enabled=false",
Expand All @@ -40,7 +39,7 @@ void test_apidocs_disabled() {
.jsonPath("$.url").isEqualTo("/api-docs/xxx/v1/openapi.yml")
.jsonPath("$.configUrl").isEqualTo("/api-docs/swagger-config")
.jsonPath("$.validatorUrl").isEqualTo("")
.jsonPath("$.oauth2RedirectUrl").isEqualTo("/webjars/swagger-ui/oauth2-redirect.html");
.jsonPath("$.oauth2RedirectUrl").isEqualTo("/swagger-ui/oauth2-redirect.html");
}

@SpringBootApplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.springdoc.core.utils.Constants;
import test.org.springdoc.ui.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.reactive.server.WebTestClient;
import test.org.springdoc.ui.AbstractSpringDocTest;


@TestPropertySource(properties = {
Expand All @@ -39,14 +38,14 @@ void shouldRedirectWithDefaultQueryParams() {
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/documentation/swagger-ui.html").exchange()
.expectStatus().isFound();
responseSpec.expectHeader()
.value("Location", Matchers.is("/documentation/webjars/swagger-ui/index.html"));
.value("Location", Matchers.is("/documentation/swagger-ui/index.html"));

webTestClient.get().uri("/documentation/v3/api-docs/swagger-config").exchange()
.expectStatus().isOk().expectBody()
.jsonPath("$.validatorUrl").isEqualTo("")
.jsonPath("$.oauth2RedirectUrl").isEqualTo("/documentation/webjars/swagger-ui/oauth2-redirect.html");
.jsonPath("$.oauth2RedirectUrl").isEqualTo("/documentation/swagger-ui/oauth2-redirect.html");

super.checkJS("index3", "/documentation/webjars" + Constants.SWAGGER_INITIALIZER_URL);
super.checkJS("index3", "/documentation" + Constants.SWAGGER_INITIALIZER_URL);
}

@SpringBootApplication
Expand Down
Loading

0 comments on commit bb0405c

Please sign in to comment.