use of org.candlepin.model.UeberCertificate in project candlepin by candlepin.
the class OwnerResourceTest method testCreateUeberCertificateFromScratch.
@Test
public void testCreateUeberCertificateFromScratch() {
Principal principal = setupPrincipal(owner, Access.ALL);
Owner owner = TestUtil.createOwner();
UeberCertificate entCert = mock(UeberCertificate.class);
OwnerCurator oc = mock(OwnerCurator.class);
ProductCurator pc = mock(ProductCurator.class);
ConsumerCurator cc = mock(ConsumerCurator.class);
EntitlementCurator ec = mock(EntitlementCurator.class);
CandlepinPoolManager cpm = mock(CandlepinPoolManager.class);
EntitlementCertificateCurator ecc = mock(EntitlementCertificateCurator.class);
UeberCertificateCurator uc = mock(UeberCertificateCurator.class);
UeberCertificateGenerator ucg = mock(UeberCertificateGenerator.class);
OwnerResource resource = new OwnerResource(oc, pc, null, cc, i18n, null, null, null, null, null, cpm, null, null, null, null, null, ecc, ec, uc, ucg, null, null, null, null, null, null, null, null, null, this.modelTranslator);
when(oc.lookupByKey(eq("admin"))).thenReturn(owner);
when(ucg.generate(eq(owner.getKey()), eq(principal))).thenReturn(entCert);
UeberCertificate result = resource.createUeberCertificate(principal, owner.getKey());
assertEquals(entCert, result);
}
use of org.candlepin.model.UeberCertificate in project candlepin by candlepin.
the class OwnerResourceTest method testComplexDeleteOwner.
@Test
public void testComplexDeleteOwner() throws Exception {
// Create some consumers:
Consumer c1 = createConsumer(owner);
Consumer c2 = createConsumer(owner);
// Create a pool for this owner:
Pool pool = TestUtil.createPool(owner, product);
poolCurator.create(pool);
// Give those consumers entitlements:
Map<String, Integer> pQs = new HashMap<>();
pQs.put(pool.getId(), 1);
poolManager.entitleByPools(c1, pQs);
assertEquals(2, consumerCurator.listByOwner(owner).list().size());
assertEquals(1, poolCurator.listByOwner(owner).list().size());
assertEquals(1, entitlementCurator.listByOwner(owner).list().size());
// Generate an ueber certificate for the Owner. This will need to
// be cleaned up along with the owner deletion.
UeberCertificate uCert = ueberCertGenerator.generate(owner.getKey(), setupAdminPrincipal("test"));
assertNotNull(uCert);
ownerResource.deleteOwner(owner.getKey(), true, false);
assertEquals(0, consumerCurator.listByOwner(owner).list().size());
assertNull(consumerCurator.findByUuid(c1.getUuid()));
assertNull(consumerCurator.findByUuid(c2.getUuid()));
assertEquals(0, poolCurator.listByOwner(owner).list().size());
assertEquals(0, entitlementCurator.listByOwner(owner).list().size());
assertNull(ueberCertCurator.findForOwner(owner));
}
use of org.candlepin.model.UeberCertificate in project candlepin by candlepin.
the class UndoImportsJobTest method testUndoImport.
@Test
public void testUndoImport() throws JobExecutionException, IOException, ImporterException {
// We need proper curators for this test
this.poolManager = this.poolManagerBase;
this.ownerCurator = super.ownerCurator;
this.exportCurator = this.exportCuratorBase;
this.undoImportsJob = new UndoImportsJob(this.i18n, this.ownerCurator, this.poolManager, this.subAdapter, this.exportCurator, this.importRecordCurator);
// Create owner w/upstream consumer
Owner owner1 = TestUtil.createOwner();
Owner owner2 = TestUtil.createOwner();
ConsumerType type = this.createConsumerType();
UpstreamConsumer uc1 = new UpstreamConsumer("uc1", null, type, "uc1");
UpstreamConsumer uc2 = new UpstreamConsumer("uc2", null, type, "uc2");
this.ownerCurator.create(owner1);
this.ownerCurator.create(owner2);
owner1.setUpstreamConsumer(uc1);
owner1.setUpstreamConsumer(uc2);
this.ownerCurator.merge(owner1);
this.ownerCurator.merge(owner2);
// Create metadata
ExporterMetadata metadata1 = new ExporterMetadata(ExporterMetadata.TYPE_PER_USER, new Date(), owner1);
ExporterMetadata metadata2 = new ExporterMetadata(ExporterMetadata.TYPE_PER_USER, new Date(), owner2);
this.exportCurator.create(metadata1);
this.exportCurator.create(metadata2);
// Create pools w/upstream pool IDs
Pool pool1 = this.createPool("pool1", owner1, true, PoolType.NORMAL);
Pool pool2 = this.createPool("pool2", owner1, true, PoolType.BONUS);
Pool pool3 = this.createPool("pool3", owner1, false, PoolType.NORMAL);
Pool pool4 = this.createPool("pool4", owner1, false, PoolType.BONUS);
Pool pool5 = this.createPool("pool5", owner1, true, PoolType.ENTITLEMENT_DERIVED);
Pool pool6 = this.createPool("pool6", owner1, false, PoolType.ENTITLEMENT_DERIVED);
Pool pool7 = this.createPool("pool7", owner2, true, PoolType.NORMAL);
Pool pool8 = this.createPool("pool8", owner2, true, PoolType.BONUS);
Pool pool9 = this.createPool("pool9", owner2, true, PoolType.ENTITLEMENT_DERIVED);
// Create an ueber certificate for the owner.
UeberCertificate uebercert = ueberCertGenerator.generate(owner1.getKey(), this.setupAdminPrincipal("test_admin"));
assertNotNull(uebercert);
// Verify initial state
assertEquals(Arrays.asList(pool1, pool2, pool3, pool4, pool5, pool6), this.poolManager.listPoolsByOwner(owner1).list());
assertEquals(Arrays.asList(pool7, pool8, pool9), this.poolManager.listPoolsByOwner(owner2).list());
assertEquals(metadata1, exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner1));
assertEquals(metadata2, exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner2));
assertEquals(0, this.importRecordCurator.findRecords(owner1).list().size());
assertEquals(0, this.importRecordCurator.findRecords(owner2).list().size());
// Execute job
Principal principal = new UserPrincipal("JarJarBinks", null, true);
this.jobDataMap.put(JobStatus.TARGET_TYPE, JobStatus.TargetType.OWNER);
this.jobDataMap.put(JobStatus.TARGET_ID, owner1.getId());
this.jobDataMap.put(UndoImportsJob.OWNER_KEY, owner1.getKey());
this.jobDataMap.put(PinsetterJobListener.PRINCIPAL_KEY, principal);
// since we locking owner we need start transaction
beginTransaction();
this.undoImportsJob.toExecute(this.jobContext);
commitTransaction();
// Verify deletions -- Ueber pools should not get deleted.
assertEquals(Arrays.asList(pool3, pool4, pool5, pool6), this.poolManager.listPoolsByOwner(owner1).list());
assertEquals(Arrays.asList(pool7, pool8, pool9), this.poolManager.listPoolsByOwner(owner2).list());
assertNull(exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner1));
assertEquals(metadata2, exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner2));
assertNull(owner1.getUpstreamConsumer());
List<ImportRecord> records = this.importRecordCurator.findRecords(owner1).list();
assertEquals(1, records.size());
assertEquals(ImportRecord.Status.DELETE, records.get(0).getStatus());
assertEquals(0, this.importRecordCurator.findRecords(owner2).list().size());
}
use of org.candlepin.model.UeberCertificate in project candlepin by candlepin.
the class OwnerResourceUeberCertOperationsTest method testUeberCertIsRegeneratedOnNextInvocation.
@Test
public void testUeberCertIsRegeneratedOnNextInvocation() throws Exception {
UeberCertificate firstCert = or.createUeberCertificate(principal, owner.getKey());
UeberCertificate secondCert = or.createUeberCertificate(principal, owner.getKey());
assertTrue(firstCert.getId() != secondCert.getId());
}
use of org.candlepin.model.UeberCertificate in project candlepin by candlepin.
the class OwnerResource method getUeberCertificate.
/**
* Retrieves the Ueber Entitlement Certificate
*
* @return an EntitlementCertificate object
* @httpcode 404
* @httpcode 200
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{owner_key}/uebercert")
@ApiOperation(notes = "Retrieves the Ueber Entitlement Certificate", value = "Get Ueber Entitlement Certificate")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public UeberCertificate getUeberCertificate(@Context Principal principal, @Verify(Owner.class) @PathParam("owner_key") String ownerKey) {
Owner owner = this.findOwnerByKey(ownerKey);
UeberCertificate ueberCert = ueberCertCurator.findForOwner(owner);
if (ueberCert == null) {
throw new NotFoundException(i18n.tr("uber certificate for owner {0} was not found. Please generate one.", owner.getKey()));
}
return ueberCert;
}
Aggregations