use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class JobStatusTranslatorTest method initSourceObject.
@Override
protected JobStatus initSourceObject() {
// JobStatus uses a JobDetail argument to populate fields instead
// of setters, which is why we need to mock here.
JobDetail jobDetail = mock(JobDetail.class);
JobDataMap jobDataMap = mock(JobDataMap.class);
Principal principal = mock(Principal.class);
JobKey jobKey = new JobKey("test-name", "test-group");
when(jobDetail.getKey()).thenReturn(jobKey);
when(jobDetail.getJobDataMap()).thenReturn(jobDataMap);
when(jobDataMap.get(PinsetterJobListener.PRINCIPAL_KEY)).thenReturn(principal);
when(principal.getPrincipalName()).thenReturn("test-principal-name");
when(jobDataMap.get(TARGET_TYPE)).thenReturn(CONSUMER);
when(jobDataMap.get(TARGET_ID)).thenReturn("test-target-id");
when(jobDataMap.get(OWNER_ID)).thenReturn("test-owner-id");
when(jobDataMap.get(CORRELATION_ID)).thenReturn("test-correlation-id");
JobStatus source = new JobStatus(jobDetail);
source.setState(JobStatus.JobState.CREATED);
source.setResult("result of job");
source.setResultData("result data of job");
return source;
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class EventFactoryTest method init.
@Before
public void init() throws Exception {
principalProvider = mock(PrincipalProvider.class);
Principal principal = mock(Principal.class);
when(principalProvider.get()).thenReturn(principal);
eventFactory = new EventFactory(principalProvider);
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class ConsumerCuratorPermissionsTest method setupOnlyMyConsumersPrincipal.
private User setupOnlyMyConsumersPrincipal() {
Set<Permission> perms = new HashSet<>();
User u = new User("fakeuser", "dontcare");
perms.add(new UsernameConsumersPermission(u, owner));
Principal p = new UserPrincipal(u.getUsername(), perms, false);
setupPrincipal(p);
return u;
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class EventBuilderTest method init.
@Before
public void init() throws Exception {
principalProvider = mock(PrincipalProvider.class);
Principal principal = mock(Principal.class);
factory = new EventFactory(principalProvider);
when(principalProvider.get()).thenReturn(principal);
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class PinsetterJobListenerDatabaseTest method verifyDatabaseConstraintIsNotViolated.
@Test
public void verifyDatabaseConstraintIsNotViolated() {
JobExecutionException e = mock(JobExecutionException.class);
String longstr = RandomStringUtils.randomAlphanumeric(300);
when(e.getMessage()).thenReturn(longstr);
JobDataMap map = new JobDataMap();
Principal principal = mock(Principal.class);
when(principal.getPrincipalName()).thenReturn("test-admin");
map.put(PinsetterJobListener.PRINCIPAL_KEY, principal);
map.put(JobStatus.TARGET_TYPE, JobStatus.TargetType.OWNER);
map.put(JobStatus.TARGET_ID, "10");
JobDetail detail = mock(JobDetail.class);
when(detail.getKey()).thenReturn(jobKey("name", "group"));
when(detail.getJobDataMap()).thenReturn(map);
JobStatus status = new JobStatus(detail);
// store a merge so we can find it in the test run
curator.merge(status);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(map);
when(ctx.getJobDetail()).thenReturn(detail);
// thing to be tested
listener.jobWasExecuted(ctx, e);
// verify the message stored is a substring of the long message
JobStatus verify = curator.find("name");
assertEquals(longstr.substring(0, JobStatus.RESULT_COL_LENGTH), verify.getResult());
}
Aggregations