Search in sources :

Example 11 with ConsumerCapability

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

the class ConsumerTranslatorTest method initSourceObject.

@Override
protected Consumer initSourceObject() {
    ConsumerType ctype = this.consumerTypeTranslatorTest.initSourceObject();
    Consumer consumer = new Consumer();
    consumer.setUuid("consumer_uuid");
    consumer.setUsername("consumer_user_name");
    consumer.setServiceLevel("consumer_service_level");
    Owner owner = this.ownerTranslatorTest.initSourceObject();
    when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
    consumer.setOwner(owner);
    consumer.setType(ctype);
    Map<String, String> facts = new HashMap<>();
    for (int i = 0; i < 5; ++i) {
        facts.put("fact-" + i, "value-" + i);
    }
    consumer.setFacts(facts);
    Set<ConsumerInstalledProduct> installedProducts = new HashSet<>();
    for (int i = 0; i < 5; ++i) {
        ConsumerInstalledProduct installedProduct = new ConsumerInstalledProduct();
        installedProduct.setProductId("installedProduct-" + i);
        installedProducts.add(installedProduct);
    }
    consumer.setInstalledProducts(installedProducts);
    Set<ConsumerCapability> capabilities = new HashSet<>();
    for (int i = 0; i < 5; ++i) {
        ConsumerCapability capability = new ConsumerCapability();
        capability.setName("capability-" + i);
        capabilities.add(capability);
    }
    consumer.setCapabilities(capabilities);
    when(mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    when(mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    return consumer;
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerCapability(org.candlepin.model.ConsumerCapability) ConsumerType(org.candlepin.model.ConsumerType) HashSet(java.util.HashSet)

Example 12 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.getUuid(), dest.getUuid());
        assertEquals(source.getUsername(), dest.getUsername());
        assertEquals(source.getServiceLevel(), dest.getServiceLevel());
        assertEquals(source.getFacts(), dest.getFacts());
        assertEquals(source.getCreated(), dest.getCreated());
        assertEquals(source.getUpdated(), dest.getUpdated());
        if (childrenGenerated) {
            ConsumerType ctype = this.mockConsumerTypeCurator.getConsumerType(source);
            assertEquals(source.getOwnerId(), dest.getOwner().getId());
            this.consumerTypeTranslatorTest.verifyOutput(ctype, dest.getType(), true);
            if (source.getInstalledProducts() != null) {
                for (ConsumerInstalledProduct cip : source.getInstalledProducts()) {
                    boolean verified = false;
                    for (String cipDTO : dest.getInstalledProducts()) {
                        assertNotNull(cip);
                        assertNotNull(cipDTO);
                        if (cip.getProductId().contentEquals(cipDTO)) {
                            verified = true;
                        }
                    }
                    assertTrue(verified);
                }
            } else {
                assertNull(dest.getInstalledProducts());
            }
            if (source.getCapabilities() != null) {
                for (ConsumerCapability cc : source.getCapabilities()) {
                    boolean verified = false;
                    for (String ccDTO : dest.getCapabilities()) {
                        assertNotNull(cc);
                        assertNotNull(ccDTO);
                        if (cc.getName().contentEquals(ccDTO)) {
                            verified = true;
                        }
                    }
                    assertTrue(verified);
                }
            } else {
                assertNull(dest.getCapabilities());
            }
        } else {
            assertNull(dest.getOwner());
            assertNull(dest.getType());
            assertNull(dest.getInstalledProducts());
            assertNull(dest.getCapabilities());
        }
    } else {
        assertNull(dest);
    }
}
Also used : ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerCapability(org.candlepin.model.ConsumerCapability) ConsumerType(org.candlepin.model.ConsumerType)

Example 13 with ConsumerCapability

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

the class DefaultEntitlementCertServiceAdapterTest method ensureV3CertIsCreatedWhenV3CapabilityPresent.

@Test
public void ensureV3CertIsCreatedWhenV3CapabilityPresent() throws Exception {
    ConsumerType ctype = new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN);
    ctype.setId("test-id");
    consumer.setType(ctype);
    when(mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    when(mockConsumerTypeCurator.getConsumerType(consumer)).thenReturn(ctype);
    Set<ConsumerCapability> set = new HashSet<>();
    set.add(new ConsumerCapability(consumer, "cert_v3"));
    consumer.setCapabilities(set);
    DefaultEntitlementCertServiceAdapter entAdapter = this.initCertServiceAdapter();
    entAdapter.createX509Certificate(consumer, owner, pool, entitlement, product, new HashSet<>(), getProductModels(product, new HashSet<>(), "prefix", entitlement), new BigInteger("1234"), keyPair, true);
    verify(mockV3extensionUtil).getExtensions();
    verify(mockV3extensionUtil).getByteExtensions(eq(product), any(List.class), any(String.class), any(Map.class));
    verifyZeroInteractions(mockExtensionUtil);
}
Also used : BigInteger(java.math.BigInteger) ConsumerCapability(org.candlepin.model.ConsumerCapability) List(java.util.List) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with ConsumerCapability

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

the class ManifestEntitlementRulesTest method preEntitlementWithDerivedProductCapabilitySuccessOnBestPools.

@Test
public void preEntitlementWithDerivedProductCapabilitySuccessOnBestPools() {
    Consumer c = this.createMockConsumer(true);
    HashSet<ConsumerCapability> capabilities = new HashSet<>();
    capabilities.add(new ConsumerCapability(c, "derived_product"));
    c.setCapabilities(capabilities);
    Product prod = TestUtil.createProduct();
    Product derived = TestUtil.createProduct("sub-prod-id");
    Pool p = TestUtil.createPool(prod);
    p.setDerivedProduct(derived);
    ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BEST_POOLS);
    assertNotNull(results);
    assertTrue("Expected no warnings or errors.", results.isSuccessful());
}
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 15 with ConsumerCapability

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

the class ManifestEntitlementRulesTest method preEntitlementNoInstanceCapableBindError.

@Test
public void preEntitlementNoInstanceCapableBindError() {
    // Test with sockets to make sure that they are skipped.
    Consumer c = this.createMockConsumer(true);
    Set<ConsumerCapability> caps = new HashSet<>();
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "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.instance.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