Search in sources :

Example 51 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();
    Environment environment = this.environmentTranslatorTest.initSourceObject();
    Owner owner = this.ownerTranslatorTest.initSourceObject();
    when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
    Consumer consumer = new Consumer();
    consumer.setId("consumer_id");
    consumer.setUuid("consumer_uuid");
    consumer.setName("consumer_name");
    consumer.setUsername("consumer_user_name");
    consumer.setEntitlementStatus("consumer_ent_status");
    consumer.setServiceLevel("consumer_service_level");
    consumer.setReleaseVer(new Release("releaseVer"));
    consumer.setOwner(owner);
    consumer.setEnvironment(environment);
    consumer.setEntitlementCount(0L);
    consumer.setLastCheckin(new Date());
    consumer.setCanActivate(Boolean.TRUE);
    consumer.setHypervisorId(hypervisorIdTranslatorTest.initSourceObject());
    consumer.setAutoheal(Boolean.TRUE);
    consumer.setRecipientOwnerKey("test_recipient_owner_key");
    consumer.setAnnotations("test_annotations");
    consumer.setContentAccessMode("test_content_access_mode");
    consumer.setIdCert((IdentityCertificate) this.certificateTranslatorTest.initSourceObject());
    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 = cipTranslatorTest.initSourceObject();
        installedProduct.setId("installedProduct-" + i);
        installedProducts.add(installedProduct);
    }
    consumer.setInstalledProducts(installedProducts);
    Set<ConsumerCapability> capabilities = new HashSet<>();
    for (int i = 0; i < 5; ++i) {
        ConsumerCapability capability = capabilityTranslatorTest.initSourceObject();
        capability.setName("capability-" + i);
        capabilities.add(capability);
    }
    consumer.setCapabilities(capabilities);
    Set<String> contentTags = new HashSet<>();
    for (int i = 0; i < 5; ++i) {
        contentTags.add("contentTag-" + i);
    }
    consumer.setContentTags(contentTags);
    List<GuestId> guestIds = new LinkedList<>();
    for (int i = 0; i < 5; ++i) {
        GuestId guestId = guestIdTranslatorTest.initSourceObject();
        guestId.setId("guestId-" + i);
        guestIds.add(guestId);
    }
    consumer.setGuestIds(guestIds);
    when(mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    when(mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    when(mockEnvironmentCurator.find(eq(environment.getId()))).thenReturn(environment);
    when(mockEnvironmentCurator.getConsumerEnvironment(eq(consumer))).thenReturn(environment);
    return consumer;
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerCapability(org.candlepin.model.ConsumerCapability) Date(java.util.Date) LinkedList(java.util.LinkedList) Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Environment(org.candlepin.model.Environment) ConsumerType(org.candlepin.model.ConsumerType) Release(org.candlepin.model.Release) HashSet(java.util.HashSet)

Example 52 with ConsumerInstalledProduct

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

the class ConsumerInstalledProductTranslatorTest method initSourceObject.

@Override
protected ConsumerInstalledProduct initSourceObject() {
    ConsumerInstalledProduct source = new ConsumerInstalledProduct();
    source.setId("test_id");
    source.setProductId("test_product_id");
    source.setProductName("test_product_name");
    source.setVersion("test_version");
    source.setArch("test_arch");
    source.setStatus("test_status");
    source.setStartDate(new Date());
    source.setEndDate(new Date());
    return source;
}
Also used : ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date)

Example 53 with ConsumerInstalledProduct

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

the class EntitlerTest method testDevPoolCreationAtBindNoFailMissingInstalledProduct.

@Test
public void testDevPoolCreationAtBindNoFailMissingInstalledProduct() throws Exception {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<>();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    Product ip1 = TestUtil.createProduct("test-product-installed-1", "Installed Test Product 1");
    Product ip2 = TestUtil.createProduct("test-product-installed-2", "Installed Test Product 2");
    devProdDTOs.add(p.toDTO());
    devProdDTOs.add(ip1.toDTO());
    Pool activePool = TestUtil.createPool(owner, p);
    List<Pool> activeList = new ArrayList<>();
    activeList.add(activePool);
    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(ip1));
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(ip2));
    when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(false);
    when(poolCurator.hasActiveEntitlementPools(eq(owner.getId()), any(Date.class))).thenReturn(true);
    when(productAdapter.getProductsByIds(any(Owner.class), any(List.class))).thenReturn(devProdDTOs);
    this.mockProducts(owner, p, ip1, ip2);
    this.mockProductImport(owner, p, ip1, ip2);
    this.mockContentImport(owner, Collections.<String, Content>emptyMap());
    Pool expectedPool = entitler.assembleDevPool(devSystem, owner, p.getId());
    when(pm.createPool(any(Pool.class))).thenReturn(expectedPool);
    AutobindData ad = new AutobindData(devSystem, owner);
    entitler.bindByProducts(ad);
}
Also used : ProductData(org.candlepin.model.dto.ProductData) Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) List(java.util.List) ArrayList(java.util.ArrayList) AutobindData(org.candlepin.resource.dto.AutobindData) Date(java.util.Date) Test(org.junit.Test)

