Java Code Examples for org.activiti.engine.history.HistoricProcessInstance#getProcessVariables()

The following examples show how to use org.activiti.engine.history.HistoricProcessInstance#getProcessVariables() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CheckEmrClusterTest.java    From herd with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckCluster() throws Exception
{
    // Run a job with Activiti XML that will start cluster, check status and terminate.
    Job job = jobServiceTestHelper.createJobForCreateCluster(ACTIVITI_XML_CHECK_CLUSTER_WITH_CLASSPATH, getParameters(true, "", "false"));
    assertNotNull(job);

    HistoricProcessInstance hisInstance =
        activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).includeProcessVariables().singleResult();
    Map<String, Object> variables = hisInstance.getProcessVariables();

    //check to be sure fields exist.  These should exist whether verbose is set or not
    assertTrue(variables.containsKey(taskName + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + CheckEmrCluster.VARIABLE_EMR_CLUSTER_ID));
    assertTrue(variables.containsKey(taskName + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + CheckEmrCluster.VARIABLE_EMR_CLUSTER_STATUS));
    assertTrue(variables.containsKey(taskName + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + CheckEmrCluster.VARIABLE_EMR_CLUSTER_CREATION_TIME));
    assertTrue(variables.containsKey(taskName + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + CheckEmrCluster.VARIABLE_EMR_CLUSTER_READY_TIME));
    assertTrue(variables.containsKey(taskName + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + CheckEmrCluster.VARIABLE_EMR_CLUSTER_END_TIME));
    assertTrue(
        variables.containsKey(taskName + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + CheckEmrCluster.VARIABLE_EMR_CLUSTER_STATUS_CHANGE_REASON_CODE));
    assertTrue(
        variables.containsKey(taskName + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + CheckEmrCluster.VARIABLE_EMR_CLUSTER_STATUS_CHANGE_REASON_MESSAGE));
}
 
Example 2
Source File: AddEmrStepsTest.java    From herd with Apache License 2.0 6 votes vote down vote up
private void createJobAndCheckStepStatusSuccess(String activitiXml, List<Parameter> parameters) throws Exception
{
    Job job = jobServiceTestHelper.createJobForCreateClusterForActivitiXml(activitiXml, parameters);
    assertNotNull(job);

    HistoricProcessInstance hisInstance =
        activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).includeProcessVariables().singleResult();
    Map<String, Object> variables = hisInstance.getProcessVariables();

    String addStepServiceTaskStatus =
        (String) variables.get("addStepServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + ActivitiRuntimeHelper.VARIABLE_STATUS);
    assertEquals(ActivitiRuntimeHelper.TASK_STATUS_SUCCESS, addStepServiceTaskStatus);

    String addStepId = (String) variables.get("addStepServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + BaseAddEmrStep.VARIABLE_EMR_STEP_ID);
    assertNotNull(addStepId);
}
 
Example 3
Source File: HistoricProcessInstanceQueryVersionTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testHistoricProcessInstanceOrQueryByProcessDefinitionVersion() {
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().or().processDefinitionVersion(1).processDefinitionId("undefined").endOr().count());
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().or().processDefinitionVersion(2).processDefinitionId("undefined").endOr().count());
  assertEquals(0, historyService.createHistoricProcessInstanceQuery().or().processDefinitionVersion(3).processDefinitionId("undefined").endOr().count());
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().or().processDefinitionVersion(1).processDefinitionId("undefined").endOr().list().size());
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().or().processDefinitionVersion(2).processDefinitionId("undefined").endOr().list().size());
  assertEquals(0, historyService.createHistoricProcessInstanceQuery().or().processDefinitionVersion(3).processDefinitionId("undefined").endOr().list().size());
  
  // Variables Case
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
      HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .or().variableValueEquals("test", "invalid").processDefinitionVersion(1).endOr().singleResult();
      assertEquals(1, processInstance.getProcessDefinitionVersion().intValue());
      Map<String, Object> variableMap = processInstance.getProcessVariables();
      assertEquals(123, variableMap.get("test"));
      
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .or().variableValueEquals("anothertest", "invalid").processDefinitionVersion(2).endOr().singleResult();
      assertEquals(2, processInstance.getProcessDefinitionVersion().intValue());
      variableMap = processInstance.getProcessVariables();
      assertEquals(456, variableMap.get("anothertest"));
      
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("anothertest", "invalid").processDefinitionVersion(3).singleResult();
      assertNull(processInstance);
  }
}
 
