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?
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();
}
}
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);
}
}
Ask for and offer help to other Alfresco Process Services and Activiti Users and members of the Alfresco team.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.