Search in sources :

Example 71 with Owner

use of org.candlepin.model.Owner in project candlepin by candlepin.

the class EntitlementCertificateGeneratorTest method testNonLazyRegenerate.

@Test
public void testNonLazyRegenerate() throws Exception {
    Owner owner = TestUtil.createOwner("test-owner", "Test Owner");
    Product product = TestUtil.createProduct();
    Pool pool = TestUtil.createPool(owner, product);
    pool.setSourceSubscription(new SourceSubscription("source-sub-id", "master"));
    Map<String, EntitlementCertificate> entCerts = new HashMap<>();
    entCerts.put(pool.getId(), new EntitlementCertificate());
    when(this.mockEntCertAdapter.generateEntitlementCerts(any(Consumer.class), anyMapOf(String.class, PoolQuantity.class), anyMapOf(String.class, Entitlement.class), anyMapOf(String.class, Product.class), eq(true))).thenReturn(entCerts);
    Consumer consumer = TestUtil.createConsumer(owner);
    Entitlement entitlement = new Entitlement(pool, consumer, owner, 1);
    entitlement.setDirty(true);
    this.ecGenerator.regenerateCertificatesOf(entitlement, false);
    assertFalse(entitlement.isDirty());
    verify(this.mockEntCertAdapter).generateEntitlementCerts(eq(consumer), this.poolQuantityMapCaptor.capture(), this.entMapCaptor.capture(), this.productMapCaptor.capture(), eq(true));
    assertEquals(entitlement, this.entMapCaptor.getValue().get(pool.getId()));
    assertEquals(product, this.productMapCaptor.getValue().get(pool.getId()));
    verify(this.mockEventSink, times(1)).queueEvent(any(Event.class));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) Event(org.candlepin.audit.Event) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 72 with Owner

use of org.candlepin.model.Owner in project candlepin by candlepin.

the class ManifestManagerTest method ensureGenerateAsyncManifestDoesNotRefreshEntitlementsBeforeStartingJob.

@Test
public void ensureGenerateAsyncManifestDoesNotRefreshEntitlementsBeforeStartingJob() throws Exception {
    Owner owner = TestUtil.createOwner();
    Consumer consumer = this.createMockConsumer(owner, true);
    Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
    String webAppPrefix = "webapp-prefix";
    String apiUrl = "api-url";
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
    manager.generateManifestAsync(consumer.getUuid(), owner.getKey(), cdn.getLabel(), webAppPrefix, apiUrl, new HashMap<>());
    verify(poolManager, never()).regenerateDirtyEntitlements(anyCollection());
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) Cdn(org.candlepin.model.Cdn) Test(org.junit.Test)

Example 73 with Owner

use of org.candlepin.model.Owner in project candlepin by candlepin.

the class ManifestManagerTest method testImportStoredManifest.

@Test
public void testImportStoredManifest() throws Exception {
    Owner owner = TestUtil.createOwner();
    String fileId = "1234";
    String filename = "manifest.zip";
    ConflictOverrides overrides = new ConflictOverrides(Conflict.DISTRIBUTOR_CONFLICT);
    ManifestFile manifest = mock(ManifestFile.class);
    when(manifest.getId()).thenReturn(fileId);
    when(fileService.get(eq(fileId))).thenReturn(manifest);
    manager.importStoredManifest(owner, fileId, overrides, filename);
    verify(importer).loadStoredExport(eq(manifest), eq(owner), eq(overrides), eq(filename));
    verify(fileService).delete(fileId);
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) Owner(org.candlepin.model.Owner) ManifestFile(org.candlepin.sync.file.ManifestFile) Test(org.junit.Test)

Example 74 with Owner

use of org.candlepin.model.Owner in project candlepin by candlepin.

the class ManifestManagerTest method verifyConsumerIsDistributorBeforeSchedulingManifestGeneration.

@Test
public void verifyConsumerIsDistributorBeforeSchedulingManifestGeneration() throws Exception {
    Owner owner = TestUtil.createOwner();
    Consumer consumer = this.createMockConsumer(owner, false);
    ConsumerType ctype = consumerTypeCurator.getConsumerType(consumer);
    Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
    String webAppPrefix = "webapp-prefix";
    String apiUrl = "api-url";
    Map<String, String> extData = new HashMap<>();
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
    try {
        manager.generateManifestAsync(consumer.getUuid(), owner.getKey(), cdn.getLabel(), webAppPrefix, apiUrl, extData);
        fail("Expected ForbiddenException not thrown");
    } catch (Exception e) {
        assertTrue(e instanceof ForbiddenException);
        String expectedMsg = String.format("Unit %s cannot be exported. A manifest cannot be made for " + "units of type \"%s\".", consumer.getUuid(), ctype.getLabel());
        assertEquals(e.getMessage(), expectedMsg);
    }
}
Also used : Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) ConsumerType(org.candlepin.model.ConsumerType) Cdn(org.candlepin.model.Cdn) NotFoundException(org.candlepin.common.exceptions.NotFoundException) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) BadRequestException(org.candlepin.common.exceptions.BadRequestException) Test(org.junit.Test)

Example 75 with Owner

use of org.candlepin.model.Owner in project candlepin by candlepin.

the class OwnerManagerTest method testContentAccessSetEmpty.

@Test
public void testContentAccessSetEmpty() {
    Owner owner = new Owner();
    when(ownerCurator.lockAndLoad(eq(owner))).thenReturn(owner);
    when(ownerServiceAdapter.getContentAccessModeList(eq(owner.getKey()))).thenReturn("");
    when(ownerServiceAdapter.getContentAccessMode(eq(owner.getKey()))).thenReturn("");
    ownerManager.refreshContentAccessMode(ownerServiceAdapter, owner);
    Assert.assertEquals(owner.getContentAccessModeList(), ContentAccessCertServiceAdapter.DEFAULT_CONTENT_ACCESS_MODE);
    Assert.assertEquals(owner.getContentAccessMode(), ContentAccessCertServiceAdapter.DEFAULT_CONTENT_ACCESS_MODE);
}
Also used : Owner(org.candlepin.model.Owner) Test(org.junit.Test)

Aggregations

Owner (org.candlepin.model.Owner)405 Test (org.junit.Test)254 Product (org.candlepin.model.Product)153 Consumer (org.candlepin.model.Consumer)127 Pool (org.candlepin.model.Pool)79 Date (java.util.Date)72 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)71 ArrayList (java.util.ArrayList)58 Produces (javax.ws.rs.Produces)52 ConsumerType (org.candlepin.model.ConsumerType)52 ApiOperation (io.swagger.annotations.ApiOperation)50 HashSet (java.util.HashSet)44 Entitlement (org.candlepin.model.Entitlement)44 Path (javax.ws.rs.Path)42 HashMap (java.util.HashMap)41 ApiResponses (io.swagger.annotations.ApiResponses)40 Content (org.candlepin.model.Content)39 BadRequestException (org.candlepin.common.exceptions.BadRequestException)37 Subscription (org.candlepin.model.dto.Subscription)32 List (java.util.List)29