Search in sources :

Example 31 with ConsumerInstalledProduct

use of org.candlepin.model.ConsumerInstalledProduct 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 32 with ConsumerInstalledProduct

use of org.candlepin.model.ConsumerInstalledProduct 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 33 with ConsumerInstalledProduct

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

the class ConsumerResourceTest method futureHealing.

@Test
public void futureHealing() throws Exception {
    Owner o = createOwner();
    o.setId(TestUtil.randomString());
    Consumer c = createConsumer(o);
    SubscriptionServiceAdapter sa = mock(SubscriptionServiceAdapter.class);
    Entitler e = mock(Entitler.class);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    ConsumerInstalledProduct cip = mock(ConsumerInstalledProduct.class);
    Set<ConsumerInstalledProduct> products = new HashSet<>();
    products.add(cip);
    when(mockOwnerCurator.findOwnerById(eq(o.getId()))).thenReturn(o);
    when(cip.getProductId()).thenReturn("product-foo");
    when(sa.hasUnacceptedSubscriptionTerms(eq(o))).thenReturn(false);
    when(cc.verifyAndLookupConsumerWithEntitlements(eq(c.getUuid()))).thenReturn(c);
    ConsumerResource cr = new ConsumerResource(cc, mockConsumerTypeCurator, null, sa, this.mockOwnerServiceAdapter, null, null, null, null, null, null, null, null, null, null, null, mockOwnerCurator, null, e, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    String dtStr = "2011-09-26T18:10:50.184081+00:00";
    Date dt = ResourceDateParser.parseDateString(dtStr);
    cr.bind(c.getUuid(), null, null, null, null, null, false, dtStr, null);
    AutobindData data = AutobindData.create(c, o).on(dt);
    verify(e).bindByProducts(eq(data));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) AutobindData(org.candlepin.resource.dto.AutobindData) Matchers.anyString(org.mockito.Matchers.anyString) Entitler(org.candlepin.controller.Entitler) SubscriptionServiceAdapter(org.candlepin.service.SubscriptionServiceAdapter) ConsumerCurator(org.candlepin.model.ConsumerCurator) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with ConsumerInstalledProduct

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

the class ConsumerBindUtilTest method registerWithKeyWithPoolAndInstalledProductsAutoAttach.

@Test
public void registerWithKeyWithPoolAndInstalledProductsAutoAttach() throws Exception {
    Product prod = TestUtil.createProduct();
    String[] prodIds = new String[] { prod.getId() };
    Pool pool = TestUtil.createPool(owner, prod);
    pool.setId("id-string");
    List<String> poolIds = new ArrayList<>();
    poolIds.add(pool.getId());
    List<ActivationKey> keys = new ArrayList<>();
    ActivationKey key1 = new ActivationKey("key1", owner);
    keys.add(key1);
    key1.addPool(pool, 0L);
    key1.setAutoAttach(true);
    Consumer consumer = new Consumer("sys.example.com", null, null, system);
    Set<ConsumerInstalledProduct> cips = new HashSet<>();
    ConsumerInstalledProduct cip = new ConsumerInstalledProduct(consumer, prod);
    cips.add(cip);
    consumer.setInstalledProducts(cips);
    AutobindData ad = new AutobindData(consumer, owner).withPools(poolIds).forProducts(prodIds);
    consumerBindUtil.handleActivationKeys(consumer, keys, false);
    verify(entitler).bindByProducts(eq(ad));
}
Also used : ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) AutobindData(org.candlepin.resource.dto.AutobindData) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 35 with ConsumerInstalledProduct

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

the class InstalledProductStatusCalculatorTest method validRangeForSingleValidEnitlement.

@Test
public void validRangeForSingleValidEnitlement() {
    Owner owner = TestUtil.createOwner();
    Product product = TestUtil.createProduct("p1", "product1");
    Consumer consumer = this.mockConsumer(owner, product);
    DateRange range = this.rangeRelativeToDate(new Date(), -6, 6);
    Entitlement entitlement = this.mockEntitlement(owner, consumer, product, range, product);
    consumer.addEntitlement(entitlement);
    this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
    this.mockOwnerProducts(owner, Arrays.asList(product));
    this.consumerEnricher.enrich(consumer);
    ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
    assertEquals(range.getStartDate(), cip.getStartDate());
    assertEquals(range.getEndDate(), cip.getEndDate());
}
Also used : Owner(org.candlepin.model.Owner) DateRange(org.candlepin.policy.js.compliance.DateRange) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)66 Consumer (org.candlepin.model.Consumer)54 Product (org.candlepin.model.Product)51 Test (org.junit.Test)49 Owner (org.candlepin.model.Owner)44 Date (java.util.Date)35 DateRange (org.candlepin.policy.js.compliance.DateRange)26 HashSet (java.util.HashSet)14 ArrayList (java.util.ArrayList)13 Entitlement (org.candlepin.model.Entitlement)11 Pool (org.candlepin.model.Pool)11 ConsumerType (org.candlepin.model.ConsumerType)10 AutobindData (org.candlepin.resource.dto.AutobindData)10 HashMap (java.util.HashMap)8 ConsumerCapability (org.candlepin.model.ConsumerCapability)7 List (java.util.List)6 ProductData (org.candlepin.model.dto.ProductData)6 ConsumerInstalledProductDTO (org.candlepin.dto.api.v1.ConsumerInstalledProductDTO)4 Environment (org.candlepin.model.Environment)4 GuestId (org.candlepin.model.GuestId)4