Search in sources :

Example 31 with Parameter

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

the class JobServiceTest method testCreateJobWithS3PropertiesWithInvalidUnicodeThrows.

/**
 * A Java Properties file is invalid when there is an invalid unicode reference. The service should throw a friendly error message when such case happens.
 *
 * @throws Exception
 */
@Test
public void testCreateJobWithS3PropertiesWithInvalidUnicodeThrows() throws Exception {
    Parameter jobCreateRequestS3Parameter = new Parameter("name2", "value2\\uxxxx");
    String s3BucketName = "s3BucketName";
    S3PropertiesLocation jobCreateRequestS3PropertiesLocation = getS3PropertiesLocation(s3BucketName, "jobCreationObjectKey", jobCreateRequestS3Parameter);
    String bucketName = jobCreateRequestS3PropertiesLocation.getBucketName();
    String key = jobCreateRequestS3PropertiesLocation.getKey();
    try {
        createJobWithParameters(null, null, jobCreateRequestS3PropertiesLocation, null);
        Assert.fail("expected IllegalArgumentException, but no exception was thrown");
    } catch (Exception e) {
        Assert.assertEquals("thrown exception type", IllegalArgumentException.class, e.getClass());
        Assert.assertEquals("thrown exception message", "The properties file in S3 bucket '" + bucketName + "' and key '" + key + "' is invalid.", e.getMessage());
    }
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) Parameter(org.finra.herd.model.api.xml.Parameter) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Test(org.junit.Test)

Example 32 with Parameter

use of org.finra.herd.model.api.xml.Parameter 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 33 with Parameter

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

the class JobServiceTest method testCreateJobWithS3PropertiesDefinitionObjectKeyNotFoundThrows.

/**
 * Creates a job where the definition's S3 object key does not exist. It should throw a not found exception.
 *
 * @throws Exception
 */
@Test
public void testCreateJobWithS3PropertiesDefinitionObjectKeyNotFoundThrows() throws Exception {
    Parameter jobDefinitionS3Parameter = new Parameter("name1", "value1");
    Parameter jobCreateRequestS3Parameter = new Parameter("name2", "value2");
    String s3BucketName = "s3BucketName";
    S3PropertiesLocation jobDefinitionS3PropertiesLocation = getS3PropertiesLocation(s3BucketName, "jobDefinitionObjectKey", jobDefinitionS3Parameter);
    S3PropertiesLocation jobCreateRequestS3PropertiesLocation = getS3PropertiesLocation(s3BucketName, "jobCreationObjectKey", jobCreateRequestS3Parameter);
    jobDefinitionS3PropertiesLocation.setKey("NOT_FOUND");
    try {
        createJobWithParameters(jobDefinitionS3PropertiesLocation, null, jobCreateRequestS3PropertiesLocation, null);
        Assert.fail("expected ObjectNotFoundException, but no exception was thrown");
    } catch (Exception e) {
        Assert.assertEquals("thrown exception type", ObjectNotFoundException.class, e.getClass());
        Assert.assertEquals("thrown exception message", "Specified S3 object key '" + jobDefinitionS3PropertiesLocation.getKey() + "' does not exist.", e.getMessage());
    }
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Parameter(org.finra.herd.model.api.xml.Parameter) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Test(org.junit.Test)

Example 34 with Parameter

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

the class JobServiceTest method testSignalJob.

@Test
public void testSignalJob() throws Exception {
    jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_TASK_WITH_CLASSPATH);
    // Start the job.
    Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
    // Job should be waiting at Receive task.
    Job jobGet = jobService.getJob(job.getId(), false);
    assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus());
    assertEquals("receivetask1", jobGet.getCurrentWorkflowStep().getId());
    // Signal job to continue.
    List<Parameter> signalParameters = new ArrayList<>();
    Parameter signalPameter1 = new Parameter("UT_SIGNAL_PARAM_1", "UT_SIGNAL_VALUE_1");
    signalParameters.add(signalPameter1);
    JobSignalRequest jobSignalRequest = new JobSignalRequest(job.getId(), "receivetask1", signalParameters, null);
    Job signalJob = jobService.signalJob(jobSignalRequest);
    assertEquals(JobStatusEnum.RUNNING, signalJob.getStatus());
    assertEquals("receivetask1", signalJob.getCurrentWorkflowStep().getId());
    assertTrue(signalJob.getParameters().contains(signalPameter1));
    // Job should have been completed.
    jobGet = jobService.getJob(job.getId(), true);
    assertEquals(JobStatusEnum.COMPLETED, jobGet.getStatus());
    assertTrue(jobGet.getParameters().contains(signalPameter1));
}
Also used : ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) JobSignalRequest(org.finra.herd.model.api.xml.JobSignalRequest) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test)

Example 35 with Parameter

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

the class JobServiceTest method testCreateJobWithS3PropertiesValidationObjectKeyRequired.

/**
 * Creates a job where the request's S3 properties is given, but object key is not. It should throw a bad request exception.
 *
 * @throws Exception
 */
@Test
public void testCreateJobWithS3PropertiesValidationObjectKeyRequired() throws Exception {
    Parameter jobCreateRequestS3Parameter = new Parameter("name2", "value2");
    String s3BucketName = "s3BucketName";
    S3PropertiesLocation jobCreateRequestS3PropertiesLocation = getS3PropertiesLocation(s3BucketName, "jobCreationObjectKey", jobCreateRequestS3Parameter);
    jobCreateRequestS3PropertiesLocation.setKey(null);
    try {
        createJobWithParameters(null, null, jobCreateRequestS3PropertiesLocation, null);
        Assert.fail("expected IllegalArgumentException, but no exception was thrown");
    } catch (Exception e) {
        Assert.assertEquals("thrown exception type", IllegalArgumentException.class, e.getClass());
        Assert.assertEquals("thrown exception message", "S3 properties location object key must be specified.", e.getMessage());
    }
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) Parameter(org.finra.herd.model.api.xml.Parameter) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Test(org.junit.Test)

Aggregations

Parameter (org.finra.herd.model.api.xml.Parameter)148 Test (org.junit.Test)121 ArrayList (java.util.ArrayList)98 FieldExtension (org.activiti.bpmn.model.FieldExtension)64 HashMap (java.util.HashMap)61 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)30 Job (org.finra.herd.model.api.xml.Job)30 SystemJobRunRequest (org.finra.herd.model.api.xml.SystemJobRunRequest)20 SystemJobRunResponse (org.finra.herd.model.api.xml.SystemJobRunResponse)14 S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)13 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)13 BusinessObjectDataAttribute (org.finra.herd.model.api.xml.BusinessObjectDataAttribute)12 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)9 BusinessObjectDataAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity)9 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)8 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)7 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)6 JobAction (org.finra.herd.model.api.xml.JobAction)6 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)6 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)5