Search in sources :

Example 6 with ConsumerTypeDTO

use of org.candlepin.dto.api.v1.ConsumerTypeDTO in project candlepin by candlepin.

the class ConsumerImporterTest method importConsumerWithMismatchedUuidShouldNotThrowExceptionIfForced.

@Test
public void importConsumerWithMismatchedUuidShouldNotThrowExceptionIfForced() throws ImporterException {
    Owner owner = mock(Owner.class);
    OwnerDTO ownerDTO = mock(OwnerDTO.class);
    ConsumerDTO consumer = mock(ConsumerDTO.class);
    ConsumerTypeDTO type = mock(ConsumerTypeDTO.class);
    when(owner.getUpstreamUuid()).thenReturn("another-test-uuid");
    when(consumer.getUuid()).thenReturn("test-uuid");
    when(consumer.getOwner()).thenReturn(ownerDTO);
    when(consumer.getType()).thenReturn(type);
    IdentityCertificate idCert = new IdentityCertificate();
    idCert.setSerial(new CertificateSerial());
    importer.store(owner, consumer, new ConflictOverrides(Importer.Conflict.DISTRIBUTOR_CONFLICT), idCert);
    // now verify that the owner has the upstream consumer set
    ArgumentCaptor<UpstreamConsumer> arg = ArgumentCaptor.forClass(UpstreamConsumer.class);
    verify(owner).setUpstreamConsumer(arg.capture());
    assertEquals("test-uuid", arg.getValue().getUuid());
    verify(curator).merge(owner);
}
Also used : Owner(org.candlepin.model.Owner) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.manifest.v1.OwnerDTO) CertificateSerial(org.candlepin.model.CertificateSerial) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ConsumerTypeDTO(org.candlepin.dto.manifest.v1.ConsumerTypeDTO) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Example 7 with ConsumerTypeDTO

use of org.candlepin.dto.api.v1.ConsumerTypeDTO in project candlepin by candlepin.

the class ConsumerResourceCreationTest method registerFailsWithKeyWhenAutobindOnKeyAndDisabledOnOwner.

@Test
public void registerFailsWithKeyWhenAutobindOnKeyAndDisabledOnOwner() {
    ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
    ConsumerTypeDTO ctypeDTO = this.modelTranslator.translate(ctype, ConsumerTypeDTO.class);
    this.mockConsumerType(ctype);
    // Disable autobind for the owner.
    owner.setAutobindDisabled(true);
    // Create a key that has autobind disabled.
    ActivationKey key = new ActivationKey("autobind-disabled-key", owner);
    key.setAutoAttach(true);
    when(activationKeyCurator.lookupForOwner(key.getName(), owner)).thenReturn(key);
    // No auth should be required for registering with keys:
    Principal p = new NoAuthPrincipal();
    ConsumerDTO consumer = TestUtil.createConsumerDTO("sys.example.com", null, null, ctypeDTO);
    resource.create(consumer, p, null, owner.getKey(), key.getName(), true);
}
Also used : NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ConsumerType(org.candlepin.model.ConsumerType) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) Test(org.junit.Test)

Example 8 with ConsumerTypeDTO

use of org.candlepin.dto.api.v1.ConsumerTypeDTO in project candlepin by candlepin.

the class ConsumerResourceIntegrationTest method testRegisterWithConsumerId.

@Test
public void testRegisterWithConsumerId() {
    ConsumerDTO toSubmit = createConsumerDTO(CONSUMER_NAME, USER_NAME, null, standardSystemTypeDTO);
    toSubmit.setUuid("1023131");
    toSubmit.setFact(METADATA_NAME, METADATA_VALUE);
    ConsumerDTO submitted = consumerResource.create(toSubmit, TestUtil.createPrincipal(someuser.getUsername(), owner, Access.ALL), null, null, null, true);
    assertNotNull(submitted);
    assertEquals(toSubmit.getUuid(), submitted.getUuid());
    assertNotNull(consumerCurator.find(submitted.getId()));
    assertEquals(standardSystemType.getLabel(), submitted.getType().getLabel());
    assertEquals(METADATA_VALUE, submitted.getFact(METADATA_NAME));
    // now pass in consumer type with null id just like the client would
    ConsumerTypeDTO type = new ConsumerTypeDTO().setLabel(standardSystemType.getLabel());
    assertNull(type.getId());
    ConsumerDTO nulltypeid = createConsumerDTO(CONSUMER_NAME, USER_NAME, null, type);
    submitted = consumerResource.create(nulltypeid, TestUtil.createPrincipal(someuser.getUsername(), owner, Access.ALL), null, null, null, true);
    assertNotNull(submitted);
    assertNotNull(submitted.getUuid());
    assertNotNull(submitted.getType().getId());
}
Also used : ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TestUtil.createConsumerDTO(org.candlepin.test.TestUtil.createConsumerDTO) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Test(org.junit.Test)

Example 9 with ConsumerTypeDTO

use of org.candlepin.dto.api.v1.ConsumerTypeDTO in project candlepin by candlepin.

the class ConsumerResourceTest method testValidateShareConsumerRequiresRecipientPermissions.

@Test
public void testValidateShareConsumerRequiresRecipientPermissions() {
    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);
    Owner o2 = mock(Owner.class);
    c.setRecipientOwnerKey("o2");
    when(mockOwnerCurator.lookupByKey(eq("o2"))).thenReturn(o2);
    when(uap.canAccess(eq(o2), eq(SubResource.ENTITLEMENTS), eq(Access.CREATE))).thenReturn(Boolean.FALSE);
    thrown.expect(NotFoundException.class);
    thrown.expectMessage("owner with key");
    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 10 with ConsumerTypeDTO

use of org.candlepin.dto.api.v1.ConsumerTypeDTO in project candlepin by candlepin.

the class ConsumerResourceTest method testNullPerson.

@Test(expected = NotFoundException.class)
public void testNullPerson() {
    Owner owner = this.createOwner();
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.PERSON));
    ConsumerTypeDTO ctypeDto = this.translator.translate(ctype, ConsumerTypeDTO.class);
    Consumer consumer = this.createConsumer(owner, ctype);
    ConsumerDTO consumerDto = this.translator.translate(consumer, ConsumerDTO.class);
    UserServiceAdapter usa = mock(UserServiceAdapter.class);
    UserPrincipal up = mock(UserPrincipal.class);
    when(up.canAccess(eq(owner), eq(SubResource.CONSUMERS), eq(Access.CREATE))).thenReturn(true);
    // usa.findByLogin() will return null by default no need for a when
    ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, usa, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    cr.create(consumerDto, up, null, owner.getKey(), null, true);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) UserServiceAdapter(org.candlepin.service.UserServiceAdapter) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)14 ConsumerType (org.candlepin.model.ConsumerType)13 Owner (org.candlepin.model.Owner)11 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)7 ConsumerTypeDTO (org.candlepin.dto.manifest.v1.ConsumerTypeDTO)7 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)6 OwnerDTO (org.candlepin.dto.manifest.v1.OwnerDTO)6 UserPrincipal (org.candlepin.auth.UserPrincipal)5 CertificateSerial (org.candlepin.model.CertificateSerial)3 Consumer (org.candlepin.model.Consumer)3 IdentityCertificate (org.candlepin.model.IdentityCertificate)3 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)3 File (java.io.File)2 Date (java.util.Date)2 Access (org.candlepin.auth.Access)2 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)2 SubResource (org.candlepin.auth.SubResource)2 CandlepinCommonTestConfig (org.candlepin.config.CandlepinCommonTestConfig)2 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)2