Example 4
Source File: CheckEmrClusterTest.java    From herd with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckClusterByClusterIdStepIdActiveStepHasNoId() throws Exception
{
    List<FieldExtension> fieldExtensions = getOptionalFieldExtensions();
    FieldExtension fieldExtension = new FieldExtension();
    fieldExtension.setFieldName("emrStepId");
    fieldExtension.setExpression("${addHiveStepServiceTask_emrStepId}");
    fieldExtensions.add(fieldExtension);

    List<Parameter> parameters = new ArrayList<>();
    parameters.add(new Parameter("clusterName", "testCluster1"));
    parameters.add(new Parameter("hiveStepName", "a_hive_step"));
    parameters.add(new Parameter("hiveScriptLocation", "a_hive_step_location"));
    parameters.add(new Parameter("shellStepName", MockEmrOperationsImpl.MOCK_STEP_RUNNING_WITHOUT_ID_NAME));
    parameters.add(new Parameter("shellScriptLocation", "a_shell_step_location"));
    parameters.add(new Parameter("verbose", "false"));
    parameters.add(new Parameter("retrieveInstanceFleets", "false"));

    // Run a job with Activiti XML that will start cluster, check status and terminate.
    Job job = jobServiceTestHelper.createJobForCreateClusterForActivitiXml(getCheckClusterActivitiXml(fieldExtensions), parameters);
    assertNotNull(job);

    HistoricProcessInstance hisInstance =
        activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).includeProcessVariables().singleResult();
    Map<String, Object> variables = hisInstance.getProcessVariables();

    String hiveStepId = (String) variables.get("addHiveStepServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "emrStepId");
    assertNotNull(hiveStepId);
    String emrStepId = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "step_id");
    assertEquals(hiveStepId, emrStepId);
    String emrStepJarLocation = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "step_jarLocation");
    assertNull(emrStepJarLocation);

    String activeStepId = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "activeStep_id");
    assertNull(activeStepId);
}
 
Example 5
Source File: CheckEmrClusterTest.java    From herd with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckClusterByClusterIdStepIdNoActiveStep() throws Exception
{
    List<FieldExtension> fieldExtensions = getOptionalFieldExtensions();

    FieldExtension fieldExtension = new FieldExtension();
    fieldExtension.setFieldName("emrStepId");
    fieldExtension.setExpression("${addHiveStepServiceTask_emrStepId}");
    fieldExtensions.add(fieldExtension);

    // Run a job with Activiti XML that will start cluster, check status and terminate.
    Job job =
        jobServiceTestHelper.createJobForCreateClusterForActivitiXml(getCheckClusterActivitiXml(fieldExtensions), getParameters(false, "false", "false"));
    assertNotNull(job);

    HistoricProcessInstance hisInstance =
        activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).includeProcessVariables().singleResult();
    Map<String, Object> variables = hisInstance.getProcessVariables();

    String hiveStepId = (String) variables.get("addHiveStepServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "emrStepId");
    assertNotNull(hiveStepId);
    String emrStepId = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "step_id");
    assertEquals(hiveStepId, emrStepId);
    String emrStepJarLocation = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "step_jarLocation");
    assertNull(emrStepJarLocation);

    String activeStepId = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "activeStep_id");
    assertNull(activeStepId);
}
 
Example 6
Source File: CheckEmrClusterTest.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * This method tests the check EMR cluster activiti task with cluster Id and step Id specified
 */
@Test
public void testCheckClusterByClusterIdStepIdVerbose() throws Exception
{
    // Run a job with Activiti XML that will start cluster, check status and terminate.
    List<FieldExtension> fieldExtensions = getOptionalFieldExtensions();

    FieldExtension fieldExtension = new FieldExtension();
    fieldExtension.setFieldName("emrStepId");
    fieldExtension.setExpression("${addHiveStepServiceTask_emrStepId}");
    fieldExtensions.add(fieldExtension);

    Job job =
        jobServiceTestHelper.createJobForCreateClusterForActivitiXml(getCheckClusterActivitiXml(fieldExtensions), getParameters(true, "true", "false"));
    assertNotNull(job);

    HistoricProcessInstance hisInstance =
        activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).includeProcessVariables().singleResult();
    Map<String, Object> variables = hisInstance.getProcessVariables();

    String hiveStepId = (String) variables.get("addHiveStepServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "emrStepId");
    assertNotNull(hiveStepId);
    String emrStepId = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "step_id");
    assertEquals(hiveStepId, emrStepId);
    String emrStepJarLocation = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "step_jarLocation");
    assertNotNull(emrStepJarLocation);

    String shellStepId = (String) variables.get("addShellStepServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "emrStepId");
    assertNotNull(shellStepId);
    String activeStepId = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "activeStep_id");
    assertEquals(shellStepId, activeStepId);
    String activeStepJarLocation =
        (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "activeStep_jarLocation");
    assertNotNull(activeStepJarLocation);
}
 
Example 7
Source File: CheckEmrClusterTest.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * This method tests the check EMR cluster activiti task with cluster Id and step Id specified
 */
