Good morning,
I have trouble understanding properly how the history services can be tested. I tried in vain to replicate the various tests in the engine GitHub repository to my own project, and feel a bit lost. Who would be kind enough to tell me what I am doing wrong here?
I am using version 6.5.1
public class ExampleApplication {
@Bean
public EngineConfigurationConfigurer<SpringCmmnEngineConfiguration> customCmmnEngineEmailLoggingListenerConfigurer() {
return engineConfiguration -> {
engineConfiguration.setAsyncExecutorActivate(false);
engineConfiguration.setAsyncHistoryExecutorActivate(false);
engineConfiguration.setEenableEntityLinks(true);
engineConfiguration.setEnableHistoricTaskLogging(true);
};
}
}
@ExtendWith(FlowableSpringExtension.class)
@ExtendWith(SpringExtension.class)
@ExtendWith(FlowableCmmnSpringExtension.class)
@SpringBootTest(classes = {ExampleApplication.class})
@Transactional
public class CaseManagementTest {
@Autowired
private CmmnRuntimeService cmmnRuntimeService;
@Autowired
private CmmnHistoryService cmmnHistoryService;
@Autowired
private ObjectMapper objectMapper;
@Value("classpath:/com/example/abc001CaseData.json")
private Resource jsonFileWithCaseVariables;
@CmmnDeployment(resources="classpath:/com/example/ABC_C001.cmmn", tenantId = "")
@Test
public void testAbcCaseInstances() {
assertTrue(CmmnHistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, cmmnEngineConfiguration));
CaseInstance caseInstance = new CaseCreationUtils(cmmnRuntimeService, objectMapper).createAbcTestCase(jsonFileWithCaseVariables, "ABC_C001");
String caseInstanceId = caseInstance.getId();
assertEquals(1, cmmnRuntimeService.createCaseInstanceQuery().count());
CmmnHistoryTestHelper.waitForJobExecutorToProcessAllHistoryJobs(cmmnEngineConfiguration, cmmnManagementService, 30000L, 100L);//FIXME: times out whether async-history-executor-activate=true or async-history-executor-activate=false
assertEquals(1, cmmnHistoryService.createHistoricCaseInstanceQuery().count());//FIXME: fails, even if CmmnHistoryTestHelper.waitForJobExecutorToProcessAllHistoryJobs is called before
cmmnRuntimeService.terminateCaseInstance(caseInstanceId);
assertEquals(0, cmmnRuntimeService.createCaseInstanceQuery().count());
CmmnHistoryTestHelper.waitForJobExecutorToProcessAllHistoryJobs(cmmnEngineConfiguration, cmmnManagementService, 30000L, 100L);//FIXME: times out whether async-history-executor-activate=true or async-history-executor-activate=false
assertEquals(1, cmmnHistoryService.createHistoricCaseInstanceQuery().count());//FIXME: fails, even if CmmnHistoryTestHelper.waitForJobExecutorToProcessAllHistoryJobs is called before
//TO BE CONTINUED
}
public class CaseCreationUtils {
private final CmmnRuntimeService cmmnRuntimeService;
private final ObjectMapper objectMapper;
public CaseCreationUtils(CmmnRuntimeService cmmnRuntimeService, ObjectMapper objectMapper) {
this.cmmnRuntimeService = cmmnRuntimeService;
this.objectMapper = objectMapper;
}
public CaseInstance createAbcTestCase(Resource jsonFile, String definitionKey) {
return cmmnRuntimeService.createCaseInstanceBuilder()
.caseDefinitionKey(definitionKey)
.tenantId("")
.variables(getVariablesFromJson(jsonFile))
.start();
}
private Map<String, Object> getVariablesFromJson(Resource jsonFile) {
//FIXME: ideally, the variables should not be serialized as a form payload (as is the case with file abc001CaseData.json) but in the following way: https://flowable.com/open-source/docs/cmmn/ch08-REST/#create-or-update-variables-on-a-case-instance
JsonNode jsonNode;
try {
jsonNode = objectMapper.readTree(jsonFile.getFile());
} catch (Exception e) {
throw new IllegalArgumentException("File path not found or is null!");
}
return objectMapper.convertValue(jsonNode, Map.class);
}
}
Many thanks in advance, and a great day to you.
Tiffany