Search in sources :

Example 26 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class ConsumerTranslatorTest method verifyOutput.

@Override
protected void verifyOutput(Consumer source, ConsumerDTO dest, boolean childrenGenerated) {
    if (source != null) {
        assertEquals(source.getId(), dest.getId());
        assertEquals(source.getUuid(), dest.getUuid());
        assertEquals(source.getName(), dest.getName());
        assertEquals(source.getUsername(), dest.getUsername());
        assertEquals(source.getEntitlementStatus(), dest.getEntitlementStatus());
        assertEquals(source.getServiceLevel(), dest.getServiceLevel());
        assertEquals(source.getEntitlementCount(), (long) dest.getEntitlementCount());
        assertEquals(source.getFacts(), dest.getFacts());
        assertEquals(source.getLastCheckin(), dest.getLastCheckin());
        assertEquals(source.isCanActivate(), dest.isCanActivate());
        assertEquals(source.getContentTags(), dest.getContentTags());
        assertEquals(source.isAutoheal(), dest.getAutoheal());
        assertEquals(source.getRecipientOwnerKey(), dest.getRecipientOwnerKey());
        assertEquals(source.getAnnotations(), dest.getAnnotations());
        assertEquals(source.getContentAccessMode(), dest.getContentAccessMode());
        if (childrenGenerated) {
            ConsumerType ctype = this.mockConsumerTypeCurator.getConsumerType(source);
            this.consumerTypeTranslatorTest.verifyOutput(ctype, dest.getType(), true);
            Environment environment = this.mockEnvironmentCurator.getConsumerEnvironment(source);
            this.environmentTranslatorTest.verifyOutput(environment, dest.getEnvironment(), true);
            assertEquals(source.getReleaseVer().getReleaseVer(), dest.getReleaseVersion());
            String destOwnerId = null;
            if (dest.getOwner() != null) {
                destOwnerId = dest.getOwner().getId();
            }
            assertEquals(source.getOwnerId(), destOwnerId);
            this.hypervisorIdTranslatorTest.verifyOutput(source.getHypervisorId(), dest.getHypervisorId(), childrenGenerated);
            this.certificateTranslatorTest.verifyOutput(source.getIdCert(), dest.getIdCert(), true);
            if (source.getInstalledProducts() != null) {
                for (ConsumerInstalledProduct cip : source.getInstalledProducts()) {
                    for (ConsumerInstalledProductDTO cipDTO : dest.getInstalledProducts()) {
                        assertNotNull(cip);
                        assertNotNull(cipDTO);
                        this.cipTranslatorTest.verifyOutput(cip, cipDTO, childrenGenerated);
                    }
                }
            } else {
                assertNull(dest.getInstalledProducts());
            }
            if (source.getCapabilities() != null) {
                for (ConsumerCapability cc : source.getCapabilities()) {
                    boolean verified = false;
                    for (CapabilityDTO ccDTO : dest.getCapabilities()) {
                        assertNotNull(cc);
                        assertNotNull(ccDTO);
                        if (cc.getName().contentEquals(ccDTO.getName())) {
                            this.capabilityTranslatorTest.verifyOutput(cc, ccDTO, childrenGenerated);
                            verified = true;
                        }
                    }
                    assertTrue(verified);
                }
            } else {
                assertNull(dest.getCapabilities());
            }
            assertEquals(0, dest.getGuestIds().size());
        } else {
            assertNull(dest.getReleaseVersion());
            assertNull(dest.getOwner());
            assertNull(dest.getEnvironment());
            assertNull(dest.getHypervisorId());
            assertNull(dest.getType());
            assertNull(dest.getIdCert());
            assertNull(dest.getInstalledProducts());
            assertNull(dest.getCapabilities());
            assertNull(dest.getGuestIds());
        }
    } else {
        assertNull(dest);
    }
}
Also used : ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Environment(org.candlepin.model.Environment) ConsumerCapability(org.candlepin.model.ConsumerCapability) ConsumerType(org.candlepin.model.ConsumerType)

Example 27 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class ConsumerTranslatorTest method verifyOutput.

