Search in sources :

Example 71 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class JobStatusTest method knownPrincipalName.

@Test
public void knownPrincipalName() {
    Principal p = mock(Principal.class);
    when(p.getPrincipalName()).thenReturn("admin");
    JobDetail detail = mock(JobDetail.class);
    JobDataMap map = new JobDataMap();
    map.put(PinsetterJobListener.PRINCIPAL_KEY, p);
    when(detail.getKey()).thenReturn(JobKey.jobKey("name", "group"));
    when(detail.getJobDataMap()).thenReturn(map);
    status = new JobStatus(detail);
    assertEquals("admin", status.getPrincipalName());
}
Also used : JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 72 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class HypervisorUpdateJobTest method hypervisorUpdateExecCreateNoHypervisorId.

@Test
public void hypervisorUpdateExecCreateNoHypervisorId() throws JobExecutionException {
    when(ownerCurator.lookupByKey(eq("joe"))).thenReturn(owner);
    hypervisorJson = "{\"hypervisors\":" + "[{" + "\"name\" : \"hypervisor_999\"," + "\"guestIds\" : [{\"guestId\" : \"guestId_1_999\"}]" + "}]}";
    JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
    JobExecutionContext ctx = mock(JobExecutionContext.class);
    when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
    when(consumerCurator.getHostConsumersMap(eq(owner), any(Set.class))).thenReturn(new VirtConsumerMap());
    HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
    injector.injectMembers(job);
    job.execute(ctx);
    verify(consumerResource, never()).createConsumerFromDTO(any(ConsumerDTO.class), any(ConsumerType.class), any(Principal.class), anyString(), anyString(), anyString(), eq(false));
}
Also used : JobDetail(org.quartz.JobDetail) Set(java.util.Set) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) JobExecutionContext(org.quartz.JobExecutionContext) ConsumerType(org.candlepin.model.ConsumerType) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 73 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class PinsetterJobListenerTest method tobeExecuted.

@Test
public void tobeExecuted() {
    Principal principal = mock(Principal.class);
    JobDataMap map = new JobDataMap();
    JobDetail detail = mock(JobDetail.class);
    JobStatus status = mock(JobStatus.class);
    map.put(PinsetterJobListener.PRINCIPAL_KEY, principal);
    when(ctx.getMergedJobDataMap()).thenReturn(map);
    when(detail.getKey()).thenReturn(jobKey("foo"));
    when(ctx.getJobDetail()).thenReturn(detail);
    when(jcurator.find(eq("foo"))).thenReturn(status);
    listener.jobToBeExecuted(ctx);
    verify(status).update(eq(ctx));
    verify(jcurator).merge(eq(status));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 74 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class PinsetterJobListenerTest method tobeExecutedNull.

@Test
public void tobeExecutedNull() {
    Principal principal = mock(Principal.class);
    JobDataMap map = new JobDataMap();
    JobDetail detail = mock(JobDetail.class);
    JobStatus status = mock(JobStatus.class);
    map.put(PinsetterJobListener.PRINCIPAL_KEY, principal);
    when(ctx.getMergedJobDataMap()).thenReturn(map);
    when(detail.getKey()).thenReturn(jobKey("foo"));
    when(ctx.getJobDetail()).thenReturn(detail);
    when(jcurator.find(eq("foo"))).thenReturn(null);
    listener.jobToBeExecuted(ctx);
    verifyZeroInteractions(status);
    verify(jcurator, never()).merge(eq(status));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) 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