Search in sources :

Example 41 with ConsumerDTO

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);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ConsumerContentOverrideCurator(org.candlepin.model.ConsumerContentOverrideCurator) ConsumerType(org.candlepin.model.ConsumerType) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Test(org.junit.Test)

Example 42 with ConsumerDTO

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()));
}
Also used : IdentityCertServiceAdapter(org.candlepin.service.IdentityCertServiceAdapter) CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) EventSink(org.candlepin.audit.EventSink) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Example 43 with ConsumerDTO

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);
}
Also used : SubResource(org.candlepin.auth.SubResource) Owner(org.candlepin.model.Owner) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Access(org.candlepin.auth.Access) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 44 with ConsumerDTO

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());
}
Also used : Owner(org.candlepin.model.Owner) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) UpstreamConsumerDTO(org.candlepin.dto.api.v1.UpstreamConsumerDTO) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 45 with ConsumerDTO

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());
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) UpstreamConsumerDTO(org.candlepin.dto.api.v1.UpstreamConsumerDTO) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)70 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)64 Consumer (org.candlepin.model.Consumer)37 Owner (org.candlepin.model.Owner)20 UserPrincipal (org.candlepin.auth.UserPrincipal)19 HashSet (java.util.HashSet)16 ConsumerType (org.candlepin.model.ConsumerType)16 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)15 Principal (org.candlepin.auth.Principal)14 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)13 TrustedUserPrincipal (org.candlepin.auth.TrustedUserPrincipal)12 Set (java.util.Set)10 ArrayList (java.util.ArrayList)9 Date (java.util.Date)8 TestUtil.createConsumerDTO (org.candlepin.test.TestUtil.createConsumerDTO)8 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)7 ConsumerTypeDTO (org.candlepin.dto.manifest.v1.ConsumerTypeDTO)7 OwnerDTO (org.candlepin.dto.manifest.v1.OwnerDTO)7 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)7 GuestIdDTO (org.candlepin.dto.api.v1.GuestIdDTO)5