From dcd18bb484876de5b5ee8014a7e3e3c68723af5b Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Thu, 15 Dec 2022 21:07:57 -0800 Subject: [PATCH] #185 Use Flyway DB #186 Upgrade to Spring Cloud Contract 3.x --- eventuate-tram-spring-flyway/build.gradle | 8 ++ ...tuateTramFlywayMigrationConfiguration.java | 14 ++++ .../tram/spring/flyway/ScriptExecutor.java | 48 +++++++++++ .../tram/spring/flyway/SqlExecutor.java | 7 ++ .../spring/flyway/V1005__MyMigration.java | 36 +++++++++ eventuate-tram-spring-logging/build.gradle | 4 + .../logging/LoggingMessageInterceptor.java | 21 +++++ ...ngMessageInterceptorAutoConfiguration.java | 13 +++ .../main/resources/META-INF/spring.factories | 2 + .../build.gradle | 28 ++----- ...> ContractVerifierEventuateMessaging.java} | 16 ++-- ...ventuateContractVerifierConfiguration.java | 8 +- .../EventuateTramMessageVerifier.java | 42 ++++------ .../EventuateTramRoutesConfigurer.java | 79 ++++++++++--------- gradle.properties | 3 +- settings.gradle | 3 + 16 files changed, 230 insertions(+), 102 deletions(-) create mode 100644 eventuate-tram-spring-flyway/build.gradle create mode 100644 eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/EventuateTramFlywayMigrationConfiguration.java create mode 100644 eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/ScriptExecutor.java create mode 100644 eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/SqlExecutor.java create mode 100644 eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/V1005__MyMigration.java create mode 100644 eventuate-tram-spring-logging/build.gradle create mode 100644 eventuate-tram-spring-logging/src/main/java/io/eventuate/tram/spring/logging/LoggingMessageInterceptor.java create mode 100644 eventuate-tram-spring-logging/src/main/java/io/eventuate/tram/spring/logging/LoggingMessageInterceptorAutoConfiguration.java create mode 100644 eventuate-tram-spring-logging/src/main/resources/META-INF/spring.factories rename eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/{EventuateContractVerifierMessaging.java => ContractVerifierEventuateMessaging.java} (55%) diff --git a/eventuate-tram-spring-flyway/build.gradle b/eventuate-tram-spring-flyway/build.gradle new file mode 100644 index 00000000..5223b134 --- /dev/null +++ b/eventuate-tram-spring-flyway/build.gradle @@ -0,0 +1,8 @@ +dependencies { + implementation "org.flywaydb:flyway-core:$flywayVersion" + implementation "org.flywaydb:flyway-mysql:$flywayVersion" + + implementation "org.springframework.boot:spring-boot-starter:$springBootVersion" + implementation "io.eventuate.common:eventuate-common-jdbc:$eventuateCommonVersion" + implementation "io.eventuate.common:eventuate-common-flyway:$eventuateCommonVersion" +} \ No newline at end of file diff --git a/eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/EventuateTramFlywayMigrationConfiguration.java b/eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/EventuateTramFlywayMigrationConfiguration.java new file mode 100644 index 00000000..300dcd0c --- /dev/null +++ b/eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/EventuateTramFlywayMigrationConfiguration.java @@ -0,0 +1,14 @@ +package io.eventuate.tram.spring.flyway; + +import io.eventuate.common.jdbc.OutboxPartitioningSpec; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class EventuateTramFlywayMigrationConfiguration { + + @Bean + public V1005__MyMigration v1005__myMigration(OutboxPartitioningSpec outboxPartitioningSpec) { + return new V1005__MyMigration(outboxPartitioningSpec); + } +} diff --git a/eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/ScriptExecutor.java b/eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/ScriptExecutor.java new file mode 100644 index 00000000..17e3ed58 --- /dev/null +++ b/eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/ScriptExecutor.java @@ -0,0 +1,48 @@ +package io.eventuate.tram.spring.flyway; + +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; +import org.springframework.util.FileCopyUtils; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.UncheckedIOException; +import java.sql.SQLException; +import java.util.Map; + +import static java.nio.charset.StandardCharsets.UTF_8; + +public class ScriptExecutor { + public static String readFileToString(String path) { + ResourceLoader resourceLoader = new DefaultResourceLoader(); + Resource resource = resourceLoader.getResource(path); + try (Reader reader = new InputStreamReader(resource.getInputStream(), UTF_8)) { + return FileCopyUtils.copyToString(reader); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + public void executeScript(Map replacements, String script, SqlExecutor sqlExecutor) { + + String s = readFileToString(script); + + for (Map.Entry entry : replacements.entrySet()) + s = s.replace("${" + entry.getKey() + "}", entry.getValue()); + + String[] t = s.split(";"); + + for (String statement : t) { + if (!statement.startsWith("USE ") && statement.trim().length() > 0) { + System.out.println(statement); + try { + sqlExecutor.execute(statement); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + } + } +} diff --git a/eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/SqlExecutor.java b/eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/SqlExecutor.java new file mode 100644 index 00000000..c97bc48e --- /dev/null +++ b/eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/SqlExecutor.java @@ -0,0 +1,7 @@ +package io.eventuate.tram.spring.flyway; + +import java.sql.SQLException; + +interface SqlExecutor { + void execute(String ddl) throws SQLException; +} diff --git a/eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/V1005__MyMigration.java b/eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/V1005__MyMigration.java new file mode 100644 index 00000000..e3ce8e93 --- /dev/null +++ b/eventuate-tram-spring-flyway/src/main/java/io/eventuate/tram/spring/flyway/V1005__MyMigration.java @@ -0,0 +1,36 @@ +package io.eventuate.tram.spring.flyway; + +import io.eventuate.common.jdbc.OutboxPartitioningSpec; +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.springframework.boot.jdbc.DatabaseDriver; + +import java.sql.Connection; +import java.util.Collections; + +public class V1005__MyMigration extends BaseJavaMigration { + + private OutboxPartitioningSpec outboxPartitioningSpec; + private ScriptExecutor scriptExecutor; + + public V1005__MyMigration(OutboxPartitioningSpec outboxPartitioningSpec) { + this.outboxPartitioningSpec = outboxPartitioningSpec; + this.scriptExecutor = new ScriptExecutor(); + } + + @Override + public void migrate(Context context) throws Exception { + System.out.println("Hi-flyway"); + + Connection connection = context.getConnection(); + DatabaseDriver driver = DatabaseDriver.fromJdbcUrl(connection.getMetaData().getURL()); + String driverId = driver.getId(); + + SqlExecutor sqlExecutor = statement -> connection.prepareStatement(statement).execute(); + + outboxPartitioningSpec.outboxTableSuffixes().forEach(suffix -> + scriptExecutor.executeScript(Collections.singletonMap("EVENTUATE_OUTBOX_SUFFIX", suffix.suffixAsString), + "flyway-templates/" + driverId + "/3.create-message-table.sql", sqlExecutor)); + } + +} diff --git a/eventuate-tram-spring-logging/build.gradle b/eventuate-tram-spring-logging/build.gradle new file mode 100644 index 00000000..faa615df --- /dev/null +++ b/eventuate-tram-spring-logging/build.gradle @@ -0,0 +1,4 @@ +dependencies { + implementation project(":eventuate-tram-messaging") + implementation "org.springframework.boot:spring-boot-starter:$springBootVersion" +} \ No newline at end of file diff --git a/eventuate-tram-spring-logging/src/main/java/io/eventuate/tram/spring/logging/LoggingMessageInterceptor.java b/eventuate-tram-spring-logging/src/main/java/io/eventuate/tram/spring/logging/LoggingMessageInterceptor.java new file mode 100644 index 00000000..2b3c3683 --- /dev/null +++ b/eventuate-tram-spring-logging/src/main/java/io/eventuate/tram/spring/logging/LoggingMessageInterceptor.java @@ -0,0 +1,21 @@ +package io.eventuate.tram.spring.logging; + +import io.eventuate.tram.messaging.common.Message; +import io.eventuate.tram.messaging.common.MessageInterceptor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LoggingMessageInterceptor implements MessageInterceptor { + + private static final Logger logger = LoggerFactory.getLogger("io.eventuate.activity"); + + @Override + public void postSend(Message message, Exception e) { + logger.info("Message Sent: {}", message); + } + + @Override + public void preHandle(String subscriberId, Message message) { + logger.info("message received: {} {}", subscriberId, message); + } +} diff --git a/eventuate-tram-spring-logging/src/main/java/io/eventuate/tram/spring/logging/LoggingMessageInterceptorAutoConfiguration.java b/eventuate-tram-spring-logging/src/main/java/io/eventuate/tram/spring/logging/LoggingMessageInterceptorAutoConfiguration.java new file mode 100644 index 00000000..8e33907a --- /dev/null +++ b/eventuate-tram-spring-logging/src/main/java/io/eventuate/tram/spring/logging/LoggingMessageInterceptorAutoConfiguration.java @@ -0,0 +1,13 @@ +package io.eventuate.tram.spring.logging; + +import io.eventuate.tram.messaging.common.MessageInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class LoggingMessageInterceptorAutoConfiguration { + @Bean + public MessageInterceptor messageLoggingInterceptor() { + return new LoggingMessageInterceptor(); + } +} diff --git a/eventuate-tram-spring-logging/src/main/resources/META-INF/spring.factories b/eventuate-tram-spring-logging/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..1dfe9d70 --- /dev/null +++ b/eventuate-tram-spring-logging/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +io.eventuate.tram.spring.logging.LoggingMessageInterceptorAutoConfiguration \ No newline at end of file diff --git a/eventuate-tram-spring-testing-support-cloud-contract/build.gradle b/eventuate-tram-spring-testing-support-cloud-contract/build.gradle index e921e147..03f557c2 100644 --- a/eventuate-tram-spring-testing-support-cloud-contract/build.gradle +++ b/eventuate-tram-spring-testing-support-cloud-contract/build.gradle @@ -1,28 +1,10 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath "io.spring.gradle:dependency-management-plugin:$springDependencyManagementPluginVersion" - // if using Stub Runner (consumer side) only remove this dependency - classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:$springCloudContractDependenciesVersion" - } -} - -apply plugin: "io.spring.dependency-management" - -dependencyManagement { - imports { - mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:$springCloudContractDependenciesVersion" - } -} - dependencies { + compile project(":eventuate-tram-messaging") + compile project(":eventuate-tram-commands") + compile "org.springframework.cloud:spring-cloud-starter-contract-verifier:$springCloudContractDependenciesVersion" + compile project(":eventuate-tram-spring-in-memory") + compile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner:$springCloudContractDependenciesVersion" - compile project(":eventuate-tram-testing-support") - - compile 'org.springframework.cloud:spring-cloud-starter-contract-verifier' - compile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner" } diff --git a/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateContractVerifierMessaging.java b/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/ContractVerifierEventuateMessaging.java similarity index 55% rename from eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateContractVerifierMessaging.java rename to eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/ContractVerifierEventuateMessaging.java index c2422ab1..9f5cc958 100644 --- a/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateContractVerifierMessaging.java +++ b/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/ContractVerifierEventuateMessaging.java @@ -5,19 +5,17 @@ import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessage; import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessaging; -import javax.inject.Inject; +import java.util.HashMap; -public class EventuateContractVerifierMessaging extends ContractVerifierMessaging { - - @Inject - ContractVerifierMessaging contractVerifierMessaging; - - public EventuateContractVerifierMessaging(MessageVerifier exchange) { +public class ContractVerifierEventuateMessaging extends ContractVerifierMessaging { + public ContractVerifierEventuateMessaging(MessageVerifier exchange) { super(exchange); } @Override - protected ContractVerifierMessage convert(Message m) { - return m == null ? null : contractVerifierMessaging.create(m.getPayload(), m.getHeaders()); + protected ContractVerifierMessage convert(Message receive) { + if (receive == null) + return null; + return new ContractVerifierMessage(receive.getPayload(), new HashMap<>(receive.getHeaders())); } } diff --git a/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateContractVerifierConfiguration.java b/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateContractVerifierConfiguration.java index c8c54eaa..9cf2c47e 100644 --- a/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateContractVerifierConfiguration.java +++ b/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateContractVerifierConfiguration.java @@ -10,14 +10,12 @@ public class EventuateContractVerifierConfiguration { @Bean - public MessageVerifier eventuateTramMessageVerifier() { - + public EventuateTramMessageVerifier newEventuateTramMessageVerifier() { return new EventuateTramMessageVerifier(); } @Bean - public ContractVerifierMessaging eventuateContractVerifierMessaging(MessageVerifier exchange) { - return new EventuateContractVerifierMessaging(exchange); + public ContractVerifierMessaging contractVerifierEventuateMessaging(MessageVerifier exchange) { + return new ContractVerifierEventuateMessaging(exchange); } - } diff --git a/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateTramMessageVerifier.java b/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateTramMessageVerifier.java index 557b2a5a..7fddc9ad 100644 --- a/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateTramMessageVerifier.java +++ b/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateTramMessageVerifier.java @@ -5,8 +5,10 @@ import io.eventuate.tram.messaging.producer.MessageBuilder; import io.eventuate.tram.messaging.producer.MessageProducer; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.contract.verifier.converter.YamlContract; import org.springframework.cloud.contract.verifier.messaging.MessageVerifier; +import javax.annotation.Nullable; import javax.annotation.PostConstruct; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -19,20 +21,11 @@ public class EventuateTramMessageVerifier implements MessageVerifier { @Autowired private MessageProducer messageProducer; - @Autowired private MessageConsumer messageConsumer; - @Override - public void send(Message message, String destination) { - throw new UnsupportedOperationException(); - } - private ConcurrentHashMap> messagesByDestination = new ConcurrentHashMap<>(); - public EventuateTramMessageVerifier() { - } - @PostConstruct public void subscribe() { messageConsumer.subscribe(getClass().getName(), singleton("*"), m -> { @@ -46,32 +39,31 @@ private LinkedBlockingQueue getForDestination(String destination) { } @Override - public void send(T payload, Map headers, String destination) { - String p = (String) payload; - MessageBuilder mb = MessageBuilder.withPayload(p); - - headers.forEach((key, value) -> { - mb.withHeader(key, (String) value); - }); - - messageProducer.send(destination, mb.build()); - } - - @Override - public Message receive(String destination, long timeout, TimeUnit timeUnit) { + public Message receive(String destination, long timeout, TimeUnit timeUnit, @Nullable YamlContract contract) { Message m; try { m = getForDestination(destination).poll(timeout, timeUnit); } catch (InterruptedException e) { throw new RuntimeException(e); } - if (m == null) - return null; return m; } @Override - public Message receive(String destination) { + public Message receive(String destination, YamlContract contract) { return receive(destination, 5, TimeUnit.SECONDS); } + + @Override + public void send(Message message, String destination, @Nullable YamlContract contract) { + messageProducer.send(destination, message); + } + + @Override + public void send(T payload, Map headers, String destination, @Nullable YamlContract contract) { + MessageBuilder messageBuilder = MessageBuilder.withPayload(payload.toString()); + headers.forEach((name, value) -> messageBuilder.withHeader(name, value.toString())); + messageProducer.send(destination, messageBuilder.build()); + + } } diff --git a/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateTramRoutesConfigurer.java b/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateTramRoutesConfigurer.java index 1a38672a..3f2d04ef 100644 --- a/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateTramRoutesConfigurer.java +++ b/eventuate-tram-spring-testing-support-cloud-contract/src/main/java/io/eventuate/tram/spring/cloudcontractsupport/EventuateTramRoutesConfigurer.java @@ -17,14 +17,12 @@ import org.springframework.cloud.contract.spec.internal.BodyMatchers; import org.springframework.cloud.contract.spec.internal.Header; import org.springframework.cloud.contract.stubrunner.BatchStubRunner; -import org.springframework.cloud.contract.stubrunner.StubConfiguration; import org.springframework.cloud.contract.verifier.util.*; import javax.annotation.PostConstruct; import java.util.Collection; import java.util.Collections; import java.util.Map; -import java.util.Optional; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -48,35 +46,34 @@ public EventuateTramRoutesConfigurer(BatchStubRunner batchStubRunner) { @PostConstruct public void initialize() { - Map> contracts = batchStubRunner - .getContracts(); - for (Collection list : contracts.values()) { - for (Contract it : list) { - if (it.getInput() != null - && it.getInput().getMessageFrom() != null - && it.getOutputMessage() != null - && it.getOutputMessage().getSentTo() != null) { - String inputClientValue = it.getInput().getMessageFrom().getClientValue(); - String outputClientValue = it.getOutputMessage().getSentTo().getClientValue(); - - messageConsumer.subscribe("Route-" + it.getLabel() + System.currentTimeMillis() + "." + idCounter++, - Collections.singleton(inputClientValue), (message) -> { - if (satisfies(message, it)) { - process(message, it).ifPresent(m -> messageProducer.send(outputClientValue, m)); - } - }); - -// from(inputClientValue) -// .filter(new StubRunnerCamelPredicate(it)) -// .process(new StubRunnerCamelProcessor(it)) -// .to(outputClientValue); + for (Collection contracts : batchStubRunner.getContracts().values()) { + for (Contract contract : contracts) { + if (isCommandMessageContract(contract)) { + + String commandChannel = contract.getInput().getMessageFrom().getClientValue(); + String replyToChannel = contract.getOutputMessage().getSentTo().getClientValue(); + + messageConsumer.subscribe("Route-" + contract.getLabel() + System.currentTimeMillis() + "." + idCounter++, + Collections.singleton(commandChannel), + message -> { + if (satisfies(message, contract)) { + messageProducer.send(replyToChannel, makeReply(message, contract)); + } + }); } } } } - private Optional process(Message message, Contract groovyDsl) { + private static boolean isCommandMessageContract(Contract contract) { + return contract.getInput() != null + && contract.getInput().getMessageFrom() != null + && contract.getOutputMessage() != null + && contract.getOutputMessage().getSentTo() != null; + } + + private Message makeReply(Message message, Contract groovyDsl) { MessageBuilder messageBuilder = MessageBuilder .withPayload(BodyExtractor .extractStubValueFrom(groovyDsl.getOutputMessage().getBody())); @@ -87,7 +84,7 @@ private Optional process(Message message, Contract groovyDsl) { } messageBuilder.withExtraHeaders("", correlationHeaders(message.getHeaders())); - return Optional.of(messageBuilder.build()); + return messageBuilder.build(); } private Map correlationHeaders(Map headers) { @@ -105,22 +102,26 @@ private boolean satisfies(Message message, Contract groovyDsl) { logger.info("Headers don't match {} {} ", groovyDsl.getLabel(), message); return false; } + return bodyMatches(message, groovyDsl); + } + + private boolean bodyMatches(Message message, Contract groovyDsl) { + DocumentContext parsedJson = JsonPath.parse(message.getPayload()); + BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers(); + Object dslBody = MapConverter.getStubSideValues(groovyDsl.getInput().getMessageBody()); - Object matchingInputMessage = JsonToJsonPathsConverter - .removeMatchingJsonPaths(dslBody, matchers); - JsonPaths jsonPaths = JsonToJsonPathsConverter - .transformToJsonPathWithStubsSideValuesAndNoArraySizeCheck( - matchingInputMessage); - DocumentContext parsedJson = JsonPath.parse(message.getPayload()); + Object matchingInputMessage = JsonToJsonPathsConverter.removeMatchingJsonPaths(dslBody, matchers); + JsonPaths jsonPaths = JsonToJsonPathsConverter.transformToJsonPathWithStubsSideValuesAndNoArraySizeCheck(matchingInputMessage); + boolean matches = true; for (MethodBufferingJsonVerifiable path : jsonPaths) { matches &= matchesJsonPath(parsedJson, path.jsonPath()); } logger.info("jsonPaths match {} {} {} ", groovyDsl.getLabel(), matches, message); - if (matchers != null && matchers.hasMatchers()) { - for (BodyMatcher matcher : matchers.jsonPathMatchers()) { + if (matches && matchers != null && matchers.hasMatchers()) { + for (BodyMatcher matcher : matchers.matchers()) { String jsonPath = JsonToJsonPathsConverter.convertJsonPathAndRegexToAJsonPath(matcher, dslBody); matches &= matchesJsonPath(parsedJson, jsonPath); } @@ -141,13 +142,13 @@ private boolean matchesJsonPath(DocumentContext parsedJson, String jsonPath) { private boolean headersMatch(Message message, Contract groovyDsl) { Map headers = message.getHeaders(); boolean matches = true; - for (Header it : groovyDsl.getInput().getMessageHeaders().getEntries()) { - String name = it.getName(); - Object value = it.getClientValue(); + for (Header contractHeader : groovyDsl.getInput().getMessageHeaders().getEntries()) { + String name = contractHeader.getName(); + Object value = contractHeader.getClientValue(); Object valueInHeader = headers.get(name); - matches &= value instanceof Pattern ? - ((Pattern) value).matcher(valueInHeader.toString()).matches() : + matches &= value instanceof Pattern ? ((Pattern) value).matcher(valueInHeader.toString()).matches() : valueInHeader != null && valueInHeader.equals(value); + logger.info("matches {} name {} pattern? {} headerValue {} value {}", matches, name, value instanceof Pattern, valueInHeader, value); } return matches; } diff --git a/gradle.properties b/gradle.properties index e8ab906e..541fbeda 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ micronautDataVersion=2.3.1 eventuateUtilVersion=0.16.0.BUILD-SNAPSHOT micronautSpringVersion=2.1.1 -springCloudContractDependenciesVersion=2.0.0.RELEASE +springCloudContractDependenciesVersion=3.1.3 springDependencyManagementPluginVersion=1.0.3.RELEASE springCloudSleuthVersion=2.0.2.RELEASE @@ -33,5 +33,6 @@ assertjVersion=3.23.1 testContainersVersion=1.17.3 reactorVersion=3.4.18 +flywayVersion=8.5.13 version=0.32.0-SNAPSHOT diff --git a/settings.gradle b/settings.gradle index 579d9f58..a95ff25a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -81,4 +81,7 @@ include 'eventuate-tram-spring-reactive-events-starter' include 'eventuate-tram-spring-commands-starter' include 'eventuate-tram-spring-reactive-integration-tests' include 'eventuate-tram-spring-reactive-optimistic-locking' +include 'eventuate-tram-spring-flyway' +include 'eventuate-tram-spring-logging' + include 'eventuate-tram-bom'