Search in sources :

Example 16 with JobStatusEnum

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

the class JobServiceGetJobsTest method testGetJobsWhenNamespaceSpecifiedButDoesNotExistAssertResultEmpty.

@Test
public void testGetJobsWhenNamespaceSpecifiedButDoesNotExistAssertResultEmpty() throws Exception {
    String namespace = "namespace";
    String jobName = "jobName";
    JobStatusEnum jobStatus = JobStatusEnum.COMPLETED;
    Set<String> authorizedNamespaces = new HashSet<>(Arrays.asList(namespace));
    when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(authorizedNamespaces);
    when(namespaceDao.getNamespaceByCd(any())).thenReturn(null);
    JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
    List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
    assertEquals(0, jobSummaries.size());
}
Also used : JobSummary(org.finra.herd.model.api.xml.JobSummary) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) JobSummaries(org.finra.herd.model.api.xml.JobSummaries) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with JobStatusEnum

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

the class JobServiceGetJobsTest method testGetJobsWhenNamespaceNotSpecifiedAssertQueryByAllAuthorizedNamespaces.

@SuppressWarnings("unchecked")
@Test
public void testGetJobsWhenNamespaceNotSpecifiedAssertQueryByAllAuthorizedNamespaces() throws Exception {
    String namespace = null;
    String jobName = "jobName";
    JobStatusEnum jobStatus = JobStatusEnum.COMPLETED;
    Set<String> authorizedNamespaces = new HashSet<>(Arrays.asList("a", "b"));
    when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(authorizedNamespaces);
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(namespace);
    when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);
    when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(new ArrayList<>());
    jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
    verify(jobDefinitionDao).getJobDefinitionsByFilter(eq(authorizedNamespaces), eq(jobName));
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) Collection(java.util.Collection) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with JobStatusEnum

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

the class JobServiceTest method testGetJobsTrimAndCaseInsensitivity.

@Test
public void testGetJobsTrimAndCaseInsensitivity() throws Exception {
    // Create and persist a job definition.
    jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH);
    // Create and start an Activiti job.
    Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
    // Job should be waiting at relative User tasks.
    // Allow READ access for the current user to the job definition namespace.
    jobServiceTestHelper.setCurrentUserNamespaceAuthorizations(TEST_ACTIVITI_NAMESPACE_CD, Arrays.asList(NamespacePermissionEnum.READ));
    // Perform the getJobs calls.
    JobSummaries resultJobSummaries;
    Map<String, JobStatusEnum> expectedJobStatuses;
    DateTime startTime = new DateTime().minusHours(1);
    DateTime endTime = new DateTime().plusHours(1);
    // Get all jobs using input parameters with leading and trailing empty spaces.
    resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.RUNNING, startTime, NO_END_TIME);
    // Validate the result job summaries.
    expectedJobStatuses = new HashMap<String, JobStatusEnum>() {

        {
            put(job.getId(), JobStatusEnum.RUNNING);
        }
    };
    validateJobSummaries(expectedJobStatuses, resultJobSummaries);
    // Query the pending task and complete it.
    List<Task> tasks = activitiTaskService.createTaskQuery().processInstanceId(job.getId()).list();
    activitiTaskService.complete(tasks.get(0).getId());
    // Jobs should have been completed.
    // Get all jobs using input parameters in uppercase.
    resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD.toUpperCase(), TEST_ACTIVITI_JOB_NAME.toUpperCase(), JobStatusEnum.COMPLETED, startTime, endTime);
    // Validate the result job summaries.
    expectedJobStatuses = new HashMap<String, JobStatusEnum>() {

        {
            put(job.getId(), JobStatusEnum.COMPLETED);
        }
    };
    validateJobSummaries(expectedJobStatuses, resultJobSummaries);
    // Get all jobs using input parameters in lowercase.
    resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD.toLowerCase(), TEST_ACTIVITI_JOB_NAME.toLowerCase(), JobStatusEnum.COMPLETED, startTime, endTime);
    // Validate the result job summaries.
    expectedJobStatuses = new HashMap<String, JobStatusEnum>() {

        {
            put(job.getId(), JobStatusEnum.COMPLETED);
        }
    };
    validateJobSummaries(expectedJobStatuses, resultJobSummaries);
}
Also used : Task(org.activiti.engine.task.Task) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) JobSummaries(org.finra.herd.model.api.xml.JobSummaries) Job(org.finra.herd.model.api.xml.Job) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 19 with JobStatusEnum

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

the class JobServiceTest method testGetJobs.

