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);
}
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());
}
}
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);
}
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);
}
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());
}
}
Aggregations