Search in sources :

Example 46 with ConsumerDTO

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

the class OwnerResourceTest method consumerCanListConsumersByIdWhenOtherParametersPresent.

@Test
public void consumerCanListConsumersByIdWhenOtherParametersPresent() {
    Consumer c = createConsumer(owner);
    List<String> uuids = new ArrayList<>();
    uuids.add(c.getUuid());
    setupPrincipal(owner, Access.ALL);
    securityInterceptor.enable();
    Set<String> types = new HashSet<>();
    types.add("type");
    consumerTypeCurator.create(new ConsumerType("type"));
    CandlepinQuery<ConsumerDTO> result = ownerResource.listConsumers(owner.getKey(), "username", types, uuids, null, null, null, null, null, new PageRequest());
    assertNotNull(result);
    List<ConsumerDTO> consumers = result.list();
    assertEquals(0, consumers.size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) 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) ConsumerType(org.candlepin.model.ConsumerType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 47 with ConsumerDTO

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

the class EntitlementImporterTest method init.

@Before
public void init() {
    this.owner = new Owner();
    this.translator = new StandardTranslator(mockConsumerTypeCurator, mockEnvironmentCurator, ownerCurator);
    i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    this.importer = new EntitlementImporter(certSerialCurator, cdnCurator, i18n, mockProductCurator, ec, translator);
    ConsumerType ctype = TestUtil.createConsumerType();
    ctype.setId("test-ctype");
    consumer = TestUtil.createConsumer(ctype, owner);
    consumerDTO = this.translator.translate(consumer, ConsumerDTO.class);
    consumerDTO.setUrlWeb("");
    consumerDTO.setUrlApi("");
    when(this.mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    when(this.mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    cert = createEntitlementCertificate("my-test-key", "my-cert");
    cert.setId("test-id");
    reader = mock(Reader.class);
    meta = new Meta();
    meta.setCdnLabel("test-cdn");
    testCdn = new Cdn("test-cdn", "Test CDN", "https://test.url.com");
    when(cdnCurator.lookupByLabel("test-cdn")).thenReturn(testCdn);
}
Also used : Owner(org.candlepin.model.Owner) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) Reader(java.io.Reader) ConsumerType(org.candlepin.model.ConsumerType) Cdn(org.candlepin.model.Cdn) StandardTranslator(org.candlepin.dto.StandardTranslator) Before(org.junit.Before)

Example 48 with ConsumerDTO

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

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

the class ConsumerImporterTest method importConsumerWithSameUuidOnAnotherOwnerShouldThrowException.

@Test(expected = SyncDataFormatException.class)
public void importConsumerWithSameUuidOnAnotherOwnerShouldThrowException() throws ImporterException {
    Owner owner = new Owner();
    UpstreamConsumer uc = new UpstreamConsumer("test-uuid");
    owner.setUpstreamConsumer(uc);
    ConsumerDTO consumer = new ConsumerDTO();
    consumer.setUuid("test-uuid");
    Owner anotherOwner = new Owner("other", "Other");
    anotherOwner.setId("blah");
    anotherOwner.setUpstreamConsumer(uc);
    when(curator.lookupWithUpstreamUuid(consumer.getUuid())).thenReturn(anotherOwner);
    importer.store(owner, consumer, new ConflictOverrides(), null);
}
Also used : Owner(org.candlepin.model.Owner) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Test(org.junit.Test)

Example 50 with ConsumerDTO

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

the class ConsumerImporterTest method importConsumerWithMismatchedUuidShouldThrowException.

@Test
public void importConsumerWithMismatchedUuidShouldThrowException() throws ImporterException {
    Owner owner = mock(Owner.class);
    OwnerDTO ownerDTO = mock(OwnerDTO.class);
    ConsumerDTO consumer = mock(ConsumerDTO.class);
    when(owner.getUpstreamUuid()).thenReturn("another-test-uuid");
    when(consumer.getUuid()).thenReturn("test-uuid");
    when(consumer.getOwner()).thenReturn(ownerDTO);
    try {
        importer.store(owner, consumer, new ConflictOverrides(), null);
        fail();
    } catch (ImportConflictException e) {
        assertFalse(e.message().getConflicts().isEmpty());
        assertTrue(e.message().getConflicts().contains(Importer.Conflict.DISTRIBUTOR_CONFLICT));
    }
}
Also used : Owner(org.candlepin.model.Owner) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.manifest.v1.OwnerDTO) 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