Skip to content

Commit 173e5f2

Browse files
committed
More tests for Delivery Service, disabled broken GraphQL-based API Gateway in build
1 parent 0006cdd commit 173e5f2

File tree

18 files changed

+326
-39
lines changed

18 files changed

+326
-39
lines changed

build-and-test-all.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ fi
8585
./run-end-to-end-tests.sh
8686

8787

88-
./run-graphql-api-gateway-tests.sh
88+
# NEED TO FIX
89+
# ./run-graphql-api-gateway-tests.sh
8990

9091
if [ -z "$KEEP_RUNNING" ] ; then
9192
${DOCKER_COMPOSE?} down --remove-orphans -v
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: '3'
2+
services:
3+
ftgo-api-gateway-graphql:
4+
build: ./ftgo-api-gateway-graphql
5+
ports:
6+
- "8088:3000"
7+
environment:
8+
ORDER_HISTORY_SERVICE_URL: http://ftgo-order-history-service:8080
9+
CONSUMER_SERVICE_URL: http://ftgo-consumer-service:8080
10+
RESTAURANT_SERVICE_URL: http://ftgo-restaurant-service:8080

docker-compose.yml

+4-8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ services:
6060
EVENTUATE_CDC_PIPELINE_PIPELINE7_READER: reader1
6161
EVENTUATE_CDC_PIPELINE_PIPELINE7_EVENTUATEDATABASESCHEMA: ftgo_accounting_service
6262

63+
EVENTUATE_CDC_PIPELINE_PIPELINE8_TYPE: eventuate-tram
64+
EVENTUATE_CDC_PIPELINE_PIPELINE8_READER: reader1
65+
EVENTUATE_CDC_PIPELINE_PIPELINE8_EVENTUATEDATABASESCHEMA: ftgo_delivery_service
66+
6367
EVENTUATE_CDC_READER_READER1_TYPE: mysql-binlog
6468
EVENTUATE_CDC_READER_READER1_DATASOURCEURL: jdbc:mysql://mysql:3306/eventuate
6569
EVENTUATE_CDC_READER_READER1_DATASOURCEUSERNAME: root
@@ -217,14 +221,6 @@ services:
217221
SPRING_SLEUTH_SAMPLER_PROBABILITY: 1
218222
SPRING_ZIPKIN_BASE_URL: http://zipkin:9411/
219223

220-
ftgo-api-gateway-graphql:
221-
build: ./ftgo-api-gateway-graphql
222-
ports:
223-
- "8088:3000"
224-
environment:
225-
ORDER_HISTORY_SERVICE_URL: http://ftgo-order-history-service:8080
226-
CONSUMER_SERVICE_URL: http://ftgo-consumer-service:8080
227-
RESTAURANT_SERVICE_URL: http://ftgo-restaurant-service:8080
228224

229225
zipkin:
230226
image: openzipkin/zipkin:2.5.0

