Search in sources :

Example 11 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method testCreateJobDefinitionAssertSuccessWhenFirstTaskAsync.

/**
 * Asserts that create job definition proceeds without exceptions when first task is set to async
 *
 * @throws Exception
 */
@Test
public void testCreateJobDefinitionAssertSuccessWhenFirstTaskAsync() throws Exception {
    String namespace = NAMESPACE;
    String jobName = JOB_NAME;
    BpmnModel bpmnModel = new BpmnModel();
    Process process = new Process();
    process.setId(namespace + '.' + jobName);
    {
        StartEvent element = new StartEvent();
        element.setId("start");
        process.addFlowElement(element);
    }
    {
        ScriptTask element = new ScriptTask();
        element.setId("script");
        element.setScriptFormat("js");
        element.setScript("// do nothing");
        element.setAsynchronous(true);
        process.addFlowElement(element);
    }
    {
        EndEvent element = new EndEvent();
        element.setId("end");
        process.addFlowElement(element);
    }
    process.addFlowElement(new SequenceFlow("start", "script"));
    process.addFlowElement(new SequenceFlow("script", "end"));
    bpmnModel.addProcess(process);
    String activitiJobXml = getActivitiXmlFromBpmnModel(bpmnModel);
    namespaceDaoTestHelper.createNamespaceEntity(namespace);
    jobDefinitionService.createJobDefinition(new JobDefinitionCreateRequest(namespace, jobName, null, activitiJobXml, null, null), true);
// Assert no exceptions
}
Also used : ScriptTask(org.activiti.bpmn.model.ScriptTask) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) StartEvent(org.activiti.bpmn.model.StartEvent) JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) EndEvent(org.activiti.bpmn.model.EndEvent) Process(org.activiti.bpmn.model.Process) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 12 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method testCreateJobDefinitionInvalidNamespace.

/**
 * This method tests the scenario in which the namespace is invalid ObjectNotFoundException is expected to be thrown
 */
@Test(expected = ObjectNotFoundException.class)
public void testCreateJobDefinitionInvalidNamespace() throws Exception {
    // Create the job request without registering the namespace entity - ${TEST_ACTIVITI_NAMESPACE_CD}
    JobDefinitionCreateRequest request = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    // Following method must throw ObjectNotFoundException, as the namespace entity ${TEST_ACTIVITI_NAMESPACE_CD} does not exist.
    jobDefinitionService.createJobDefinition(request, false);
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) Test(org.junit.Test)

Example 13 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTestHelper method createJobDefinitionForActivitiXml.

/**
 * Creates a job definition based on the specified Activiti XML.
 *
 * @param activitiXml the Activiti XML.
 *
 * @return the job definition.
 * @throws Exception if any errors were encountered.
 */
public JobDefinition createJobDefinitionForActivitiXml(String activitiXml) throws Exception {
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(AbstractServiceTest.TEST_ACTIVITI_NAMESPACE_CD);
    // Create and persist a valid job definition.
    JobDefinitionCreateRequest jobDefinitionCreateRequest = createJobDefinitionCreateRequestFromActivitiXml(activitiXml);
    JobDefinition jobDefinition = jobDefinitionService.createJobDefinition(jobDefinitionCreateRequest, false);
    // Validate the returned object against the input.
    assertNotNull(jobDefinition);
    assertTrue(jobDefinition.getNamespace().equals(jobDefinitionCreateRequest.getNamespace()));
    assertTrue(jobDefinition.getJobName().equals(jobDefinitionCreateRequest.getJobName()));
    assertTrue(jobDefinition.getDescription().equals(jobDefinitionCreateRequest.getDescription()));
    return jobDefinition;
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) JobDefinition(org.finra.herd.model.api.xml.JobDefinition)

Example 14 with JobDefinitionCreateRequest

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

the class JobServiceTest method testCreateJobNoParams.

