use of org.candlepin.model.Product in project candlepin by candlepin.
the class ConsumerBindUtilTest method registerWithKeyWithInstalledProductsAutoAttach.
@Test
public void registerWithKeyWithInstalledProductsAutoAttach() throws Exception {
Product prod = TestUtil.createProduct();
String[] prodIds = new String[] { prod.getId() };
List<ActivationKey> keys = new ArrayList<>();
ActivationKey key1 = new ActivationKey("key1", owner);
keys.add(key1);
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).forProducts(prodIds);
consumerBindUtil.handleActivationKeys(consumer, keys, false);
verify(entitler).bindByProducts(eq(ad));
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class ConsumerBindUtilTest method registerFailWithNoGoodKeyPool.
@Test(expected = BadRequestException.class)
public void registerFailWithNoGoodKeyPool() throws Exception {
List<ActivationKey> keys = new ArrayList<>();
ActivationKey key1 = new ActivationKey("key1", owner);
keys.add(key1);
Product prod1 = TestUtil.createProduct();
Pool ghost = TestUtil.createPool(owner, prod1, 5);
ghost.setId("ghost-pool");
key1.addPool(ghost, 10L);
Consumer consumer = new Consumer("sys.example.com", null, null, system);
when(entitler.bindByPoolQuantity(eq(consumer), eq(ghost.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
consumerBindUtil.handleActivationKeys(consumer, keys, false);
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class ConsumerBindUtilTest method registerWithKeyWithInstalledProductsPlusAutoAttach.
@Test
public void registerWithKeyWithInstalledProductsPlusAutoAttach() throws Exception {
// installed product
Product prod1 = TestUtil.createProduct();
// key product
Product prod2 = TestUtil.createProduct();
String[] prodIds = new String[] { prod1.getId(), prod2.getId() };
List<ActivationKey> keys = new ArrayList<>();
ActivationKey key1 = new ActivationKey("key1", owner);
keys.add(key1);
key1.addProduct(prod2);
key1.setAutoAttach(true);
Consumer consumer = new Consumer("sys.example.com", null, null, system);
Set<ConsumerInstalledProduct> cips = new HashSet<>();
ConsumerInstalledProduct cip = new ConsumerInstalledProduct(consumer, prod1);
cips.add(cip);
consumer.setInstalledProducts(cips);
AutobindData ad = new AutobindData(consumer, owner).forProducts(prodIds);
consumerBindUtil.handleActivationKeys(consumer, keys, false);
verify(entitler).bindByProducts(eq(ad));
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class ConsumerBindUtilTest method registerPassWhenAutobindDisabledForOwnerAndKeyHasAutobindEnabled.
@Test
public void registerPassWhenAutobindDisabledForOwnerAndKeyHasAutobindEnabled() throws Exception {
List<ActivationKey> keys = new ArrayList<>();
ActivationKey key1 = new ActivationKey("key1", owner);
key1.setAutoAttach(true);
keys.add(key1);
Product prod1 = TestUtil.createProduct();
Pool pool1 = TestUtil.createPool(owner, prod1, 5);
pool1.setId("pool1");
key1.addPool(pool1, 10L);
Consumer consumer = new Consumer("sys.example.com", null, null, system);
when(entitler.bindByPoolQuantity(eq(consumer), eq(pool1.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
consumerBindUtil.handleActivationKeys(consumer, keys, true);
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class EntitlementImporterTest method fullImport.
@Test
public void fullImport() throws Exception {
Product parentProduct = TestUtil.createProduct();
Product derivedProduct = TestUtil.createProduct();
Product provided1 = TestUtil.createProduct();
Set<Product> providedProducts = new HashSet<>();
providedProducts.add(new Product(provided1));
Product derivedProvided1 = TestUtil.createProduct();
Set<Product> derivedProvidedProducts = new HashSet<>();
derivedProvidedProducts.add(new Product(derivedProvided1));
Pool pool = TestUtil.createPool(owner, parentProduct, new HashSet<>(), derivedProduct, new HashSet<>(), 3);
pool.setProvidedProducts(providedProducts);
pool.setDerivedProvidedProducts(derivedProvidedProducts);
Entitlement ent = TestUtil.createEntitlement(owner, consumer, pool, cert);
ent.setQuantity(3);
EntitlementDTO dtoEnt = this.translator.translate(ent, EntitlementDTO.class);
when(om.readValue(reader, EntitlementDTO.class)).thenReturn(dtoEnt);
// Create our expected products
Map<String, ProductDTO> productsById = buildProductCache(parentProduct, provided1, derivedProduct, derivedProvided1);
Subscription sub = importer.importObject(om, reader, owner, productsById, consumerDTO.getUuid(), meta);
assertEquals(pool.getId(), sub.getUpstreamPoolId());
assertEquals(consumer.getUuid(), sub.getUpstreamConsumerId());
assertEquals(ent.getId(), sub.getUpstreamEntitlementId());
assertEquals(owner, sub.getOwner());
assertEquals(ent.getStartDate(), sub.getStartDate());
assertEquals(ent.getEndDate(), sub.getEndDate());
assertEquals(pool.getAccountNumber(), sub.getAccountNumber());
assertEquals(pool.getContractNumber(), sub.getContractNumber());
assertEquals(pool.getOrderNumber(), sub.getOrderNumber());
assertEquals(ent.getQuantity().intValue(), sub.getQuantity().intValue());
assertEquals(parentProduct.toDTO(), sub.getProduct());
assertEquals(providedProducts.size(), sub.getProvidedProducts().size());
assertEquals(provided1.getId(), sub.getProvidedProducts().iterator().next().getId());
assertEquals(derivedProduct.toDTO(), sub.getDerivedProduct());
assertEquals(1, sub.getDerivedProvidedProducts().size());
assertEquals(derivedProvided1.getId(), sub.getDerivedProvidedProducts().iterator().next().getId());
assertNotNull(sub.getCertificate());
CertificateSerial serial = sub.getCertificate().getSerial();
assertEquals(cert.getSerial().isCollected(), serial.isCollected());
assertEquals(cert.getSerial().getExpiration(), serial.getExpiration());
assertEquals(cert.getSerial().getCreated(), serial.getCreated());
assertEquals(cert.getSerial().getUpdated(), serial.getUpdated());
assertEquals(sub.getCdn().getLabel(), meta.getCdnLabel());
}
Aggregations