ftgo-api-gateway/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ dependencies {
4747
compile 'org.springframework.cloud:spring-cloud-starter-gateway'
4848
compile "org.apache.commons:commons-lang3:3.6"
4949

50-
compile 'org.springframework.cloud:spring-cloud-starter-sleuth'
51-
compile 'org.springframework.cloud:spring-cloud-starter-zipkin'
52-
compile 'io.zipkin.brave:brave-bom:4.17.1'
50+
// compile 'org.springframework.cloud:spring-cloud-starter-sleuth'
51+
//compile 'org.springframework.cloud:spring-cloud-starter-zipkin'
52+
// compile 'io.zipkin.brave:brave-bom:4.17.1'
5353

5454
compile "io.micrometer:micrometer-registry-prometheus:$micrometerVersion"
5555
compile "org.springframework.boot:spring-boot-starter-actuator"

ftgo-api-gateway/src/test/java/net/chrisrichardson/ftgo/apiagateway/ApiGatewayIntegrationTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ public class ApiGatewayIntegrationTest {
4848
@Test
4949
public void shouldProxyCreateOrder() {
5050

51+
String expectedResponse = "{}";
52+
5153
stubFor(post(urlEqualTo("/orders"))
5254
.willReturn(aResponse()
5355
.withStatus(200)
54-
.withHeader("Content-Type", "text/xml")
55-
.withBody("<response>Some content</response>")));
56+
.withHeader("Content-Type", "application/json")
57+
.withBody(expectedResponse)));
5658

5759

5860
WebClient client = WebClient.create("http://localhost:" + port + "/orders");
@@ -66,7 +68,7 @@ public void shouldProxyCreateOrder() {
6668

6769
assertNotNull(z);
6870
assertEquals(HttpStatus.OK, z.getStatusCode());
69-
assertEquals("<response>Some content</response>", z.getBody());
71+
assertEquals(expectedResponse, z.getBody());
7072

7173
verify(postRequestedFor(urlMatching("/orders")));
7274

ftgo-api-gateway/src/test/java/net/chrisrichardson/ftgo/apiagateway/contract/OrderServiceProxyIntegrationTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public class OrderServiceProxyIntegrationTest {
3434
public void setUp() throws Exception {
3535
orderDestinations = new OrderDestinations();
3636
String orderServiceUrl = "http://localhost:" + port;
37-
System.out.println("orderServiceUrl=" + orderServiceUrl);
3837
orderDestinations.setOrderServiceUrl(orderServiceUrl);
3938
orderService = new OrderServiceProxy(orderDestinations, WebClient.create());
4039
}

ftgo-delivery-service/build.gradle

+19-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ dependencies {
2424
compile "io.micrometer:micrometer-registry-prometheus:$micrometerVersion"
2525

2626
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
27+
testCompile "io.eventuate.tram.core:eventuate-tram-in-memory:$eventuateTramVersion"
28+
testCompile "io.eventuate.util:eventuate-util-test:$eventuateUtilVersion"
2729

30+
componentTestCompile "com.jayway.restassured:rest-assured:$restAssuredVersion"
31+
componentTestCompile "com.jayway.jsonpath:json-path:2.3.0"
32+
33+
34+
}
35+
36+
dockerCompose {
37+
38+
componentTests {
39+
startedServices = [ 'ftgo-delivery-service']
40+
stopContainers = true
41+
}
42+
43+
}
44+
45+
componentTestsComposeUp.dependsOn(assemble)
46+
dockerCompose.componentTests.isRequiredBy(componentTest)
2847

29-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package net.chrisrichardson.ftgo.deliveryservice;
2+
3+
import io.eventuate.tram.events.publisher.DomainEventPublisher;
4+
import io.eventuate.tram.events.publisher.TramEventsPublisherConfiguration;
5+
import io.eventuate.tram.inmemory.TramInMemoryConfiguration;
6+
import net.chrisrichardson.ftgo.deliveryservice.domain.DeliveryRepository;
7+
import net.chrisrichardson.ftgo.deliveryservice.domain.DeliveryServiceTestData;
8+
import net.chrisrichardson.ftgo.deliveryservice.domain.RestaurantRepository;
9+
import net.chrisrichardson.ftgo.deliveryservice.messaging.DeliveryServiceMessagingConfiguration;
10+
import net.chrisrichardson.ftgo.deliveryservice.web.DeliveryServiceWebConfiguration;
11+
import net.chrisrichardson.ftgo.orderservice.api.OrderServiceChannels;
12+
import net.chrisrichardson.ftgo.orderservice.api.events.OrderCreatedEvent;
13+
import net.chrisrichardson.ftgo.orderservice.api.events.OrderDetails;
14+
import net.chrisrichardson.ftgo.restaurantservice.RestaurantServiceChannels;
15+
import net.chrisrichardson.ftgo.restaurantservice.events.RestaurantCreated;
16+
import org.junit.Test;
17+
import org.junit.runner.RunWith;
18+
import org.springframework.beans.factory.annotation.Autowired;
19+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
20+
import org.springframework.boot.test.context.SpringBootTest;
21+
import org.springframework.boot.web.server.LocalServerPort;
22+
import org.springframework.context.annotation.Configuration;
23+
import org.springframework.context.annotation.Import;
24+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
25+
import org.springframework.test.context.junit4.SpringRunner;
26+
27+
import java.util.Collections;
28+
29+
import static com.jayway.restassured.RestAssured.given;
30+
import static io.eventuate.util.test.async.Eventually.eventually;
31+
import static org.junit.Assert.*;
32+
33+
@RunWith(SpringRunner.class)
34+
@SpringBootTest(classes = DeliveryServiceInProcessComponentTest.Config.class,
35+
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
36+
public class DeliveryServiceInProcessComponentTest {
37+
38+
private long restaurantId;
39+
private long orderId;
40+
41+
@Configuration
42+
@EnableJpaRepositories
43+
@EnableAutoConfiguration
44+
@Import({DeliveryServiceMessagingConfiguration.class,
45+
DeliveryServiceWebConfiguration.class,
46+
TramInMemoryConfiguration.class,
47+
TramEventsPublisherConfiguration.class
48+
})
49+
public static class Config {
50+
}
51+
52+
@LocalServerPort
53+
private int port;
54+
55+
private String host = "localhost";
56+
57+
@Autowired
58+
private DomainEventPublisher domainEventPublisher;
59+
60+
@Autowired
61+
private RestaurantRepository restaurantRepository;
62+
63+
@Autowired
64+
private DeliveryRepository deliveryRepository;
65+
66+
@Test
67+
public void shouldScheduleDelivery() {
68+
69+
createRestaurant();
70+
71+
createOrder();
72+
73+
assertDeliveryCreated();
74+
75+
// createCourier
76+
// acceptTicket
77+
// TicketCancelled
78+
}
79+
80+
private String baseUrl(int port, String path, String... pathElements) {
81+
assertNotNull("host", host);
82+
83+
StringBuilder sb = new StringBuilder("http://");
84+
sb.append(host);
85+
sb.append(":");
86+
sb.append(port);
87+
sb.append("/");
88+
sb.append(path);
89+
90+
for (String pe : pathElements) {
91+
sb.append("/");
92+
sb.append(pe);
93+
}
94+
String s = sb.toString();
95+
System.out.println("url=" + s);
96+
return s;
97+
}
98+
99+
100+
private void assertDeliveryCreated() {
101+
102+
String state = given().
103+
when().
104+
get(baseUrl(port, "deliveries", Long.toString(orderId))).
105+
then().
106+
statusCode(200).extract().path("deliveryInfo.state");
107+
108+
assertEquals("PENDING", state);
109+
}
110+
111+
private void createOrder() {
112+
orderId = System.currentTimeMillis();
113+
domainEventPublisher.publish(OrderServiceChannels.ORDER_EVENT_CHANNEL, orderId, Collections.singletonList(
114+
new OrderCreatedEvent(new OrderDetails(0L, restaurantId, null, null),
115+
DeliveryServiceTestData.DELIVERY_ADDRESS, null)));
116+
eventually(() -> assertTrue(deliveryRepository.findById(orderId).isPresent()));
117+
118+
119+
}
120+
121+
private void createRestaurant() {
122+
restaurantId = System.currentTimeMillis();
123+
124+
domainEventPublisher.publish(RestaurantServiceChannels.RESTAURANT_EVENT_CHANNEL, restaurantId, Collections.singletonList(new RestaurantCreated("Delicious Indian", DeliveryServiceTestData.PICKUP_ADDRESS, null)));
125+
126+
eventually(() -> assertTrue(restaurantRepository.findById(restaurantId).isPresent()));
127+
}
128+
129+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package net.chrisrichardson.ftgo.deliveryservice;
2+
3+
import io.eventuate.tram.events.publisher.DomainEventPublisher;
4+
import io.eventuate.tram.events.publisher.TramEventsPublisherConfiguration;
5+
import io.eventuate.tram.jdbckafka.TramJdbcKafkaConfiguration;
6+
import net.chrisrichardson.ftgo.deliveryservice.domain.DeliveryServiceTestData;
7+
import net.chrisrichardson.ftgo.orderservice.api.OrderServiceChannels;
8+
import net.chrisrichardson.ftgo.orderservice.api.events.OrderCreatedEvent;
9+
import net.chrisrichardson.ftgo.orderservice.api.events.OrderDetails;
10+
import net.chrisrichardson.ftgo.restaurantservice.RestaurantServiceChannels;
11+
import net.chrisrichardson.ftgo.restaurantservice.events.RestaurantCreated;
12+
import org.junit.Test;
13+
import org.junit.runner.RunWith;
14+
import org.springframework.beans.factory.annotation.Autowired;
15+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
16+
import org.springframework.boot.test.context.SpringBootTest;
17+
import org.springframework.context.annotation.Configuration;
18+
import org.springframework.context.annotation.Import;
19+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
20+
import org.springframework.test.context.junit4.SpringRunner;
21+
22+
import java.util.Collections;
23+
import java.util.concurrent.TimeUnit;
24+
25+
import static com.jayway.restassured.RestAssured.given;
26+
import static io.eventuate.util.test.async.Eventually.eventually;
27+
import static org.junit.Assert.*;
28+
29+
@RunWith(SpringRunner.class)
30+
@SpringBootTest(classes = DeliveryServiceOutOfProcessComponentTest.Config.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
31+
public class DeliveryServiceOutOfProcessComponentTest {
32+
33+
@Configuration
34+
@EnableJpaRepositories
35+
@EnableAutoConfiguration
36+
@Import({TramJdbcKafkaConfiguration.class, TramEventsPublisherConfiguration.class
37+
})
38+
public static class Config {
39+
}
40+
41+
private String host = System.getenv("DOCKER_HOST_IP");
42+
private int port = 8089;
43+
private long restaurantId;
44+
private long orderId;
45+
46+
@Autowired
47+
private DomainEventPublisher domainEventPublisher;
48+
49+
// Duplication
50+
51+
private String baseUrl(int port, String path, String... pathElements) {
52+
assertNotNull("host", host);
53+
54+
StringBuilder sb = new StringBuilder("http://");
55+
sb.append(host);
56+
sb.append(":");
57+
sb.append(port);
58+
sb.append("/");
59+
sb.append(path);
60+
61+
for (String pe : pathElements) {
62+
sb.append("/");
63+
sb.append(pe);
64+
}
65+
String s = sb.toString();
66+
System.out.println("url=" + s);
67+
return s;
68+
}
69+
70+
@Test
71+
public void shouldScheduleDelivery() {
72+
73+
createRestaurant();
74+
75+
createOrder();
76+
77+
assertDeliveryCreated();
78+
79+
// createCourier
80+
// acceptTicket
81+
// TicketCancelled
82+
}
83+
84+
private void assertDeliveryCreated() {
85+
86+
eventually(() -> {
87+
String state = given().
88+
when().
89+
get(baseUrl(port, "deliveries", Long.toString(orderId))).
90+
then().
91+
statusCode(200).extract().path("deliveryInfo.state");
92+
93+
assertEquals("PENDING", state);
94+
});
95+
}
96+
97+
private void createOrder() {
98+
orderId = System.currentTimeMillis();
99+
domainEventPublisher.publish(OrderServiceChannels.ORDER_EVENT_CHANNEL, orderId, Collections.singletonList(
100+
new OrderCreatedEvent(new OrderDetails(0L, restaurantId, null, null),
101+
DeliveryServiceTestData.DELIVERY_ADDRESS, null)));
102+
103+
104+
}
105+
106+
private void createRestaurant() {
107+
restaurantId = System.currentTimeMillis();
108+
109+
domainEventPublisher.publish(RestaurantServiceChannels.RESTAURANT_EVENT_CHANNEL, restaurantId, Collections.singletonList(new RestaurantCreated("Delicious Indian", DeliveryServiceTestData.PICKUP_ADDRESS, null)));
110+
111+
sleep();
112+
}
113+
114+
private void sleep() {
115+
try {
116+
TimeUnit.SECONDS.sleep(5);
117+
} catch (InterruptedException e) {
118+
throw new RuntimeException(e);
119+
}
120+
}
121+
122+
}

0 commit comments

Comments
 (0)