Skip to content

Commit b13a444

Browse files
committed
#51 Replace shared API classes with codegen from OpenAPI/JSON schema - Used JSON schema for Restaurant events in Delivery Service
1 parent a6f077a commit b13a444

File tree

6 files changed

+50
-8
lines changed

6 files changed

+50
-8
lines changed

ftgo-delivery-service/build.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ apply plugin: 'docker-compose'
77

88
apply plugin: IntegrationTestsPlugin
99
apply plugin: ComponentTestsPlugin
10+
apply plugin: FtgoJSONSchema2PojoPlugin
1011

1112
dependencies {
13+
ftgoApiSpecification project(":ftgo-restaurant-service-api-spec")
14+
1215
compile project(":ftgo-delivery-service-api")
1316
compile project(":ftgo-kitchen-service-api")
14-
compile project(":ftgo-restaurant-service-api")
17+
compile project(":ftgo-restaurant-service-api-temp")
1518
compile project(":ftgo-order-service-api")
1619
compile project(":ftgo-common")
1720
compile project(":ftgo-common-jpa")
@@ -45,3 +48,15 @@ dockerCompose {
4548

4649
componentTestsComposeUp.dependsOn(assemble)
4750
dockerCompose.componentTests.isRequiredBy(componentTest)
51+
52+
ftgoJsonSchema2Pojo {
53+
54+
ftgoRestaurantService {
55+
source = files("${ftgoApiSpecsDir}/ftgo-restaurant-service-api-spec")
56+
targetPackage = "net.chrisrichardson.ftgo.restaurantservice.events"
57+
includeAdditionalProperties = false
58+
generateBuilders = true
59+
useLongIntegers = true
60+
}
61+
62+
}

ftgo-delivery-service/src/component-test/java/net/chrisrichardson/ftgo/deliveryservice/DeliveryServiceInProcessComponentTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import net.chrisrichardson.ftgo.orderservice.api.events.OrderCreatedEvent;
1313
import net.chrisrichardson.ftgo.orderservice.api.events.OrderDetails;
1414
import net.chrisrichardson.ftgo.restaurantservice.RestaurantServiceChannels;
15-
import net.chrisrichardson.ftgo.restaurantservice.events.RestaurantCreated;
1615
import org.junit.Test;
1716
import org.junit.runner.RunWith;
1817
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,7 +20,6 @@
2120
import org.springframework.boot.web.server.LocalServerPort;
2221
import org.springframework.context.annotation.Configuration;
2322
import org.springframework.context.annotation.Import;
24-
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
2523
import org.springframework.test.context.junit4.SpringRunner;
2624

2725
import java.util.Collections;
@@ -120,7 +118,8 @@ private void createOrder() {
120118
private void createRestaurant() {
121119
restaurantId = System.currentTimeMillis();
122120

123-
domainEventPublisher.publish(RestaurantServiceChannels.RESTAURANT_EVENT_CHANNEL, restaurantId, Collections.singletonList(new RestaurantCreated("Delicious Indian", DeliveryServiceTestData.PICKUP_ADDRESS, null)));
121+
domainEventPublisher.publish(RestaurantServiceChannels.RESTAURANT_EVENT_CHANNEL, restaurantId,
122+
Collections.singletonList(RestaurantEventMother.makeRestaurantCreated()));
124123

125124
eventually(() -> assertTrue(restaurantRepository.findById(restaurantId).isPresent()));
126125
}

ftgo-delivery-service/src/component-test/java/net/chrisrichardson/ftgo/deliveryservice/DeliveryServiceOutOfProcessComponentTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import net.chrisrichardson.ftgo.orderservice.api.events.OrderCreatedEvent;
99
import net.chrisrichardson.ftgo.orderservice.api.events.OrderDetails;
1010
import net.chrisrichardson.ftgo.restaurantservice.RestaurantServiceChannels;
11-
import net.chrisrichardson.ftgo.restaurantservice.events.RestaurantCreated;
1211
import org.junit.Test;
1312
import org.junit.runner.RunWith;
1413
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,7 +23,8 @@
2423

2524
import static com.jayway.restassured.RestAssured.given;
2625
import static io.eventuate.util.test.async.Eventually.eventually;
27-
import static org.junit.Assert.*;
26+
import static org.junit.Assert.assertEquals;
27+
import static org.junit.Assert.assertNotNull;
2828

2929
@RunWith(SpringRunner.class)
3030
@SpringBootTest(classes = DeliveryServiceOutOfProcessComponentTest.Config.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@@ -106,7 +106,7 @@ private void createOrder() {
106106
private void createRestaurant() {
107107
restaurantId = System.currentTimeMillis();
108108

109-
domainEventPublisher.publish(RestaurantServiceChannels.RESTAURANT_EVENT_CHANNEL, restaurantId, Collections.singletonList(new RestaurantCreated("Delicious Indian", DeliveryServiceTestData.PICKUP_ADDRESS, null)));
109+
domainEventPublisher.publish(RestaurantServiceChannels.RESTAURANT_EVENT_CHANNEL, restaurantId, Collections.singletonList(RestaurantEventMother.makeRestaurantCreated()));
110110

111111
sleep();
112112
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package net.chrisrichardson.ftgo.deliveryservice;
2+
3+
import net.chrisrichardson.ftgo.deliveryservice.domain.DeliveryServiceTestData;
4+
import net.chrisrichardson.ftgo.deliveryservice.messaging.RestaurantEventMapper;
5+
import net.chrisrichardson.ftgo.restaurantservice.events.RestaurantCreated;
6+
7+
public class RestaurantEventMother {
8+
static RestaurantCreated makeRestaurantCreated() {
9+
return new RestaurantCreated()
10+
.withName("Delicious Indian")
11+
.withAddress(RestaurantEventMapper.fromAddress(DeliveryServiceTestData.PICKUP_ADDRESS)).withMenu(null);
12+
}
13+
}

ftgo-delivery-service/src/main/java/net/chrisrichardson/ftgo/deliveryservice/messaging/DeliveryMessageHandlers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public DomainEventHandlers domainEventHandlers() {
3636
}
3737

3838
public void handleRestaurantCreated(DomainEventEnvelope<RestaurantCreated> dee) {
39-
Address address = dee.getEvent().getAddress();
39+
Address address = RestaurantEventMapper.toAddress(dee.getEvent().getAddress());
4040
deliveryService.createRestaurant(Long.parseLong(dee.getAggregateId()), dee.getEvent().getName(), address);
4141
}
4242

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package net.chrisrichardson.ftgo.deliveryservice.messaging;
2+
3+
import net.chrisrichardson.ftgo.common.Address;
4+
5+
public class RestaurantEventMapper {
6+
7+
public static Address toAddress(net.chrisrichardson.ftgo.restaurantservice.events.Address address) {
8+
return new Address(address.getStreet1(), address.getStreet2(), address.getCity(), address.getState(), address.getZip());
9+
}
10+
11+
public static net.chrisrichardson.ftgo.restaurantservice.events.Address fromAddress(net.chrisrichardson.ftgo.common.Address a) {
12+
return new net.chrisrichardson.ftgo.restaurantservice.events.Address().withStreet1(a.getStreet1()).withStreet2(a.getStreet2()).withCity(a.getCity()).withZip(a.getZip());
13+
}
14+
15+
}

0 commit comments

Comments
 (0)