Search in sources :

Example 16 with ConsumerTypeDTO

use of org.candlepin.dto.api.v1.ConsumerTypeDTO 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 17 with ConsumerTypeDTO

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

the class ConsumerImporterTest method importConsumerWithNullUuidOnOwnerShouldSetUuid.

@Test
public void importConsumerWithNullUuidOnOwnerShouldSetUuid() throws ImporterException {
    OwnerDTO ownerDTO = mock(OwnerDTO.class);
    Owner owner = mock(Owner.class);
    ConsumerDTO consumer = mock(ConsumerDTO.class);
    ConsumerTypeDTO type = mock(ConsumerTypeDTO.class);
    when(ownerDTO.getId()).thenReturn("test-owner-id");
    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(), 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 18 with ConsumerTypeDTO

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

the class ConsumerTypeResourceTest method testUpdateTypeWithNullId.

@Test(expected = NotFoundException.class)
public void testUpdateTypeWithNullId() {
    ConsumerTypeDTO dto = new ConsumerTypeDTO();
    dto.setId(null);
    ConsumerTypeDTO output = this.consumerTypeResource.update(dto);
}
Also used : ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Test(org.junit.Test)

Example 19 with ConsumerTypeDTO

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

the class ConsumerTypeResourceTest method testUpdateTypeWithBadId.

@Test(expected = NotFoundException.class)
public void testUpdateTypeWithBadId() {
    ConsumerTypeDTO dto = new ConsumerTypeDTO();
    dto.setId("some bad id");
    ConsumerTypeDTO output = this.consumerTypeResource.update(dto);
}
Also used : ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Test(org.junit.Test)

Example 20 with ConsumerTypeDTO

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

the class ConsumerTypeResourceTest method testUpdateTypeUpdatesManifestButNotLabel.

@Test
public void testUpdateTypeUpdatesManifestButNotLabel() {
    String label = this.testType.getLabel();
    boolean manifest = !this.testType.isManifest();
    ConsumerTypeDTO dto = new ConsumerTypeDTO();
    dto.setId(this.testType.getId());
    dto.setManifest(manifest);
    // Update the type with our DTO
    ConsumerTypeDTO output = this.consumerTypeResource.update(dto);
    assertNotNull(output);
    assertEquals(label, output.getLabel());
    assertEquals(dto.isManifest(), output.isManifest());
    // Flush & clear DB state
    this.consumerTypeCurator.flush();
    this.consumerTypeCurator.clear();
    // Ensure the update actually hit the DB
    ConsumerType existing = this.consumerTypeCurator.find(this.testType.getId());
    assertNotNull(existing);
    assertEquals(label, existing.getLabel());
    assertEquals(dto.isManifest(), existing.isManifest());
}
Also used : ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) 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