use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class ExporterTest method exportProducts.
@SuppressWarnings("unchecked")
@Test
public void exportProducts() throws Exception {
config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
Consumer consumer = mock(Consumer.class);
Entitlement ent = mock(Entitlement.class);
Pool pool = mock(Pool.class);
Rules mrules = mock(Rules.class);
Principal principal = mock(Principal.class);
IdentityCertificate idcert = new IdentityCertificate();
Set<Entitlement> entitlements = new HashSet<>();
entitlements.add(ent);
Owner owner = TestUtil.createOwner("Example-Corporation");
Product prod = TestUtil.createProduct("12345", "RHEL Product");
prod.setMultiplier(1L);
prod.setCreated(new Date());
prod.setUpdated(new Date());
prod.setAttributes(Collections.<String, String>emptyMap());
Product prod1 = TestUtil.createProduct("MKT-prod", "RHEL Product");
prod1.setMultiplier(1L);
prod1.setCreated(new Date());
prod1.setUpdated(new Date());
prod1.setAttributes(Collections.<String, String>emptyMap());
Product subProduct = TestUtil.createProduct("MKT-sub-prod", "Sub Product");
subProduct.setMultiplier(1L);
subProduct.setCreated(new Date());
subProduct.setUpdated(new Date());
subProduct.setAttributes(Collections.<String, String>emptyMap());
Product subProvidedProduct = TestUtil.createProduct("332211", "Sub Product");
subProvidedProduct.setMultiplier(1L);
subProvidedProduct.setCreated(new Date());
subProvidedProduct.setUpdated(new Date());
subProvidedProduct.setAttributes(Collections.<String, String>emptyMap());
ProductCertificate pcert = new ProductCertificate();
pcert.setKey("euh0876puhapodifbvj094");
pcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
pcert.setCreated(new Date());
pcert.setUpdated(new Date());
Set<Product> ppset = new HashSet<>();
ppset.add(prod);
Set<Product> sppSet = new HashSet<>();
sppSet.add(subProvidedProduct);
when(pool.getId()).thenReturn("MockedPoolId");
when(pool.getProvidedProducts()).thenReturn(ppset);
when(pc.getPoolProvidedProductsCached(pool)).thenReturn(ppset);
when(pool.getProduct()).thenReturn(prod1);
when(pool.getDerivedProvidedProducts()).thenReturn(sppSet);
when(pc.getPoolDerivedProvidedProductsCached(pool)).thenReturn(sppSet);
when(pool.getDerivedProduct()).thenReturn(subProduct);
when(ent.getPool()).thenReturn(pool);
when(mrules.getRules()).thenReturn("foobar");
when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
when(rc.getRules()).thenReturn(mrules);
when(consumer.getEntitlements()).thenReturn(entitlements);
when(psa.getProductCertificate(any(Owner.class), any(String.class))).thenReturn(pcert);
when(pprov.get()).thenReturn(principal);
when(principal.getUsername()).thenReturn("testUser");
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);
CandlepinQuery emptyIteratorMock = mock(CandlepinQuery.class);
when(emptyIteratorMock.iterate()).thenReturn(new MockResultIterator(Arrays.asList().iterator()));
when(emptyIteratorMock.iterator()).thenReturn(Arrays.asList().iterator());
when(cdnc.listAll()).thenReturn(emptyIteratorMock);
when(ctc.listAll()).thenReturn(emptyIteratorMock);
// FINALLY test this badboy
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);
File export = e.getFullExport(consumer);
// VERIFY
assertNotNull(export);
verifyContent(export, "export/products/12345.pem", new VerifyProductCert("12345.pem"));
assertFalse(verifyHasEntry(export, "export/products/MKT-prod.pem"));
verifyContent(export, "export/products/332211.pem", new VerifyProductCert("332211.pem"));
assertFalse(verifyHasEntry(export, "export/products/MKT-sub-prod.pem"));
FileUtils.deleteDirectory(export.getParentFile());
assertTrue(new File("/tmp/consumer_export.zip").delete());
assertTrue(new File("/tmp/12345.pem").delete());
assertTrue(new File("/tmp/332211.pem").delete());
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class ExporterTest method exportMetadata.
@Test
public void exportMetadata() throws ExportCreationException, IOException {
config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
Date start = new Date();
Rules mrules = mock(Rules.class);
Consumer consumer = mock(Consumer.class);
Principal principal = mock(Principal.class);
IdentityCertificate idcert = new IdentityCertificate();
when(mrules.getRules()).thenReturn("foobar");
when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
when(rc.getRules()).thenReturn(mrules);
when(pprov.get()).thenReturn(principal);
when(principal.getUsername()).thenReturn("testUser");
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);
CandlepinQuery emptyIteratorMock = mock(CandlepinQuery.class);
when(emptyIteratorMock.iterate()).thenReturn(new MockResultIterator(Arrays.asList().iterator()));
when(cdnc.listAll()).thenReturn(emptyIteratorMock);
// FINALLY test this badboy
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);
File export = e.getFullExport(consumer);
// VERIFY
assertNotNull(export);
assertTrue(export.exists());
verifyContent(export, "export/meta.json", new VerifyMetadata(start));
// cleanup the mess
FileUtils.deleteDirectory(export.getParentFile());
assertTrue(new File("/tmp/consumer_export.zip").delete());
assertTrue(new File("/tmp/meta.json").delete());
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class EntitlementCertificateGeneratorTest method testLazyRegnerateForEnvironmentContent.
@Test
public void testLazyRegnerateForEnvironmentContent() {
Environment environment = new Environment();
List<Entitlement> entitlements = this.generateEntitlements();
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(entitlements.iterator());
when(this.mockEntitlementCurator.listByEnvironment(environment)).thenReturn(cqmock);
this.ecGenerator.regenerateCertificatesOf(environment, Arrays.asList("c1", "c2", "c4"), true);
assertTrue(entitlements.get(0).isDirty());
assertTrue(entitlements.get(1).isDirty());
assertFalse(entitlements.get(2).isDirty());
verifyZeroInteractions(this.mockEntCertAdapter);
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class PoolManagerTest method testFind.
@Test
public void testFind() {
List<Pool> pools = new ArrayList<>();
List<String> ids = new ArrayList<>();
for (int i = 0; i < 5; i++) {
pools.add(TestUtil.createPool(owner, product));
pools.get(i).setId("id" + i);
ids.add("id" + i);
}
Class<List<String>> listClass = (Class<List<String>>) (Class) ArrayList.class;
ArgumentCaptor<List<String>> poolsArg = ArgumentCaptor.forClass(listClass);
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(pools);
when(mockPoolCurator.listAllByIds(poolsArg.capture())).thenReturn(cqmock);
List<Pool> found = manager.secureFind(ids);
List<String> argument = poolsArg.getValue();
assertEquals(pools, found);
assertEquals(argument, ids);
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class PoolManagerTest method testRefreshPoolsRemovesExpiredSubscriptionsAlongWithItsPoolsAndEnts.
@Test
public void testRefreshPoolsRemovesExpiredSubscriptionsAlongWithItsPoolsAndEnts() {
PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
Date expiredStart = TestUtil.createDate(2004, 5, 5);
Date expiredDate = TestUtil.createDate(2005, 5, 5);
List<Subscription> subscriptions = new ArrayList<>();
Owner owner = this.getOwner();
Product product = TestUtil.createProduct();
Subscription sub = TestUtil.createSubscription(owner, product);
sub.setStartDate(expiredStart);
sub.setEndDate(expiredDate);
sub.setId("123");
subscriptions.add(sub);
mockSubsList(subscriptions);
List<Pool> pools = new ArrayList<>();
Pool p = TestUtil.createPool(owner, product);
p.setId("test-pool");
p.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
p.setStartDate(expiredStart);
p.setEndDate(expiredDate);
p.setConsumed(1L);
pools.add(p);
when(mockPoolCurator.lockAndLoadByIds(anyCollection())).thenReturn(pools);
mockPoolsList(pools);
List<Entitlement> poolEntitlements = new ArrayList<>();
Entitlement ent = TestUtil.createEntitlement();
ent.setId("test-ent");
ent.setPool(p);
ent.setQuantity(1);
poolEntitlements.add(ent);
p.getEntitlements().addAll(poolEntitlements);
when(mockPoolCurator.getEntitlementIdsForPools(anyCollection())).thenReturn(Arrays.asList(ent.getId()));
CandlepinQuery<Entitlement> cqmockEnt = mock(CandlepinQuery.class);
when(cqmockEnt.list()).thenReturn(poolEntitlements);
when(cqmockEnt.iterator()).thenReturn(poolEntitlements.iterator());
when(entitlementCurator.listAllByIds(anyCollection())).thenReturn(cqmockEnt);
ValidationResult result = new ValidationResult();
when(preHelper.getResult()).thenReturn(result);
when(mockOwnerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
this.mockProducts(owner, product);
this.mockProductImport(owner, product);
this.mockContentImport(owner, new Content[] {});
CandlepinQuery<Pool> cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(pools);
when(cqmock.iterator()).thenReturn(pools.iterator());
when(mockPoolCurator.listByOwnerAndType(eq(owner), any(PoolType.class))).thenReturn(cqmock);
cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(Collections.<Pool>emptyList());
when(mockPoolCurator.getPoolsBySubscriptionIds(anyList())).thenReturn(cqmock);
this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
verify(mockPoolCurator).batchDelete(eq(pools), anyCollectionOf(String.class));
verify(entitlementCurator).batchDelete(eq(poolEntitlements));
}
Aggregations