Search in sources :

Example 1 with UeberCertificate

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);
}
Also used : EntitlementCurator(org.candlepin.model.EntitlementCurator) OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) UeberCertificate(org.candlepin.model.UeberCertificate) ProductCurator(org.candlepin.model.ProductCurator) UeberCertificateCurator(org.candlepin.model.UeberCertificateCurator) EntitlementCertificateCurator(org.candlepin.model.EntitlementCertificateCurator) UeberCertificateGenerator(org.candlepin.model.UeberCertificateGenerator) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) ConsumerCurator(org.candlepin.model.ConsumerCurator) CandlepinPoolManager(org.candlepin.controller.CandlepinPoolManager) Test(org.junit.Test)

Example 2 with UeberCertificate

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));
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) UeberCertificate(org.candlepin.model.UeberCertificate) HashMap(java.util.HashMap) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 3 with UeberCertificate

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());
}
Also used : Owner(org.candlepin.model.Owner) UeberCertificate(org.candlepin.model.UeberCertificate) ExporterMetadata(org.candlepin.model.ExporterMetadata) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 4 with UeberCertificate

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());
}
Also used : UeberCertificate(org.candlepin.model.UeberCertificate) Test(org.junit.Test)

Example 5 with UeberCertificate

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;
}
Also used : Owner(org.candlepin.model.Owner) UeberCertificate(org.candlepin.model.UeberCertificate) NotFoundException(org.candlepin.common.exceptions.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

UeberCertificate (org.candlepin.model.UeberCertificate)7 Test (org.junit.Test)6 Owner (org.candlepin.model.Owner)4 Principal (org.candlepin.auth.Principal)3 UserPrincipal (org.candlepin.auth.UserPrincipal)3 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)2 CandlepinPoolManager (org.candlepin.controller.CandlepinPoolManager)2 ConsumerCurator (org.candlepin.model.ConsumerCurator)2 EntitlementCertificateCurator (org.candlepin.model.EntitlementCertificateCurator)2 EntitlementCurator (org.candlepin.model.EntitlementCurator)2 OwnerCurator (org.candlepin.model.OwnerCurator)2 Pool (org.candlepin.model.Pool)2 ProductCurator (org.candlepin.model.ProductCurator)2 UeberCertificateCurator (org.candlepin.model.UeberCertificateCurator)2 UeberCertificateGenerator (org.candlepin.model.UeberCertificateGenerator)2 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1