Collapse stub runners into one project
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
# Auto Configuration
|
||||
org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner=\
|
||||
org.springframework.cloud.contract.stubrunner.messaging.camel.StubRunnerCamelConfiguration
|
||||
@@ -1,3 +0,0 @@
|
||||
# Auto Configuration
|
||||
org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner=\
|
||||
org.springframework.cloud.contract.stubrunner.messaging.integration.StubRunnerIntegrationConfiguration
|
||||
@@ -12,13 +12,15 @@
|
||||
<packaging>jar</packaging>
|
||||
<name>Spring Cloud Contract Stub Runner Stream</name>
|
||||
<description>Spring Cloud Contract Stub Runner Stream</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-stub-runner</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
@@ -28,14 +30,12 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-verifier</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-stream</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-stream-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
# Auto Configuration
|
||||
org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner=\
|
||||
org.springframework.cloud.contract.stubrunner.messaging.stream.StubRunnerStreamConfiguration
|
||||
@@ -17,6 +17,11 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-verifier</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-stream-test-support</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-wiremock</artifactId>
|
||||
@@ -53,6 +58,21 @@
|
||||
<groupId>args4j</groupId>
|
||||
<artifactId>args4j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-spring-boot-starter</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-jackson</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-java-dsl</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.aether</groupId>
|
||||
<artifactId>aether-api</artifactId>
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Map;
|
||||
|
||||
import org.apache.camel.RoutesBuilder;
|
||||
import org.apache.camel.spring.SpringRouteBuilder;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.cloud.contract.spec.Contract;
|
||||
import org.springframework.cloud.contract.stubrunner.BatchStubRunner;
|
||||
import org.springframework.cloud.contract.stubrunner.StubConfiguration;
|
||||
@@ -34,6 +35,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(RoutesBuilder.class)
|
||||
public class StubRunnerCamelConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -18,16 +18,23 @@ package org.springframework.cloud.contract.stubrunner.messaging.integration;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.cloud.contract.spec.Contract;
|
||||
import org.springframework.cloud.contract.stubrunner.BatchStubRunner;
|
||||
import org.springframework.cloud.contract.stubrunner.StubConfiguration;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.dsl.FilterEndpointSpec;
|
||||
import org.springframework.integration.dsl.GenericEndpointSpec;
|
||||
import org.springframework.integration.dsl.IntegrationFlowBuilder;
|
||||
import org.springframework.integration.dsl.IntegrationFlows;
|
||||
import org.springframework.integration.dsl.support.Consumer;
|
||||
import org.springframework.integration.transformer.MessageTransformingHandler;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
/**
|
||||
@@ -37,26 +44,39 @@ import org.springframework.messaging.Message;
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(IntegrationFlowBuilder.class)
|
||||
public class StubRunnerIntegrationConfiguration {
|
||||
|
||||
@Bean
|
||||
public FlowRegistrar flowRegistrar(AutowireCapableBeanFactory beanFactory,
|
||||
@ConditionalOnMissingBean(name="stubFlowRegistrar")
|
||||
public FlowRegistrar stubFlowRegistrar(AutowireCapableBeanFactory beanFactory,
|
||||
BatchStubRunner batchStubRunner) {
|
||||
Map<StubConfiguration, Collection<Contract>> contracts = batchStubRunner
|
||||
.getContracts();
|
||||
contracts.entrySet().stream().forEach(entry -> {
|
||||
for (Entry<StubConfiguration, Collection<Contract>> entry : contracts.entrySet()) {
|
||||
String name = entry.getKey().getGroupId() + "_"
|
||||
+ entry.getKey().getArtifactId();
|
||||
entry.getValue().stream().forEach(dsl -> {
|
||||
for (Contract dsl : entry.getValue()) {
|
||||
if (dsl.getInput() != null && dsl.getInput().getMessageFrom() != null
|
||||
&& dsl.getInput().getMessageFrom().getClientValue() != null) {
|
||||
String flowName = name + "_" + dsl.getLabel() + "_" + dsl.hashCode();
|
||||
final String flowName = name + "_" + dsl.getLabel() + "_" + dsl.hashCode();
|
||||
IntegrationFlowBuilder builder = IntegrationFlows
|
||||
.from(dsl.getInput().getMessageFrom().getClientValue())
|
||||
.filter(new StubRunnerIntegrationMessageSelector(dsl),
|
||||
e -> e.id(flowName + ".filter"))
|
||||
new Consumer<FilterEndpointSpec>() {
|
||||
@Override
|
||||
public void accept(FilterEndpointSpec e) {
|
||||
e.id(flowName + ".filter");
|
||||
}
|
||||
})
|
||||
.transform(new StubRunnerIntegrationTransformer(dsl),
|
||||
e -> e.id(flowName + ".transformer"));
|
||||
new Consumer<GenericEndpointSpec<MessageTransformingHandler>>() {
|
||||
@Override
|
||||
public void accept(
|
||||
GenericEndpointSpec<MessageTransformingHandler> e) {
|
||||
e.id(flowName + ".transformer");
|
||||
}
|
||||
});
|
||||
if (dsl.getOutputMessage() != null) {
|
||||
builder = builder.channel(
|
||||
dsl.getOutputMessage().getSentTo().getClientValue());
|
||||
@@ -68,9 +88,9 @@ public class StubRunnerIntegrationConfiguration {
|
||||
beanFactory.getBean(flowName + ".filter", Lifecycle.class).start();
|
||||
beanFactory.getBean(flowName + ".transformer", Lifecycle.class)
|
||||
.start();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return new FlowRegistrar();
|
||||
}
|
||||
|
||||
@@ -23,16 +23,24 @@ import java.util.Map.Entry;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.cloud.contract.spec.Contract;
|
||||
import org.springframework.cloud.contract.stubrunner.BatchStubRunner;
|
||||
import org.springframework.cloud.contract.stubrunner.StubConfiguration;
|
||||
import org.springframework.cloud.contract.stubrunner.messaging.stream.StubRunnerStreamConfiguration.FlowRegistrar;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.config.BindingProperties;
|
||||
import org.springframework.cloud.stream.config.ChannelBindingServiceProperties;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.dsl.FilterEndpointSpec;
|
||||
import org.springframework.integration.dsl.GenericEndpointSpec;
|
||||
import org.springframework.integration.dsl.IntegrationFlowBuilder;
|
||||
import org.springframework.integration.dsl.IntegrationFlows;
|
||||
import org.springframework.integration.dsl.support.Consumer;
|
||||
import org.springframework.integration.transformer.MessageTransformingHandler;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -43,13 +51,15 @@ import org.springframework.util.StringUtils;
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({FlowRegistrar.class, EnableBinding.class})
|
||||
public class StubRunnerStreamConfiguration {
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(StubRunnerStreamConfiguration.class);
|
||||
|
||||
@Bean
|
||||
public FlowRegistrar flowRegistrar(AutowireCapableBeanFactory beanFactory,
|
||||
@ConditionalOnMissingBean(name="stubFlowRegistrar")
|
||||
public FlowRegistrar stubFlowRegistrar(AutowireCapableBeanFactory beanFactory,
|
||||
BatchStubRunner batchStubRunner) {
|
||||
Map<StubConfiguration, Collection<Contract>> contracts = batchStubRunner
|
||||
.getContracts();
|
||||
@@ -58,35 +68,46 @@ public class StubRunnerStreamConfiguration {
|
||||
StubConfiguration key = entry.getKey();
|
||||
Collection<Contract> value = entry.getValue();
|
||||
String name = key.getGroupId() + "_" + key.getArtifactId();
|
||||
value.stream()
|
||||
.filter(dsl -> dsl != null && dsl.getInput() != null
|
||||
for (Contract dsl : value) {
|
||||
if (dsl != null && dsl.getInput() != null
|
||||
&& dsl.getInput().getMessageFrom() != null
|
||||
&& StringUtils.hasText(
|
||||
dsl.getInput().getMessageFrom().getClientValue()))
|
||||
.forEach(dsl -> {
|
||||
String flowName = name + "_" + dsl.getLabel() + "_"
|
||||
+ dsl.hashCode();
|
||||
String from = resolvedDestination(beanFactory,
|
||||
dsl.getInput().getMessageFrom().getClientValue());
|
||||
IntegrationFlowBuilder builder = IntegrationFlows.from(from)
|
||||
.filter(new StubRunnerStreamMessageSelector(dsl),
|
||||
e -> e.id(flowName + ".filter"))
|
||||
.transform(new StubRunnerStreamTransformer(dsl),
|
||||
e -> e.id(flowName + ".transformer"));
|
||||
if (dsl.getOutputMessage() != null
|
||||
&& dsl.getOutputMessage().getSentTo() != null) {
|
||||
builder = builder.channel(resolvedDestination(beanFactory,
|
||||
dsl.getOutputMessage().getSentTo().getClientValue()));
|
||||
}
|
||||
else {
|
||||
builder = builder.handle(new DummyMessageHandler(), "handle");
|
||||
}
|
||||
beanFactory.initializeBean(builder.get(), flowName);
|
||||
beanFactory.getBean(flowName + ".filter", Lifecycle.class)
|
||||
.start();
|
||||
beanFactory.getBean(flowName + ".transformer", Lifecycle.class)
|
||||
.start();
|
||||
});
|
||||
dsl.getInput().getMessageFrom().getClientValue())) {
|
||||
final String flowName = name + "_" + dsl.getLabel() + "_"
|
||||
+ dsl.hashCode();
|
||||
String from = resolvedDestination(beanFactory,
|
||||
dsl.getInput().getMessageFrom().getClientValue());
|
||||
IntegrationFlowBuilder builder = IntegrationFlows.from(from)
|
||||
.filter(new StubRunnerStreamMessageSelector(dsl),
|
||||
new Consumer<FilterEndpointSpec>() {
|
||||
@Override
|
||||
public void accept(FilterEndpointSpec e) {
|
||||
e.id(flowName + ".filter");
|
||||
}
|
||||
})
|
||||
.transform(new StubRunnerStreamTransformer(dsl),
|
||||
new Consumer<GenericEndpointSpec<MessageTransformingHandler>>() {
|
||||
@Override
|
||||
public void accept(
|
||||
GenericEndpointSpec<MessageTransformingHandler> e) {
|
||||
e.id(flowName + ".transformer");
|
||||
}
|
||||
});
|
||||
if (dsl.getOutputMessage() != null
|
||||
&& dsl.getOutputMessage().getSentTo() != null) {
|
||||
builder = builder.channel(resolvedDestination(beanFactory,
|
||||
dsl.getOutputMessage().getSentTo().getClientValue()));
|
||||
}
|
||||
else {
|
||||
builder = builder.handle(new DummyMessageHandler(), "handle");
|
||||
}
|
||||
beanFactory.initializeBean(builder.get(), flowName);
|
||||
beanFactory.getBean(flowName + ".filter", Lifecycle.class)
|
||||
.start();
|
||||
beanFactory.getBean(flowName + ".transformer", Lifecycle.class)
|
||||
.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
return new FlowRegistrar();
|
||||
}
|
||||
@@ -2,4 +2,7 @@
|
||||
org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner=\
|
||||
org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration,\
|
||||
org.springframework.cloud.contract.stubrunner.spring.cloud.StubRunnerSpringCloudAutoConfiguration,\
|
||||
org.springframework.cloud.contract.stubrunner.spring.cloud.ribbon.StubRunnerRibbonAutoConfiguration
|
||||
org.springframework.cloud.contract.stubrunner.spring.cloud.ribbon.StubRunnerRibbonAutoConfiguration,\
|
||||
org.springframework.cloud.contract.stubrunner.messaging.stream.StubRunnerStreamConfiguration,\
|
||||
org.springframework.cloud.contract.stubrunner.messaging.integration.StubRunnerIntegrationConfiguration,\
|
||||
org.springframework.cloud.contract.stubrunner.messaging.camel.StubRunnerCamelConfiguration
|
||||
|
||||
Reference in New Issue
Block a user