Search in sources :

Example 1 with ConsumerCapability

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

the class CapabilityTranslatorTest method initSourceObject.

@Override
protected ConsumerCapability initSourceObject() {
    ConsumerCapability source = new ConsumerCapability();
    source.setName("test_name");
    return source;
}
Also used : ConsumerCapability(org.candlepin.model.ConsumerCapability)

Example 2 with ConsumerCapability

use of org.candlepin.model.ConsumerCapability 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 3 with ConsumerCapability

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

the class ConsumerResourceUpdateTest method consumerChangeDetection.

@Test
public void consumerChangeDetection() {
    Consumer existing = getFakeConsumer();
    Set<ConsumerCapability> caps1 = new HashSet<>();
    Set<ConsumerCapability> caps2 = new HashSet<>();
    ConsumerCapability cca = new ConsumerCapability(existing, "capability_a");
    ConsumerCapability ccb = new ConsumerCapability(existing, "capability_b");
    ConsumerCapability ccc = new ConsumerCapability(existing, "capability_c");
    caps1.add(cca);
    caps1.add(ccb);
    caps1.add(ccc);
    caps2.add(ccb);
    existing.setCapabilities(caps1);
    Consumer update = getFakeConsumer();
    update.setCapabilities(caps1);
    assertFalse(resource.performConsumerUpdates(this.translator.translate(update, ConsumerDTO.class), existing, testMigration));
    update.setCapabilities(caps2);
    assertTrue(resource.performConsumerUpdates(this.translator.translate(update, ConsumerDTO.class), existing, testMigration));
    // need a new consumer here, can't null out capabilities
    update = getFakeConsumer();
    assertFalse(resource.performConsumerUpdates(this.translator.translate(update, ConsumerDTO.class), existing, testMigration));
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerCapability(org.candlepin.model.ConsumerCapability) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ConsumerCapability

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

the class ManifestEntitlementRulesTest method preEntitlementSuccessInstanceCapable.

@Test
public void preEntitlementSuccessInstanceCapable() {
    // Test with sockets to make sure that they are skipped.
    Consumer c = this.createMockConsumer(true);
    Set<ConsumerCapability> caps = new HashSet<>();
    ConsumerCapability cc = new ConsumerCapability(c, "instance_multiplier");
    caps.add(cc);
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "2");
    Pool p = TestUtil.createPool(prod);
    ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BEST_POOLS);
    assertNotNull(results);
    assertEquals(0, results.getErrors().size());
    assertEquals(0, results.getWarnings().size());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) ConsumerCapability(org.candlepin.model.ConsumerCapability) Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ConsumerCapability

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

the class ManifestEntitlementRulesTest method preEntitlementNoRamCapableBindError.

@Test
public void preEntitlementNoRamCapableBindError() {
    // Test with sockets to make sure that they are skipped.
    Consumer c = this.createMockConsumer(true);
    c.setFact("memory.memtotal", "2000000");
    Set<ConsumerCapability> caps = new HashSet<>();
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.RAM, "2");
    Pool p = TestUtil.createPool(prod);
    p.setId("poolId");
    ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BIND);
    assertNotNull(results);
    assertEquals(0, results.getWarnings().size());
    ValidationError error = results.getErrors().get(0);
    assertEquals("rulefailed.ram.unsupported.by.consumer", error.getResourceKey());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) ConsumerCapability(org.candlepin.model.ConsumerCapability) Pool(org.candlepin.model.Pool) ValidationError(org.candlepin.policy.ValidationError) ValidationResult(org.candlepin.policy.ValidationResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ConsumerCapability (org.candlepin.model.ConsumerCapability)26 HashSet (java.util.HashSet)19 Consumer (org.candlepin.model.Consumer)15 Test (org.junit.Test)14 ConsumerType (org.candlepin.model.ConsumerType)11 Pool (org.candlepin.model.Pool)11 Product (org.candlepin.model.Product)11 ValidationResult (org.candlepin.policy.ValidationResult)11 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)7 Environment (org.candlepin.model.Environment)4 Owner (org.candlepin.model.Owner)4 HashMap (java.util.HashMap)3 Release (org.candlepin.model.Release)3 ValidationError (org.candlepin.policy.ValidationError)3 ValidationWarning (org.candlepin.policy.ValidationWarning)3 ArrayList (java.util.ArrayList)2 GuestId (org.candlepin.model.GuestId)2 BigInteger (java.math.BigInteger)1 Date (java.util.Date)1 LinkedHashSet (java.util.LinkedHashSet)1