Search in sources :

Example 41 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Gatekeeper by FINRAOS.

the class AccessRequestServiceTest method initMocks.

@Before
public void initMocks() {
    testDate = new Date();
    Integer mockMaximum = 180;
    // Setting up the spring values
    Map<String, Map<String, Integer>> mockDev = new HashMap<>();
    Map<String, Integer> mockDba = new HashMap<>();
    mockDba.put("dev", 180);
    mockDba.put("qa", 180);
    mockDba.put("prod", 180);
    mockDev.put("datafix", mockDba);
    Region[] regions = new Region[] { new Region("us-east-1") };
    Account mockAccount = new Account(1234L, "Dev Test", "dev", "dev-test", Arrays.asList(regions));
    when(approvalThreshold.getApprovalPolicy(GatekeeperRdsRole.DEV)).thenReturn(mockDev);
    when(approvalThreshold.getApprovalPolicy(GatekeeperRdsRole.OPS)).thenReturn(mockDev);
    when(approvalThreshold.getApprovalPolicy(GatekeeperRdsRole.DBA)).thenReturn(mockDev);
    when(overridePolicy.getMaxDaysForRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(mockMaximum);
    List<AWSRdsDatabase> instances = new ArrayList<>();
    when(awsRdsDatabase.getApplication()).thenReturn("TestApplication");
    when(awsRdsDatabase.getInstanceId()).thenReturn("testId");
    when(awsRdsDatabase.getDbName()).thenReturn("testDbName");
    when(awsRdsDatabase.getEndpoint()).thenReturn("testEndpoint");
    when(awsRdsDatabase.getEngine()).thenReturn("testEngine");
    when(awsRdsDatabase.getStatus()).thenReturn("UP");
    instances.add(awsRdsDatabase);
    // Owner mock
    when(ownerRequest.getAccount()).thenReturn("DEV");
    when(ownerRequest.getAwsRdsInstances()).thenReturn(instances);
    when(ownerRequest.getDays()).thenReturn(1);
    when(ownerRequest.getRequestorId()).thenReturn("owner");
    when(ownerRequest.getId()).thenReturn(1L);
    when(ownerRequest.getAccountSdlc()).thenReturn("dev");
    // Non-owner mock
    when(nonOwnerRequest.getAccount()).thenReturn("DEV");
    when(nonOwnerRequest.getAwsRdsInstances()).thenReturn(instances);
    when(nonOwnerRequest.getDays()).thenReturn(1);
    when(nonOwnerRequest.getRequestorId()).thenReturn("non-owner");
    when(nonOwnerRequest.getId()).thenReturn(2L);
    when(nonOwnerRequest.getAccountSdlc()).thenReturn("dev");
    Set<String> ownerMemberships = new HashSet<String>();
    ownerMemberships.add("TestApplication");
    List<UserRole> roles = new ArrayList<>();
    UserRole userRole = new UserRole();
    userRole.setRole("datafix");
    roles.add(userRole);
    when(nonOwnerRequest.getRoles()).thenReturn(roles);
    when(ownerRequest.getRoles()).thenReturn(roles);
    when(ownerRequestWrapper.getInstances()).thenReturn(instances);
    when(ownerRequestWrapper.getDays()).thenReturn(1);
    when(ownerRequestWrapper.getRequestorId()).thenReturn("owner");
    when(ownerRequestWrapper.getAccount()).thenReturn("testAccount");
    when(ownerRequestWrapper.getRegion()).thenReturn("testRegion");
    when(ownerRequestWrapper.getAccountSdlc()).thenReturn("dev");
    when(userEntry.getUserId()).thenReturn("testUserId");
    when(userEntry.getName()).thenReturn("testName");
    when(userEntry.getEmail()).thenReturn("testEmail@finra.org");
    when(user.getUserId()).thenReturn("testUserId");
    List<User> users = new ArrayList<>();
    users.add(user);
    when(ownerRequestWrapper.getUsers()).thenReturn(users);
    when(ownerRequest.getUsers()).thenReturn(users);
    when(gatekeeperRoleService.getRole()).thenReturn(GatekeeperRdsRole.DEV);
    when(gatekeeperRoleService.getUserProfile()).thenReturn(userEntry);
    when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
    when(runtimeService.createProcessInstanceQuery().count()).thenReturn(2L);
    // Mocks for getActiveRequest()
    when(ownerOneTask.getExecutionId()).thenReturn("ownerOneTask");
    when(ownerOneTask.getCreateTime()).thenReturn(new Date(4500000));
    when(ownerOneTask.getId()).thenReturn("taskOne");
    when(ownerTwoTask.getExecutionId()).thenReturn("ownerTwoTask");
    when(ownerTwoTask.getCreateTime()).thenReturn(testDate);
    when(ownerTwoTask.getId()).thenReturn("taskTwo");
    when(runtimeService.getVariable("ownerOneTask", "accessRequest")).thenReturn(ownerRequest);
    when(runtimeService.getVariable("ownerTwoTask", "accessRequest")).thenReturn(nonOwnerRequest);
    List<Task> activeTasks = new ArrayList<>();
    activeTasks.add(ownerOneTask);
    activeTasks.add(ownerTwoTask);
    when(taskService.createTaskQuery()).thenReturn(taskQuery);
    when(taskService.createTaskQuery().active()).thenReturn(taskQuery);
    when(taskService.createTaskQuery().active().list()).thenReturn(activeTasks);
    // Mocks for getCompletedRequest()
    List<HistoricVariableInstance> taskVars = new ArrayList<>();
    when(ownerHistoricVariableInstanceAttempt.getProcessInstanceId()).thenReturn("ownerRequest");
    when(ownerHistoricVariableInstanceStatus.getProcessInstanceId()).thenReturn("ownerRequest");
    when(ownerHistoricVariableInstanceAccessRequest.getProcessInstanceId()).thenReturn("ownerRequest");
    when(nonOwnerHistoricVariableInstanceAttempt.getProcessInstanceId()).thenReturn("nonOwnerRequest");
    when(nonOwnerHistoricVariableInstanceStatus.getProcessInstanceId()).thenReturn("nonOwnerRequest");
    when(nonOwnerHistoricVariableInstanceAccessRequest.getProcessInstanceId()).thenReturn("nonOwnerRequest");
    when(ownerHistoricVariableInstanceAttempt.getValue()).thenReturn(1);
    when(ownerHistoricVariableInstanceAttempt.getVariableName()).thenReturn("attempts");
    when(ownerHistoricVariableInstanceAttempt.getCreateTime()).thenReturn(new Date(45000));
    when(ownerHistoricVariableInstanceStatus.getValue()).thenReturn(RequestStatus.APPROVAL_GRANTED);
    when(ownerHistoricVariableInstanceStatus.getVariableName()).thenReturn("requestStatus");
    when(ownerHistoricVariableInstanceStatus.getLastUpdatedTime()).thenReturn(new Date(45002));
    when(ownerHistoricVariableInstanceAccessRequest.getValue()).thenReturn(ownerRequest);
    when(ownerHistoricVariableInstanceAccessRequest.getVariableName()).thenReturn("accessRequest");
    when(nonOwnerHistoricVariableInstanceAttempt.getValue()).thenReturn(2);
    when(nonOwnerHistoricVariableInstanceAttempt.getVariableName()).thenReturn("attempts");
    when(nonOwnerHistoricVariableInstanceAttempt.getCreateTime()).thenReturn(new Date(45002));
    when(nonOwnerHistoricVariableInstanceStatus.getValue()).thenReturn(null);
    when(nonOwnerHistoricVariableInstanceStatus.getVariableName()).thenReturn("requestStatus");
    when(nonOwnerHistoricVariableInstanceStatus.getLastUpdatedTime()).thenReturn(new Date(45003));
    when(nonOwnerHistoricVariableInstanceAccessRequest.getValue()).thenReturn(nonOwnerRequest);
    when(nonOwnerHistoricVariableInstanceAccessRequest.getVariableName()).thenReturn("accessRequest");
    taskVars.add(ownerHistoricVariableInstanceAttempt);
    taskVars.add(ownerHistoricVariableInstanceStatus);
    taskVars.add(ownerHistoricVariableInstanceAccessRequest);
    taskVars.add(nonOwnerHistoricVariableInstanceAttempt);
    taskVars.add(nonOwnerHistoricVariableInstanceStatus);
    taskVars.add(nonOwnerHistoricVariableInstanceAccessRequest);
    when(historyService.createHistoricVariableInstanceQuery()).thenReturn(historicVariableInstanceQuery);
    when(historyService.createHistoricVariableInstanceQuery().list()).thenReturn(taskVars);
    Map<String, String> statusMap = new HashMap<>();
    statusMap.put("testId", "Unknown");
    when(accountInformationService.getAccountByAlias(any())).thenReturn(mockAccount);
}
Also used : Account(org.finra.gatekeeper.common.services.account.model.Account) Task(org.activiti.engine.task.Task) Region(org.finra.gatekeeper.common.services.account.model.Region) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Before(org.junit.Before)

Example 42 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Gatekeeper by FINRAOS.

the class AccessRequestServiceTests method initMocks.

@Before
public void initMocks() {
    testDate = new Date();
    // Setting up the spring values
    Map<String, Object> mockValues = new HashMap<>();
    Map<String, Integer> mockDev = new HashMap<>();
    mockDev.put("dev", 48);
    mockDev.put("qa", 48);
    mockDev.put("prod", 2);
    Map<String, Integer> mockOps = new HashMap<>();
    mockOps.put("dev", 48);
    mockOps.put("qa", 48);
    mockOps.put("prod", 2);
    Map<String, Integer> mockSupp = new HashMap<>();
    mockSupp.put("dev", 48);
    mockSupp.put("qa", 48);
    mockSupp.put("prod", 2);
    mockValues.put("dev", mockDev);
    mockValues.put("ops", mockOps);
    mockValues.put("support", mockSupp);
    Region[] regions = new Region[] { new Region("us-east-1") };
    Account mockAccount = new Account(1234L, "Dev Test", "dev", "dev-test", Arrays.asList(regions));
    when(approvalPolicy.getApprovalPolicy(GatekeeperRole.DEV)).thenReturn(mockDev);
    when(approvalPolicy.getApprovalPolicy(GatekeeperRole.OPS)).thenReturn(mockOps);
    when(approvalPolicy.getApprovalPolicy(GatekeeperRole.SUPPORT)).thenReturn(mockSupp);
    List<AWSInstance> instances = new ArrayList<>();
    when(awsInstance.getApplication()).thenReturn("TestApp");
    when(awsInstance.getInstanceId()).thenReturn("testId");
    when(awsInstance.getPlatform()).thenReturn("testPlatform");
    instances.add(awsInstance);
    // Owner mock
    when(ownerRequest.getAccount()).thenReturn("DEV");
    when(ownerRequest.getInstances()).thenReturn(instances);
    when(ownerRequest.getHours()).thenReturn(1);
    when(ownerRequest.getRequestorId()).thenReturn("owner");
    when(ownerRequest.getId()).thenReturn(1L);
    // Non-owner mock
    when(nonOwnerRequest.getAccount()).thenReturn("DEV");
    when(nonOwnerRequest.getInstances()).thenReturn(instances);
    when(nonOwnerRequest.getHours()).thenReturn(1);
    when(nonOwnerRequest.getRequestorId()).thenReturn("non-owner");
    when(nonOwnerRequest.getId()).thenReturn(2L);
    when(nonOwnerRequest.getPlatform()).thenReturn("testPlatform");
    Set<String> ownerMemberships = new HashSet<String>();
    ownerMemberships.add("TestApp");
    when(ownerRequestWrapper.getInstances()).thenReturn(instances);
    when(ownerRequestWrapper.getHours()).thenReturn(1);
    when(ownerRequestWrapper.getRequestorId()).thenReturn("owner");
    when(ownerRequestWrapper.getAccount()).thenReturn("testAccount");
    when(ownerRequestWrapper.getRegion()).thenReturn("testRegion");
    when(ownerRequestWrapper.getPlatform()).thenReturn("testPlatform");
    when(gatekeeperUserEntry.getUserId()).thenReturn("testUserId");
    when(gatekeeperUserEntry.getName()).thenReturn("testName");
    when(gatekeeperUserEntry.getEmail()).thenReturn("testEmail@finra.org");
    when(user.getUserId()).thenReturn("testUserId");
    List<User> users = new ArrayList<>();
    users.add(user);
    when(ownerRequestWrapper.getUsers()).thenReturn(users);
    when(ownerRequest.getUsers()).thenReturn(users);
    when(gatekeeperLdapService.getRole()).thenReturn(GatekeeperRole.DEV);
    when(gatekeeperLdapService.getMemberships()).thenReturn(ownerMemberships);
    when(gatekeeperLdapService.getUserProfile()).thenReturn(gatekeeperUserEntry);
    when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
    when(runtimeService.createProcessInstanceQuery().count()).thenReturn(2L);
    // Mocks for getActiveRequest()
    when(ownerOneTask.getExecutionId()).thenReturn("ownerOneTask");
    when(ownerOneTask.getCreateTime()).thenReturn(new Date(4500000));
    when(ownerOneTask.getId()).thenReturn("taskOne");
    when(ownerTwoTask.getExecutionId()).thenReturn("ownerTwoTask");
    when(ownerTwoTask.getCreateTime()).thenReturn(testDate);
    when(ownerTwoTask.getId()).thenReturn("taskTwo");
    when(runtimeService.getVariable("ownerOneTask", "accessRequest")).thenReturn(ownerRequest);
    when(runtimeService.getVariable("ownerTwoTask", "accessRequest")).thenReturn(nonOwnerRequest);
    List<Task> activeTasks = new ArrayList<>();
    activeTasks.add(ownerOneTask);
    activeTasks.add(ownerTwoTask);
    when(taskService.createTaskQuery()).thenReturn(taskQuery);
    when(taskService.createTaskQuery().active()).thenReturn(taskQuery);
    when(taskService.createTaskQuery().active().list()).thenReturn(activeTasks);
    // Mocks for getCompletedRequest()
    List<HistoricVariableInstance> taskVars = new ArrayList<>();
    when(ownerHistoricVariableInstanceAttempt.getProcessInstanceId()).thenReturn("ownerRequest");
    when(ownerHistoricVariableInstanceStatus.getProcessInstanceId()).thenReturn("ownerRequest");
    when(ownerHistoricVariableInstanceAccessRequest.getProcessInstanceId()).thenReturn("ownerRequest");
    when(nonOwnerHistoricVariableInstanceAttempt.getProcessInstanceId()).thenReturn("nonOwnerRequest");
    when(nonOwnerHistoricVariableInstanceStatus.getProcessInstanceId()).thenReturn("nonOwnerRequest");
    when(nonOwnerHistoricVariableInstanceAccessRequest.getProcessInstanceId()).thenReturn("nonOwnerRequest");
    when(ownerHistoricVariableInstanceAttempt.getValue()).thenReturn(1);
    when(ownerHistoricVariableInstanceAttempt.getVariableName()).thenReturn("attempts");
    when(ownerHistoricVariableInstanceAttempt.getCreateTime()).thenReturn(new Date(45000));
    when(ownerHistoricVariableInstanceStatus.getValue()).thenReturn(RequestStatus.APPROVAL_GRANTED);
    when(ownerHistoricVariableInstanceStatus.getVariableName()).thenReturn("requestStatus");
    when(ownerHistoricVariableInstanceStatus.getLastUpdatedTime()).thenReturn(new Date(45002));
    when(ownerHistoricVariableInstanceAccessRequest.getValue()).thenReturn(ownerRequest);
    when(ownerHistoricVariableInstanceAccessRequest.getVariableName()).thenReturn("accessRequest");
    when(nonOwnerHistoricVariableInstanceAttempt.getValue()).thenReturn(2);
    when(nonOwnerHistoricVariableInstanceAttempt.getVariableName()).thenReturn("attempts");
    when(nonOwnerHistoricVariableInstanceAttempt.getCreateTime()).thenReturn(new Date(45002));
    when(nonOwnerHistoricVariableInstanceStatus.getValue()).thenReturn(null);
    when(nonOwnerHistoricVariableInstanceStatus.getVariableName()).thenReturn("requestStatus");
    when(nonOwnerHistoricVariableInstanceStatus.getLastUpdatedTime()).thenReturn(new Date(45003));
    when(nonOwnerHistoricVariableInstanceAccessRequest.getValue()).thenReturn(nonOwnerRequest);
    when(nonOwnerHistoricVariableInstanceAccessRequest.getVariableName()).thenReturn("accessRequest");
    taskVars.add(ownerHistoricVariableInstanceAttempt);
    taskVars.add(ownerHistoricVariableInstanceStatus);
    taskVars.add(ownerHistoricVariableInstanceAccessRequest);
    taskVars.add(nonOwnerHistoricVariableInstanceAttempt);
    taskVars.add(nonOwnerHistoricVariableInstanceStatus);
    taskVars.add(nonOwnerHistoricVariableInstanceAccessRequest);
    when(historyService.createHistoricVariableInstanceQuery()).thenReturn(historicVariableInstanceQuery);
    when(historyService.createHistoricVariableInstanceQuery().list()).thenReturn(taskVars);
    Map<String, String> statusMap = new HashMap<>();
    statusMap.put("testId", "Unknown");
    when(ssmService.checkInstancesWithSsm(any(), any())).thenReturn(statusMap);
    when(accountInformationService.getAccountByAlias(any())).thenReturn(mockAccount);
}
Also used : Account(org.finra.gatekeeper.common.services.account.model.Account) Task(org.activiti.engine.task.Task) Region(org.finra.gatekeeper.common.services.account.model.Region) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Before(org.junit.Before)

Example 43 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.

the class FullHistoryTest method testVariableUpdates.

@Deployment
public void testVariableUpdates() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("number", "one");
    variables.put("character", "a");
    variables.put("bytes", ":-(".getBytes());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveTask", variables);
    runtimeService.setVariable(processInstance.getId(), "number", "two");
    runtimeService.setVariable(processInstance.getId(), "bytes", ":-)".getBytes());
    // Start-task should be added to history
    HistoricActivityInstance historicStartEvent = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("theStart").singleResult();
    assertThat(historicStartEvent).isNotNull();
    HistoricActivityInstance waitStateActivity = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("waitState").singleResult();
    assertThat(waitStateActivity).isNotNull();
    HistoricActivityInstance serviceTaskActivity = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("serviceTask").singleResult();
    assertThat(serviceTaskActivity).isNotNull();
    List<HistoricDetail> historicDetails = historyService.createHistoricDetailQuery().orderByVariableName().asc().orderByVariableRevision().asc().list();
    assertThat(historicDetails).hasSize(10);
    HistoricVariableUpdate historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(0);
    assertThat(historicVariableUpdate.getVariableName()).isEqualTo("bytes");
    assertThat(new String((byte[]) historicVariableUpdate.getValue())).isEqualTo(":-(");
    assertThat(historicVariableUpdate.getRevision()).isEqualTo(0);
    // Activiti 6: we don't store the start event activityId anymore!
    // assertThat(historicVariableUpdate.getActivityInstanceId()).isEqualTo(historicStartEvent.getId());
    assertThat(historicVariableUpdate.getActivityInstanceId()).isNull();
    // Variable is updated when process was in waitstate
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(1);
    assertThat(historicVariableUpdate.getVariableName()).isEqualTo("bytes");
    assertThat(new String((byte[]) historicVariableUpdate.getValue())).isEqualTo(":-)");
    assertThat(historicVariableUpdate.getRevision()).isEqualTo(1);
    // assertThat(historicVariableUpdate.getActivityInstanceId()).isEqualTo(waitStateActivity.getId());
    assertThat(historicVariableUpdate.getActivityInstanceId()).isNull();
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(2);
    assertThat(historicVariableUpdate.getVariableName()).isEqualTo("character");
    assertThat(historicVariableUpdate.getValue()).isEqualTo("a");
    assertThat(historicVariableUpdate.getRevision()).isEqualTo(0);
    // assertThat(historicVariableUpdate.getActivityInstanceId()).isEqualTo(historicStartEvent.getId());
    assertThat(historicVariableUpdate.getActivityInstanceId()).isNull();
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(3);
    assertThat(historicVariableUpdate.getVariableName()).isEqualTo("number");
    assertThat(historicVariableUpdate.getValue()).isEqualTo("one");
    assertThat(historicVariableUpdate.getRevision()).isEqualTo(0);
    // assertThat(historicVariableUpdate.getActivityInstanceId()).isEqualTo(historicStartEvent.getId());
    assertThat(historicVariableUpdate.getActivityInstanceId()).isNull();
    // Variable is updated when process was in waitstate
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(4);
    assertThat(historicVariableUpdate.getVariableName()).isEqualTo("number");
    assertThat(historicVariableUpdate.getValue()).isEqualTo("two");
    assertThat(historicVariableUpdate.getRevision()).isEqualTo(1);
    // assertThat(historicVariableUpdate.getActivityInstanceId()).isEqualTo(waitStateActivity.getId());
    assertThat(historicVariableUpdate.getActivityInstanceId()).isNull();
    // Variable set from process-start execution listener
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(5);
    assertThat(historicVariableUpdate.getVariableName()).isEqualTo("zVar1");
    assertThat(historicVariableUpdate.getValue()).isEqualTo("Event: start");
    assertThat(historicVariableUpdate.getRevision()).isEqualTo(0);
    assertThat(historicVariableUpdate.getActivityInstanceId()).isNull();
    // Variable set from transition take execution listener
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(6);
    assertThat(historicVariableUpdate.getVariableName()).isEqualTo("zVar2");
    assertThat(historicVariableUpdate.getValue()).isEqualTo("Event: take");
    assertThat(historicVariableUpdate.getRevision()).isEqualTo(0);
    assertThat(historicVariableUpdate.getActivityInstanceId()).isNull();
    // Variable set from activity start execution listener on the servicetask
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(7);
    assertThat(historicVariableUpdate.getVariableName()).isEqualTo("zVar3");
    assertThat(historicVariableUpdate.getValue()).isEqualTo("Event: start");
    assertThat(historicVariableUpdate.getRevision()).isEqualTo(0);
    assertThat(historicVariableUpdate.getActivityInstanceId()).isEqualTo(serviceTaskActivity.getId());
    // Variable set from activity end execution listener on the servicetask
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(8);
    assertThat(historicVariableUpdate.getVariableName()).isEqualTo("zVar4");
    assertThat(historicVariableUpdate.getValue()).isEqualTo("Event: end");
    assertThat(historicVariableUpdate.getRevision()).isEqualTo(0);
    assertThat(historicVariableUpdate.getActivityInstanceId()).isEqualTo(serviceTaskActivity.getId());
    // Variable set from service-task
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(9);
    assertThat(historicVariableUpdate.getVariableName()).isEqualTo("zzz");
    assertThat(historicVariableUpdate.getValue()).isEqualTo(123456789L);
    assertThat(historicVariableUpdate.getRevision()).isEqualTo(0);
    assertThat(historicVariableUpdate.getActivityInstanceId()).isEqualTo(serviceTaskActivity.getId());
    // trigger receive task
    runtimeService.trigger(runtimeService.createExecutionQuery().activityId("waitState").singleResult().getId());
    assertProcessEnded(processInstance.getId());
    // check for historic process variables set
    HistoricVariableInstanceQuery historicProcessVariableQuery = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc();
    assertThat(historicProcessVariableQuery.count()).isEqualTo(8);
    List<HistoricVariableInstance> historicVariables = historicProcessVariableQuery.list();
    // Variable status when process is finished
    HistoricVariableInstance historicVariable = historicVariables.get(0);
    assertThat(historicVariable.getVariableName()).isEqualTo("bytes");
    assertThat(new String((byte[]) historicVariable.getValue())).isEqualTo(":-)");
    assertThat(historicVariable.getCreateTime()).isNotNull();
    assertThat(historicVariable.getLastUpdatedTime()).isNotNull();
    historicVariable = historicVariables.get(1);
    assertThat(historicVariable.getVariableName()).isEqualTo("character");
    assertThat(historicVariable.getValue()).isEqualTo("a");
    assertThat(historicVariable.getCreateTime()).isNotNull();
    assertThat(historicVariable.getLastUpdatedTime()).isNotNull();
    historicVariable = historicVariables.get(2);
    assertThat(historicVariable.getVariableName()).isEqualTo("number");
    assertThat(historicVariable.getValue()).isEqualTo("two");
    assertThat(historicVariable.getCreateTime()).isNotNull();
    assertThat(historicVariable.getLastUpdatedTime()).isNotNull();
    assertThat(historicVariable.getLastUpdatedTime()).isNotSameAs(historicVariable.getCreateTime());
    historicVariable = historicVariables.get(3);
    assertThat(historicVariable.getVariableName()).isEqualTo("zVar1");
    assertThat(historicVariable.getValue()).isEqualTo("Event: start");
    assertThat(historicVariable.getCreateTime()).isNotNull();
    assertThat(historicVariable.getLastUpdatedTime()).isNotNull();
    historicVariable = historicVariables.get(4);
    assertThat(historicVariable.getVariableName()).isEqualTo("zVar2");
    assertThat(historicVariable.getValue()).isEqualTo("Event: take");
    assertThat(historicVariable.getCreateTime()).isNotNull();
    assertThat(historicVariable.getLastUpdatedTime()).isNotNull();
    historicVariable = historicVariables.get(5);
    assertThat(historicVariable.getVariableName()).isEqualTo("zVar3");
    assertThat(historicVariable.getValue()).isEqualTo("Event: start");
    assertThat(historicVariable.getCreateTime()).isNotNull();
    assertThat(historicVariable.getLastUpdatedTime()).isNotNull();
    historicVariable = historicVariables.get(6);
    assertThat(historicVariable.getVariableName()).isEqualTo("zVar4");
    assertThat(historicVariable.getValue()).isEqualTo("Event: end");
    assertThat(historicVariable.getCreateTime()).isNotNull();
    assertThat(historicVariable.getLastUpdatedTime()).isNotNull();
    historicVariable = historicVariables.get(7);
    assertThat(historicVariable.getVariableName()).isEqualTo("zzz");
    assertThat(historicVariable.getValue()).isEqualTo(123456789L);
    assertThat(historicVariable.getCreateTime()).isNotNull();
    assertThat(historicVariable.getLastUpdatedTime()).isNotNull();
    historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLike("number", "tw%").singleResult();
    assertThat(historicVariable).isNotNull();
    assertThat(historicVariable.getVariableName()).isEqualTo("number");
    assertThat(historicVariable.getValue()).isEqualTo("two");
    historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLikeIgnoreCase("number", "TW%").singleResult();
    assertThat(historicVariable).isNotNull();
    assertThat(historicVariable.getVariableName()).isEqualTo("number");
    assertThat(historicVariable.getValue()).isEqualTo("two");
    historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLikeIgnoreCase("number", "TW2%").singleResult();
    assertThat(historicVariable).isNull();
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) HashMap(java.util.HashMap) HistoricVariableInstanceQuery(org.activiti.engine.history.HistoricVariableInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Example 44 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.

the class HistoricJPAVariableTest method testGetJPAEntityAsHistoricVariable.

@Deployment
public void testGetJPAEntityAsHistoricVariable() {
    setupJPAEntities();
    // -----------------------------------------------------------------------------
    // Simple test, Start process with JPA entities as variables
    // -----------------------------------------------------------------------------
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("simpleEntityFieldAccess", simpleEntityFieldAccess);
    // Start the process with the JPA-entities as variables. They will be stored in the DB.
    this.processInstanceId = runtimeService.startProcessInstanceByKey("JPAVariableProcess", variables).getId();
    for (Task task : taskService.createTaskQuery().includeTaskLocalVariables().list()) {
        taskService.complete(task.getId());
    }
    // Get JPAEntity Variable by HistoricVariableInstanceQuery
    HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).variableName("simpleEntityFieldAccess").singleResult();
    Object value = historicVariableInstance.getValue();
    assertThat(value).isInstanceOf(FieldAccessJPAEntity.class);
    assertThat(simpleEntityFieldAccess.getValue()).isEqualTo(((FieldAccessJPAEntity) value).getValue());
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Example 45 with HistoricVariableInstance

use of org.activiti.engine.history.HistoricVariableInstance in project Activiti by Activiti.

the class AsyncTaskTest method testAsyncEndEvent.

@Deployment
public void testAsyncEndEvent() {
    // start process
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncEndEvent");
    // now there should be one job in the database:
    assertThat(managementService.createJobQuery().count()).isEqualTo(1);
    Object value = runtimeService.getVariable(processInstance.getId(), "variableSetInExecutionListener");
    assertThat(value).isNull();
    waitForJobExecutorToProcessAllJobs(2000L, 200L);
    // the job is done
    assertThat(managementService.createJobQuery().count()).isEqualTo(0);
    assertProcessEnded(processInstance.getId());
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
        List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).list();
        assertThat(variables).hasSize(3);
        Object historyValue = null;
        for (HistoricVariableInstance variable : variables) {
            if ("variableSetInExecutionListener".equals(variable.getVariableName())) {
                historyValue = variable.getValue();
            }
        }
        assertThat(historyValue).isEqualTo("firstValue");
    }
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)56 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)28 Deployment (org.activiti.engine.test.Deployment)25 HashMap (java.util.HashMap)20 Task (org.activiti.engine.task.Task)18 HistoricVariableInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5 Test (org.junit.Test)5 HistoricData (org.activiti.engine.history.HistoricData)4 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)4 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 BpmnModel (org.activiti.bpmn.model.BpmnModel)3 HistoryService (org.activiti.engine.HistoryService)3 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)3 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)3 HistoricVariableInstanceQuery (org.activiti.engine.history.HistoricVariableInstanceQuery)3 ProcessInstanceHistoryLog (org.activiti.engine.history.ProcessInstanceHistoryLog)3