activiti7 cloud connectors and bpmn testing

cancel
Showing results for 
Search instead for 
Did you mean: 
Member II

activiti7 cloud connectors and bpmn testing

i am using activiti cloud 7 and cloud connectors. i would like to write automated (junit-like) tests to test the bpmn processes.

i can deploy my bpmn models in my test, but i am having difficulties mocking the service tasks. my service tasks are implemented using cloud connectors.

how can i mock my service tasks? is there an example somewhere?  

2 Replies
Member II

Re: activiti7 cloud connectors and bpmn testing

Hi,

May be you can try out this way using a junit test case.

@Test
public void testConnectorSuccess() {
try {
   IntegrationContextImpl ic=new IntegrationContextImpl();
   IntegrationRequest ir=new IntegrationRequestImpl(ic);

   // Create an instance of your connector class

   Connector con=new Connector();   

   //Call method in connector e.g. performTask is a sample method in above connector

   con.performTask(ir);
   } catch (InterruptedException e) {
      e.printStackTrace();
   }
}

Member II

Re: activiti7 cloud connectors and bpmn testing

thank you venkataramana.

to be more specific, I am talking about the trending-topic-campaigns (https://activiti.gitbook.io/activiti-7-developers-guide/blueprints/trending-topic-campaigns),

and I would like to test the CampaignService.java by starting en-campaign.bpmn20.xml.

the bpmn flow is started, but the workflow hangs at the first service task (there is no one to reply to the integration request).

the connector (TwitterProcessingConnector) is located in another module (connectors-processing), I can not instantiate it in module rb-english-campaign.

here is my test (simplified):

@RunWith(SpringRunner.class)
@SpringBootTest()
@DirtiesContext
public class CampaignServiceTest {

private static final Logger LOGGER = LoggerFactory.getLogger(CampaignServiceTest.class);

@Autowired
private RuntimeService runtimeService;
@Autowired
private RepositoryService repositoryService;
@Autowired
private CampaignService campaignService;

@Autowired
private MessageCollector messageCollector;

@Autowired
private ProcessingConnectorChannels processingConnectorChannels;
@Before
public void before() {
deployModels();
}

@Test
public void testProcessTweet() {
Tweet tweet = new Tweet("text", "author", "en", new Date().getTime());
campaignService.processTweet(tweet);

assertEquals(0L, getExecutionCount());
assertEquals(0L, getActiveProcessesCount());
}

private void deployModels() {
DeploymentBuilder builder = repositoryService.createDeployment();
builder.addClasspathResource("processes/en-campaign.bpmn20.xml");
builder.deploy();
}

public void processTweet(Tweet tweet) {
Map<String, Object> vars = new HashMap<>();
vars.put("text",
tweet.getText());
vars.put("author",
tweet.getAuthor());
vars.put("lang",
tweet.getLang());
vars.put("timestamp",
tweet.getTimestamp());
vars.put("campaign",
currentTopic);
runtimeService.startProcessInstanceByKey("launchCampaign",
currentTopic,
//BusinessKey
vars);
}

}