use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceTest method testCreatePersonConsumerWithActivationKey.
@Test(expected = BadRequestException.class)
public void testCreatePersonConsumerWithActivationKey() {
ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.PERSON));
ConsumerTypeDTO ctypeDto = this.translator.translate(ctype, ConsumerTypeDTO.class);
Owner owner = this.createOwner();
Consumer consumer = this.createConsumer(owner, ctype);
ConsumerDTO consumerDto = this.translator.translate(consumer, ConsumerDTO.class);
ActivationKey ak = mock(ActivationKey.class);
NoAuthPrincipal nap = mock(NoAuthPrincipal.class);
ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
ConsumerContentOverrideCurator ccoc = mock(ConsumerContentOverrideCurator.class);
when(ak.getId()).thenReturn("testKey");
when(akc.lookupForOwner(eq(owner.getKey()), eq(owner))).thenReturn(ak);
ConsumerResource cr = new ConsumerResource(null, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, akc, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
cr.create(consumerDto, nap, null, owner.getKey(), "testKey", true);
}
use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceTest method testRegenerateIdCerts.
@Test
public void testRegenerateIdCerts() throws GeneralSecurityException, IOException {
// using lconsumer simply to avoid hiding consumer. This should
// get renamed once we refactor this test suite.
IdentityCertServiceAdapter mockIdSvc = Mockito.mock(IdentityCertServiceAdapter.class);
EventSink sink = Mockito.mock(EventSinkImpl.class);
Consumer consumer = createConsumer(createOwner());
consumer.setIdCert(createIdCert());
IdentityCertificate ic = consumer.getIdCert();
assertNotNull(ic);
when(mockIdSvc.regenerateIdentityCert(consumer)).thenReturn(createIdCert());
ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, mockIdSvc, null, null, sink, eventFactory, null, null, null, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
ConsumerDTO fooc = cr.regenerateIdentityCertificates(consumer.getUuid());
assertNotNull(fooc);
CertificateDTO ic1 = fooc.getIdCert();
assertNotNull(ic1);
assertFalse(ic.getId().equals(ic1.getId()));
}
use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceTest method testValidateShareConsumerRequiresRecipientFact.
@Test
public void testValidateShareConsumerRequiresRecipientFact() {
ConsumerType share = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SHARE));
ConsumerTypeDTO shareDto = this.translator.translate(share, ConsumerTypeDTO.class);
OwnerDTO ownerDto = new OwnerDTO().setDisplayName("Test Owner");
ConsumerDTO c = createConsumerDTO("test-consumer", "test-user", ownerDto, shareDto);
ConsumerResource consumerResource = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, i18n, null, null, null, null, null, mockPoolManager, null, mockOwnerCurator, null, null, null, null, null, null, new CandlepinCommonTestConfig(), null, null, null, consumerBindUtil, null, null, factValidator, null, consumerEnricher, migrationProvider, translator);
UserPrincipal uap = mock(UserPrincipal.class);
when(uap.canAccess(any(Object.class), any(SubResource.class), any(Access.class))).thenReturn(Boolean.TRUE);
Owner o = mock(Owner.class);
when(mockOwnerCurator.lookupByKey(any(String.class))).thenReturn(o);
c.setFact("foo", "bar");
thrown.expect(BadRequestException.class);
thrown.expectMessage("must specify a recipient org");
consumerResource.create(c, uap, "test-user", "test-owner", null, false);
}
use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class OwnerResourceTest method consumerCannotListConsumersFromAnotherOwner.
@Test
public void consumerCannotListConsumersFromAnotherOwner() {
Consumer c = createConsumer(owner);
Owner owner2 = ownerCurator.create(new Owner("Owner2"));
Consumer c2 = createConsumer(owner2);
List<String> uuids = new ArrayList<>();
uuids.add(c.getUuid());
uuids.add(c2.getUuid());
setupPrincipal(owner, Access.ALL);
securityInterceptor.enable();
CandlepinQuery<ConsumerDTO> result = ownerResource.listConsumers(owner.getKey(), null, null, uuids, null, null, null, null, null, null);
assertNotNull(result);
List<ConsumerDTO> consumers = result.list();
assertEquals(1, consumers.size());
}
use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class OwnerResourceTest method consumerCanListMultipleConsumers.
@Test
public void consumerCanListMultipleConsumers() {
Consumer c = createConsumer(owner);
Consumer c2 = createConsumer(owner);
List<String> uuids = new ArrayList<>();
uuids.add(c.getUuid());
uuids.add(c2.getUuid());
setupPrincipal(owner, Access.ALL);
securityInterceptor.enable();
CandlepinQuery<ConsumerDTO> result = ownerResource.listConsumers(owner.getKey(), null, null, uuids, null, null, null, null, null, null);
assertNotNull(result);
List<ConsumerDTO> consumers = result.list();
assertEquals(2, consumers.size());
}
Aggregations