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;
}
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;
}
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);
}
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());
}
}
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;
}
Aggregations