Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#54: swagger ui is not available for api-gateway. Fixed. Added tests … #55

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions api-gateway-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

This file was deleted.

10 changes: 9 additions & 1 deletion api-gateway-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


spring.webflux.static-path-pattern: /**

spring.application.name: api-gateway
Expand Down Expand Up @@ -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/static-content
cloud:
gateway:
routes:
Expand Down
2 changes: 2 additions & 0 deletions customer-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=*
Original file line number Diff line number Diff line change
Expand Up @@ -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 io.eventuate.util.test.async.UrlTesting;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -21,6 +22,9 @@
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

Expand Down Expand Up @@ -94,7 +98,7 @@ public void shouldSupportOrderHistory() {
new CreateOrderRequest(createCustomerResponse.getCustomerId(), new Money("100.00")),
CreateOrderResponse.class);

Eventually.eventually(() -> {
Eventually.eventually(60, 500, TimeUnit.MILLISECONDS, () -> {
ResponseEntity<GetCustomerHistoryResponse> customerResponseEntity =
restTemplate.getForEntity(baseUrl("customers", Long.toString(createCustomerResponse.getCustomerId()), "orderhistory"),
GetCustomerHistoryResponse.class);
Expand All @@ -112,8 +116,19 @@ public void shouldSupportOrderHistory() {
});
}

@Test
public void testSwaggerUiUrls() throws IOException {
testSwaggerUiUrl(8081);
testSwaggerUiUrl(8082);
testSwaggerUiUrl(8083);
}

private void testSwaggerUiUrl(int port) throws IOException {
UrlTesting.assertUrlStatusIsOk("localhost", port, "/swagger-ui/index.html");
}

private void assertOrderState(Long id, OrderState expectedState, RejectionReason expectedRejectionReason) {
Eventually.eventually(() -> {
Eventually.eventually(60, 500, TimeUnit.MILLISECONDS, () -> {
ResponseEntity<GetOrderResponse> getOrderResponseEntity = restTemplate.getForEntity(baseUrl("orders/" + id), GetOrderResponse.class);
assertEquals(HttpStatus.OK, getOrderResponseEntity.getStatusCode());
GetOrderResponse order = getOrderResponseEntity.getBody();
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.12.0.RELEASE

eventuateTramSagasImageVersion=0.18.0.RELEASE

Expand Down
2 changes: 2 additions & 0 deletions order-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=*