Example 54 with ConsumerInstalledProduct

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

the class EntitlerTest method testDevPoolCreationAtBindFailNoSkuProduct.

@Test
public void testDevPoolCreationAtBindFailNoSkuProduct() throws Exception {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<>();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    Product ip = TestUtil.createProduct("test-product-installed", "Installed Test Product");
    devProdDTOs.add(ip.toDTO());
    Pool activePool = TestUtil.createPool(owner, p);
    List<Pool> activeList = new ArrayList<>();
    activeList.add(activePool);
    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(ip));
    when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(false);
    when(poolCurator.hasActiveEntitlementPools(eq(owner.getId()), any(Date.class))).thenReturn(true);
    when(productAdapter.getProductsByIds(any(Owner.class), any(List.class))).thenReturn(devProdDTOs);
    when(ownerProductCurator.getProductById(eq(owner), eq(p.getId()))).thenReturn(p);
    when(ownerProductCurator.getProductById(eq(owner), eq(ip.getId()))).thenReturn(ip);
    mockUpdateProduct(p, owner);
    mockUpdateProduct(ip, owner);
    mockProductImport(owner, p, ip);
    mockContentImport(owner, new Content[] {});
    AutobindData ad = new AutobindData(devSystem, owner);
    try {
        entitler.bindByProducts(ad);
    } catch (ForbiddenException fe) {
        assertEquals(i18n.tr("SKU product not available to this development unit: \"{0}\"", p.getId()), fe.getMessage());
    }
}
Also used : ProductData(org.candlepin.model.dto.ProductData) Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) List(java.util.List) ArrayList(java.util.ArrayList) AutobindData(org.candlepin.resource.dto.AutobindData) Test(org.junit.Test)

Example 55 with ConsumerInstalledProduct

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

the class ConsumerResource method populateInstalledProducts.

/**
 * Utility method that translates a ConsumerDTO's installed products to
 * Consumer model entity installed products.
 *
 * @param entity the Consumer model entity which the installed products are to reference
 *
 * @param dto the ConsumerDTO whose installed products we want to translate
 *
 * @return the model entity ConsumerInstalledProduct set that was created
 */
private Set<ConsumerInstalledProduct> populateInstalledProducts(Consumer entity, ConsumerDTO dto) {
    Set<ConsumerInstalledProduct> installedProducts = new HashSet<>();
    for (ConsumerInstalledProductDTO installedProductDTO : dto.getInstalledProducts()) {
        if (installedProductDTO != null) {
            ConsumerInstalledProduct installedProduct = new ConsumerInstalledProduct(installedProductDTO.getProductId(), installedProductDTO.getProductName(), entity, installedProductDTO.getVersion(), installedProductDTO.getArch(), installedProductDTO.getStatus(), installedProductDTO.getStartDate(), installedProductDTO.getEndDate());
            installedProducts.add(installedProduct);
        }
    }
    return installedProducts;
}
Also used : ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerInstalledProductDTO(org.candlepin.dto.api.v1.ConsumerInstalledProductDTO) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

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