@Test
public void testCheckClusterByClusterIdStepId() throws Exception
{
    List<FieldExtension> fieldExtensions = getOptionalFieldExtensions();

    FieldExtension fieldExtension = new FieldExtension();
    fieldExtension.setFieldName("emrStepId");
    fieldExtension.setExpression("${addHiveStepServiceTask_emrStepId}");
    fieldExtensions.add(fieldExtension);

    // Run a job with Activiti XML that will start cluster, check status and terminate.
    Job job =
        jobServiceTestHelper.createJobForCreateClusterForActivitiXml(getCheckClusterActivitiXml(fieldExtensions), getParameters(true, "false", "false"));
    assertNotNull(job);

    HistoricProcessInstance hisInstance =
        activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).includeProcessVariables().singleResult();
    Map<String, Object> variables = hisInstance.getProcessVariables();

    String hiveStepId = (String) variables.get("addHiveStepServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "emrStepId");
    String emrStepId = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "step_id");
    assertEquals(hiveStepId, emrStepId);
    String emrStepJarLocation = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "step_jarLocation");
    assertNull(emrStepJarLocation);

    String shellStepId = (String) variables.get("addShellStepServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "emrStepId");
    assertNotNull(shellStepId);
    String activeStepId = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "activeStep_id");
    assertEquals(shellStepId, activeStepId);
    String activeStepJarLocation =
        (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "activeStep_jarLocation");
    assertNull(activeStepJarLocation);
}
 
Example 8
Source File: ActivitiResourceMapper.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
public <T extends HistoricProcessInstanceResource> T mapToResource(Class<T> resourceClass,
                                                                      HistoricProcessInstance processInstance) {
	T resource = io.crnk.core.engine.internal.utils.ClassUtils.newInstance(resourceClass);
	Map<String, Object> processVariables = processInstance.getProcessVariables();
	copyInternal(resource, null, processVariables, true, Optional.of(processInstance));
	return resource;
}
 
Example 9
Source File: HistoricProcessInstanceAndVariablesQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByprocessDefinition() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
      // DeploymentId
      String deploymentId = repositoryService.createDeploymentQuery().list().get(0).getId();
      HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("anothertest", 123).deploymentId(deploymentId).singleResult();
      Map<String, Object> variableMap = processInstance.getProcessVariables();
      assertEquals(1, variableMap.size());
      assertEquals(123, variableMap.get("anothertest"));
      assertEquals(deploymentId, processInstance.getDeploymentId());
      
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("anothertest", "invalid").deploymentId(deploymentId).singleResult();
      assertNull(processInstance);
      
    // ProcessDefinitionName
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("anothertest", 123).processDefinitionName(PROCESS_DEFINITION_NAME_2).singleResult();
      variableMap = processInstance.getProcessVariables();
      assertEquals(1, variableMap.size());
      assertEquals(123, variableMap.get("anothertest"));
      assertEquals(PROCESS_DEFINITION_NAME_2, processInstance.getProcessDefinitionName());
      
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("test", "test").processDefinitionName(PROCESS_DEFINITION_NAME_2).singleResult();
      assertNull(processInstance);
      
      // ProcessDefinitionCategory
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("anothertest", 123).processDefinitionCategory(PROCESS_DEFINITION_CATEGORY_2).singleResult();
      variableMap = processInstance.getProcessVariables();
      assertEquals(1, variableMap.size());
      assertEquals(123, variableMap.get("anothertest"));
      
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("test", "test").processDefinitionCategory(PROCESS_DEFINITION_CATEGORY_2).singleResult();
      assertNull(processInstance);
  }
}
 
Example 10
Source File: HistoricProcessInstanceQueryVersionTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testHistoricProcessInstanceQueryByProcessDefinitionVersion() {
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(1).list().get(0).getProcessDefinitionVersion().intValue());
  assertEquals(2, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(2).list().get(0).getProcessDefinitionVersion().intValue());
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(1).count());
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(2).count());
  assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(3).count());
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(1).count());
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(2).list().size());
  assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(3).list().size());
  
  // Variables Case
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
      HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("test", 123).processDefinitionVersion(1).singleResult();
      assertEquals(1, processInstance.getProcessDefinitionVersion().intValue());
      Map<String, Object> variableMap = processInstance.getProcessVariables();
      assertEquals(123, variableMap.get("test"));

      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("anothertest", 456).processDefinitionVersion(1).singleResult();
      assertNull(processInstance);
      
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("anothertest", 456).processDefinitionVersion(2).singleResult();
      assertEquals(2, processInstance.getProcessDefinitionVersion().intValue());
      variableMap = processInstance.getProcessVariables();
      assertEquals(456, variableMap.get("anothertest"));
  }
}
 
Example 11
Source File: HistoricProcessInstanceAndVariablesQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByprocessDefinition() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
      // DeploymentId
      String deploymentId = repositoryService.createDeploymentQuery().list().get(0).getId();
      HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("anothertest", 123).deploymentId(deploymentId).singleResult();
      Map<String, Object> variableMap = processInstance.getProcessVariables();
      assertEquals(1, variableMap.size());
      assertEquals(123, variableMap.get("anothertest"));
      assertEquals(deploymentId, processInstance.getDeploymentId());
      
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("anothertest", "invalid").deploymentId(deploymentId).singleResult();
      assertNull(processInstance);
      
    // ProcessDefinitionName
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("anothertest", 123).processDefinitionName(PROCESS_DEFINITION_NAME_2).singleResult();
      variableMap = processInstance.getProcessVariables();
      assertEquals(1, variableMap.size());
      assertEquals(123, variableMap.get("anothertest"));
      assertEquals(PROCESS_DEFINITION_NAME_2, processInstance.getProcessDefinitionName());
      
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("test", "test").processDefinitionName(PROCESS_DEFINITION_NAME_2).singleResult();
      assertNull(processInstance);
      
      // ProcessDefinitionCategory
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("anothertest", 123).processDefinitionCategory(PROCESS_DEFINITION_CATEGORY_2).singleResult();
      variableMap = processInstance.getProcessVariables();
      assertEquals(1, variableMap.size());
      assertEquals(123, variableMap.get("anothertest"));
      
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("test", "test").processDefinitionCategory(PROCESS_DEFINITION_CATEGORY_2).singleResult();
      assertNull(processInstance);
  }
}
 
