Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
More tests for Delivery Service, disabled broken GraphQL-based API Ga…
…teway in build
- Loading branch information
Showing
18 changed files
with
326 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: '3' | ||
services: | ||
ftgo-api-gateway-graphql: | ||
build: ./ftgo-api-gateway-graphql | ||
ports: | ||
- "8088:3000" | ||
environment: | ||
ORDER_HISTORY_SERVICE_URL: http://ftgo-order-history-service:8080 | ||
CONSUMER_SERVICE_URL: http://ftgo-consumer-service:8080 | ||
RESTAURANT_SERVICE_URL: http://ftgo-restaurant-service:8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
.../java/net/chrisrichardson/ftgo/deliveryservice/DeliveryServiceInProcessComponentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package net.chrisrichardson.ftgo.deliveryservice; | ||
|
||
import io.eventuate.tram.events.publisher.DomainEventPublisher; | ||
import io.eventuate.tram.events.publisher.TramEventsPublisherConfiguration; | ||
import io.eventuate.tram.inmemory.TramInMemoryConfiguration; | ||
import net.chrisrichardson.ftgo.deliveryservice.domain.DeliveryRepository; | ||
import net.chrisrichardson.ftgo.deliveryservice.domain.DeliveryServiceTestData; | ||
import net.chrisrichardson.ftgo.deliveryservice.domain.RestaurantRepository; | ||
import net.chrisrichardson.ftgo.deliveryservice.messaging.DeliveryServiceMessagingConfiguration; | ||
import net.chrisrichardson.ftgo.deliveryservice.web.DeliveryServiceWebConfiguration; | ||
import net.chrisrichardson.ftgo.orderservice.api.OrderServiceChannels; | ||
import net.chrisrichardson.ftgo.orderservice.api.events.OrderCreatedEvent; | ||
import net.chrisrichardson.ftgo.orderservice.api.events.OrderDetails; | ||
import net.chrisrichardson.ftgo.restaurantservice.RestaurantServiceChannels; | ||
import net.chrisrichardson.ftgo.restaurantservice.events.RestaurantCreated; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.web.server.LocalServerPort; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import java.util.Collections; | ||
|
||
import static com.jayway.restassured.RestAssured.given; | ||
import static io.eventuate.util.test.async.Eventually.eventually; | ||
import static org.junit.Assert.*; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(classes = DeliveryServiceInProcessComponentTest.Config.class, | ||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class DeliveryServiceInProcessComponentTest { | ||
|
||
private long restaurantId; | ||
private long orderId; | ||
|
||
@Configuration | ||
@EnableJpaRepositories | ||
@EnableAutoConfiguration | ||
@Import({DeliveryServiceMessagingConfiguration.class, | ||
DeliveryServiceWebConfiguration.class, | ||
TramInMemoryConfiguration.class, | ||
TramEventsPublisherConfiguration.class | ||
}) | ||
public static class Config { | ||
} | ||
|
||
@LocalServerPort | ||
private int port; | ||
|
||
private String host = "localhost"; | ||
|
||
@Autowired | ||
private DomainEventPublisher domainEventPublisher; | ||
|
||
@Autowired | ||
private RestaurantRepository restaurantRepository; | ||
|
||
@Autowired | ||
private DeliveryRepository deliveryRepository; | ||
|
||
@Test | ||
public void shouldScheduleDelivery() { | ||
|
||
createRestaurant(); | ||
|
||
createOrder(); | ||
|
||
assertDeliveryCreated(); | ||
|
||
// createCourier | ||
// acceptTicket | ||
// TicketCancelled | ||
} | ||
|
||
private String baseUrl(int port, String path, String... pathElements) { | ||
assertNotNull("host", host); | ||
|
||
StringBuilder sb = new StringBuilder("http://"); | ||
sb.append(host); | ||
sb.append(":"); | ||
sb.append(port); | ||
sb.append("/"); | ||
sb.append(path); | ||
|
||
for (String pe : pathElements) { | ||
sb.append("/"); | ||
sb.append(pe); | ||
} | ||
String s = sb.toString(); | ||
System.out.println("url=" + s); | ||
return s; | ||
} | ||
|
||
|
||
private void assertDeliveryCreated() { | ||
|
||
String state = given(). | ||
when(). | ||
get(baseUrl(port, "deliveries", Long.toString(orderId))). | ||
then(). | ||
statusCode(200).extract().path("deliveryInfo.state"); | ||
|
||
assertEquals("PENDING", state); | ||
} | ||
|
||
private void createOrder() { | ||
orderId = System.currentTimeMillis(); | ||
domainEventPublisher.publish(OrderServiceChannels.ORDER_EVENT_CHANNEL, orderId, Collections.singletonList( | ||
new OrderCreatedEvent(new OrderDetails(0L, restaurantId, null, null), | ||
DeliveryServiceTestData.DELIVERY_ADDRESS, null))); | ||
eventually(() -> assertTrue(deliveryRepository.findById(orderId).isPresent())); | ||
|
||
|
||
} | ||
|
||
private void createRestaurant() { | ||
restaurantId = System.currentTimeMillis(); | ||
|
||
domainEventPublisher.publish(RestaurantServiceChannels.RESTAURANT_EVENT_CHANNEL, restaurantId, Collections.singletonList(new RestaurantCreated("Delicious Indian", DeliveryServiceTestData.PICKUP_ADDRESS, null))); | ||
|
||
eventually(() -> assertTrue(restaurantRepository.findById(restaurantId).isPresent())); | ||
} | ||
|
||
} |
122 changes: 122 additions & 0 deletions
122
...va/net/chrisrichardson/ftgo/deliveryservice/DeliveryServiceOutOfProcessComponentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package net.chrisrichardson.ftgo.deliveryservice; | ||
|
||
import io.eventuate.tram.events.publisher.DomainEventPublisher; | ||
import io.eventuate.tram.events.publisher.TramEventsPublisherConfiguration; | ||
import io.eventuate.tram.jdbckafka.TramJdbcKafkaConfiguration; | ||
import net.chrisrichardson.ftgo.deliveryservice.domain.DeliveryServiceTestData; | ||
import net.chrisrichardson.ftgo.orderservice.api.OrderServiceChannels; | ||
import net.chrisrichardson.ftgo.orderservice.api.events.OrderCreatedEvent; | ||
import net.chrisrichardson.ftgo.orderservice.api.events.OrderDetails; | ||
import net.chrisrichardson.ftgo.restaurantservice.RestaurantServiceChannels; | ||
import net.chrisrichardson.ftgo.restaurantservice.events.RestaurantCreated; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import java.util.Collections; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static com.jayway.restassured.RestAssured.given; | ||
import static io.eventuate.util.test.async.Eventually.eventually; | ||
import static org.junit.Assert.*; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(classes = DeliveryServiceOutOfProcessComponentTest.Config.class, webEnvironment = SpringBootTest.WebEnvironment.NONE) | ||
public class DeliveryServiceOutOfProcessComponentTest { | ||
|
||
@Configuration | ||
@EnableJpaRepositories | ||
@EnableAutoConfiguration | ||
@Import({TramJdbcKafkaConfiguration.class, TramEventsPublisherConfiguration.class | ||
}) | ||
public static class Config { | ||
} | ||
|
||
private String host = System.getenv("DOCKER_HOST_IP"); | ||
private int port = 8089; | ||
private long restaurantId; | ||
private long orderId; | ||
|
||
@Autowired | ||
private DomainEventPublisher domainEventPublisher; | ||
|
||
// Duplication | ||
|
||
private String baseUrl(int port, String path, String... pathElements) { | ||
assertNotNull("host", host); | ||
|
||
StringBuilder sb = new StringBuilder("http://"); | ||
sb.append(host); | ||
sb.append(":"); | ||
sb.append(port); | ||
sb.append("/"); | ||
sb.append(path); | ||
|
||
for (String pe : pathElements) { | ||
sb.append("/"); | ||
sb.append(pe); | ||
} | ||
String s = sb.toString(); | ||
System.out.println("url=" + s); | ||
return s; | ||
} | ||
|
||
@Test | ||
public void shouldScheduleDelivery() { | ||
|
||
createRestaurant(); | ||
|
||
createOrder(); | ||
|
||
assertDeliveryCreated(); | ||
|
||
// createCourier | ||
// acceptTicket | ||
// TicketCancelled | ||
} | ||
|
||
private void assertDeliveryCreated() { | ||
|
||
eventually(() -> { | ||
String state = given(). | ||
when(). | ||
get(baseUrl(port, "deliveries", Long.toString(orderId))). | ||
then(). | ||
statusCode(200).extract().path("deliveryInfo.state"); | ||
|
||
assertEquals("PENDING", state); | ||
}); | ||
} | ||
|
||
private void createOrder() { | ||
orderId = System.currentTimeMillis(); | ||
domainEventPublisher.publish(OrderServiceChannels.ORDER_EVENT_CHANNEL, orderId, Collections.singletonList( | ||
new OrderCreatedEvent(new OrderDetails(0L, restaurantId, null, null), | ||
DeliveryServiceTestData.DELIVERY_ADDRESS, null))); | ||
|
||
|
||
} | ||
|
||
private void createRestaurant() { | ||
restaurantId = System.currentTimeMillis(); | ||
|
||
domainEventPublisher.publish(RestaurantServiceChannels.RESTAURANT_EVENT_CHANNEL, restaurantId, Collections.singletonList(new RestaurantCreated("Delicious Indian", DeliveryServiceTestData.PICKUP_ADDRESS, null))); | ||
|
||
sleep(); | ||
} | ||
|
||
private void sleep() { | ||
try { | ||
TimeUnit.SECONDS.sleep(5); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.