Skip to content
This repository has been archived by the owner on May 18, 2020. It is now read-only.

Commit

Permalink
fix: add activiti-cloud-starter-connector test module dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
igdianov committed Sep 11, 2019
1 parent 17e11a6 commit d2f5a08
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 42 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.activiti.cloud.connector</groupId>
<artifactId>activiti-cloud-starter-connector</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
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;
import org.activiti.api.process.runtime.ProcessRuntime;
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String, Object> result = Collections.singletonMap("result",
event.getIntegrationContext()
.getBusinessKey());
event.getIntegrationContext()
.addOutBoundVariables(result);

IntegrationResult integrationResult = new IntegrationResultImpl(event,
event.getIntegrationContext());

integrationResultSender.send(integrationResult, ExampleConnectorChannels.IMPLEMENTATION);
Map<String, Object> results = Collections.singletonMap("result",
event.getIntegrationContext()
.getBusinessKey());

assertThat(result).containsEntry("result", BUSINESS_KEY);
Message<IntegrationResult> message = IntegrationResultBuilder.resultFor(event, connectorProperties)
.withOutboundVariables(results)
.buildMessage();
integrationResultSender.send(message);

assertThat(results).containsEntry("result", BUSINESS_KEY);

exampleConnectorConsumer.countDown();
}
Expand All @@ -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();
Expand Down Expand Up @@ -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<String> message = MessageBuilder.withPayload(objectMapper.writeValueAsString(integrationResult))
.setHeader("targetService", targetService)
.build();

resolver.resolveDestination("integrationResultsConsumer")
.send(message);
}
}
}

0 comments on commit d2f5a08

Please sign in to comment.