package com.tmobile.services.camunda.controller; import org.camunda.bpm.engine.ProcessEngine; import org.camunda.bpm.engine.ProcessEngines; import org.camunda.bpm.engine.runtime.ProcessInstance; import org.camunda.bpm.engine.runtime.ProcessInstantiationBuilder; import org.camunda.bpm.engine.test.Deployment; import org.camunda.bpm.engine.test.ProcessEngineRule; import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests; import org.camunda.bpm.extension.process_test_coverage.junit.rules.TestCoverageProcessEngineRuleBuilder; import org.camunda.bpm.scenario.ProcessScenario; import org.camunda.bpm.scenario.Scenario; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.runtimeService; import static org.mockito.Mockito.when; public class CreateTemplateUnitTest { @Rule @ClassRule public static ProcessEngineRule rule = TestCoverageProcessEngineRuleBuilder.create() .withDetailedCoverageLogging().build(); private Map variables = new HashMap<>(); @Mock private ProcessScenario validateTemplateDmnProcessScenario; @Mock private ProcessScenario createTemplateProcessScenario; @Before public void setupDefaultScenario() { MockitoAnnotations.initMocks(this); } @Test @Deployment(resources = { "create-template.bpmn", "task-validation.dmn"}) public void shouldCreateTemplate() throws IOException { // Given we create a new process instance /* ProcessInstance processInstance = runtimeService().startProcessInstanceByKey("create-template"); Scenario scenario = Scenario.run(bundleOrderApplication) .startByKey("bundle_ordering_process", variables) .execute();*/ ProcessEngine engine = ProcessEngines.getDefaultProcessEngine(); ProcessInstantiationBuilder instance = engine.getRuntimeService().createProcessInstanceByKey("create-template"); instance.setVariable("wf_search_api_base_url", "https://wf-search-api-dev.ext.px-npe02b.cf.t-mobile.com/"); String file = "src/test/resources/create-template.json"; when(createTemplateProcessScenario.runsCallActivity("validate-template")).thenReturn(Scenario.use(validateTemplateDmnProcessScenario)); String requestPayload = new String(Files.readAllBytes(Paths.get(file))); //String requestPayload = "{\\\"name\\\": \\\"test1 template Sep 29 2020 test1\\\"}"; variables.put("data", requestPayload); ProcessInstance pi = runtimeService().startProcessInstanceByKey("create-template", BpmnAwareTests.withVariables("data", requestPayload)); System.out.println(pi); } }