Example 12
Source File: HistoricProcessInstanceQueryVersionTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testHistoricProcessInstanceQueryByProcessDefinitionVersion() {
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(1).list().get(0).getProcessDefinitionVersion().intValue());
  assertEquals(2, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(2).list().get(0).getProcessDefinitionVersion().intValue());
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(1).count());
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(2).count());
  assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(3).count());
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(1).count());
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(2).list().size());
  assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionVersion(3).list().size());
  
  // Variables Case
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
      HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("test", 123).processDefinitionVersion(1).singleResult();
      assertEquals(1, processInstance.getProcessDefinitionVersion().intValue());
      Map<String, Object> variableMap = processInstance.getProcessVariables();
      assertEquals(123, variableMap.get("test"));

      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("anothertest", 456).processDefinitionVersion(1).singleResult();
      assertNull(processInstance);
      
      processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
              .variableValueEquals("anothertest", 456).processDefinitionVersion(2).singleResult();
      assertEquals(2, processInstance.getProcessDefinitionVersion().intValue());
      variableMap = processInstance.getProcessVariables();
      assertEquals(456, variableMap.get("anothertest"));
  }
}
 
Example 13
Source File: CreateBusinessObjectDataAttributeTest.java    From herd with Apache License 2.0 4 votes vote down vote up
@Test
public void testCreateBusinessObjectDataAttribute() throws Exception
{
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey =
        new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES,
            DATA_VERSION);

    // Create a business object data entity.
    businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS);

    List<FieldExtension> fieldExtensionList = new ArrayList<>();

    fieldExtensionList.add(buildFieldExtension("namespace", "${namespace}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDefinitionName", "${businessObjectDefinitionName}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatUsage", "${businessObjectFormatUsage}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatFileType", "${businessObjectFormatFileType}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatVersion", "${businessObjectFormatVersion}"));
    fieldExtensionList.add(buildFieldExtension("partitionValue", "${partitionValue}"));
    fieldExtensionList.add(buildFieldExtension("subPartitionValues", "${subPartitionValues}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDataVersion", "${businessObjectDataVersion}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDataAttributeName", "${businessObjectDataAttributeName}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDataAttributeValue", "${businessObjectDataAttributeValue}"));

    List<Parameter> parameters = new ArrayList<>();

    parameters.add(buildParameter("namespace", BDEF_NAMESPACE));
    parameters.add(buildParameter("businessObjectDefinitionName", BDEF_NAME));
    parameters.add(buildParameter("businessObjectFormatUsage", FORMAT_USAGE_CODE));
    parameters.add(buildParameter("businessObjectFormatFileType", FORMAT_FILE_TYPE_CODE));
    parameters.add(buildParameter("businessObjectFormatVersion", FORMAT_VERSION.toString()));
    parameters.add(buildParameter("partitionValue", PARTITION_VALUE));
    parameters.add(buildParameter("subPartitionValues", herdStringHelper.buildStringWithDefaultDelimiter(SUBPARTITION_VALUES)));
    parameters.add(buildParameter("businessObjectDataVersion", DATA_VERSION.toString()));
    parameters.add(buildParameter("businessObjectDataAttributeName", ATTRIBUTE_NAME_1_MIXED_CASE));
    parameters.add(buildParameter("businessObjectDataAttributeValue", ATTRIBUTE_VALUE_1));

    // Run the activiti task.
    String activitiXml = buildActivitiXml(CreateBusinessObjectDataAttribute.class.getCanonicalName(), fieldExtensionList);
    Job job = jobServiceTestHelper.createJobFromActivitiXml(activitiXml, parameters);
    assertNotNull(job);
    HistoricProcessInstance hisInstance =
        activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).includeProcessVariables().singleResult();
    Map<String, Object> variables = hisInstance.getProcessVariables();

    // Validate status.
    String serviceTaskStatus = (String) variables.get(getServiceTaskVariableName(ActivitiRuntimeHelper.VARIABLE_STATUS));
    assertEquals(ActivitiRuntimeHelper.TASK_STATUS_SUCCESS, serviceTaskStatus);

    // Retrieve JSON response.
    String jsonResponse = (String) variables.get(getServiceTaskVariableName(BaseJavaDelegate.VARIABLE_JSON_RESPONSE));
    ObjectMapper objectMapper = new ObjectMapper();
    BusinessObjectDataAttribute businessObjectDataAttribute = objectMapper.readValue(jsonResponse.getBytes(), BusinessObjectDataAttribute.class);

    // Validate JSON response.
    assertEquals(BDEF_NAMESPACE, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getNamespace());
    assertEquals(BDEF_NAME, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getBusinessObjectDefinitionName());
    assertEquals(FORMAT_USAGE_CODE, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getBusinessObjectFormatUsage());
    assertEquals(FORMAT_FILE_TYPE_CODE, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getBusinessObjectFormatFileType());
    assertEquals(FORMAT_VERSION, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getBusinessObjectFormatVersion());
    assertEquals(PARTITION_VALUE, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getPartitionValue());
    assertEquals(SUBPARTITION_VALUES, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getSubPartitionValues());
    assertEquals(DATA_VERSION, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getBusinessObjectDataVersion());
    assertEquals(ATTRIBUTE_NAME_1_MIXED_CASE, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName());
    assertEquals(ATTRIBUTE_VALUE_1, businessObjectDataAttribute.getBusinessObjectDataAttributeValue());
}
 
