Search in sources :

Example 41 with Job

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

the class LogVariablesTest method testLogVariablesDm.

@Test
public void testLogVariablesDm() throws Exception {
    // This does the same thing as the testLogVariables test above, but uses a workflow that uses a deprecated service task.
    // This test can be removed once all deprecated service tasks are removed.
    Job job = jobServiceTestHelper.createJob(ACTIVITI_XML_LOG_VARIABLES_WITH_CLASSPATH_DM);
    assertNotNull(job);
}
Also used : Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 42 with Job

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

the class JobServiceTest method testGetJobAssertAccessDeniedGivenJobCompletedAndUserDoesNotHavePermissions.

@Test
public void testGetJobAssertAccessDeniedGivenJobCompletedAndUserDoesNotHavePermissions() throws Exception {
    jobDefinitionServiceTestHelper.createJobDefinition(null);
    Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
    String username = "username";
    ApplicationUser applicationUser = new ApplicationUser(getClass());
    applicationUser.setUserId(username);
    applicationUser.setNamespaceAuthorizations(new HashSet<>());
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(username, "password", false, false, false, false, Collections.emptyList(), applicationUser), null));
    try {
        jobService.getJob(job.getId(), false);
        fail();
    } catch (Exception e) {
        assertEquals(AccessDeniedException.class, e.getClass());
        assertEquals(String.format("User \"%s\" does not have \"[READ]\" permission(s) to the namespace \"%s\"", username, TEST_ACTIVITI_NAMESPACE_CD), e.getMessage());
    }
}
Also used : ApplicationUser(org.finra.herd.model.dto.ApplicationUser) AccessDeniedException(org.springframework.security.access.AccessDeniedException) SecurityUserWrapper(org.finra.herd.model.dto.SecurityUserWrapper) Job(org.finra.herd.model.api.xml.Job) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Test(org.junit.Test)

Example 43 with Job

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

the class JobServiceTest method testCreateJobWithS3PropertiesPrecedenceDefinitionParamsOverridesDefinitionS3.

/**
 * Creates a job where the definition has S3 properties and parameters and request has no parameters. The job definition parameters should take precedence
 * if there are name clashes.
 *
 * @throws Exception
 */
@Test
public void testCreateJobWithS3PropertiesPrecedenceDefinitionParamsOverridesDefinitionS3() throws Exception {
    Parameter jobDefinitionS3Parameter = new Parameter("testName", "testValue1");
    Parameter jobDefinitionRequestParameter = new Parameter("testName", "expectedValue");
    String s3BucketName = "s3BucketName";
    S3PropertiesLocation jobDefinitionS3PropertiesLocation = getS3PropertiesLocation(s3BucketName, "jobDefinitionObjectKey", jobDefinitionS3Parameter);
    Job resultJob = createJobWithParameters(jobDefinitionS3PropertiesLocation, Arrays.asList(jobDefinitionRequestParameter), null, null);
    List<Parameter> actualParameters = resultJob.getParameters();
    assertParameterEquals(jobDefinitionRequestParameter, actualParameters);
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) Parameter(org.finra.herd.model.api.xml.Parameter) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test)

Example 44 with Job

use of org.finra.herd.model.api.xml.Job 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 45 with Job

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

the class JobServiceTest method testGetJobAssertAccessDeniedGivenJobRunningAndUserDoesNotHavePermissions.

@Test
public void testGetJobAssertAccessDeniedGivenJobRunningAndUserDoesNotHavePermissions() throws Exception {
    jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH);
    Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
    String username = "username";
    ApplicationUser applicationUser = new ApplicationUser(getClass());
    applicationUser.setUserId(username);
    applicationUser.setNamespaceAuthorizations(new HashSet<>());
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(username, "password", false, false, false, false, Collections.emptyList(), applicationUser), null));
    try {
        jobService.getJob(job.getId(), false);
        fail();
    } catch (Exception e) {
        assertEquals(AccessDeniedException.class, e.getClass());
        assertEquals(String.format("User \"%s\" does not have \"[READ]\" permission(s) to the namespace \"%s\"", username, TEST_ACTIVITI_NAMESPACE_CD), e.getMessage());
    }
}
Also used : ApplicationUser(org.finra.herd.model.dto.ApplicationUser) AccessDeniedException(org.springframework.security.access.AccessDeniedException) SecurityUserWrapper(org.finra.herd.model.dto.SecurityUserWrapper) Job(org.finra.herd.model.api.xml.Job) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Test(org.junit.Test)

Aggregations

Job (org.finra.herd.model.api.xml.Job)71 Test (org.junit.Test)60 Parameter (org.finra.herd.model.api.xml.Parameter)30 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)21 ArrayList (java.util.ArrayList)20 FieldExtension (org.activiti.bpmn.model.FieldExtension)11 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)11 Task (org.activiti.engine.task.Task)9 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)9 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)8 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)7 JobDeleteRequest (org.finra.herd.model.api.xml.JobDeleteRequest)7 JobSignalRequest (org.finra.herd.model.api.xml.JobSignalRequest)7 S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)7 AccessDeniedException (org.springframework.security.access.AccessDeniedException)7 JobAction (org.finra.herd.model.api.xml.JobAction)6 JobUpdateRequest (org.finra.herd.model.api.xml.JobUpdateRequest)6 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)6 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)6 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)6