Search in sources :

Example 1 with JobDefinitionCreateRequest

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

the class JobDefinitionRestControllerTest method testCreateJobDefinition.

@Test
public void testCreateJobDefinition() throws Exception {
    String namespace = NAMESPACE;
    String jobName = JOB_NAME;
    String activitiJobXml = getActivitiJobXml(namespace, jobName);
    JobDefinitionCreateRequest request = new JobDefinitionCreateRequest(namespace, jobName, null, activitiJobXml, null, null);
    JobDefinition jobDefinition = getJobDefinition(NAMESPACE, JOB_NAME);
    when(jobDefinitionService.createJobDefinition(request, true)).thenReturn(jobDefinition);
    JobDefinition resultJobDefinition = jobDefinitionRestController.createJobDefinition(new JobDefinitionCreateRequest(namespace, jobName, null, activitiJobXml, null, null));
    // Verify the external calls.
    verify(jobDefinitionService).createJobDefinition(request, true);
    verifyNoMoreInteractions(jobDefinitionService);
    // Validate the returned object.
    assertEquals(jobDefinition, resultJobDefinition);
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) JobDefinition(org.finra.herd.model.api.xml.JobDefinition) Test(org.junit.Test)

Example 2 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method testUpdateJobDefinitionWithS3Properties.

@Test
public void testUpdateJobDefinitionWithS3Properties() throws Exception {
    S3PropertiesLocation s3PropertiesLocation = getS3PropertiesLocation();
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    // Create job definition create request using hard coded test values.
    JobDefinitionCreateRequest createRequest = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    // Create the job definition in the database.
    JobDefinition jobDefinition = jobDefinitionService.createJobDefinition(createRequest, false);
    // Create an update request with a varied set of data that is based on the same data used in the create request.
    JobDefinitionUpdateRequest updateRequest = createUpdateRequest(createRequest);
    updateRequest.setS3PropertiesLocation(s3PropertiesLocation);
    // Update the job definition in the database.
    JobDefinition updatedJobDefinition = jobDefinitionService.updateJobDefinition(createRequest.getNamespace(), createRequest.getJobName(), updateRequest, false);
    JobDefinitionEntity updatedJobDefinitionEntity = herdDao.findById(JobDefinitionEntity.class, updatedJobDefinition.getId());
    // Validate the updated job definition.
    assertEquals(new JobDefinition(jobDefinition.getId(), jobDefinition.getNamespace(), jobDefinition.getJobName(), updateRequest.getDescription(), updateRequest.getActivitiJobXml(), updateRequest.getParameters(), s3PropertiesLocation, HerdDaoSecurityHelper.SYSTEM_USER), updatedJobDefinition);
    // Validate the updated job definition entity.
    Assert.assertEquals("updatedJobDefinitionEntity s3BucketName", s3PropertiesLocation.getBucketName(), updatedJobDefinitionEntity.getS3BucketName());
    Assert.assertEquals("updatedJobDefinitionEntity s3ObjectKey", s3PropertiesLocation.getKey(), updatedJobDefinitionEntity.getS3ObjectKey());
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) JobDefinition(org.finra.herd.model.api.xml.JobDefinition) JobDefinitionUpdateRequest(org.finra.herd.model.api.xml.JobDefinitionUpdateRequest) Test(org.junit.Test)

Example 3 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method testCreateJobDefinitionWithS3PropertiesLocationValidate.

/**
 * Asserts that when a job definition is created with the given {@link S3PropertiesLocation}, then an exception of the given type and message is thrown.
 *
 * @param s3PropertiesLocation {@link S3PropertiesLocation}
 * @param exceptionType expected exception type
 * @param exceptionMessage expected exception message
 */
private void testCreateJobDefinitionWithS3PropertiesLocationValidate(S3PropertiesLocation s3PropertiesLocation, Class<? extends Exception> exceptionType, String exceptionMessage) {
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    JobDefinitionCreateRequest request = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    request.setS3PropertiesLocation(s3PropertiesLocation);
    try {
        jobDefinitionService.createJobDefinition(request, false);
        Assert.fail("expected " + exceptionType + ", but no exception was thrown");
    } catch (Exception e) {
        Assert.assertEquals("thrown exception type", exceptionType, e.getClass());
        Assert.assertEquals("thrown exception message", exceptionMessage, e.getMessage());
    }
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException)

Example 4 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method testUpdateJobDefinitionAssertSuccessWhenFirstTaskAsync.

/**
 * Asserts that update job definition proceeds without exceptions when first task is set to async
 *
 * @throws Exception
 */
@Test
public void testUpdateJobDefinitionAssertSuccessWhenFirstTaskAsync() 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);
    jobDefinitionService.updateJobDefinition(namespace, jobName, new JobDefinitionUpdateRequest(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) JobDefinitionUpdateRequest(org.finra.herd.model.api.xml.JobDefinitionUpdateRequest) Test(org.junit.Test)

Example 5 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method testCreateJobDefinitionNoJobName.

/**
 * This method tests the scenario in which the jobName is invalid IllegalArgumentException is expected to be thrown.
 */
@Test(expected = IllegalArgumentException.class)
public void testCreateJobDefinitionNoJobName() throws Exception {
    String invalidJobName = TEST_ACTIVITI_NAMESPACE_CD;
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    JobDefinitionCreateRequest request = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    // Enter the invalid job name.
    request.setJobName(invalidJobName);
    // The following method is expected to throw an IllegalArgumentException.
    jobDefinitionService.createJobDefinition(request, false);
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) 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