Example 14
Source File: HistoricProcessInstanceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Validation for https://activiti.atlassian.net/browse/ACT-2182
 */
public void testNameAndTenantIdSetWhenFetchingVariables() {
	
	String tenantId = "testTenantId";
	String processInstanceName = "myProcessInstance";
	
	String deploymentId = repositoryService.createDeployment()
		.addClasspathResource("org/activiti5/engine/test/history/oneTaskProcess.bpmn20.xml")
		.tenantId(tenantId)
		.deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE)
		.deploy()
		.getId();
	
	Map<String, Object> vars = new HashMap<String, Object>();
	vars.put("name", "Kermit");
	vars.put("age", 60);
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKeyAndTenantId("oneTaskProcess", vars, tenantId);
	runtimeService.setProcessInstanceName(processInstance.getId(), processInstanceName);
	
	// Verify name and tenant id (didnt work on mssql and db2) on process instance
	List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().includeProcessVariables().list();
	assertEquals(1, processInstances.size());
	processInstance = processInstances.get(0);
	
	assertEquals(processInstanceName, processInstance.getName());
	assertEquals(tenantId, processInstance.getTenantId());
	
	Map<String, Object> processInstanceVars = processInstance.getProcessVariables();
	assertEquals(2, processInstanceVars.size());
	assertEquals("Kermit", processInstanceVars.get("name"));
	assertEquals(60, processInstanceVars.get("age"));
	
	
	// Verify name and tenant id (didnt work on mssql and db2) on historic process instance
	List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().list();
	assertEquals(1, historicProcessInstances.size());
	HistoricProcessInstance historicProcessInstance = historicProcessInstances.get(0);
	
	// Verify name and tenant id (didnt work on mssql and db2) on process instance
	assertEquals(processInstanceName, historicProcessInstance.getName());
	assertEquals(tenantId, historicProcessInstance.getTenantId());
	
	Map<String, Object> historicProcessInstanceVars = historicProcessInstance.getProcessVariables();
	assertEquals(2, historicProcessInstanceVars.size());
	assertEquals("Kermit", historicProcessInstanceVars.get("name"));
	assertEquals(60, historicProcessInstanceVars.get("age"));
	
	// cleanup
	repositoryService.deleteDeployment(deploymentId, true);
}
 
