Search in sources :

Example 21 with Principal

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;
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) JobKey(org.quartz.JobKey) Principal(org.candlepin.auth.Principal)

Example 22 with Principal

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);
}
Also used : PrincipalProvider(org.candlepin.guice.PrincipalProvider) Principal(org.candlepin.auth.Principal) Before(org.junit.Before)

Example 23 with Principal

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;
}
Also used : User(org.candlepin.model.User) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) UserPrincipal(org.candlepin.auth.UserPrincipal) HashSet(java.util.HashSet)

Example 24 with Principal

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);
}
Also used : PrincipalProvider(org.candlepin.guice.PrincipalProvider) Principal(org.candlepin.auth.Principal) Before(org.junit.Before)

Example 25 with 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());
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) JobExecutionException(org.quartz.JobExecutionException) JobExecutionContext(org.quartz.JobExecutionContext) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Aggregations

Principal (org.candlepin.auth.Principal)74 Test (org.junit.Test)54 UserPrincipal (org.candlepin.auth.UserPrincipal)40 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)20 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)17 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)15 Consumer (org.candlepin.model.Consumer)15 Owner (org.candlepin.model.Owner)15 TrustedUserPrincipal (org.candlepin.auth.TrustedUserPrincipal)14 Date (java.util.Date)12 ConsumerType (org.candlepin.model.ConsumerType)11 HashSet (java.util.HashSet)10 Pool (org.candlepin.model.Pool)10 JobDetail (org.quartz.JobDetail)10 Method (java.lang.reflect.Method)9 Permission (org.candlepin.auth.permissions.Permission)9 JobDataMap (org.quartz.JobDataMap)9 CandlepinQuery (org.candlepin.model.CandlepinQuery)8 File (java.io.File)7 FileInputStream (java.io.FileInputStream)7