use of org.finra.herd.model.api.xml.JobDeleteRequest in project herd by FINRAOS.
the class JobServiceTest method testDeleteJobAssertNoErrorWhenUserHasPermissions.
@Test
public void testDeleteJobAssertNoErrorWhenUserHasPermissions() throws Exception {
// Start a job that will wait in a receive task
jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_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<>());
applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization(TEST_ACTIVITI_NAMESPACE_CD, Arrays.asList(NamespacePermissionEnum.EXECUTE)));
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(username, "password", false, false, false, false, Collections.emptyList(), applicationUser), null));
try {
jobService.deleteJob(job.getId(), new JobDeleteRequest("test delete reason"));
} catch (AccessDeniedException e) {
fail();
}
}
use of org.finra.herd.model.api.xml.JobDeleteRequest in project herd by FINRAOS.
the class JobServiceTest method testDeleteJobAssertErrorJobDoesNotExist.
/**
* Asserts that the deleteJob call will throw an error when specified job does not exist.
*
* @throws Exception
*/
@Test
public void testDeleteJobAssertErrorJobDoesNotExist() throws Exception {
// Create a job delete request
JobDeleteRequest jobDeleteRequest = new JobDeleteRequest();
jobDeleteRequest.setDeleteReason("test delete reason");
try {
jobService.deleteJob("DOES_NOT_EXIST", jobDeleteRequest);
} catch (Exception e) {
assertEquals(ObjectNotFoundException.class, e.getClass());
assertEquals("Job with ID \"DOES_NOT_EXIST\" does not exist or is already completed.", e.getMessage());
}
}
use of org.finra.herd.model.api.xml.JobDeleteRequest in project herd by FINRAOS.
the class JobServiceTest method testDeleteJobAssertAccessDeniedWhenUserHasNoPermissions.
@Test
public void testDeleteJobAssertAccessDeniedWhenUserHasNoPermissions() throws Exception {
// Start a job that will wait in a receive task
jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_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.deleteJob(job.getId(), new JobDeleteRequest("test delete reason"));
fail();
} catch (Exception e) {
assertEquals(AccessDeniedException.class, e.getClass());
assertEquals(String.format("User \"%s\" does not have \"[EXECUTE]\" permission(s) to the namespace \"%s\"", username, TEST_ACTIVITI_NAMESPACE_CD), e.getMessage());
}
}
Aggregations