@SuppressWarnings({"unchecked", "rawtypes"})

@Test
public void testMigrateUserTaskProcessInstanceWithRollback() {
    createRuntimeManagers("migration/v1/BPMN2-UserTask-v1.bpmn2", "migration/v2/BPMN2-UserTask-v2.bpmn2");
    assertNotNull(managerV1);
    assertNotNull(managerV2);
    
    RuntimeEngine runtime = managerV1.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession); 
    
    ProcessInstance pi1 = ksession.startProcess(PROCESS_ID_V1);
    assertNotNull(pi1);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());        
    managerV1.disposeRuntimeEngine(runtime);
    
    MigrationSpec migrationSpec = new MigrationSpec(DEPLOYMENT_ID_V1, pi1.getId(), DEPLOYMENT_ID_V2, PROCESS_ID_V2);        
    MigrationManager migrationManager = new MigrationManager(migrationSpec);
    MigrationReport report = null;              
    try {
        // explicitly without generic to cause error (class cast) in migration process to test rollback
        Map erronousMapping = Collections.singletonMap("_2", 2);            
        migrationManager.migrate(erronousMapping);
    } catch (MigrationException e) {
       report = e.getReport(); 
    }        
    assertNotNull(report);
    assertFalse(report.isSuccessful());
    
    JPAAuditLogService auditService = new JPAAuditLogService(emf);
    ProcessInstanceLog log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(PROCESS_ID_V1, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
    
    auditService.dispose();
}