@Override
protected void verifyOutput(Consumer source, ConsumerDTO dest, boolean childrenGenerated) {
    if (source != null) {
        assertEquals(source.getUuid(), dest.getUuid());
        assertEquals(source.getName(), dest.getName());
        assertEquals(source.getContentAccessMode(), dest.getContentAccessMode());
        if (childrenGenerated) {
            if (dest.getOwner() != null) {
                assertEquals(source.getOwnerId(), dest.getOwner().getId());
            } else {
                assertNull(source.getOwnerId());
            }
            ConsumerType ctype = this.mockConsumerTypeCurator.getConsumerType(source);
            this.consumerTypeTranslatorTest.verifyOutput(ctype, dest.getType(), true);
        } else {
            assertNull(dest.getOwner());
            assertNull(dest.getType());
        }
    } else {
        assertNull(dest);
    }
}
Also used : ConsumerType(org.candlepin.model.ConsumerType)

Example 28 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class TestUtil method createDistributor.

public static Consumer createDistributor(Owner owner) {
    ConsumerType ctype = new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN);
    ctype.setId("test-ctype-" + randomInt());
    return createConsumer(ctype, owner);
}
Also used : ConsumerType(org.candlepin.model.ConsumerType)

Example 29 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class ManifestManagerTest method createMockConsumer.

protected Consumer createMockConsumer(Owner owner, boolean manifestDistributor) {
    ConsumerType type = manifestDistributor ? new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN) : new ConsumerType("test-consumer-type-" + TestUtil.randomInt());
    type.setId("test-ctype-" + TestUtil.randomInt());
    Consumer consumer = new Consumer("TestConsumer" + TestUtil.randomInt(), "User", owner, type);
    when(consumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(type);
    when(consumerTypeCurator.find(eq(type.getId()))).thenReturn(type);
    return consumer;
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType)

Example 30 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class ManifestManagerTest method verifyConsumerIsDistributorBeforeGeneratingManifest.

@Test
public void verifyConsumerIsDistributorBeforeGeneratingManifest() throws Exception {
    Consumer consumer = this.createMockConsumer(false);
    ConsumerType ctype = consumerTypeCurator.getConsumerType(consumer);
    Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
    String webAppPrefix = "webapp-prefix";
    String apiUrl = "api-url";
    Map<String, String> extData = new HashMap<>();
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
    try {
        manager.generateManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, extData);
        fail("Expected ForbiddenException not thrown");
    } catch (Exception e) {
        assertTrue(e instanceof ForbiddenException);
        String expectedMsg = String.format("Unit %s cannot be exported. A manifest cannot be made for " + "units of type \"%s\".", consumer.getUuid(), ctype.getLabel());
        assertEquals(e.getMessage(), expectedMsg);
    }
}
Also used : ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) ConsumerType(org.candlepin.model.ConsumerType) Cdn(org.candlepin.model.Cdn) NotFoundException(org.candlepin.common.exceptions.NotFoundException) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) BadRequestException(org.candlepin.common.exceptions.BadRequestException) Test(org.junit.Test)

Aggregations

ConsumerType (org.candlepin.model.ConsumerType)169 Consumer (org.candlepin.model.Consumer)92 Test (org.junit.Test)71 Owner (org.candlepin.model.Owner)53 Pool (org.candlepin.model.Pool)47 Entitlement (org.candlepin.model.Entitlement)33 ArrayList (java.util.ArrayList)29 Date (java.util.Date)27 HashMap (java.util.HashMap)24 HashSet (java.util.HashSet)24 ValidationResult (org.candlepin.policy.ValidationResult)22 ApiOperation (io.swagger.annotations.ApiOperation)21 Produces (javax.ws.rs.Produces)21 Before (org.junit.Before)20 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)18 LinkedList (java.util.LinkedList)16 BadRequestException (org.candlepin.common.exceptions.BadRequestException)16 DeletedConsumer (org.candlepin.model.DeletedConsumer)16 Matchers.anyString (org.mockito.Matchers.anyString)16