Example 15
Source File: CreateBusinessObjectDataAttributeTest.java    From herd with Apache License 2.0 4 votes vote down vote up
@Test
public void testCreateBusinessObjectDataAttributeMissingOptionalParameters() throws Exception
{
    // Create a business object data key without sub-partition values.
    BusinessObjectDataKey businessObjectDataKey =
        new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE,
            NO_SUBPARTITION_VALUES, DATA_VERSION);

    // Create a business object data entity.
    businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS);

    List<FieldExtension> fieldExtensionList = new ArrayList<>();

    fieldExtensionList.add(buildFieldExtension("namespace", "${namespace}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDefinitionName", "${businessObjectDefinitionName}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatUsage", "${businessObjectFormatUsage}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatFileType", "${businessObjectFormatFileType}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatVersion", "${businessObjectFormatVersion}"));
    fieldExtensionList.add(buildFieldExtension("partitionValue", "${partitionValue}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDataVersion", "${businessObjectDataVersion}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDataAttributeName", "${businessObjectDataAttributeName}"));

    List<Parameter> parameters = new ArrayList<>();

    parameters.add(buildParameter("namespace", BDEF_NAMESPACE));
    parameters.add(buildParameter("businessObjectDefinitionName", BDEF_NAME));
    parameters.add(buildParameter("businessObjectFormatUsage", FORMAT_USAGE_CODE));
    parameters.add(buildParameter("businessObjectFormatFileType", FORMAT_FILE_TYPE_CODE));
    parameters.add(buildParameter("businessObjectFormatVersion", FORMAT_VERSION.toString()));
    parameters.add(buildParameter("partitionValue", PARTITION_VALUE));
    parameters.add(buildParameter("businessObjectDataVersion", DATA_VERSION.toString()));
    parameters.add(buildParameter("businessObjectDataAttributeName", ATTRIBUTE_NAME_1_MIXED_CASE));

    // Run the activiti task.
    String activitiXml = buildActivitiXml(CreateBusinessObjectDataAttribute.class.getCanonicalName(), fieldExtensionList);
    Job job = jobServiceTestHelper.createJobFromActivitiXml(activitiXml, parameters);
    assertNotNull(job);
    HistoricProcessInstance hisInstance =
        activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).includeProcessVariables().singleResult();
    Map<String, Object> variables = hisInstance.getProcessVariables();

    // Validate status.
    String serviceTaskStatus = (String) variables.get(getServiceTaskVariableName(ActivitiRuntimeHelper.VARIABLE_STATUS));
    assertEquals(ActivitiRuntimeHelper.TASK_STATUS_SUCCESS, serviceTaskStatus);

    // Retrieve JSON response.
    String jsonResponse = (String) variables.get(getServiceTaskVariableName(BaseJavaDelegate.VARIABLE_JSON_RESPONSE));
    ObjectMapper objectMapper = new ObjectMapper();
    BusinessObjectDataAttribute businessObjectDataAttribute = objectMapper.readValue(jsonResponse.getBytes(), BusinessObjectDataAttribute.class);

    // Validate JSON response.
    assertEquals(BDEF_NAMESPACE, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getNamespace());
    assertEquals(BDEF_NAME, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getBusinessObjectDefinitionName());
    assertEquals(FORMAT_USAGE_CODE, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getBusinessObjectFormatUsage());
    assertEquals(FORMAT_FILE_TYPE_CODE, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getBusinessObjectFormatFileType());
    assertEquals(FORMAT_VERSION, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getBusinessObjectFormatVersion());
    assertEquals(PARTITION_VALUE, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getPartitionValue());
    assertEquals(NO_SUBPARTITION_VALUES, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getSubPartitionValues());
    assertEquals(DATA_VERSION, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getBusinessObjectDataVersion());
    assertEquals(ATTRIBUTE_NAME_1_MIXED_CASE, businessObjectDataAttribute.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName());
    assertNull(businessObjectDataAttribute.getBusinessObjectDataAttributeValue());
}
 
Example 16
Source File: GetBusinessObjectDataTest.java    From herd with Apache License 2.0 4 votes vote down vote up
/**
 * Executes the Activiti job with the given parameters and returns variables. The parameters are as defined in the documentation.
 *
 * @param businessObjectDefinitionName the business object definition name.
 * @param businessObjectFormatUsage the business object format usage.
 * @param fileTypeCode the file type code.
 * @param partitionKey the partition key.
 * @param partitionValue the partition value.
 * @param subPartitionValues the sub-partition values.
 * @param businessObjectFormatVersion the business object format version (optional).
 * @param businessObjectDataVersion the business object data version (optional).
 *
 * @return map of variable name to variable value
 * @throws Exception
 */
private Map<String, Object> executeJob(String namespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String fileTypeCode,
    String partitionKey, String partitionValue, String subPartitionValues, String businessObjectFormatVersion, String businessObjectDataVersion)
    throws Exception
{
    // Prepare input data
    List<FieldExtension> fieldExtensionList = new ArrayList<>();
    if (namespace != null)
    {
        fieldExtensionList.add(buildFieldExtension("namespace", "${businessObjectDefinitionNamespace}"));
    }
    fieldExtensionList.add(buildFieldExtension("businessObjectDefinitionName", "${businessObjectDefinitionName}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatUsage", "${businessObjectFormatUsage}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatFileType", "${businessObjectFormatFileType}"));
    fieldExtensionList.add(buildFieldExtension("partitionKey", "${partitionKey}"));
    fieldExtensionList.add(buildFieldExtension("partitionValue", "${partitionValue}"));
    fieldExtensionList.add(buildFieldExtension("subPartitionValues", "${subPartitionValues}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectFormatVersion", "${businessObjectFormatVersion}"));
    fieldExtensionList.add(buildFieldExtension("businessObjectDataVersion", "${businessObjectDataVersion}"));

    List<Parameter> parameters = new ArrayList<>();
    if (namespace != null)
    {
        parameters.add(buildParameter("businessObjectDefinitionNamespace", namespace));
    }
    parameters.add(buildParameter("businessObjectDefinitionName", businessObjectDefinitionName));
    parameters.add(buildParameter("businessObjectFormatUsage", businessObjectFormatUsage));
    parameters.add(buildParameter("businessObjectFormatFileType", fileTypeCode));
    parameters.add(buildParameter("partitionKey", partitionKey));
    parameters.add(buildParameter("partitionValue", partitionValue));
    parameters.add(buildParameter("subPartitionValues", subPartitionValues));
    parameters.add(buildParameter("businessObjectFormatVersion", businessObjectFormatVersion));
    parameters.add(buildParameter("businessObjectDataVersion", businessObjectDataVersion));

    String activitiXml = buildActivitiXml(IMPLEMENTATION, fieldExtensionList);

    // Execute job
    Job job = jobServiceTestHelper.createJobForCreateClusterForActivitiXml(activitiXml, parameters);
    assertNotNull(job);

    HistoricProcessInstance hisInstance =
        activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).includeProcessVariables().singleResult();
    return hisInstance.getProcessVariables();
}
 
