From d2f5a087100e1abf2ab31b1eac179c11c2920ca4 Mon Sep 17 00:00:00 2001 From: Igor Dianov Date: Mon, 9 Sep 2019 18:59:57 -0700 Subject: [PATCH] fix: add activiti-cloud-starter-connector test module dependency --- pom.xml | 6 ++ .../runtime/RuntimeBundleApplicationTest.java | 58 +++++-------------- 2 files changed, 22 insertions(+), 42 deletions(-) diff --git a/pom.xml b/pom.xml index 224e469b..ec4a379c 100755 --- a/pom.xml +++ b/pom.xml @@ -90,6 +90,12 @@ awaitility test + + org.activiti.cloud.connector + activiti-cloud-starter-connector + test + + diff --git a/src/test/java/org/activiti/cloud/runtime/RuntimeBundleApplicationTest.java b/src/test/java/org/activiti/cloud/runtime/RuntimeBundleApplicationTest.java index 2442aee5..7ecce922 100644 --- a/src/test/java/org/activiti/cloud/runtime/RuntimeBundleApplicationTest.java +++ b/src/test/java/org/activiti/cloud/runtime/RuntimeBundleApplicationTest.java @@ -12,9 +12,7 @@ import java.util.concurrent.TimeUnit; import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; import org.activiti.api.process.model.ProcessInstance; import org.activiti.api.process.model.builders.StartProcessPayloadBuilder; import org.activiti.api.process.model.payloads.StartProcessPayload; @@ -22,7 +20,9 @@ import org.activiti.api.runtime.shared.security.SecurityManager; import org.activiti.cloud.api.process.model.IntegrationRequest; import org.activiti.cloud.api.process.model.IntegrationResult; -import org.activiti.cloud.api.process.model.impl.IntegrationResultImpl; +import org.activiti.cloud.connectors.starter.channels.IntegrationResultSender; +import org.activiti.cloud.connectors.starter.configuration.ConnectorProperties; +import org.activiti.cloud.connectors.starter.model.IntegrationResultBuilder; import org.activiti.core.common.spring.identity.ExtendedInMemoryUserDetailsManager; import org.activiti.engine.RuntimeService; import org.awaitility.Awaitility; @@ -38,11 +38,9 @@ import org.springframework.cloud.stream.annotation.Input; import org.springframework.cloud.stream.annotation.StreamListener; import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration; -import org.springframework.cloud.stream.binding.BinderAwareChannelResolver; import org.springframework.context.annotation.Bean; import org.springframework.messaging.Message; import org.springframework.messaging.SubscribableChannel; -import org.springframework.messaging.support.MessageBuilder; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -126,23 +124,24 @@ public static interface ExampleConnectorChannels { public static class ExampleConnectorConsumer { @Autowired - TestIntegrationResultSender integrationResultSender; + IntegrationResultSender integrationResultSender; + + @Autowired + private ConnectorProperties connectorProperties; @StreamListener(ExampleConnectorChannels.IMPLEMENTATION) public void perfromTask(IntegrationRequest event) throws JsonParseException, JsonMappingException, IOException { - Map result = Collections.singletonMap("result", - event.getIntegrationContext() - .getBusinessKey()); - event.getIntegrationContext() - .addOutBoundVariables(result); - - IntegrationResult integrationResult = new IntegrationResultImpl(event, - event.getIntegrationContext()); - - integrationResultSender.send(integrationResult, ExampleConnectorChannels.IMPLEMENTATION); + Map results = Collections.singletonMap("result", + event.getIntegrationContext() + .getBusinessKey()); - assertThat(result).containsEntry("result", BUSINESS_KEY); + Message message = IntegrationResultBuilder.resultFor(event, connectorProperties) + .withOutboundVariables(results) + .buildMessage(); + integrationResultSender.send(message); + + assertThat(results).containsEntry("result", BUSINESS_KEY); exampleConnectorConsumer.countDown(); } @@ -151,11 +150,6 @@ public void perfromTask(IntegrationRequest event) throws JsonParseException, Jso @TestConfiguration public static class TestSupportConfig { - @Bean - public TestIntegrationResultSender testIntegrationResultSender() { - return new TestIntegrationResultSender(); - } - @Bean public UserDetailsService myUserDetailsService() { ExtendedInMemoryUserDetailsManager extendedInMemoryUserDetailsManager = new ExtendedInMemoryUserDetailsManager(); @@ -254,24 +248,4 @@ public String getName() { assertThat(securityManager.getAuthenticatedUserId()).isEqualTo(username); } } - - - public static class TestIntegrationResultSender { - - @Autowired - private BinderAwareChannelResolver resolver; - - @Autowired - private ObjectMapper objectMapper; - - public void send(IntegrationResult integrationResult, String targetService) throws JsonProcessingException { - - Message message = MessageBuilder.withPayload(objectMapper.writeValueAsString(integrationResult)) - .setHeader("targetService", targetService) - .build(); - - resolver.resolveDestination("integrationResultsConsumer") - .send(message); - } - } } \ No newline at end of file