@Test
public void testCreateJobNoParams() throws Exception {
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    // Create a job definition create request using hard coded test values.
    JobDefinitionCreateRequest jobDefinitionCreateRequest = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    jobDefinitionCreateRequest.setParameters(null);
    // Create the job definition.
    jobDefinitionService.createJobDefinition(jobDefinitionCreateRequest, false);
    // Create a job create request using hard coded test values.
    JobCreateRequest jobCreateRequest = jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
    jobCreateRequest.setParameters(null);
    // Create the job.
    Job resultJob = jobService.createAndStartJob(jobCreateRequest);
    // expected default parameter
    List<Parameter> expectedParameters = Arrays.asList(new Parameter(HERD_WORKFLOW_ENVIRONMENT, configurationHelper.getProperty(ConfigurationValue.HERD_ENVIRONMENT)));
    // Validate the results.
    assertNotNull(resultJob);
    assertNotNull(resultJob.getId());
    assertTrue(!resultJob.getId().isEmpty());
    assertEquals(TEST_ACTIVITI_NAMESPACE_CD, resultJob.getNamespace());
    assertEquals(TEST_ACTIVITI_JOB_NAME, resultJob.getJobName());
    assertTrue(resultJob.getParameters().size() == 1);
    assertTrue(expectedParameters.containsAll(resultJob.getParameters()));
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) Parameter(org.finra.herd.model.api.xml.Parameter) Job(org.finra.herd.model.api.xml.Job) JobCreateRequest(org.finra.herd.model.api.xml.JobCreateRequest) Test(org.junit.Test)

Example 15 with JobDefinitionCreateRequest

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

the class JobServiceTest method testCreateJob.

@Test
public void testCreateJob() throws Exception {
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    // Create a job definition create request using hard coded test values.
    JobDefinitionCreateRequest jobDefinitionCreateRequest = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    // Create the job definition.
    jobDefinitionService.createJobDefinition(jobDefinitionCreateRequest, false);
    // Create a job create request using hard coded test values.
    JobCreateRequest jobCreateRequest = jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
    // Create the job.
    Job resultJob = jobService.createAndStartJob(jobCreateRequest);
    // Validate the results.
    assertNotNull(resultJob);
    assertNotNull(resultJob.getId());
    assertTrue(!resultJob.getId().isEmpty());
    assertEquals(TEST_ACTIVITI_NAMESPACE_CD, resultJob.getNamespace());
    assertEquals(TEST_ACTIVITI_JOB_NAME, resultJob.getJobName());
    assertEquals(jobDefinitionCreateRequest.getParameters().size() + jobCreateRequest.getParameters().size() + 1, resultJob.getParameters().size());
    List<String> expectedParameters = new ArrayList<>();
    expectedParameters.addAll(parametersToStringList(jobDefinitionCreateRequest.getParameters()));
    expectedParameters.addAll(parametersToStringList(jobCreateRequest.getParameters()));
    expectedParameters.addAll(parametersToStringList(Arrays.asList(new Parameter(HERD_WORKFLOW_ENVIRONMENT, configurationHelper.getProperty(ConfigurationValue.HERD_ENVIRONMENT)))));
    List<String> resultParameters = parametersToStringList(resultJob.getParameters());
    assertTrue(expectedParameters.containsAll(resultParameters));
    assertTrue(resultParameters.containsAll(expectedParameters));
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) Job(org.finra.herd.model.api.xml.Job) JobCreateRequest(org.finra.herd.model.api.xml.JobCreateRequest) Test(org.junit.Test)

Aggregations

JobDefinitionCreateRequest (org.finra.herd.model.api.xml.JobDefinitionCreateRequest)26 Test (org.junit.Test)19 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)9 Parameter (org.finra.herd.model.api.xml.Parameter)5 BpmnModel (org.activiti.bpmn.model.BpmnModel)4 EndEvent (org.activiti.bpmn.model.EndEvent)4 Process (org.activiti.bpmn.model.Process)4 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)4 StartEvent (org.activiti.bpmn.model.StartEvent)4 JobCreateRequest (org.finra.herd.model.api.xml.JobCreateRequest)4 JobDefinitionUpdateRequest (org.finra.herd.model.api.xml.JobDefinitionUpdateRequest)4 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)4 ArrayList (java.util.ArrayList)3 ScriptTask (org.activiti.bpmn.model.ScriptTask)3 Job (org.finra.herd.model.api.xml.Job)3 S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)3 InputStream (java.io.InputStream)2 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 Transactional (org.springframework.transaction.annotation.Transactional)1