Example 17
Source File: JobServiceTest.java    From herd with Apache License 2.0 4 votes vote down vote up
@Test
public void testSignalJobWithCheckEmrClusterTask() throws Exception
{
    // Create a list of parameters for the job.
    List<Parameter> parameters = new ArrayList<>();
    Parameter parameter = new Parameter("clusterName", EMR_CLUSTER_NAME);
    parameters.add(parameter);

    // Run a job with Activiti XML that will start cluster, check status, wait on receive task and terminate.
    Job job = jobServiceTestHelper.createJobForCreateCluster(ACTIVITI_XML_CHECK_CLUSTER_AND_RECEIVE_TASK_WITH_CLASSPATH, parameters);
    assertNotNull(job);

    // Job should be waiting at receive task.
    Job getJobResponse = jobService.getJob(job.getId(), false);
    assertEquals(JobStatusEnum.RUNNING, getJobResponse.getStatus());
    assertEquals("receiveTask", getJobResponse.getCurrentWorkflowStep().getId());

    // Validate that create and check cluster tasks were successful.
    assertTrue(getJobResponse.getParameters().contains(new Parameter("createClusterServiceTask_taskStatus", ActivitiRuntimeHelper.TASK_STATUS_SUCCESS)));
    assertTrue(getJobResponse.getParameters().contains(new Parameter("checkClusterServiceTask_taskStatus", ActivitiRuntimeHelper.TASK_STATUS_SUCCESS)));

    // Signal job to continue.
    Parameter signalParameter = new Parameter(PARAMETER_NAME, PARAMETER_VALUE);
    JobSignalRequest jobSignalRequest = new JobSignalRequest(job.getId(), "receiveTask", Collections.singletonList(signalParameter), null);
    Job signalJobResponse = jobService.signalJob(jobSignalRequest);

    // Validate the signal job response.
    assertEquals(JobStatusEnum.RUNNING, signalJobResponse.getStatus());
    assertEquals("receiveTask", signalJobResponse.getCurrentWorkflowStep().getId());
    assertTrue(signalJobResponse.getParameters().contains(signalParameter));

    // Validate the cluster status information.
    Map<String, Parameter> jobParameters = jobServiceTestHelper.toMap(signalJobResponse.getParameters());
    assertTrue(jobParameters.containsKey("checkClusterServiceTask_emrClusterStatus_creationTime"));
    assertTrue(jobParameters.containsKey("checkClusterServiceTask_emrClusterStatus_readyTime"));
    assertTrue(jobParameters.containsKey("checkClusterServiceTask_emrClusterStatus_endTime"));

    // Job should have been completed.
    getJobResponse = jobService.getJob(job.getId(), false);
    assertEquals(JobStatusEnum.COMPLETED, getJobResponse.getStatus());
    assertTrue(getJobResponse.getParameters().contains(signalParameter));

    // Get the process variables.
    HistoricProcessInstance historicProcessInstance =
        activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).includeProcessVariables().singleResult();
    Map<String, Object> processVariables = historicProcessInstance.getProcessVariables();

    // Validate the cluster status information.
    assertTrue(processVariables.containsKey("checkClusterServiceTask_emrClusterStatus_creationTime"));
    assertNotNull(processVariables.get("checkClusterServiceTask_emrClusterStatus_creationTime"));
    assertTrue(processVariables.containsKey("checkClusterServiceTask_emrClusterStatus_readyTime"));
    assertNull(processVariables.get("checkClusterServiceTask_emrClusterStatus_readyTime"));
    assertTrue(processVariables.containsKey("checkClusterServiceTask_emrClusterStatus_endTime"));
    assertNull(processVariables.get("checkClusterServiceTask_emrClusterStatus_endTime"));
}
 
Example 18
Source File: CheckEmrClusterTest.java    From herd with Apache License 2.0 4 votes vote down vote up
/**
 * This method tests the check EMR cluster activiti task with cluster Id and step Id specified and requested step contains no id in response
 */
