From c1ea106bc1b27c7f37153d1f3637fb032e85ff06 Mon Sep 17 00:00:00 2001 From: Artem Sidorkin Date: Fri, 14 May 2021 13:44:35 +0300 Subject: [PATCH 1/4] #54: swagger ui is not available for api-gateway. Fixed. Added tests for swagger-ui. --- README.adoc | 4 +-- api-gateway-service/build.gradle | 4 +++ .../CustomersAndOrdersE2ETest.java | 27 +++++++++++++++++-- gradle.properties | 2 +- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/README.adoc b/README.adoc index e65ac6e6..adb93c31 100644 --- a/README.adoc +++ b/README.adoc @@ -95,8 +95,8 @@ You can also run the Postgres version using `./gradlew postgresComposeBuild` and Once the application has started, you can use the application via the Swagger UI: -* `Order Service` - `http://localhost:8081/swagger-ui.html` -* `Customer Service` - `http://localhost:8082/swagger-ui.html` +* `Order Service` - `http://localhost:8081/swagger-ui/index.html` +* `Customer Service` - `http://localhost:8082/swagger-ui/index.html` * `API Gateway` - `http://localhost:8083/swagger-ui.html` You can also use `curl` to interact with the services. diff --git a/api-gateway-service/build.gradle b/api-gateway-service/build.gradle index cfdbc741..bc9f686e 100755 --- a/api-gateway-service/build.gradle +++ b/api-gateway-service/build.gradle @@ -39,3 +39,7 @@ dependencies { testCompile "junit:junit:4.12" testCompile "org.springframework.boot:spring-boot-starter-test" } + +bootJar { + requiresUnpack '**/eventuate-util-swagger-ui-*.jar' +} \ No newline at end of file diff --git a/end-to-end-tests/src/test/java/io/eventuate/examples/tram/sagas/ordersandcustomers/endtoendtests/CustomersAndOrdersE2ETest.java b/end-to-end-tests/src/test/java/io/eventuate/examples/tram/sagas/ordersandcustomers/endtoendtests/CustomersAndOrdersE2ETest.java index fbf16448..d886f045 100644 --- a/end-to-end-tests/src/test/java/io/eventuate/examples/tram/sagas/ordersandcustomers/endtoendtests/CustomersAndOrdersE2ETest.java +++ b/end-to-end-tests/src/test/java/io/eventuate/examples/tram/sagas/ordersandcustomers/endtoendtests/CustomersAndOrdersE2ETest.java @@ -10,6 +10,7 @@ import io.eventuate.examples.tram.sagas.ordersandcustomers.orders.api.web.CreateOrderResponse; import io.eventuate.examples.tram.sagas.ordersandcustomers.orders.api.web.GetOrderResponse; import io.eventuate.util.test.async.Eventually; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -21,6 +22,11 @@ import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.concurrent.TimeUnit; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -94,7 +100,7 @@ public void shouldSupportOrderHistory() { new CreateOrderRequest(createCustomerResponse.getCustomerId(), new Money("100.00")), CreateOrderResponse.class); - Eventually.eventually(() -> { + Eventually.eventually(60, 500, TimeUnit.MILLISECONDS, () -> { ResponseEntity customerResponseEntity = restTemplate.getForEntity(baseUrl("customers", Long.toString(createCustomerResponse.getCustomerId()), "orderhistory"), GetCustomerHistoryResponse.class); @@ -112,8 +118,25 @@ public void shouldSupportOrderHistory() { }); } + @Test + public void testSwaggerUiUrls() throws IOException { + testSwaggerUiUrl(8081, "swagger-ui/index.html"); + testSwaggerUiUrl(8082, "swagger-ui/index.html"); + testSwaggerUiUrl(8083, "swagger-ui.html"); + } + + private void testSwaggerUiUrl(int port, String relativeUrl) throws IOException { + assertUrlStatusIsOk(String.format("http://%s:%s/%s", hostName, port, relativeUrl)); + } + + private void assertUrlStatusIsOk(String url) throws IOException { + HttpURLConnection connection = (HttpURLConnection)new URL(url).openConnection(); + + Assert.assertEquals(200, connection.getResponseCode()); + } + private void assertOrderState(Long id, OrderState expectedState, RejectionReason expectedRejectionReason) { - Eventually.eventually(() -> { + Eventually.eventually(60, 500, TimeUnit.MILLISECONDS, () -> { ResponseEntity getOrderResponseEntity = restTemplate.getForEntity(baseUrl("orders/" + id), GetOrderResponse.class); assertEquals(HttpStatus.OK, getOrderResponseEntity.getStatusCode()); GetOrderResponse order = getOrderResponseEntity.getBody(); diff --git a/gradle.properties b/gradle.properties index e29cfec8..f9269866 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ springBootVersion=2.2.6.RELEASE springCloudSleuthVersion=2.2.2.RELEASE springCloudGatewayVersion=2.2.2.RELEASE springCloudContractDependenciesVersion=2.2.0.RELEASE -eventuateUtilVersion=0.10.0.RELEASE +eventuateUtilVersion=0.11.0-SNAPSHOT eventuateTramSagasImageVersion=0.18.0.RELEASE From 49ae8fcce78ef498a7c62dedaede54ccb4a523e8 Mon Sep 17 00:00:00 2001 From: Artem Sidorkin Date: Fri, 14 May 2021 21:26:20 +0300 Subject: [PATCH 2/4] Made swagger urls consistent. Enabled .../actuator/mappings (includes swagger) --- .../apigateway/common/SwaggerController.java | 2 +- api-gateway-service/src/main/resources/application.yml | 10 +++++++++- .../src/main/resources/application.properties | 2 ++ .../endtoendtests/CustomersAndOrdersE2ETest.java | 10 +++++----- .../src/main/resources/application.properties | 2 ++ 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/api-gateway-service/src/main/java/io/eventuate/examples/tram/sagas/ordersandcustomers/apigateway/common/SwaggerController.java b/api-gateway-service/src/main/java/io/eventuate/examples/tram/sagas/ordersandcustomers/apigateway/common/SwaggerController.java index 22834663..24e4d490 100644 --- a/api-gateway-service/src/main/java/io/eventuate/examples/tram/sagas/ordersandcustomers/apigateway/common/SwaggerController.java +++ b/api-gateway-service/src/main/java/io/eventuate/examples/tram/sagas/ordersandcustomers/apigateway/common/SwaggerController.java @@ -7,7 +7,7 @@ @RestController public class SwaggerController { - @GetMapping("/swagger-ui.html") + @GetMapping("/swagger-ui/index.html") public Resource getFile() { return new ClassPathResource("META-INF/swagger-ui/index.html"); } diff --git a/api-gateway-service/src/main/resources/application.yml b/api-gateway-service/src/main/resources/application.yml index d09beb2a..a5a04311 100644 --- a/api-gateway-service/src/main/resources/application.yml +++ b/api-gateway-service/src/main/resources/application.yml @@ -1,3 +1,5 @@ + + spring.webflux.static-path-pattern: /** spring.application.name: api-gateway @@ -27,9 +29,15 @@ resilience4j.circuitbreaker: waitDurationInOpenState: 10000 failureRateThreshold: 60 +management: + endpoints: + web: + exposure: + include: "*" + spring: resources: - static-locations: classpath:/static, classpath:META-INF/swagger-ui + static-locations: classpath:/static, classpath:META-INF cloud: gateway: routes: diff --git a/customer-service/src/main/resources/application.properties b/customer-service/src/main/resources/application.properties index ec0b51f1..08de4366 100644 --- a/customer-service/src/main/resources/application.properties +++ b/customer-service/src/main/resources/application.properties @@ -15,3 +15,5 @@ spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.sleuth.enabled=true spring.sleuth.sampler.probability=1 spring.zipkin.base.url=http://${DOCKER_HOST_IP:localhost}:9411/ + +management.endpoints.web.exposure.include=* \ No newline at end of file diff --git a/end-to-end-tests/src/test/java/io/eventuate/examples/tram/sagas/ordersandcustomers/endtoendtests/CustomersAndOrdersE2ETest.java b/end-to-end-tests/src/test/java/io/eventuate/examples/tram/sagas/ordersandcustomers/endtoendtests/CustomersAndOrdersE2ETest.java index d886f045..a7f3edea 100644 --- a/end-to-end-tests/src/test/java/io/eventuate/examples/tram/sagas/ordersandcustomers/endtoendtests/CustomersAndOrdersE2ETest.java +++ b/end-to-end-tests/src/test/java/io/eventuate/examples/tram/sagas/ordersandcustomers/endtoendtests/CustomersAndOrdersE2ETest.java @@ -120,13 +120,13 @@ public void shouldSupportOrderHistory() { @Test public void testSwaggerUiUrls() throws IOException { - testSwaggerUiUrl(8081, "swagger-ui/index.html"); - testSwaggerUiUrl(8082, "swagger-ui/index.html"); - testSwaggerUiUrl(8083, "swagger-ui.html"); + testSwaggerUiUrl(8081); + testSwaggerUiUrl(8082); + testSwaggerUiUrl(8083); } - private void testSwaggerUiUrl(int port, String relativeUrl) throws IOException { - assertUrlStatusIsOk(String.format("http://%s:%s/%s", hostName, port, relativeUrl)); + private void testSwaggerUiUrl(int port) throws IOException { + assertUrlStatusIsOk(String.format("http://%s:%s/swagger-ui/index.html", hostName, port)); } private void assertUrlStatusIsOk(String url) throws IOException { diff --git a/order-service/src/main/resources/application.properties b/order-service/src/main/resources/application.properties index 1b95edf3..92f2e005 100644 --- a/order-service/src/main/resources/application.properties +++ b/order-service/src/main/resources/application.properties @@ -15,3 +15,5 @@ spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.sleuth.enabled=true spring.sleuth.sampler.probability=1 spring.zipkin.base.url=http://${DOCKER_HOST_IP:localhost}:9411/ + +management.endpoints.web.exposure.include=* \ No newline at end of file From cd4bd1d4aceb710727db1a24b967514ea2e369c7 Mon Sep 17 00:00:00 2001 From: Artem Sidorkin Date: Tue, 18 May 2021 17:29:21 +0300 Subject: [PATCH 3/4] Updated eventuate util version --- .../apigateway/common/SwaggerController.java | 14 -------------- .../src/main/resources/application.yml | 2 +- gradle.properties | 2 +- 3 files changed, 2 insertions(+), 16 deletions(-) delete mode 100644 api-gateway-service/src/main/java/io/eventuate/examples/tram/sagas/ordersandcustomers/apigateway/common/SwaggerController.java diff --git a/api-gateway-service/src/main/java/io/eventuate/examples/tram/sagas/ordersandcustomers/apigateway/common/SwaggerController.java b/api-gateway-service/src/main/java/io/eventuate/examples/tram/sagas/ordersandcustomers/apigateway/common/SwaggerController.java deleted file mode 100644 index 24e4d490..00000000 --- a/api-gateway-service/src/main/java/io/eventuate/examples/tram/sagas/ordersandcustomers/apigateway/common/SwaggerController.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.eventuate.examples.tram.sagas.ordersandcustomers.apigateway.common; - -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class SwaggerController { - @GetMapping("/swagger-ui/index.html") - public Resource getFile() { - return new ClassPathResource("META-INF/swagger-ui/index.html"); - } -} diff --git a/api-gateway-service/src/main/resources/application.yml b/api-gateway-service/src/main/resources/application.yml index a5a04311..6d3670f9 100644 --- a/api-gateway-service/src/main/resources/application.yml +++ b/api-gateway-service/src/main/resources/application.yml @@ -37,7 +37,7 @@ management: spring: resources: - static-locations: classpath:/static, classpath:META-INF + static-locations: classpath:/static, classpath:META-INF/static-content cloud: gateway: routes: diff --git a/gradle.properties b/gradle.properties index f9269866..085dd49f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ springBootVersion=2.2.6.RELEASE springCloudSleuthVersion=2.2.2.RELEASE springCloudGatewayVersion=2.2.2.RELEASE springCloudContractDependenciesVersion=2.2.0.RELEASE -eventuateUtilVersion=0.11.0-SNAPSHOT +eventuateUtilVersion=0.12.0.BUILD-SNAPSHOT eventuateTramSagasImageVersion=0.18.0.RELEASE From 88b86b7270008f85410408ca414da3dca630e326 Mon Sep 17 00:00:00 2001 From: Artem Sidorkin Date: Wed, 19 May 2021 15:12:29 +0300 Subject: [PATCH 4/4] Updated eventuate utils. --- .../endtoendtests/CustomersAndOrdersE2ETest.java | 12 ++---------- gradle.properties | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/end-to-end-tests/src/test/java/io/eventuate/examples/tram/sagas/ordersandcustomers/endtoendtests/CustomersAndOrdersE2ETest.java b/end-to-end-tests/src/test/java/io/eventuate/examples/tram/sagas/ordersandcustomers/endtoendtests/CustomersAndOrdersE2ETest.java index a7f3edea..068bdb4e 100644 --- a/end-to-end-tests/src/test/java/io/eventuate/examples/tram/sagas/ordersandcustomers/endtoendtests/CustomersAndOrdersE2ETest.java +++ b/end-to-end-tests/src/test/java/io/eventuate/examples/tram/sagas/ordersandcustomers/endtoendtests/CustomersAndOrdersE2ETest.java @@ -10,7 +10,7 @@ import io.eventuate.examples.tram.sagas.ordersandcustomers.orders.api.web.CreateOrderResponse; import io.eventuate.examples.tram.sagas.ordersandcustomers.orders.api.web.GetOrderResponse; import io.eventuate.util.test.async.Eventually; -import org.junit.Assert; +import io.eventuate.util.test.async.UrlTesting; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -23,8 +23,6 @@ import org.springframework.web.client.RestTemplate; import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertEquals; @@ -126,13 +124,7 @@ public void testSwaggerUiUrls() throws IOException { } private void testSwaggerUiUrl(int port) throws IOException { - assertUrlStatusIsOk(String.format("http://%s:%s/swagger-ui/index.html", hostName, port)); - } - - private void assertUrlStatusIsOk(String url) throws IOException { - HttpURLConnection connection = (HttpURLConnection)new URL(url).openConnection(); - - Assert.assertEquals(200, connection.getResponseCode()); + UrlTesting.assertUrlStatusIsOk("localhost", port, "/swagger-ui/index.html"); } private void assertOrderState(Long id, OrderState expectedState, RejectionReason expectedRejectionReason) { diff --git a/gradle.properties b/gradle.properties index 085dd49f..35b1c087 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ springBootVersion=2.2.6.RELEASE springCloudSleuthVersion=2.2.2.RELEASE springCloudGatewayVersion=2.2.2.RELEASE springCloudContractDependenciesVersion=2.2.0.RELEASE -eventuateUtilVersion=0.12.0.BUILD-SNAPSHOT +eventuateUtilVersion=0.12.0.RELEASE eventuateTramSagasImageVersion=0.18.0.RELEASE