Search in sources :

Example 6 with JobDefinitionEntity

use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.

the class BaseJavaDelegateTest method testSetSecurityContext.

@Test
public void testSetSecurityContext() throws Exception {
    // Set up expected values.
    String jobDefinitionNamespace = "jobDefinitionNamespace";
    String jobDefinitionName = "jobDefinitionName";
    String processDefinitionId = "processDefinitionId";
    String processDefinitionKey = String.format("%s.%s", jobDefinitionNamespace, jobDefinitionName);
    String updatedBy = "updatedBy";
    JobDefinitionEntity jobDefinitionEntity = new JobDefinitionEntity();
    jobDefinitionEntity.setUpdatedBy(updatedBy);
    // Mock dependency methods.
    when(delegateExecution.getProcessDefinitionId()).thenReturn(processDefinitionId);
    ProcessDefinition processDefinition = mock(ProcessDefinition.class);
    when(processDefinition.getKey()).thenReturn(processDefinitionKey);
    when(activitiService.getProcessDefinitionById(any())).thenReturn(processDefinition);
    when(jobDefinitionDaoHelper.getJobDefinitionEntity(any(), any())).thenReturn(jobDefinitionEntity);
    // Clear the security context.
    SecurityContextHolder.clearContext();
    // Execute test method.
    baseJavaDelegate.setSecurityContext(delegateExecution);
    // Verify dependencies were invoked correctly.
    InOrder inOrder = inOrder(activitiService, jobDefinitionDaoHelper, userNamespaceAuthorizationHelper);
    inOrder.verify(activitiService).getProcessDefinitionById(processDefinitionId);
    inOrder.verify(jobDefinitionDaoHelper).getJobDefinitionEntity(jobDefinitionNamespace, jobDefinitionName);
    inOrder.verify(userNamespaceAuthorizationHelper).buildNamespaceAuthorizations(applicationUserUserIdEq(updatedBy));
    inOrder.verifyNoMoreInteractions();
    verifyNoMoreInteractions(activitiService, jobDefinitionDaoHelper, userNamespaceAuthorizationHelper);
    // Assert correct user is in the security context.
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    assertAuthenticationUserIdEquals(updatedBy, authentication);
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) InOrder(org.mockito.InOrder) Authentication(org.springframework.security.core.Authentication) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 7 with JobDefinitionEntity

use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.

the class JobDefinitionServiceTest method testUpdateJobDefinitionWithS3Properties.

@Test
public void testUpdateJobDefinitionWithS3Properties() 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();
    // 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);
    updateRequest.setS3PropertiesLocation(s3PropertiesLocation);
    // 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(), s3PropertiesLocation, HerdDaoSecurityHelper.SYSTEM_USER), updatedJobDefinition);
    // Validate the updated job definition entity.
    Assert.assertEquals("updatedJobDefinitionEntity s3BucketName", s3PropertiesLocation.getBucketName(), updatedJobDefinitionEntity.getS3BucketName());
    Assert.assertEquals("updatedJobDefinitionEntity s3ObjectKey", s3PropertiesLocation.getKey(), updatedJobDefinitionEntity.getS3ObjectKey());
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) JobDefinition(org.finra.herd.model.api.xml.JobDefinition) JobDefinitionUpdateRequest(org.finra.herd.model.api.xml.JobDefinitionUpdateRequest) Test(org.junit.Test)

Example 8 with JobDefinitionEntity

use of org.finra.herd.model.jpa.JobDefinitionEntity 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 9 with JobDefinitionEntity

use of org.finra.herd.model.jpa.JobDefinitionEntity 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)

Example 10 with JobDefinitionEntity

use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.

the class JobServiceGetJobsTest method testGetJobsWhenActivitiIdIsNotExpectedFormatAssertSuccess.

@SuppressWarnings("unchecked")
@Test
public void testGetJobsWhenActivitiIdIsNotExpectedFormatAssertSuccess() throws Exception {
    String namespace = "namespace";
    String jobName = "jobName";
    String processDefinitionKey = String.format("%s.%s", namespace, jobName);
    when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(new HashSet<>(asList(namespace)));
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(namespace);
    when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);
    JobDefinitionEntity jobDefinitionEntity = new JobDefinitionEntity();
    jobDefinitionEntity.setNamespace(namespaceEntity);
    jobDefinitionEntity.setName(jobName);
    jobDefinitionEntity.setActivitiId("123456");
    when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(asList(jobDefinitionEntity));
    ProcessDefinition processDefinition = mock(ProcessDefinition.class);
    when(processDefinition.getKey()).thenReturn(processDefinitionKey);
    when(activitiService.getProcessDefinitionsByIds(any())).thenReturn(asList(processDefinition));
    jobServiceImpl.getJobs(namespace, jobName, AbstractServiceTest.NO_ACTIVITI_JOB_STATUS, NO_START_TIME, NO_END_TIME);
    verify(activitiService).getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(any(), equalsCollection(asList(processDefinitionKey)), any(), any());
    verify(activitiService).getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), equalsCollection(asList(processDefinitionKey)), any(), any());
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) Collection(java.util.Collection) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Test(org.junit.Test)

Aggregations

JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)36 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)18 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)12 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)11 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)7 Collection (java.util.Collection)6 HashSet (java.util.HashSet)6 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)5 JobStatusEnum (org.finra.herd.model.api.xml.JobStatusEnum)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 Predicate (javax.persistence.criteria.Predicate)4 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)4 JobAction (org.finra.herd.model.api.xml.JobAction)4 JobDefinitionCreateRequest (org.finra.herd.model.api.xml.JobDefinitionCreateRequest)4 JobSummaries (org.finra.herd.model.api.xml.JobSummaries)4 JobSummary (org.finra.herd.model.api.xml.JobSummary)4 NotificationActionEntity (org.finra.herd.model.jpa.NotificationActionEntity)4 NotificationJobActionEntity (org.finra.herd.model.jpa.NotificationJobActionEntity)4 Date (java.util.Date)3