use of org.finra.herd.model.api.xml.JobSummaries in project herd by FINRAOS.
the class JobServiceGetJobsTest method testGetJobsGivenOneCompletedJobAndPassingStartAndEndTimeAssertReturnCompletedJob.
@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenOneCompletedJobAndPassingStartAndEndTimeAssertReturnCompletedJob() throws Exception {
String namespace = "namespace";
String jobName = "jobName";
DateTime startTime = new DateTime(new Date(0123));
DateTime endTime = new DateTime(new Date(3456));
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);
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));
historicProcessInstanceEntity1.setEndTime(new Date(2345));
historicProcessInstances.add(historicProcessInstanceEntity1);
when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);
JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, startTime, endTime);
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.COMPLETED, jobSummary.getStatus());
assertEquals(historicProcessInstanceEntity1.getStartTime().getTime(), jobSummary.getStartTime().toGregorianCalendar().getTimeInMillis());
assertEquals(historicProcessInstanceEntity1.getEndTime().getTime(), jobSummary.getEndTime().toGregorianCalendar().getTimeInMillis());
assertEquals(0, jobSummary.getTotalExceptions());
verify(activitiService).getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.COMPLETED), any(), eq(startTime), eq(endTime));
verify(activitiService).getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.COMPLETED), any(), eq(startTime), eq(endTime));
}
use of org.finra.herd.model.api.xml.JobSummaries in project herd by FINRAOS.
the class JobServiceGetJobsTest method testGetJobsGivenMultipleHistoricProcessInstanceWithSamKeyJobAssertReturnCompletedJob.
/**
* Tests case where multiple process instances were created, but the job definition entities were deleted at some point without removing the old historic
* instances, then a new process instance is created with the same namespace and job name pair. When a ListJobs is called, it should not return the old
* instance information. <p/> This case was added as a verification to the bug raised by test automation.
*/
@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenMultipleHistoricProcessInstanceWithSamKeyJobAssertReturnCompletedJob() 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);
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));
historicProcessInstanceEntity1.setEndTime(new Date(2345));
historicProcessInstances.add(historicProcessInstanceEntity1);
}
{
HistoricProcessInstanceEntity historicProcessInstanceEntity1 = new HistoricProcessInstanceEntity();
historicProcessInstanceEntity1.setId("historicProcessInstanceEntity2.id");
historicProcessInstanceEntity1.setProcessDefinitionId("a.b:1:2");
historicProcessInstanceEntity1.setStartTime(new Date(1234));
historicProcessInstanceEntity1.setEndTime(new Date(2345));
historicProcessInstances.add(historicProcessInstanceEntity1);
}
when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);
JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
assertEquals(1, jobSummaries.size());
}
use of org.finra.herd.model.api.xml.JobSummaries 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());
}
use of org.finra.herd.model.api.xml.JobSummaries 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);
}
use of org.finra.herd.model.api.xml.JobSummaries 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);
}
Aggregations