@Test
public void testGetJobs() throws Exception {
    // Create and persist a job definition.
    jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH);
    // Create and start three Activiti jobs.
    List<Job> jobs = Arrays.asList(jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)), jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)), jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)));
    // Jobs should be waiting at relative User tasks.
    // Allow READ access for the current user to the job definition namespace.
    jobServiceTestHelper.setCurrentUserNamespaceAuthorizations(TEST_ACTIVITI_NAMESPACE_CD, Arrays.asList(NamespacePermissionEnum.READ));
    JobSummaries resultJobSummaries;
    Map<String, JobStatusEnum> expectedJobStatuses;
    DateTime startTime = new DateTime().minusHours(1);
    DateTime endTime = new DateTime().plusHours(1);
    // Get all jobs for the relative job definition and expected job status.
    resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.RUNNING, startTime, NO_END_TIME);
    // Validate the result job summaries.
    expectedJobStatuses = new HashMap<String, JobStatusEnum>() {

        {
            put(jobs.get(0).getId(), JobStatusEnum.RUNNING);
            put(jobs.get(1).getId(), JobStatusEnum.RUNNING);
            put(jobs.get(2).getId(), JobStatusEnum.RUNNING);
        }
    };
    validateJobSummaries(expectedJobStatuses, resultJobSummaries);
    // Query the pending tasks and complete them.
    for (Job job : jobs) {
        List<Task> tasks = activitiTaskService.createTaskQuery().processInstanceId(job.getId()).list();
        activitiTaskService.complete(tasks.get(0).getId());
    }
    // Jobs should have been completed.
    // Get all jobs for the relative job definition and expected job status.
    resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.COMPLETED, startTime, endTime);
    // Validate the result job summaries.
    expectedJobStatuses = new HashMap<String, JobStatusEnum>() {

        {
            put(jobs.get(0).getId(), JobStatusEnum.COMPLETED);
            put(jobs.get(1).getId(), JobStatusEnum.COMPLETED);
            put(jobs.get(2).getId(), JobStatusEnum.COMPLETED);
        }
    };
    validateJobSummaries(expectedJobStatuses, resultJobSummaries);
}
Also used : Task(org.activiti.engine.task.Task) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) JobSummaries(org.finra.herd.model.api.xml.JobSummaries) Job(org.finra.herd.model.api.xml.Job) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 20 with JobStatusEnum

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

the class ActivitiServiceTest method testGetHistoricProcessInstancesByStatusAndProcessDefinitionKeysWhenStatusCompleted.

@Test
public void testGetHistoricProcessInstancesByStatusAndProcessDefinitionKeysWhenStatusCompleted() {
    JobStatusEnum jobStatus = JobStatusEnum.COMPLETED;
    Collection<String> processDefinitionKeys = new ArrayList<>();
    DateTime startTime = new DateTime();
    DateTime endTime = new DateTime();
    HistoricProcessInstanceQuery historicProcessInstanceQuery = mock(HistoricProcessInstanceQuery.class);
    when(activitiHistoryService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery);
    when(historicProcessInstanceQuery.processDefinitionKeyIn(new ArrayList<>(processDefinitionKeys))).thenReturn(historicProcessInstanceQuery);
    when(historicProcessInstanceQuery.unfinished()).thenReturn(historicProcessInstanceQuery);
    when(historicProcessInstanceQuery.startedAfter(startTime.toDate())).thenReturn(historicProcessInstanceQuery);
    when(historicProcessInstanceQuery.finishedBefore(endTime.toDate())).thenReturn(historicProcessInstanceQuery);
    List<HistoricProcessInstance> expectedHistoricProcessInstances = new ArrayList<>();
    when(historicProcessInstanceQuery.list()).thenReturn(expectedHistoricProcessInstances);
    List<HistoricProcessInstance> actualHistoricProcessInstance = activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(jobStatus, processDefinitionKeys, startTime, endTime);
    assertSame(expectedHistoricProcessInstances, actualHistoricProcessInstance);
    InOrder inOrder = inOrder(historicProcessInstanceQuery);
    inOrder.verify(historicProcessInstanceQuery).processDefinitionKeyIn(new ArrayList<>(processDefinitionKeys));
    inOrder.verify(historicProcessInstanceQuery).finished();
    inOrder.verify(historicProcessInstanceQuery).startedAfter(startTime.toDate());
    inOrder.verify(historicProcessInstanceQuery).finishedBefore(endTime.toDate());
    inOrder.verify(historicProcessInstanceQuery).list();
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

JobStatusEnum (org.finra.herd.model.api.xml.JobStatusEnum)23 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)11 JobSummaries (org.finra.herd.model.api.xml.JobSummaries)10 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)10 DateTime (org.joda.time.DateTime)10 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)8 Collection (java.util.Collection)7 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)6 JobSummary (org.finra.herd.model.api.xml.JobSummary)6 InOrder (org.mockito.InOrder)6 Task (org.activiti.engine.task.Task)5 Job (org.finra.herd.model.api.xml.Job)5 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)5 Date (java.util.Date)3 HistoricProcessInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity)3 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)3 HashMap (java.util.HashMap)1 JobUpdateRequest (org.finra.herd.model.api.xml.JobUpdateRequest)1