Search in sources :

Example 6 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method testCreateJobDefinitionAlreadyExists.

/**
 * This method tests the scenario in which the user tries to register the same job flow twice AlreadyExistsException is expected to be thrown.
 */
@Test(expected = AlreadyExistsException.class)
public void testCreateJobDefinitionAlreadyExists() throws Exception {
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    // Create and persist a valid job definition.
    JobDefinitionCreateRequest request = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    jobDefinitionService.createJobDefinition(request, false);
    // Create the same request again which is an invalid operation, as the workflow exists.
    // Following must throw AlreadyExistsException
    jobDefinitionService.createJobDefinition(request, false);
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) Test(org.junit.Test)

Example 7 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method testCreateJobDefinitionWithNoParams.

/**
 * This method tests the happy path scenario in which no parameters are given.
 */
@Test
public void testCreateJobDefinitionWithNoParams() throws Exception {
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    // Create and persist a valid job definition.
    JobDefinitionCreateRequest request = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    request.setParameters(null);
    // Try creating the job definition.
    jobDefinitionService.createJobDefinition(request, false);
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) Test(org.junit.Test)

Example 8 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method testCreateJobDefinitionAssertSuccessWhenFirstTaskNotAsyncable.

/**
 * Asserts that create job definition proceeds without exceptions when first task does not support async (ex. events)
 *
 * @throws Exception
 */
@Test
public void testCreateJobDefinitionAssertSuccessWhenFirstTaskNotAsyncable() 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);
    }
    {
        EndEvent element = new EndEvent();
        element.setId("end");
        process.addFlowElement(element);
    }
    process.addFlowElement(new SequenceFlow("start", "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 : 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 9 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method testCreateJobDefinitionWithParams.

/**
 * This method tests the happy path scenario in which all the parameters including the attributes are given.
 */
@Test
public void testCreateJobDefinitionWithParams() throws Exception {
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    // Create and persist a valid job definition.
    JobDefinitionCreateRequest request = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    // Add parameters
    List<Parameter> parameterEntities = new ArrayList<>();
    Parameter parameterEntity = new Parameter();
    parameterEntity.setName(ATTRIBUTE_NAME_1_MIXED_CASE);
    parameterEntity.setValue(ATTRIBUTE_VALUE_1);
    parameterEntities.add(parameterEntity);
    request.setParameters(parameterEntities);
    // Try creating the job definition.
    jobDefinitionService.createJobDefinition(request, false);
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) Test(org.junit.Test)

Example 10 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method testCreateJobDefinitionInvalidActivitiXml.

/**
 * This method tests the scenario in which the user passes an ill-formatted xml file XMLException is expected to be thrown
 */
@Test(expected = IllegalArgumentException.class)
public void testCreateJobDefinitionInvalidActivitiXml() throws Exception {
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    // Create and persist a valid job definition.
    JobDefinitionCreateRequest request = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    // Get the XML file for the test workflow.
    InputStream xmlStream = resourceLoader.getResource(ACTIVITI_XML_HERD_WORKFLOW_WITH_CLASSPATH).getInputStream();
    // Just remove "startEvent" text from the XML file which makes the following line in the XML file as INVALID
    // <startEvent id="startevent1" name="Start"></startEvent>
    request.setActivitiJobXml(IOUtils.toString(xmlStream).replaceAll("startEvent", ""));
    // Try creating the job definition and this must throw XMLException.
    jobDefinitionService.createJobDefinition(request, false);
}
Also used : InputStream(java.io.InputStream) 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