Search in sources :

Example 61 with Job

use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.

the class CreateBusinessObjectDataAttributeTest method testCreateBusinessObjectDataAttribute.

@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());
}
Also used : HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataAttribute(org.finra.herd.model.api.xml.BusinessObjectDataAttribute) FieldExtension(org.activiti.bpmn.model.FieldExtension) Parameter(org.finra.herd.model.api.xml.Parameter) Job(org.finra.herd.model.api.xml.Job) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 62 with Job

use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.

the class HerdActivitiServiceTaskTest method createJobAndCheckTaskStatusFailure.

private Job createJobAndCheckTaskStatusFailure(String activitiXml, List<Parameter> parameters, Map<String, Object> variableValuesToValidate) throws Exception {
    Job job = jobServiceTestHelper.createJobFromActivitiXml(activitiXml, parameters);
    assertNotNull(job);
    HistoricProcessInstance hisInstance = activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).includeProcessVariables().singleResult();
    Map<String, Object> variables = hisInstance.getProcessVariables();
    String serviceTaskStatus = (String) variables.get(getServiceTaskVariableName(ActivitiRuntimeHelper.VARIABLE_STATUS));
    assertEquals(ActivitiRuntimeHelper.TASK_STATUS_ERROR, serviceTaskStatus);
    if (variableValuesToValidate != null) {
        for (Map.Entry<String, Object> varEntry : variableValuesToValidate.entrySet()) {
            Object wfVariableValue = variables.get(getServiceTaskVariableName(varEntry.getKey()));
            Object expectedVariableValue = varEntry.getValue();
            if (expectedVariableValue.equals(VARIABLE_VALUE_NOT_NULL)) {
                assertNotNull(wfVariableValue);
            } else if (expectedVariableValue.equals(VARIABLE_VALUE_IS_NULL)) {
                assertNull(wfVariableValue);
            } else {
                assertEquals(expectedVariableValue, wfVariableValue);
            }
        }
    }
    return job;
}
Also used : HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) Job(org.finra.herd.model.api.xml.Job) Map(java.util.Map)

Example 63 with Job

use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.

the class LogVariablesTest method testLogVariablesNoRegex.

@Test
public void testLogVariablesNoRegex() throws Exception {
    // Run a job with Activiti XML that will log variables. The XML will log all variables present in the test workflow because no Regex is specified.
    Job job = jobServiceTestHelper.createJob(ACTIVITI_XML_LOG_VARIABLES_NO_REGEX_WITH_CLASSPATH);
    assertNotNull(job);
}
Also used : Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 64 with Job

use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.

the class LogVariablesTest method testLogVariables.

@Test
public void testLogVariables() throws Exception {
    // Run a job with Activiti XML that will log variables. The XML will only log 1 of the 2 variables present in the test workflow.
    // Since we can't really test what got logged, we'll just ensure that no exceptions were thrown and that the job isn't null.
    Job job = jobServiceTestHelper.createJob(ACTIVITI_XML_LOG_VARIABLES_WITH_CLASSPATH);
    assertNotNull(job);
}
Also used : Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 65 with Job

use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.

the class CheckEmrClusterTest method testCheckClusterByClusterIdStepIdNoActiveStep.

@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);
}
Also used : FieldExtension(org.activiti.bpmn.model.FieldExtension) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Aggregations

Job (org.finra.herd.model.api.xml.Job)71 Test (org.junit.Test)60 Parameter (org.finra.herd.model.api.xml.Parameter)30 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)21 ArrayList (java.util.ArrayList)20 FieldExtension (org.activiti.bpmn.model.FieldExtension)11 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)11 Task (org.activiti.engine.task.Task)9 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)9 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)8 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)7 JobDeleteRequest (org.finra.herd.model.api.xml.JobDeleteRequest)7 JobSignalRequest (org.finra.herd.model.api.xml.JobSignalRequest)7 S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)7 AccessDeniedException (org.springframework.security.access.AccessDeniedException)7 JobAction (org.finra.herd.model.api.xml.JobAction)6 JobUpdateRequest (org.finra.herd.model.api.xml.JobUpdateRequest)6 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)6 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)6 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)6