Search in sources :

Example 1 with JobStatusEnum

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

the class ActivitiServiceTest method getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys.

@Test
public void getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys() {
    JobStatusEnum jobStatus = JobStatusEnum.RUNNING;
    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);
    long expectedResult = 1234l;
    when(historicProcessInstanceQuery.count()).thenReturn(expectedResult);
    long actualResult = activitiService.getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(jobStatus, processDefinitionKeys, startTime, endTime);
    assertEquals(expectedResult, actualResult);
    InOrder inOrder = inOrder(historicProcessInstanceQuery);
    inOrder.verify(historicProcessInstanceQuery).processDefinitionKeyIn(new ArrayList<>(processDefinitionKeys));
    inOrder.verify(historicProcessInstanceQuery).unfinished();
    inOrder.verify(historicProcessInstanceQuery).startedAfter(startTime.toDate());
    inOrder.verify(historicProcessInstanceQuery).finishedBefore(endTime.toDate());
    inOrder.verify(historicProcessInstanceQuery).count();
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with JobStatusEnum

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

the class ActivitiServiceTest method testGetHistoricProcessInstancesByStatusAndProcessDefinitionKeysWhenStatusNotSpecified.

@Test
public void testGetHistoricProcessInstancesByStatusAndProcessDefinitionKeysWhenStatusNotSpecified() {
    JobStatusEnum jobStatus = null;
    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).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)

Example 3 with JobStatusEnum

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

the class JobServiceGetJobsTest method testGetJobsWhenResultTooLargeAssertThrowException.

@SuppressWarnings("unchecked")
@Test
public void testGetJobsWhenResultTooLargeAssertThrowException() 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);
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(namespace);
    when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);
    List<JobDefinitionEntity> jobDefinitionEntities = new ArrayList<>();
    JobDefinitionEntity jobDefinitionEntity1 = new JobDefinitionEntity();
    jobDefinitionEntity1.setActivitiId(namespace + "." + jobName + ":1" + ":1");
    jobDefinitionEntities.add(jobDefinitionEntity1);
    when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(jobDefinitionEntities);
    when(activitiService.getProcessDefinitionsByIds(any())).thenReturn(asList());
    when(activitiService.getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(1000l);
    try {
        jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("Too many jobs found for the specified filter parameters. The maximum number of results allowed is 1 and the number of results " + "returned was 1000.", e.getMessage());
    }
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) ArrayList(java.util.ArrayList) Collection(java.util.Collection) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with JobStatusEnum

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

the class JobServiceGetJobsTest method testGetJobsAssertJobNameTrimmed.

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

Example 5 with JobStatusEnum

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

the class JobServiceGetJobsTest method testGetJobsGivenOneRunningJobAssertReturnCompletedJob.

@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenOneRunningJobAssertReturnCompletedJob() throws Exception {
    String namespace = "namespace";
    String jobName = "jobName";
    JobStatusEnum jobStatus = JobStatusEnum.RUNNING;
    long expectedNumberOfExceptions = 1234l;
    Set<String> authorizedNamespaces = new HashSet<>(Arrays.asList(namespace));
    when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(authorizedNamespaces);
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(namespace);
    when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);
    List<JobDefinitionEntity> jobDefinitionEntities = new ArrayList<>();
    JobDefinitionEntity jobDefinitionEntity1 = new JobDefinitionEntity();
    jobDefinitionEntity1.setActivitiId(namespace + "." + jobName + ":1" + ":1");
    jobDefinitionEntities.add(jobDefinitionEntity1);
    when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(jobDefinitionEntities);
    ProcessDefinition processDefinition = mock(ProcessDefinition.class);
    when(processDefinition.getId()).thenReturn("a.b:1:1");
    when(processDefinition.getKey()).thenReturn("a.b");
    when(activitiService.getProcessDefinitionsByIds(any())).thenReturn(asList(processDefinition));
    when(activitiService.getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(1l);
    List<HistoricProcessInstance> historicProcessInstances = new ArrayList<>();
    HistoricProcessInstanceEntity historicProcessInstanceEntity1 = new HistoricProcessInstanceEntity();
    historicProcessInstanceEntity1.setId("historicProcessInstanceEntity1.id");
    historicProcessInstanceEntity1.setProcessDefinitionId("a.b:1:1");
    historicProcessInstanceEntity1.setStartTime(new Date(1234));
    historicProcessInstances.add(historicProcessInstanceEntity1);
    when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);
    when(activitiService.getJobsWithExceptionCountByProcessInstanceId(any())).thenReturn(expectedNumberOfExceptions);
    JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
    List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
    assertEquals(1, jobSummaries.size());
    JobSummary jobSummary = jobSummaries.get(0);
    assertEquals(historicProcessInstanceEntity1.getId(), jobSummary.getId());
    assertEquals("a", jobSummary.getNamespace());
    assertEquals("b", jobSummary.getJobName());
    assertEquals(JobStatusEnum.RUNNING, jobSummary.getStatus());
    assertEquals(historicProcessInstanceEntity1.getStartTime().getTime(), jobSummary.getStartTime().toGregorianCalendar().getTimeInMillis());
    assertNull(jobSummary.getEndTime());
    assertEquals(expectedNumberOfExceptions, jobSummary.getTotalExceptions());
    verify(activitiService).getJobsWithExceptionCountByProcessInstanceId(historicProcessInstanceEntity1.getId());
    verify(activitiService).getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.RUNNING), any(), any(), any());
    verify(activitiService).getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.RUNNING), any(), any(), any());
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JobSummaries(org.finra.herd.model.api.xml.JobSummaries) Date(java.util.Date) JobSummary(org.finra.herd.model.api.xml.JobSummary) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) Collection(java.util.Collection) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) HashSet(java.util.HashSet) 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