@Test
public void testCheckClusterByClusterIdStepIdRequestedStepHasNoId() throws Exception
{
    List<FieldExtension> fieldExtensions = getOptionalFieldExtensions();
    FieldExtension fieldExtension = new FieldExtension();
    fieldExtension.setFieldName("emrStepId");
    fieldExtension.setExpression("${addHiveStepServiceTask_emrStepId}");
    fieldExtensions.add(fieldExtension);

    List<Parameter> parameters = new ArrayList<>();
    parameters.add(new Parameter("clusterName", "testCluster1"));
    parameters.add(new Parameter("hiveStepName", MockEmrOperationsImpl.MOCK_STEP_WITHOUT_ID_NAME));
    parameters.add(new Parameter("hiveScriptLocation", "a_hive_step_location"));
    parameters.add(new Parameter("shellStepName", MockEmrOperationsImpl.MOCK_STEP_RUNNING_NAME));
    parameters.add(new Parameter("shellScriptLocation", "a_shell_step_location"));
    parameters.add(new Parameter("verbose", "false"));
    parameters.add(new Parameter("retrieveInstanceFleets", "false"));

    // Run a job with Activiti XML that will start cluster, check status and terminate.
    Job job = jobServiceTestHelper.createJobForCreateClusterForActivitiXml(getCheckClusterActivitiXml(fieldExtensions), parameters);
    assertNotNull(job);

    HistoricProcessInstance hisInstance =
        activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).includeProcessVariables().singleResult();
    Map<String, Object> variables = hisInstance.getProcessVariables();

    String hiveStepId = (String) variables.get("addHiveStepServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "emrStepId");
    assertNotNull(hiveStepId);
    String emrStepId = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "step_id");
    assertNull(emrStepId);
    String emrStepJarLocation = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "step_jarLocation");
    assertNull(emrStepJarLocation);

    String shellStepId = (String) variables.get("addShellStepServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "emrStepId");
    assertNotNull(shellStepId);
    String activeStepId = (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "activeStep_id");
    assertEquals(shellStepId, activeStepId);
    String activeStepJarLocation =
        (String) variables.get("checkClusterServiceTask" + ActivitiRuntimeHelper.TASK_VARIABLE_MARKER + "activeStep_jarLocation");
    assertNull(activeStepJarLocation);
}
 
Example 19
Source File: HistoricProcessInstanceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Validation for https://jira.codehaus.org/browse/ACT-2182
 */
public void testNameAndTenantIdSetWhenFetchingVariables() {

  String tenantId = "testTenantId";
  String processInstanceName = "myProcessInstance";

  String deploymentId = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/history/oneTaskProcess.bpmn20.xml").tenantId(tenantId).deploy().getId();

  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("name", "Kermit");
  vars.put("age", 60);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKeyAndTenantId("oneTaskProcess", vars, tenantId);
  runtimeService.setProcessInstanceName(processInstance.getId(), processInstanceName);

  // Verify name and tenant id (didn't work on mssql and db2) on process
  // instance
  List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().includeProcessVariables().list();
  assertEquals(1, processInstances.size());
  processInstance = processInstances.get(0);

  assertEquals(processInstanceName, processInstance.getName());
  assertEquals(tenantId, processInstance.getTenantId());

  Map<String, Object> processInstanceVars = processInstance.getProcessVariables();
  assertEquals(2, processInstanceVars.size());
  assertEquals("Kermit", processInstanceVars.get("name"));
  assertEquals(60, processInstanceVars.get("age"));

  // Verify name and tenant id (didn't work on mssql and db2) on historic
  // process instance
  List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().list();
  assertEquals(1, historicProcessInstances.size());
  HistoricProcessInstance historicProcessInstance = historicProcessInstances.get(0);

  // Verify name and tenant id (didn't work on mssql and db2) on process
  // instance
  assertEquals(processInstanceName, historicProcessInstance.getName());
  assertEquals(tenantId, historicProcessInstance.getTenantId());

  Map<String, Object> historicProcessInstanceVars = historicProcessInstance.getProcessVariables();
  assertEquals(2, historicProcessInstanceVars.size());
  assertEquals("Kermit", historicProcessInstanceVars.get("name"));
  assertEquals(60, historicProcessInstanceVars.get("age"));

  // cleanup
  repositoryService.deleteDeployment(deploymentId, true);
}
 
Example 20
Source File: HistoricProcessInstanceAndVariablesQueryTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testOrQueryMultipleVariableValues() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    HistoricProcessInstanceQuery query0 = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or();
    for (int i = 0; i < 20; i++) {
        query0 = query0.variableValueEquals("anothertest", i);
    }
    query0 = query0.processDefinitionId("undefined").endOr();

    assertNull(query0.singleResult());

    HistoricProcessInstanceQuery query1 = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 123);
    for (int i = 0; i < 20; i++) {
        query1 = query1.variableValueEquals("anothertest", i);
    }
    query1 = query1.processDefinitionId("undefined").endOr();

    HistoricProcessInstance processInstance = query1.singleResult();
    Map<String, Object> variableMap = processInstance.getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));

    HistoricProcessInstanceQuery query2 = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
            .or();
    for (int i = 0; i < 20; i++) {
        query2 = query2.variableValueEquals("anothertest", i);
    }
    query2 = query2.processDefinitionId("undefined")
            .endOr()
            .or()
              .processDefinitionKey(PROCESS_DEFINITION_KEY_2)
              .processDefinitionId("undefined")
            .endOr();
    assertNull(query2.singleResult());

    HistoricProcessInstanceQuery query3 = historyService.createHistoricProcessInstanceQuery().includeProcessVariables()
            .or().variableValueEquals("anothertest", 123);
    for (int i = 0; i < 20; i++) {
        query3 = query3.variableValueEquals("anothertest", i);
    }
    query3 = query3.processDefinitionId("undefined")
            .endOr()
            .or()
              .processDefinitionKey(PROCESS_DEFINITION_KEY_2)
              .processDefinitionId("undefined")
            .endOr();
    variableMap = query3.singleResult().getProcessVariables();
    assertEquals(1, variableMap.size());
    assertEquals(123, variableMap.get("anothertest"));
  }
}