use of org.finra.herd.model.api.xml.JobDefinitionCreateRequest in project herd by FINRAOS.
the class JobServiceTest method testCreateJobWithS3PropertiesJobDefinitionWrongDatafixSafety.
/**
* Tests an edge case where the job definition was persisted with some S3 properties location, but due to some datafix, the S3 properties location's object
* key was removed, but not the bucket name. The service should still work, it would simply ignore the definition's S3 properties location.
*
* @throws Exception
*/
@Test
public void testCreateJobWithS3PropertiesJobDefinitionWrongDatafixSafety() 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.setS3PropertiesLocation(getS3PropertiesLocation("testBucketName", "testObjectKey", new Parameter("testName", "testValue")));
jobDefinitionCreateRequest.setParameters(null);
// Create the job definition.
JobDefinition jobDefinition = jobDefinitionService.createJobDefinition(jobDefinitionCreateRequest, false);
Integer jobDefinitionId = jobDefinition.getId();
JobDefinitionEntity jobDefinitionEntity = herdDao.findById(JobDefinitionEntity.class, jobDefinitionId);
jobDefinitionEntity.setS3ObjectKey(null);
// 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);
Assert.assertNotNull("resultJob parameters", resultJob.getParameters());
}
use of org.finra.herd.model.api.xml.JobDefinitionCreateRequest in project herd by FINRAOS.
the class JobDefinitionServiceTest method testCreateJobDefinitionWithS3PropertiesLocationPersistsEntity.
/**
* Asserts that when a job definition is created using {@link S3PropertiesLocation}, the S3 location information is persisted.
*
* @throws Exception
*/
@Test
public void testCreateJobDefinitionWithS3PropertiesLocationPersistsEntity() throws Exception {
S3PropertiesLocation s3PropertiesLocation = getS3PropertiesLocation();
namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
JobDefinitionCreateRequest request = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
request.setS3PropertiesLocation(s3PropertiesLocation);
JobDefinition jobDefinition = jobDefinitionService.createJobDefinition(request, false);
Assert.assertEquals("jobDefinition s3PropertiesLocation", request.getS3PropertiesLocation(), jobDefinition.getS3PropertiesLocation());
JobDefinitionEntity jobDefinitionEntity = herdDao.findById(JobDefinitionEntity.class, jobDefinition.getId());
Assert.assertNotNull("jobDefinitionEntity is null", jobDefinitionEntity);
Assert.assertEquals("jobDefinitionEntity s3BucketName", s3PropertiesLocation.getBucketName(), jobDefinitionEntity.getS3BucketName());
Assert.assertEquals("jobDefinitionEntity s3ObjectKey", s3PropertiesLocation.getKey(), jobDefinitionEntity.getS3ObjectKey());
}
use of org.finra.herd.model.api.xml.JobDefinitionCreateRequest in project herd by FINRAOS.
the class JobDefinitionServiceTest method testUpdateJobDefinitionWithS3PropertiesClear.
@Test
public void testUpdateJobDefinitionWithS3PropertiesClear() 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();
createRequest.setS3PropertiesLocation(s3PropertiesLocation);
// 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);
// 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(), null, HerdDaoSecurityHelper.SYSTEM_USER), updatedJobDefinition);
// Validate the updated job definition entity.
Assert.assertNull("updatedJobDefinitionEntity s3BucketName", updatedJobDefinitionEntity.getS3BucketName());
Assert.assertNull("updatedJobDefinitionEntity s3ObjectKey", updatedJobDefinitionEntity.getS3ObjectKey());
}
use of org.finra.herd.model.api.xml.JobDefinitionCreateRequest in project herd by FINRAOS.
the class JobDefinitionServiceTest method testCreateJobDefinitionInvalidActivitiElement.
/**
* This method tests the scenario in which an invalid Java class name is given. This must throw IllegalArgumentException from the Activiti layer.
*/
@Test(expected = IllegalArgumentException.class)
public void testCreateJobDefinitionInvalidActivitiElement() throws Exception {
// Create the namespace entity.
namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
// Create and persist a valid job definition.
JobDefinitionCreateRequest request = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
// Read the Activiti XML file so that an error can be injected.
InputStream xmlStream = resourceLoader.getResource(ACTIVITI_XML_HERD_WORKFLOW_WITH_CLASSPATH).getInputStream();
// Inject an error by having an invalid Activiti element name in the XML file.
// Note that XML file structure is correct as per the XML schema. However, there is an invalid Activiti element in the XML file.
// The line below will be affected in the XML file as per this error injection.
// <serviceTask id="servicetask1" name="Test Service Step" activiti:class="org.activiti.engine.impl.test.NoOpServiceTask">
request.setActivitiJobXml(IOUtils.toString(xmlStream).replaceAll("serviceTask", "invalidActivitiTask"));
// Try creating the job definition and the Activiti layer mush throw an exception.
jobDefinitionService.createJobDefinition(request, false);
}
use of org.finra.herd.model.api.xml.JobDefinitionCreateRequest in project herd by FINRAOS.
the class JobDefinitionServiceTestHelper method createJobDefinitionCreateRequest.
/**
* Creates a new job definition create request based on user specified parameters.
*
* @param namespaceCd the namespace code.
* @param jobName the job name.
* @param jobDescription the job description.
* @param activitiXml the Activiti XML.
* @param parameters the parameters.
*
* @return the job definition create request.
*/
public JobDefinitionCreateRequest createJobDefinitionCreateRequest(String namespaceCd, String jobName, String jobDescription, String activitiXml, List<Parameter> parameters) {
// Create and return a new job definition create request.
JobDefinitionCreateRequest request = new JobDefinitionCreateRequest();
request.setNamespace(namespaceCd);
request.setJobName(jobName);
request.setDescription(jobDescription);
request.setActivitiJobXml(activitiXml);
request.setParameters(parameters);
return request;
}
Aggregations