From 712a7494fb9186b3203203318841682781969287 Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Thu, 14 Nov 2019 22:56:55 -0800 Subject: [PATCH 1/3] Experiment with Skaffold + Local Kubernetes --- .../ftgo-kafka-deployment.yml | 2 +- .../ftgo-zookeeper-deployment.yml | 2 +- .../kubernetes/ftgo-consumer-service.yml | 2 +- skaffold.yaml | 20 +++++++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 skaffold.yaml diff --git a/deployment/kubernetes/stateful-services/ftgo-kafka-deployment.yml b/deployment/kubernetes/stateful-services/ftgo-kafka-deployment.yml index e1bb7863..c9318b41 100644 --- a/deployment/kubernetes/stateful-services/ftgo-kafka-deployment.yml +++ b/deployment/kubernetes/stateful-services/ftgo-kafka-deployment.yml @@ -26,7 +26,7 @@ spec: terminationGracePeriodSeconds: 10 containers: - name: ftgo-kafka - image: eventuateio/eventuateio-local-kafka:0.14.0 + image: eventuateio/eventuate-kafka:0.3.0.RELEASE env: - name: KAFKA_HEAP_OPTS value: -Xmx320m -Xms320m diff --git a/deployment/kubernetes/stateful-services/ftgo-zookeeper-deployment.yml b/deployment/kubernetes/stateful-services/ftgo-zookeeper-deployment.yml index d300ab39..fc5def7f 100644 --- a/deployment/kubernetes/stateful-services/ftgo-zookeeper-deployment.yml +++ b/deployment/kubernetes/stateful-services/ftgo-zookeeper-deployment.yml @@ -27,7 +27,7 @@ spec: terminationGracePeriodSeconds: 10 containers: - name: ftgo-zookeeper - image: eventuateio/eventuateio-local-zookeeper:0.14.0 + image: eventuateio/eventuate-zookeeper:0.4.0.RELEASE ports: - containerPort: 2181 volumeMounts: diff --git a/ftgo-consumer-service/src/deployment/kubernetes/ftgo-consumer-service.yml b/ftgo-consumer-service/src/deployment/kubernetes/ftgo-consumer-service.yml index e5caa055..7d3b3acf 100644 --- a/ftgo-consumer-service/src/deployment/kubernetes/ftgo-consumer-service.yml +++ b/ftgo-consumer-service/src/deployment/kubernetes/ftgo-consumer-service.yml @@ -29,7 +29,7 @@ spec: containers: - name: ftgo-consumer-service image: msapatterns/ftgo-consumer-service:latest - imagePullPolicy: Always + imagePullPolicy: IfNotPresent ports: - containerPort: 8080 name: httpport diff --git a/skaffold.yaml b/skaffold.yaml new file mode 100644 index 00000000..c0f566ad --- /dev/null +++ b/skaffold.yaml @@ -0,0 +1,20 @@ +apiVersion: skaffold/v1 +kind: Config +metadata: + name: ftgo-application +build: + artifacts: + - image: msapatterns/ftgo-consumer-service + context: ftgo-consumer-service +deploy: + kubectl: + manifests: + - deployment/kubernetes/cdc-services/eventuate-local-cdc-service.yml + - deployment/kubernetes/cdc-services/ftgo-tram-cdc-service.yml + - deployment/kubernetes/stateful-services/ftgo-db-secret.yml + - deployment/kubernetes/stateful-services/ftgo-dynamodb-local.yml + - deployment/kubernetes/stateful-services/ftgo-kafka-config.yml + - deployment/kubernetes/stateful-services/ftgo-kafka-deployment.yml + - deployment/kubernetes/stateful-services/ftgo-mysql-deployment.yml + - deployment/kubernetes/stateful-services/ftgo-zookeeper-deployment.yml + - ftgo-consumer-service/src/deployment/kubernetes/ftgo-consumer-service.yml From fe4da9c7a03950b734f884b40b768451ee31e22e Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Thu, 5 Dec 2019 21:18:57 -0800 Subject: [PATCH 2/3] Upgraded to Spring Boot 2.2.x and fixed duplicate bean definitions --- build-and-test-all.sh | 13 +++++++-- build.gradle | 3 +- .../main/groovy/ComponentTestsPlugin.groovy | 6 ++-- .../main/groovy/IntegrationTestsPlugin.groovy | 2 +- ftgo-accounting-service/build.gradle | 2 ++ .../AccountingMessagingConfiguration.java | 8 ++---- .../NoopDuplicateMessageDetector.java | 17 ----------- .../src/main/resources/application.properties | 2 +- .../AccountingServiceCommandHandlerTest.java | 28 +++---------------- ftgo-consumer-service/build.gradle | 2 ++ .../src/main/resources/application.properties | 4 +-- ftgo-delivery-service/build.gradle | 6 ++-- ...DeliveryServiceInProcessComponentTest.java | 1 - .../src/main/resources/application.properties | 2 +- ftgo-kitchen-service/build.gradle | 12 ++++++++ .../contract/MessagingBase.java | 8 ++---- .../src/main/resources/application.properties | 2 +- ...KitchenServiceInMemoryIntegrationTest.java | 19 ++----------- ftgo-order-history-service/build.gradle | 3 +- .../src/main/resources/application.properties | 2 +- .../OrderHistoryEventHandlersTest.java | 5 +++- .../resources/contracts/http/GetOrder.groovy | 2 +- ftgo-order-service/build.gradle | 16 ++++++++++- .../domain/OrderServiceIntegrationTest.java | 19 ++----------- .../KitchenServiceProxyIntegrationTest.java | 28 ++++--------------- .../domain/OrderServiceConfiguration.java | 8 ------ .../src/main/resources/application.properties | 2 +- ftgo-restaurant-service/build.gradle | 11 ++++++++ .../src/main/resources/application.properties | 2 +- gradle.properties | 19 +++++++------ gradle/wrapper/gradle-wrapper.properties | 2 +- 31 files changed, 104 insertions(+), 152 deletions(-) delete mode 100644 ftgo-accounting-service/src/main/java/net/chrisrichardson/ftgo/accountingservice/messaging/NoopDuplicateMessageDetector.java diff --git a/build-and-test-all.sh b/build-and-test-all.sh index 58390c9a..bdcace23 100755 --- a/build-and-test-all.sh +++ b/build-and-test-all.sh @@ -2,6 +2,7 @@ KEEP_RUNNING= ASSEMBLE_ONLY= +USE_EXISTING_CONTAINERS= DATABASE_SERVICES="dynamodblocal mysql dynamodblocal-init" if [ -z "$DOCKER_COMPOSE" ] ; then @@ -16,8 +17,11 @@ while [ ! -z "$*" ] ; do "--assemble-only" ) ASSEMBLE_ONLY=yes ;; + "--use-existing-containers" ) + USE_EXISTING_CONTAINERS=yes + ;; "--help" ) - echo ./build-and-test-all.sh --keep-running --assemble-only + echo ./build-and-test-all.sh --keep-running --assemble-only --use-existing-containers exit 0 ;; esac @@ -32,9 +36,12 @@ echo KEEP_RUNNING=$KEEP_RUNNING ./gradlew buildContracts -./gradlew testClasses +./gradlew testClasses compileIntegrationTestJava compileComponentTestJava + +if [ -z "$USE_EXISTING_CONTAINERS" ] ; then + ${DOCKER_COMPOSE?} down --remove-orphans -v +fi -${DOCKER_COMPOSE?} down --remove-orphans -v ${DOCKER_COMPOSE?} up -d --build ${DATABASE_SERVICES?} ./gradlew waitForMySql diff --git a/build.gradle b/build.gradle index 1cda4b5a..badd0038 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,8 @@ apply plugin: WaitForMySqlPlugin subprojects { apply plugin: "java" - apply plugin: 'pmd' + + // TODO apply plugin: 'pmd' sourceCompatibility = '1.8' targetCompatibility = '1.8' diff --git a/buildSrc/src/main/groovy/ComponentTestsPlugin.groovy b/buildSrc/src/main/groovy/ComponentTestsPlugin.groovy index 4a07c81b..d4f5d728 100644 --- a/buildSrc/src/main/groovy/ComponentTestsPlugin.groovy +++ b/buildSrc/src/main/groovy/ComponentTestsPlugin.groovy @@ -6,9 +6,9 @@ class ComponentTestsPlugin implements Plugin { @Override void apply(Project project) { - + project.apply(plugin: 'eclipse') - + project.sourceSets { componentTest { java { @@ -28,7 +28,7 @@ class ComponentTestsPlugin implements Plugin { project.eclipse.classpath.plusConfigurations << project.configurations.componentTestCompile project.task("componentTest", type: Test) { - testClassesDir = project.sourceSets.componentTest.output.classesDir + testClassesDirs = project.sourceSets.componentTest.output.classesDirs classpath = project.sourceSets.componentTest.runtimeClasspath } diff --git a/buildSrc/src/main/groovy/IntegrationTestsPlugin.groovy b/buildSrc/src/main/groovy/IntegrationTestsPlugin.groovy index 9f5bce54..ccb722a1 100644 --- a/buildSrc/src/main/groovy/IntegrationTestsPlugin.groovy +++ b/buildSrc/src/main/groovy/IntegrationTestsPlugin.groovy @@ -23,7 +23,7 @@ class IntegrationTestsPlugin implements Plugin { } project.task("integrationTest", type: Test) { - testClassesDir = project.sourceSets.integrationTest.output.classesDir + testClassesDirs = project.sourceSets.integrationTest.output.classesDirs classpath = project.sourceSets.integrationTest.runtimeClasspath } diff --git a/ftgo-accounting-service/build.gradle b/ftgo-accounting-service/build.gradle index 456dbd94..b2b556dc 100644 --- a/ftgo-accounting-service/build.gradle +++ b/ftgo-accounting-service/build.gradle @@ -21,6 +21,8 @@ dependencies { compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion" compile "io.eventuate.local.java:eventuate-local-java-jdbc:${eventuateLocalVersion}" + testCompile "io.eventuate.tram.core:eventuate-tram-in-memory:$eventuateTramVersion" + testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion" testCompile "io.eventuate.util:eventuate-util-test:$eventuateUtilVersion" testCompile "io.eventuate.tram.core:eventuate-tram-test-util:$eventuateTramVersion" diff --git a/ftgo-accounting-service/src/main/java/net/chrisrichardson/ftgo/accountingservice/messaging/AccountingMessagingConfiguration.java b/ftgo-accounting-service/src/main/java/net/chrisrichardson/ftgo/accountingservice/messaging/AccountingMessagingConfiguration.java index b03cd7a9..cd9cd194 100644 --- a/ftgo-accounting-service/src/main/java/net/chrisrichardson/ftgo/accountingservice/messaging/AccountingMessagingConfiguration.java +++ b/ftgo-accounting-service/src/main/java/net/chrisrichardson/ftgo/accountingservice/messaging/AccountingMessagingConfiguration.java @@ -5,6 +5,7 @@ import io.eventuate.tram.commands.consumer.CommandDispatcherFactory; import io.eventuate.tram.commands.consumer.TramCommandConsumerConfiguration; import io.eventuate.tram.consumer.common.DuplicateMessageDetector; +import io.eventuate.tram.consumer.jdbc.TransactionalNoopDuplicateMessageDetectorConfiguration; import io.eventuate.tram.events.subscriber.DomainEventDispatcher; import io.eventuate.tram.events.subscriber.DomainEventDispatcherFactory; import io.eventuate.tram.events.subscriber.TramEventSubscriberConfiguration; @@ -20,7 +21,7 @@ @Configuration @EnableEventHandlers -@Import({AccountServiceConfiguration.class, CommonConfiguration.class, TramEventSubscriberConfiguration.class, TramCommandConsumerConfiguration.class}) +@Import({AccountServiceConfiguration.class, CommonConfiguration.class, TramEventSubscriberConfiguration.class, TramCommandConsumerConfiguration.class, TransactionalNoopDuplicateMessageDetectorConfiguration.class}) public class AccountingMessagingConfiguration { @Bean @@ -45,11 +46,6 @@ public CommandDispatcher commandDispatcher(AccountingServiceCommandHandler targe return commandDispatcherFactory.make(data.getCommandDispatcherId(), target.commandHandlers()); } - @Bean - public DuplicateMessageDetector duplicateMessageDetector() { - return new NoopDuplicateMessageDetector(); - } - @Bean public AccountServiceChannelConfiguration accountServiceChannelConfiguration() { return new AccountServiceChannelConfiguration("accountCommandDispatcher", "accountCommandChannel"); diff --git a/ftgo-accounting-service/src/main/java/net/chrisrichardson/ftgo/accountingservice/messaging/NoopDuplicateMessageDetector.java b/ftgo-accounting-service/src/main/java/net/chrisrichardson/ftgo/accountingservice/messaging/NoopDuplicateMessageDetector.java deleted file mode 100644 index 5bab9c4d..00000000 --- a/ftgo-accounting-service/src/main/java/net/chrisrichardson/ftgo/accountingservice/messaging/NoopDuplicateMessageDetector.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.chrisrichardson.ftgo.accountingservice.messaging; - -import io.eventuate.tram.consumer.common.DuplicateMessageDetector; -import io.eventuate.tram.consumer.common.SubscriberIdAndMessage; - -public class NoopDuplicateMessageDetector implements DuplicateMessageDetector { - - @Override - public boolean isDuplicate(String consumerId, String messageId) { - return false; - } - - @Override - public void doWithMessage(SubscriberIdAndMessage subscriberIdAndMessage, Runnable callback) { - callback.run(); - } -} diff --git a/ftgo-accounting-service/src/main/resources/application.properties b/ftgo-accounting-service/src/main/resources/application.properties index 62030ad1..70c4dcd6 100644 --- a/ftgo-accounting-service/src/main/resources/application.properties +++ b/ftgo-accounting-service/src/main/resources/application.properties @@ -7,7 +7,7 @@ logging.level.org.springframework.orm.jpa=INFO logging.level.org.hibernate.SQL=DEBUG logging.level.io.eventuate=DEBUG logging.level.net.chrisrichardson.ftgo=DEBUG -logging.level.io.eventuate.tram=TRACE +logging.level.io.eventuate.tram=DEBUG spring.datasource.url=jdbc:mysql://${DOCKER_HOST_IP:localhost}/ftgo_accounting_service spring.datasource.username=ftgo_accounting_service_user spring.datasource.password=ftgo_accounting_service_password diff --git a/ftgo-accounting-service/src/test/java/net/chrisrichardson/ftgo/accountingservice/messaging/AccountingServiceCommandHandlerTest.java b/ftgo-accounting-service/src/test/java/net/chrisrichardson/ftgo/accountingservice/messaging/AccountingServiceCommandHandlerTest.java index 425a4ce2..f6f164f9 100644 --- a/ftgo-accounting-service/src/test/java/net/chrisrichardson/ftgo/accountingservice/messaging/AccountingServiceCommandHandlerTest.java +++ b/ftgo-accounting-service/src/test/java/net/chrisrichardson/ftgo/accountingservice/messaging/AccountingServiceCommandHandlerTest.java @@ -1,24 +1,22 @@ package net.chrisrichardson.ftgo.accountingservice.messaging; -import io.eventuate.sync.AggregateRepository; import io.eventuate.javaclient.spring.jdbc.EmbeddedTestAggregateStoreConfiguration; +import io.eventuate.sync.AggregateRepository; import io.eventuate.tram.commands.producer.CommandProducer; import io.eventuate.tram.commands.producer.TramCommandProducerConfiguration; import io.eventuate.tram.events.publisher.DomainEventPublisher; import io.eventuate.tram.events.publisher.TramEventsPublisherConfiguration; -import io.eventuate.tram.inmemory.TramInMemoryConfiguration; -import io.eventuate.tram.messaging.common.ChannelMapping; -import io.eventuate.tram.messaging.common.DefaultChannelMapping; import io.eventuate.tram.sagas.common.SagaCommandHeaders; +import io.eventuate.tram.sagas.inmemory.TramSagaInMemoryConfiguration; import io.eventuate.tram.testutil.TestMessageConsumer; import io.eventuate.tram.testutil.TestMessageConsumerFactory; +import io.eventuate.util.test.async.Eventually; import net.chrisrichardson.ftgo.accountingservice.domain.Account; import net.chrisrichardson.ftgo.accountingservice.domain.AccountCommand; import net.chrisrichardson.ftgo.accountservice.api.AccountingServiceChannels; import net.chrisrichardson.ftgo.accountservice.api.AuthorizeCommand; import net.chrisrichardson.ftgo.common.Money; import net.chrisrichardson.ftgo.consumerservice.domain.ConsumerCreated; -import io.eventuate.util.test.async.Eventually; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -27,17 +25,11 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.test.context.junit4.SpringRunner; -import javax.sql.DataSource; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; @RunWith(SpringRunner.class) @SpringBootTest(classes = AccountingServiceCommandHandlerTest.AccountingServiceCommandHandlerTestConfiguration.class) @@ -49,25 +41,13 @@ public class AccountingServiceCommandHandlerTest { TramCommandProducerConfiguration.class, EmbeddedTestAggregateStoreConfiguration.class, TramEventsPublisherConfiguration.class, // TODO - TramInMemoryConfiguration.class}) + TramSagaInMemoryConfiguration.class}) static public class AccountingServiceCommandHandlerTestConfiguration { - @Bean public TestMessageConsumerFactory testMessageConsumerFactory() { return new TestMessageConsumerFactory(); } - @Bean - public DataSource dataSource() { - EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); - return builder.setType(EmbeddedDatabaseType.H2) - .addScript("eventuate-tram-embedded-schema.sql") - .addScript("eventuate-tram-sagas-embedded.sql") - .addScript("eventuate-embedded-schema.sql") - .build(); - } - - } @Autowired diff --git a/ftgo-consumer-service/build.gradle b/ftgo-consumer-service/build.gradle index 5baff76f..277aa8e7 100644 --- a/ftgo-consumer-service/build.gradle +++ b/ftgo-consumer-service/build.gradle @@ -21,9 +21,11 @@ dependencies { testCompile "io.eventuate.util:eventuate-util-test:$eventuateUtilVersion" testCompile "io.eventuate.tram.core:eventuate-tram-test-util:$eventuateTramVersion" + testCompile "io.eventuate.tram.core:eventuate-tram-in-memory:$eventuateTramVersion" testCompile "io.eventuate.tram.sagas:eventuate-tram-sagas-in-memory:$eventuateTramSagasVersion" testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion" testCompile "com.jayway.restassured:rest-assured:$restAssuredVersion" testCompile "com.jayway.jsonpath:json-path:2.3.0" + testCompile "org.hamcrest:hamcrest:2.1" } diff --git a/ftgo-consumer-service/src/main/resources/application.properties b/ftgo-consumer-service/src/main/resources/application.properties index 0eeee8bd..1afc72aa 100644 --- a/ftgo-consumer-service/src/main/resources/application.properties +++ b/ftgo-consumer-service/src/main/resources/application.properties @@ -5,9 +5,9 @@ management.endpoint.health.show-details=always spring.jpa.generate-ddl=true logging.level.org.springframework.orm.jpa=INFO logging.level.org.hibernate.SQL=DEBUG -logging.level.io.eventuate=TRACE +logging.level.io.eventuate=DEBUG logging.level.net.chrisrichardson.ftgo=DEBUG -logging.level.io.eventuate.tram=TRACE +logging.level.io.eventuate.tram=DEBUG spring.datasource.url=jdbc:mysql://${DOCKER_HOST_IP:localhost}/ftgo_consumer_service spring.datasource.username=ftgo_consumer_service_user spring.datasource.password=ftgo_consumer_service_password diff --git a/ftgo-delivery-service/build.gradle b/ftgo-delivery-service/build.gradle index 40c4b9b8..7e8cb683 100644 --- a/ftgo-delivery-service/build.gradle +++ b/ftgo-delivery-service/build.gradle @@ -1,7 +1,8 @@ apply plugin: FtgoServicePlugin -apply plugin: 'spring-cloud-contract' +// apply plugin: 'spring-cloud-contract' + apply plugin: 'docker-compose' apply plugin: IntegrationTestsPlugin @@ -29,7 +30,7 @@ dependencies { componentTestCompile "com.jayway.restassured:rest-assured:$restAssuredVersion" componentTestCompile "com.jayway.jsonpath:json-path:2.3.0" - + componentTestCompile "org.hamcrest:hamcrest:2.1" } @@ -44,4 +45,3 @@ dockerCompose { componentTestsComposeUp.dependsOn(assemble) dockerCompose.componentTests.isRequiredBy(componentTest) - diff --git a/ftgo-delivery-service/src/component-test/java/net/chrisrichardson/ftgo/deliveryservice/DeliveryServiceInProcessComponentTest.java b/ftgo-delivery-service/src/component-test/java/net/chrisrichardson/ftgo/deliveryservice/DeliveryServiceInProcessComponentTest.java index e7e7c2de..91685255 100644 --- a/ftgo-delivery-service/src/component-test/java/net/chrisrichardson/ftgo/deliveryservice/DeliveryServiceInProcessComponentTest.java +++ b/ftgo-delivery-service/src/component-test/java/net/chrisrichardson/ftgo/deliveryservice/DeliveryServiceInProcessComponentTest.java @@ -39,7 +39,6 @@ public class DeliveryServiceInProcessComponentTest { private long orderId; @Configuration - @EnableJpaRepositories @EnableAutoConfiguration @Import({DeliveryServiceMessagingConfiguration.class, DeliveryServiceWebConfiguration.class, diff --git a/ftgo-delivery-service/src/main/resources/application.properties b/ftgo-delivery-service/src/main/resources/application.properties index 6a90d524..1ad5dce5 100644 --- a/ftgo-delivery-service/src/main/resources/application.properties +++ b/ftgo-delivery-service/src/main/resources/application.properties @@ -11,7 +11,7 @@ logging.level.org.springframework.orm.jpa=INFO logging.level.org.hibernate.SQL=DEBUG logging.level.io.eventuate=DEBUG logging.level.net.chrisrichardson.ftgo=DEBUG -logging.level.io.eventuate.tram=TRACE +logging.level.io.eventuate.tram=DEBUG eventuate.database.schema=none spring.datasource.url=jdbc:mysql://${DOCKER_HOST_IP:localhost}/ftgo_delivery_service diff --git a/ftgo-kitchen-service/build.gradle b/ftgo-kitchen-service/build.gradle index 6f153f27..6168e550 100644 --- a/ftgo-kitchen-service/build.gradle +++ b/ftgo-kitchen-service/build.gradle @@ -37,6 +37,16 @@ sourceSets { } } +task deregisterContractTestSources() { + doLast { + project.sourceSets.test.java { + exclude '**/MessagingTest.java' + } + } +} + +compileTestJava.dependsOn deregisterContractTestSources + compileTestGroovy.enabled=false apply plugin: FtgoServicePlugin @@ -63,6 +73,8 @@ dependencies { testCompile "io.eventuate.util:eventuate-util-test:$eventuateUtilVersion" testCompile "io.eventuate.tram.core:eventuate-tram-test-util:$eventuateTramVersion" + testCompile "io.eventuate.tram.core:eventuate-tram-in-memory:$eventuateTramVersion" + testCompile "io.eventuate.tram.sagas:eventuate-tram-sagas-in-memory:$eventuateTramSagasVersion" testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion" testCompile "com.jayway.restassured:rest-assured:$restAssuredVersion" diff --git a/ftgo-kitchen-service/src/integration-test/java/net/chrisrichardson/ftgo/kitchenservice/contract/MessagingBase.java b/ftgo-kitchen-service/src/integration-test/java/net/chrisrichardson/ftgo/kitchenservice/contract/MessagingBase.java index 863d3bce..4e09d2ef 100644 --- a/ftgo-kitchen-service/src/integration-test/java/net/chrisrichardson/ftgo/kitchenservice/contract/MessagingBase.java +++ b/ftgo-kitchen-service/src/integration-test/java/net/chrisrichardson/ftgo/kitchenservice/contract/MessagingBase.java @@ -9,6 +9,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureMessageVerifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -32,14 +33,9 @@ public abstract class MessagingBase { @Import({KitchenServiceMessageHandlersConfiguration.class, EventuateContractVerifierConfiguration.class}) public static class TestConfiguration { - @Bean - public KitchenService kitchenService() { - return mock(KitchenService.class); - } - } - @Autowired + @MockBean private KitchenService kitchenService; @Before diff --git a/ftgo-kitchen-service/src/main/resources/application.properties b/ftgo-kitchen-service/src/main/resources/application.properties index 9c7a95bb..09c3fd86 100644 --- a/ftgo-kitchen-service/src/main/resources/application.properties +++ b/ftgo-kitchen-service/src/main/resources/application.properties @@ -7,7 +7,7 @@ logging.level.org.springframework.orm.jpa=INFO logging.level.org.hibernate.SQL=DEBUG logging.level.io.eventuate=DEBUG logging.level.net.chrisrichardson.ftgo=DEBUG -logging.level.io.eventuate.tram=TRACE +logging.level.io.eventuate.tram=DEBUG spring.datasource.url=jdbc:mysql://${DOCKER_HOST_IP:localhost}/ftgo_kitchen_service spring.datasource.username=ftgo_kitchen_service_user diff --git a/ftgo-kitchen-service/src/test/java/net/chrisrichardson/ftgo/kitchenservice/domain/KitchenServiceInMemoryIntegrationTest.java b/ftgo-kitchen-service/src/test/java/net/chrisrichardson/ftgo/kitchenservice/domain/KitchenServiceInMemoryIntegrationTest.java index e4dede94..318cef96 100644 --- a/ftgo-kitchen-service/src/test/java/net/chrisrichardson/ftgo/kitchenservice/domain/KitchenServiceInMemoryIntegrationTest.java +++ b/ftgo-kitchen-service/src/test/java/net/chrisrichardson/ftgo/kitchenservice/domain/KitchenServiceInMemoryIntegrationTest.java @@ -3,10 +3,8 @@ import io.eventuate.tram.commands.producer.CommandProducer; import io.eventuate.tram.commands.producer.TramCommandProducerConfiguration; -import io.eventuate.tram.inmemory.TramInMemoryConfiguration; -import io.eventuate.tram.messaging.common.ChannelMapping; -import io.eventuate.tram.messaging.common.DefaultChannelMapping; import io.eventuate.tram.sagas.common.SagaCommandHeaders; +import io.eventuate.tram.sagas.inmemory.TramSagaInMemoryConfiguration; import io.eventuate.tram.testutil.TestMessageConsumer; import io.eventuate.tram.testutil.TestMessageConsumerFactory; import net.chrisrichardson.ftgo.common.Money; @@ -25,11 +23,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.test.context.junit4.SpringRunner; -import javax.sql.DataSource; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -48,7 +43,7 @@ public class KitchenServiceInMemoryIntegrationTest { @EnableAutoConfiguration @Import({KitchenServiceWebConfiguration.class, KitchenServiceMessageHandlersConfiguration.class, TramCommandProducerConfiguration.class, - TramInMemoryConfiguration.class}) + TramSagaInMemoryConfiguration.class}) public static class TestConfiguration { @Bean @@ -57,16 +52,6 @@ public TestMessageConsumerFactory testMessageConsumerFactory() { } - @Bean - public DataSource dataSource() { - EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); - return builder.setType(EmbeddedDatabaseType.H2) - .addScript("eventuate-tram-embedded-schema.sql") - .addScript("eventuate-tram-sagas-embedded.sql") - .build(); - } - - } private String baseUrl(String path) { diff --git a/ftgo-order-history-service/build.gradle b/ftgo-order-history-service/build.gradle index a7667f56..884c8749 100644 --- a/ftgo-order-history-service/build.gradle +++ b/ftgo-order-history-service/build.gradle @@ -13,7 +13,7 @@ buildscript { apply plugin: FtgoServicePlugin apply plugin: "io.spring.dependency-management" -apply plugin: 'spring-cloud-contract' +// apply plugin: 'spring-cloud-contract' apply plugin: IntegrationTestsPlugin apply plugin: 'docker-compose' @@ -54,6 +54,7 @@ dependencies { testCompile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner" testCompile "io.eventuate.tram.core:eventuate-tram-testing-support-spring-cloud-contract:$eventuateTramVersion" + testCompile "org.hamcrest:hamcrest:2.1" } diff --git a/ftgo-order-history-service/src/main/resources/application.properties b/ftgo-order-history-service/src/main/resources/application.properties index 1fe0f6d5..da78bbf7 100644 --- a/ftgo-order-history-service/src/main/resources/application.properties +++ b/ftgo-order-history-service/src/main/resources/application.properties @@ -4,7 +4,7 @@ management.endpoint.health.show-details=always logging.level.io.eventuate=DEBUG logging.level.net.chrisrichardson.ftgo=DEBUG -logging.level.io.eventuate.tram=TRACE +logging.level.io.eventuate.tram=DEBUG logging.level.root=INFO eventuatelocal.kafka.bootstrap.servers=${DOCKER_HOST_IP:localhost}:9092 diff --git a/ftgo-order-history-service/src/test/java/net/chrisrichardson/ftgo/orderhistory/contracts/OrderHistoryEventHandlersTest.java b/ftgo-order-history-service/src/test/java/net/chrisrichardson/ftgo/orderhistory/contracts/OrderHistoryEventHandlersTest.java index 18b8342c..8276b52d 100644 --- a/ftgo-order-history-service/src/test/java/net/chrisrichardson/ftgo/orderhistory/contracts/OrderHistoryEventHandlersTest.java +++ b/ftgo-order-history-service/src/test/java/net/chrisrichardson/ftgo/orderhistory/contracts/OrderHistoryEventHandlersTest.java @@ -1,6 +1,8 @@ package net.chrisrichardson.ftgo.orderhistory.contracts; import io.eventuate.tram.commands.producer.TramCommandProducerConfiguration; +import io.eventuate.tram.consumer.common.TramNoopDuplicateMessageDetectorConfiguration; +import io.eventuate.tram.inmemory.TramInMemoryCommonConfiguration; import io.eventuate.tram.inmemory.TramInMemoryConfiguration; import io.eventuate.tram.messaging.common.ChannelMapping; import io.eventuate.tram.messaging.common.DefaultChannelMapping; @@ -45,7 +47,8 @@ public class OrderHistoryEventHandlersTest { @EnableAutoConfiguration @Import({OrderHistoryServiceMessagingConfiguration.class, TramCommandProducerConfiguration.class, - TramInMemoryConfiguration.class, + TramInMemoryCommonConfiguration.class, + TramNoopDuplicateMessageDetectorConfiguration.class, EventuateContractVerifierConfiguration.class}) public static class TestConfiguration { diff --git a/ftgo-order-service-contracts/src/main/resources/contracts/http/GetOrder.groovy b/ftgo-order-service-contracts/src/main/resources/contracts/http/GetOrder.groovy index 65db5352..5da9763c 100644 --- a/ftgo-order-service-contracts/src/main/resources/contracts/http/GetOrder.groovy +++ b/ftgo-order-service-contracts/src/main/resources/contracts/http/GetOrder.groovy @@ -8,7 +8,7 @@ org.springframework.cloud.contract.spec.Contract.make { response { status 200 headers { - header('Content-Type': 'application/json;charset=UTF-8') + header('Content-Type': 'application/json') } body('''{"orderId" : "99", "state" : "APPROVAL_PENDING"}''') } diff --git a/ftgo-order-service/build.gradle b/ftgo-order-service/build.gradle index 3f308ac7..a574fbf0 100644 --- a/ftgo-order-service/build.gradle +++ b/ftgo-order-service/build.gradle @@ -10,7 +10,7 @@ buildscript { dependencies { classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:$springCloudContractDependenciesVersion" classpath "com.avast.gradle:gradle-docker-compose-plugin:$dockerComposePluginVersion" - classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0' + classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10' } } @@ -44,6 +44,17 @@ sourceSets { } } +task deregisterContractTestSources() { + doLast { + project.sourceSets.test.java { + exclude '**/MessagingTest.java' + exclude '**/HttpTest.java' + } + } +} + +compileTestJava.dependsOn deregisterContractTestSources + compileTestGroovy.enabled=false componentTest.dependsOn(assemble) @@ -160,5 +171,8 @@ dependencies { componentTestCompile 'info.cukes:cucumber-junit:1.2.5' componentTestCompile 'info.cukes:cucumber-spring:1.2.5' testCompile project(":ftgo-test-util") + testCompile "org.hamcrest:hamcrest:2.1" + + integrationTestCompile "io.eventuate.tram.core:eventuate-tram-in-memory:$eventuateTramVersion" } diff --git a/ftgo-order-service/src/integration-test/java/net/chrisrichardson/ftgo/orderservice/domain/OrderServiceIntegrationTest.java b/ftgo-order-service/src/integration-test/java/net/chrisrichardson/ftgo/orderservice/domain/OrderServiceIntegrationTest.java index 6bc78f60..698fe0d2 100644 --- a/ftgo-order-service/src/integration-test/java/net/chrisrichardson/ftgo/orderservice/domain/OrderServiceIntegrationTest.java +++ b/ftgo-order-service/src/integration-test/java/net/chrisrichardson/ftgo/orderservice/domain/OrderServiceIntegrationTest.java @@ -4,10 +4,8 @@ import io.eventuate.tram.commands.common.CommandMessageHeaders; import io.eventuate.tram.commands.producer.TramCommandProducerConfiguration; import io.eventuate.tram.events.publisher.DomainEventPublisher; -import io.eventuate.tram.inmemory.TramInMemoryConfiguration; -import io.eventuate.tram.messaging.common.ChannelMapping; -import io.eventuate.tram.messaging.common.DefaultChannelMapping; import io.eventuate.tram.messaging.common.Message; +import io.eventuate.tram.sagas.inmemory.TramSagaInMemoryConfiguration; import io.eventuate.tram.testutil.TestMessageConsumerFactory; import io.eventuate.util.test.async.Eventually; import net.chrisrichardson.ftgo.common.Money; @@ -33,11 +31,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.test.context.junit4.SpringRunner; -import javax.sql.DataSource; import java.util.Collections; import java.util.function.Predicate; @@ -61,7 +56,7 @@ private String baseUrl(String path) { @EnableAutoConfiguration @Import({OrderWebConfiguration.class, OrderServiceMessagingConfiguration.class, OrderCommandHandlersConfiguration.class, TramCommandProducerConfiguration.class, - TramInMemoryConfiguration.class}) + TramSagaInMemoryConfiguration.class}) public static class TestConfiguration { @Bean @@ -70,16 +65,6 @@ public TestMessageConsumerFactory testMessageConsumerFactory() { } - @Bean - public DataSource dataSource() { - EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); - return builder.setType(EmbeddedDatabaseType.H2) - .addScript("eventuate-tram-embedded-schema.sql") - .addScript("eventuate-tram-sagas-embedded.sql") - .build(); - } - - @Bean public TestMessageConsumer2 mockConsumerService() { return new TestMessageConsumer2("mockConsumerService", ConsumerServiceChannels.consumerServiceChannel); diff --git a/ftgo-order-service/src/integration-test/java/net/chrisrichardson/ftgo/orderservice/sagaparticipants/KitchenServiceProxyIntegrationTest.java b/ftgo-order-service/src/integration-test/java/net/chrisrichardson/ftgo/orderservice/sagaparticipants/KitchenServiceProxyIntegrationTest.java index d16ccd07..f9caad8d 100644 --- a/ftgo-order-service/src/integration-test/java/net/chrisrichardson/ftgo/orderservice/sagaparticipants/KitchenServiceProxyIntegrationTest.java +++ b/ftgo-order-service/src/integration-test/java/net/chrisrichardson/ftgo/orderservice/sagaparticipants/KitchenServiceProxyIntegrationTest.java @@ -1,18 +1,16 @@ package net.chrisrichardson.ftgo.orderservice.sagaparticipants; import io.eventuate.tram.commands.producer.TramCommandProducerConfiguration; -import io.eventuate.tram.inmemory.TramInMemoryConfiguration; -import io.eventuate.tram.messaging.common.ChannelMapping; -import io.eventuate.tram.messaging.common.DefaultChannelMapping; +import io.eventuate.tram.sagas.inmemory.TramSagaInMemoryConfiguration; import io.eventuate.tram.sagas.orchestration.SagaCommandProducer; import io.eventuate.tram.springcloudcontractsupport.EventuateContractVerifierConfiguration; import io.eventuate.tram.springcloudcontractsupport.EventuateTramRoutesConfigurer; -import net.chrisrichardson.ftgo.orderservice.OrderDetailsMother; -import net.chrisrichardson.ftgo.orderservice.sagas.createorder.CreateOrderSaga; import net.chrisrichardson.ftgo.kitchenservice.api.CreateTicket; import net.chrisrichardson.ftgo.kitchenservice.api.CreateTicketReply; import net.chrisrichardson.ftgo.kitchenservice.api.TicketDetails; import net.chrisrichardson.ftgo.kitchenservice.api.TicketLineItem; +import net.chrisrichardson.ftgo.orderservice.OrderDetailsMother; +import net.chrisrichardson.ftgo.orderservice.sagas.createorder.CreateOrderSaga; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -23,18 +21,13 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import javax.sql.DataSource; import java.util.Collections; import static net.chrisrichardson.ftgo.orderservice.OrderDetailsMother.CHICKEN_VINDALOO_QUANTITY; -import static net.chrisrichardson.ftgo.orderservice.RestaurantMother.AJANTA_ID; -import static net.chrisrichardson.ftgo.orderservice.RestaurantMother.CHICKEN_VINDALOO; -import static net.chrisrichardson.ftgo.orderservice.RestaurantMother.CHICKEN_VINDALOO_MENU_ITEM_ID; +import static net.chrisrichardson.ftgo.orderservice.RestaurantMother.*; import static org.junit.Assert.assertEquals; @RunWith(SpringRunner.class) @@ -50,20 +43,9 @@ public class KitchenServiceProxyIntegrationTest { @Configuration @EnableAutoConfiguration @Import({TramCommandProducerConfiguration.class, - TramInMemoryConfiguration.class, EventuateContractVerifierConfiguration.class}) + TramSagaInMemoryConfiguration.class, EventuateContractVerifierConfiguration.class}) public static class TestConfiguration { - /// TramSagaInMemoryConfiguration - - @Bean - public DataSource dataSource() { - EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); - return builder.setType(EmbeddedDatabaseType.H2) - .addScript("eventuate-tram-embedded-schema.sql") - .addScript("eventuate-tram-sagas-embedded.sql") - .build(); - } - @Bean public EventuateTramRoutesConfigurer eventuateTramRoutesConfigurer(BatchStubRunner batchStubRunner) { diff --git a/ftgo-order-service/src/main/java/net/chrisrichardson/ftgo/orderservice/domain/OrderServiceConfiguration.java b/ftgo-order-service/src/main/java/net/chrisrichardson/ftgo/orderservice/domain/OrderServiceConfiguration.java index 1b716413..cf659a75 100644 --- a/ftgo-order-service/src/main/java/net/chrisrichardson/ftgo/orderservice/domain/OrderServiceConfiguration.java +++ b/ftgo-order-service/src/main/java/net/chrisrichardson/ftgo/orderservice/domain/OrderServiceConfiguration.java @@ -2,7 +2,6 @@ import io.eventuate.tram.events.publisher.DomainEventPublisher; import io.eventuate.tram.events.publisher.TramEventsPublisherConfiguration; -import io.eventuate.tram.sagas.orchestration.SagaCommandProducer; import io.eventuate.tram.sagas.orchestration.SagaManager; import io.eventuate.tram.sagas.orchestration.SagaManagerImpl; import io.eventuate.tram.sagas.orchestration.SagaOrchestratorConfiguration; @@ -23,19 +22,12 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import org.springframework.transaction.annotation.EnableTransactionManagement; import java.util.Optional; @Configuration @Import({TramEventsPublisherConfiguration.class, SagaOrchestratorConfiguration.class, CommonConfiguration.class}) public class OrderServiceConfiguration { - // TODO move to framework - - @Bean - public SagaCommandProducer sagaCommandProducer() { - return new SagaCommandProducer(); - } @Bean public OrderService orderService(RestaurantRepository restaurantRepository, OrderRepository orderRepository, DomainEventPublisher eventPublisher, diff --git a/ftgo-order-service/src/main/resources/application.properties b/ftgo-order-service/src/main/resources/application.properties index 0b310096..89121df7 100644 --- a/ftgo-order-service/src/main/resources/application.properties +++ b/ftgo-order-service/src/main/resources/application.properties @@ -11,7 +11,7 @@ logging.level.org.springframework.orm.jpa=INFO logging.level.org.hibernate.SQL=DEBUG logging.level.io.eventuate=DEBUG logging.level.net.chrisrichardson.ftgo=DEBUG -logging.level.io.eventuate.tram=TRACE +logging.level.io.eventuate.tram=DEBUG eventuate.database.schema=none spring.datasource.url=jdbc:mysql://${DOCKER_HOST_IP:localhost}/ftgo_order_service diff --git a/ftgo-restaurant-service/build.gradle b/ftgo-restaurant-service/build.gradle index e89c84bd..cc580e97 100644 --- a/ftgo-restaurant-service/build.gradle +++ b/ftgo-restaurant-service/build.gradle @@ -19,6 +19,16 @@ sourceSets { } } +task deregisterContractTestSources() { + doLast { + project.sourceSets.test.java { + exclude '**/MessagingTest.java' + } + } +} + +compileTestJava.dependsOn deregisterContractTestSources + compileTestGroovy.enabled=false dependencyManagement { @@ -57,5 +67,6 @@ dependencies { integrationTestCompile "org.springframework.cloud:spring-cloud-contract-wiremock" integrationTestCompile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner" integrationTestCompile "io.eventuate.tram.sagas:eventuate-tram-sagas-testing-support:$eventuateTramSagasVersion" + integrationTestCompile "io.eventuate.tram.core:eventuate-tram-in-memory:$eventuateTramVersion" } diff --git a/ftgo-restaurant-service/src/main/resources/application.properties b/ftgo-restaurant-service/src/main/resources/application.properties index edbdf369..b1085fc2 100644 --- a/ftgo-restaurant-service/src/main/resources/application.properties +++ b/ftgo-restaurant-service/src/main/resources/application.properties @@ -7,7 +7,7 @@ logging.level.org.springframework.orm.jpa=INFO logging.level.org.hibernate.SQL=DEBUG logging.level.io.eventuate=DEBUG logging.level.net.chrisrichardson.ftgo=DEBUG -logging.level.io.eventuate.tram=TRACE +logging.level.io.eventuate.tram=DEBUG spring.datasource.url=jdbc:mysql://${DOCKER_HOST_IP:localhost}/ftgo_restaurant_service spring.datasource.username=ftgo_restaurant_service_user diff --git a/gradle.properties b/gradle.properties index d31a6d0b..c7ddf3c2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,28 +5,29 @@ eventuateMavenRepoUrl=https://dl.bintray.com/eventuateio-oss/eventuate-maven-rel springBootVersion=2.1.1.RELEASE restAssuredVersion=2.9.0 - # TODO Upgrading to 2.0.2.RELEASE requires addressing this issue: https://stackoverflow.com/questions/54268428/spring-cloud-contracts-plugin-change-sourceset -springCloudContractDependenciesVersion=2.0.1.RELEASE +#springCloudContractDependenciesVersion=2.0.1.RELEASE +springCloudContractDependenciesVersion=2.2.0.RELEASE + springDependencyManagementPluginVersion=1.0.3.RELEASE # springBootVersion = '1.5.6.RELEASE' -eventuateClientVersion=0.22.0.RC1 -eventuateLocalVersion=0.31.0.RC3 +eventuateClientVersion=0.22.0.RC2 +eventuateLocalVersion=0.31.0.RC5 -eventuateTramVersion=0.22.0.RC5 -eventuateTramSagasVersion=0.12.0.RC5 +eventuateTramVersion=0.22.0.RC7 +eventuateTramSagasVersion=0.12.0.RC6 eventuateUtilVersion=0.2.0.RELEASE -eventuateCommonVersion=0.4.0.RELEASE -eventuateMessagingKafkaVersion=0.2.0.RELEASE +eventuateCommonVersion=0.8.3.RELEASE +eventuateMessagingKafkaVersion=0.5.0.RELEASE #dockerComposePluginVersion=0.4.5 dockerComposePluginVersion=0.6.6 grpcVersion = 1.13.2 -springCloudSleuthVersion=2.0.0.RELEASE +springCloudSleuthVersion=2.2.0.RELEASE springCloudGatewayVersion=2.0.0.RELEASE micrometerVersion=1.0.4 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e5cade3e..c7a610b0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip From 9be99aa310e261737cd59f726c967dcbf6c6cd3a Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Tue, 17 Dec 2019 06:01:48 -0800 Subject: [PATCH 3/3] Work on #51 - Replace shared API classes with codegen from OpenAPI/JSON schema --- build-and-test-all.sh | 2 +- build.gradle | 4 + .../ftgo-consumer-service-swagger.json | 136 ++++++++++++++++++ ftgo-consumer-service/build.gradle | 3 + .../web/ConsumerController.java | 8 +- .../web/CreateConsumerRequest.java | 2 +- .../web/CreateConsumerResponse.java | 2 +- .../web/GetConsumerResponse.java | 2 - ...onsumerServiceInMemoryIntegrationTest.java | 2 +- .../web/ConsumerControllerTest.java | 80 +++++++++++ ftgo-end-to-end-tests/build.gradle | 31 +++- .../ftgo/endtoendtests/EndToEndTests.java | 6 +- .../consumer-service.json | 4 + gradle.properties | 1 + 14 files changed, 269 insertions(+), 14 deletions(-) create mode 100644 ftgo-consumer-service-api/src/main/resources/ftgo-consumer-service-swagger.json rename {ftgo-consumer-service-api/src/main/java/net/chrisrichardson/ftgo/consumerservice/api => ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice}/web/CreateConsumerRequest.java (86%) rename {ftgo-consumer-service-api/src/main/java/net/chrisrichardson/ftgo/consumerservice/api => ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice}/web/CreateConsumerResponse.java (85%) create mode 100644 ftgo-consumer-service/src/test/java/net/chrisrichardson/ftgo/consumerservice/web/ConsumerControllerTest.java create mode 100644 ftgo-end-to-end-tests/swagger-codegen-config/consumer-service.json diff --git a/build-and-test-all.sh b/build-and-test-all.sh index bdcace23..5e607d99 100755 --- a/build-and-test-all.sh +++ b/build-and-test-all.sh @@ -36,7 +36,7 @@ echo KEEP_RUNNING=$KEEP_RUNNING ./gradlew buildContracts -./gradlew testClasses compileIntegrationTestJava compileComponentTestJava +./gradlew compileAll if [ -z "$USE_EXISTING_CONTAINERS" ] ; then ${DOCKER_COMPOSE?} down --remove-orphans -v diff --git a/build.gradle b/build.gradle index badd0038..e3f4897c 100644 --- a/build.gradle +++ b/build.gradle @@ -52,3 +52,7 @@ subprojects { task buildContracts(type: GradleBuild) { tasks = subprojects.collect { it.name }.findAll { it.endsWith("-contracts") }.collect { ":" + it + ":publish"} } + +task compileAll(type: GradleBuild) { + tasks = ["testClasses", "compileIntegrationTestJava", "compileComponentTestJava"] +} diff --git a/ftgo-consumer-service-api/src/main/resources/ftgo-consumer-service-swagger.json b/ftgo-consumer-service-api/src/main/resources/ftgo-consumer-service-swagger.json new file mode 100644 index 00000000..6649f86d --- /dev/null +++ b/ftgo-consumer-service-api/src/main/resources/ftgo-consumer-service-swagger.json @@ -0,0 +1,136 @@ +{ + "swagger": "2.0", + "info": { + "description": "Api Documentation", + "version": "1.0", + "title": "Api Documentation", + "termsOfService": "urn:tos", + "contact": {}, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0" + } + }, + "host": "localhost:8081", + "basePath": "/", + "tags": [ + { + "name": "consumer-controller", + "description": "Consumer Controller" + } + ], + "paths": { + "/consumers": { + "post": { + "tags": [ + "consumer-controller" + ], + "summary": "create", + "operationId": "createUsingPOST", + "consumes": [ + "application/json" + ], + "produces": [ + "*/*" + ], + "parameters": [ + { + "in": "body", + "name": "request", + "description": "request", + "required": true, + "schema": { + "$ref": "#/definitions/CreateConsumerRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/CreateConsumerResponse" + } + } + } + } + }, + "/consumers/{consumerId}": { + "get": { + "tags": [ + "consumer-controller" + ], + "summary": "get", + "operationId": "getUsingGET", + "produces": [ + "*/*" + ], + "parameters": [ + { + "name": "consumerId", + "in": "path", + "description": "consumerId", + "required": true, + "type": "integer", + "format": "int64" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/GetConsumerResponse" + } + } + } + } + } + }, + "definitions": { + "CreateConsumerRequest": { + "type": "object", + "properties": { + "name": { + "$ref": "#/definitions/PersonName" + } + }, + "title": "CreateConsumerRequest" + }, + "CreateConsumerResponse": { + "type": "object", + "properties": { + "consumerId": { + "type": "integer", + "format": "int64" + } + }, + "title": "CreateConsumerResponse" + }, + "GetConsumerResponse": { + "type": "object", + "properties": { + "consumerId": { + "type": "integer", + "format": "int64" + }, + "name": { + "$ref": "#/definitions/PersonName" + } + }, + "title": "GetConsumerResponse" + }, + "PersonName": { + "type": "object", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + }, + "required" : ["lastName", "firstName"], + "additionalProperties": true, + "title": "PersonName" + } + } +} diff --git a/ftgo-consumer-service/build.gradle b/ftgo-consumer-service/build.gradle index 277aa8e7..1e519bf3 100644 --- a/ftgo-consumer-service/build.gradle +++ b/ftgo-consumer-service/build.gradle @@ -28,4 +28,7 @@ dependencies { testCompile "com.jayway.jsonpath:json-path:2.3.0" testCompile "org.hamcrest:hamcrest:2.1" + testCompile "com.atlassian.oai:swagger-request-validator-springmvc:${swaggerRequestValidatorVersion}" + testCompile 'io.rest-assured:spring-mock-mvc:3.0.6' + } diff --git a/ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/ConsumerController.java b/ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/ConsumerController.java index ef736883..76b2761c 100644 --- a/ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/ConsumerController.java +++ b/ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/ConsumerController.java @@ -1,11 +1,8 @@ package net.chrisrichardson.ftgo.consumerservice.web; import io.eventuate.tram.events.publisher.ResultWithEvents; -import net.chrisrichardson.ftgo.consumerservice.api.web.CreateConsumerRequest; -import net.chrisrichardson.ftgo.consumerservice.api.web.CreateConsumerResponse; import net.chrisrichardson.ftgo.consumerservice.domain.Consumer; import net.chrisrichardson.ftgo.consumerservice.domain.ConsumerService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -14,9 +11,12 @@ @RequestMapping(path="/consumers") public class ConsumerController { - @Autowired private ConsumerService consumerService; + public ConsumerController(ConsumerService consumerService) { + this.consumerService = consumerService; + } + @RequestMapping(method= RequestMethod.POST) public CreateConsumerResponse create(@RequestBody CreateConsumerRequest request) { ResultWithEvents result = consumerService.create(request.getName()); diff --git a/ftgo-consumer-service-api/src/main/java/net/chrisrichardson/ftgo/consumerservice/api/web/CreateConsumerRequest.java b/ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/CreateConsumerRequest.java similarity index 86% rename from ftgo-consumer-service-api/src/main/java/net/chrisrichardson/ftgo/consumerservice/api/web/CreateConsumerRequest.java rename to ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/CreateConsumerRequest.java index 09a0eb2c..43f17c95 100644 --- a/ftgo-consumer-service-api/src/main/java/net/chrisrichardson/ftgo/consumerservice/api/web/CreateConsumerRequest.java +++ b/ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/CreateConsumerRequest.java @@ -1,4 +1,4 @@ -package net.chrisrichardson.ftgo.consumerservice.api.web; +package net.chrisrichardson.ftgo.consumerservice.web; import net.chrisrichardson.ftgo.common.PersonName; diff --git a/ftgo-consumer-service-api/src/main/java/net/chrisrichardson/ftgo/consumerservice/api/web/CreateConsumerResponse.java b/ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/CreateConsumerResponse.java similarity index 85% rename from ftgo-consumer-service-api/src/main/java/net/chrisrichardson/ftgo/consumerservice/api/web/CreateConsumerResponse.java rename to ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/CreateConsumerResponse.java index c666063b..4a98ec1b 100644 --- a/ftgo-consumer-service-api/src/main/java/net/chrisrichardson/ftgo/consumerservice/api/web/CreateConsumerResponse.java +++ b/ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/CreateConsumerResponse.java @@ -1,4 +1,4 @@ -package net.chrisrichardson.ftgo.consumerservice.api.web; +package net.chrisrichardson.ftgo.consumerservice.web; public class CreateConsumerResponse { private long consumerId; diff --git a/ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/GetConsumerResponse.java b/ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/GetConsumerResponse.java index e996d396..0185bb91 100644 --- a/ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/GetConsumerResponse.java +++ b/ftgo-consumer-service/src/main/java/net/chrisrichardson/ftgo/consumerservice/web/GetConsumerResponse.java @@ -1,8 +1,6 @@ package net.chrisrichardson.ftgo.consumerservice.web; import net.chrisrichardson.ftgo.common.PersonName; -import net.chrisrichardson.ftgo.consumerservice.api.web.CreateConsumerResponse; -import net.chrisrichardson.ftgo.consumerservice.domain.Consumer; public class GetConsumerResponse extends CreateConsumerResponse { private PersonName name; diff --git a/ftgo-consumer-service/src/test/java/net/chrisrichardson/ftgo/consumerservice/ConsumerServiceInMemoryIntegrationTest.java b/ftgo-consumer-service/src/test/java/net/chrisrichardson/ftgo/consumerservice/ConsumerServiceInMemoryIntegrationTest.java index 14467b83..affba1e3 100644 --- a/ftgo-consumer-service/src/test/java/net/chrisrichardson/ftgo/consumerservice/ConsumerServiceInMemoryIntegrationTest.java +++ b/ftgo-consumer-service/src/test/java/net/chrisrichardson/ftgo/consumerservice/ConsumerServiceInMemoryIntegrationTest.java @@ -9,7 +9,7 @@ import net.chrisrichardson.ftgo.common.Money; import net.chrisrichardson.ftgo.common.PersonName; import net.chrisrichardson.ftgo.consumerservice.api.ValidateOrderByConsumer; -import net.chrisrichardson.ftgo.consumerservice.api.web.CreateConsumerRequest; +import net.chrisrichardson.ftgo.consumerservice.web.CreateConsumerRequest; import net.chrisrichardson.ftgo.consumerservice.web.ConsumerWebConfiguration; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/ftgo-consumer-service/src/test/java/net/chrisrichardson/ftgo/consumerservice/web/ConsumerControllerTest.java b/ftgo-consumer-service/src/test/java/net/chrisrichardson/ftgo/consumerservice/web/ConsumerControllerTest.java new file mode 100644 index 00000000..9ede24d0 --- /dev/null +++ b/ftgo-consumer-service/src/test/java/net/chrisrichardson/ftgo/consumerservice/web/ConsumerControllerTest.java @@ -0,0 +1,80 @@ +package net.chrisrichardson.ftgo.consumerservice.web; + +import com.atlassian.oai.validator.OpenApiInteractionValidator; +import com.atlassian.oai.validator.springmvc.OpenApiValidationFilter; +import com.atlassian.oai.validator.springmvc.OpenApiValidationInterceptor; +import com.atlassian.oai.validator.springmvc.SpringMVCLevelResolverFactory; +import io.eventuate.common.json.mapper.JSonMapper; +import net.chrisrichardson.ftgo.common.CommonJsonMapperInitializer; +import net.chrisrichardson.ftgo.common.PersonName; +import net.chrisrichardson.ftgo.consumerservice.domain.Consumer; +import net.chrisrichardson.ftgo.consumerservice.domain.ConsumerService; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder; +import org.springframework.util.StreamUtils; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.Optional; + +import static io.restassured.module.mockmvc.RestAssuredMockMvc.given; +import static org.mockito.Mockito.mock; + +public class ConsumerControllerTest { + + private ConsumerController consumerController; + private ConsumerService consumerService; + private Consumer consumer; + + @Before + public void setUp() { + consumerService = mock(ConsumerService.class); + consumerController = new ConsumerController(consumerService); + consumer = new Consumer(new PersonName("x", "y")); + } + + @Test + public void shouldGetConsumer() throws IOException { + Mockito.when(consumerService.findById(1)).thenReturn(Optional.of(consumer)); + given(). + standaloneSetup(configureControllers(consumerController)). + when(). + get("/consumers/1"). + then(). + statusCode(200) + ; + + } + + private StandaloneMockMvcBuilder configureControllers(Object... controllers) throws IOException { + CommonJsonMapperInitializer.registerMoneyModule(); + MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(JSonMapper.objectMapper); + + ClassPathResource swaggerResource = new ClassPathResource("ftgo-consumer-service-swagger.json"); + + String specification = StreamUtils.copyToString(swaggerResource.getInputStream(), Charset.forName("UTF-8")); + + OpenApiInteractionValidator validator = OpenApiInteractionValidator + .createForInlineApiSpecification(specification) + .withLevelResolver(SpringMVCLevelResolverFactory.create()) + .build(); + + OpenApiValidationInterceptor validationInterceptor = new OpenApiValidationInterceptor(validator); + + OpenApiValidationFilter openApiValidationFilter = new OpenApiValidationFilter( + true, // enable request validation + true // enable response validation + ); + + return MockMvcBuilders.standaloneSetup(controllers) + .setMessageConverters(converter) + .addFilters(openApiValidationFilter) + .addInterceptors(validationInterceptor); + } + +} \ No newline at end of file diff --git a/ftgo-end-to-end-tests/build.gradle b/ftgo-end-to-end-tests/build.gradle index 1aabbb00..5a7f539d 100644 --- a/ftgo-end-to-end-tests/build.gradle +++ b/ftgo-end-to-end-tests/build.gradle @@ -1,5 +1,33 @@ +plugins { + id 'org.hidetake.swagger.generator' version '2.18.1' +} + apply plugin: 'docker-compose' +dependencies { + swaggerCodegen 'org.openapitools:openapi-generator-cli:3.3.4' // or OpenAPI Generator +} + +swaggerSources { + consumerService { + inputFile = file('../ftgo-consumer-service-api/src/main/resources/ftgo-consumer-service-swagger.json') + code { + language = 'java' + configFile = file('swagger-codegen-config/consumer-service.json') + components = ['models'] + // Supports additionalProperties: https://github.com/swagger-api/swagger-codegen#to-generate-a-sample-client-library + } + } +} + +compileJava.dependsOn swaggerSources.consumerService.code + +sourceSets.main.java.srcDir "${swaggerSources.consumerService.code.outputDir}/src/main/java" + +// This is unnecessary + +sourceSets.main.resources.srcDir "${swaggerSources.consumerService.code.outputDir}/src/main/resources" + dependencies { compile project(":ftgo-accounting-service-api") compile project(":ftgo-consumer-service-api") @@ -7,9 +35,10 @@ dependencies { compile project(":ftgo-restaurant-service-api") compile project(":ftgo-order-service-api") compile project(":ftgo-delivery-service-api") - + compile "io.eventuate.util:eventuate-util-test:$eventuateUtilVersion" + compile 'io.swagger:swagger-annotations:1.5.24' testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion" testCompile "com.jayway.restassured:rest-assured:$restAssuredVersion" diff --git a/ftgo-end-to-end-tests/src/test/java/net/chrisrichardson/ftgo/endtoendtests/EndToEndTests.java b/ftgo-end-to-end-tests/src/test/java/net/chrisrichardson/ftgo/endtoendtests/EndToEndTests.java index bf783a12..fb54c586 100644 --- a/ftgo-end-to-end-tests/src/test/java/net/chrisrichardson/ftgo/endtoendtests/EndToEndTests.java +++ b/ftgo-end-to-end-tests/src/test/java/net/chrisrichardson/ftgo/endtoendtests/EndToEndTests.java @@ -4,11 +4,11 @@ import com.jayway.restassured.config.ObjectMapperConfig; import com.jayway.restassured.config.RestAssuredConfig; import io.eventuate.common.json.mapper.JSonMapper; +import net.chrisrichardson.ftgo.apis.model.consumerservice.CreateConsumerRequest; +import net.chrisrichardson.ftgo.apis.model.consumerservice.PersonName; import net.chrisrichardson.ftgo.common.Address; import net.chrisrichardson.ftgo.common.CommonJsonMapperInitializer; import net.chrisrichardson.ftgo.common.Money; -import net.chrisrichardson.ftgo.common.PersonName; -import net.chrisrichardson.ftgo.consumerservice.api.web.CreateConsumerRequest; import net.chrisrichardson.ftgo.deliveryservice.api.web.CourierAvailability; import net.chrisrichardson.ftgo.kitchenservice.api.web.TicketAcceptance; import net.chrisrichardson.ftgo.orderservice.api.web.CreateOrderRequest; @@ -234,7 +234,7 @@ private void cancelOrder(int orderId) { private Integer createConsumer() { Integer consumerId = given(). - body(new CreateConsumerRequest(new PersonName("John", "Doe"))). + body(new CreateConsumerRequest().name(new PersonName().firstName("John").lastName("Doe"))). contentType("application/json"). when(). post(consumerBaseUrl()). diff --git a/ftgo-end-to-end-tests/swagger-codegen-config/consumer-service.json b/ftgo-end-to-end-tests/swagger-codegen-config/consumer-service.json new file mode 100644 index 00000000..9642250e --- /dev/null +++ b/ftgo-end-to-end-tests/swagger-codegen-config/consumer-service.json @@ -0,0 +1,4 @@ +{ + "modelPackage": "net.chrisrichardson.ftgo.apis.model.consumerservice", + "library" : "jersey2" +} diff --git a/gradle.properties b/gradle.properties index c7ddf3c2..66f778c8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,3 +32,4 @@ springCloudGatewayVersion=2.0.0.RELEASE micrometerVersion=1.0.4 microserviceCanvasVersion=0.1.1.RELEASE +swaggerRequestValidatorVersion=2.8.3