use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method mockEntitlement.
private Entitlement mockEntitlement(Owner owner, Consumer consumer, Product product, DateRange range, Product... providedProducts) {
Set<Product> provided = new HashSet<>();
for (Product pp : providedProducts) {
provided.add(pp);
}
final Pool p = new Pool(owner, product, provided, new Long(1000), range.getStartDate(), range.getEndDate(), "1000", "1000", "1000");
p.setId("" + lastPoolId++);
Entitlement e = new Entitlement(p, consumer, owner, 1);
when(poolCurator.provides(p, product.getId())).thenReturn(true);
for (Product pp : providedProducts) {
when(poolCurator.provides(p, pp.getId())).thenReturn(true);
}
Random gen = new Random();
int id = gen.nextInt(Integer.MAX_VALUE);
e.setId(String.valueOf(id));
return e;
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class OwnerResourceTest method createEntitlementWithQ.
/**
* @param pool
* @param owner
* @param consumer
* @return
*/
private Entitlement createEntitlementWithQ(Pool pool, Owner owner, Consumer consumer, int quantity, String date) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Entitlement e1 = createEntitlement(owner, consumer, pool, null);
e1.setQuantity(quantity);
pool.getEntitlements().add(e1);
this.entitlementCurator.create(e1);
e1.getPool().setConsumed(e1.getPool().getConsumed() + quantity);
this.poolCurator.merge(e1.getPool());
e1.setCreated(dateFormat.parse(date));
this.entitlementCurator.merge(e1);
return e1;
}
use of org.candlepin.model.Entitlement 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());
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class ImporterTest method testReturnsSubscriptionsFromManifest.
@Test
public void testReturnsSubscriptionsFromManifest() throws IOException, ImporterException {
Owner owner = new Owner("admin", "Admin Owner");
ExporterMetadataCurator emc = mock(ExporterMetadataCurator.class);
when(emc.lookupByTypeAndOwner("per_user", owner)).thenReturn(null);
ConsumerType stype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
stype.setId("test-ctype");
when(consumerTypeCurator.lookupByLabel(eq("system"))).thenReturn(stype);
when(consumerTypeCurator.find(eq(stype.getId()))).thenReturn(stype);
OwnerCurator oc = mock(OwnerCurator.class);
when(oc.lookupWithUpstreamUuid(any(String.class))).thenReturn(null);
PoolManager pm = mock(PoolManager.class);
Refresher refresher = mock(Refresher.class);
when(pm.getRefresher(any(SubscriptionServiceAdapter.class), any(OwnerServiceAdapter.class))).thenReturn(refresher);
Map<String, File> importFiles = new HashMap<>();
File ruleDir = mock(File.class);
File[] rulesFiles = createMockJsFile(mockJsPath);
when(ruleDir.listFiles()).thenReturn(rulesFiles);
File actualmeta = createFile("meta.json", "0.0.3", new Date(), "test_user", "prefix");
importFiles.put(ImportFile.META.fileName(), actualmeta);
ConsumerDTO consumerDTO = new ConsumerDTO();
consumerDTO.setUuid("eb5e04bf-be27-44cf-abe3-0c0b1edd523e");
consumerDTO.setName("mymachine");
ConsumerTypeDTO typeDTO = new ConsumerTypeDTO();
typeDTO.setLabel("candlepin");
typeDTO.setManifest(true);
consumerDTO.setType(typeDTO);
consumerDTO.setUrlWeb("foo.example.com/subscription");
consumerDTO.setUrlApi("/candlepin");
consumerDTO.setContentAccessMode("");
OwnerDTO ownerDTO = new OwnerDTO();
ownerDTO.setKey("admin");
ownerDTO.setDisplayName("Admin Owner");
consumerDTO.setOwner(ownerDTO);
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
ctype.setId("test-ctype");
when(consumerTypeCurator.lookupByLabel(eq("candlepin"))).thenReturn(ctype);
when(consumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
File consumerFile = new File(folder.getRoot(), "consumer.json");
mapper.writeValue(consumerFile, consumerDTO);
importFiles.put(ImportFile.CONSUMER.fileName(), consumerFile);
File cTypes = mock(File.class);
when(cTypes.listFiles()).thenReturn(new File[] {});
importFiles.put(ImportFile.CONSUMER_TYPE.fileName(), cTypes);
Product prod = new Product("prodId", "prodTest", null);
prod.setDependentProductIds(null);
File prodFile = new File(folder.getRoot(), "product.json");
mapper.writeValue(prodFile, prod);
File products = mock(File.class);
when(products.listFiles()).thenReturn(new File[] { prodFile });
importFiles.put(ImportFile.PRODUCTS.fileName(), products);
Entitlement ent = new Entitlement();
Pool pool = new Pool();
pool.setProduct(prod);
ent.setPool(pool);
ent.setQuantity(2);
File entFile = new File(folder.getRoot(), "entitlement.json");
mapper.writeValue(entFile, ent);
File entitlements = mock(File.class);
when(entitlements.listFiles()).thenReturn(new File[] { entFile });
importFiles.put(ImportFile.ENTITLEMENTS.fileName(), entitlements);
RulesImporter ri = mock(RulesImporter.class);
importFiles.put(ImportFile.RULES_FILE.fileName(), rulesFiles[0]);
ConflictOverrides co = mock(ConflictOverrides.class);
Importer i = new Importer(consumerTypeCurator, pc, ri, oc, null, null, pm, null, config, emc, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
List<Subscription> subscriptions = i.importObjects(owner, importFiles, co);
assertEquals(1, subscriptions.size());
assertEquals("prodId", subscriptions.get(0).getProduct().getId());
assertEquals(2, subscriptions.get(0).getQuantity().longValue());
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class ExporterTest method doNotExportDirtyEntitlements.
@Test(expected = ExportCreationException.class)
public void doNotExportDirtyEntitlements() throws Exception {
config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
Consumer consumer = mock(Consumer.class);
Entitlement ent = mock(Entitlement.class);
Principal principal = mock(Principal.class);
IdentityCertificate idcert = new IdentityCertificate();
List<Entitlement> entitlements = new ArrayList<>();
entitlements.add(ent);
when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
when(pprov.get()).thenReturn(principal);
when(principal.getUsername()).thenReturn("testUser");
when(ec.listByConsumer(consumer)).thenReturn(entitlements);
when(ent.isDirty()).thenReturn(true);
idcert.setSerial(new CertificateSerial(10L, new Date()));
idcert.setKey("euh0876puhapodifbvj094");
idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
idcert.setCreated(new Date());
idcert.setUpdated(new Date());
when(consumer.getIdCert()).thenReturn(idcert);
KeyPair keyPair = createKeyPair();
when(consumer.getKeyPair()).thenReturn(keyPair);
when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(Arrays.asList(new ConsumerType("system")).iterator());
when(ctc.listAll()).thenReturn(cqmock);
Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator);
e.getFullExport(consumer);
}
Aggregations