Search in sources :

Example 6 with Cdn

use of org.candlepin.model.Cdn 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 7 with Cdn

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

the class ManifestManagerTest method testGenerateManifest.

@Test
public void testGenerateManifest() throws Exception {
    Consumer consumer = this.createMockConsumer(true);
    Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
    String webAppPrefix = "webapp-prefix";
    String apiUrl = "api-url";
    Map<String, String> extData = new HashMap<>();
    Event event = mock(Event.class);
    when(eventFactory.exportCreated(eq(consumer))).thenReturn(event);
    List<Entitlement> ents = new ArrayList<>();
    when(entitlementCurator.listByConsumer(eq(consumer))).thenReturn(ents);
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
    File manifestFile = mock(File.class);
    when(exporter.getFullExport(eq(consumer), eq(cdn.getLabel()), eq(webAppPrefix), eq(apiUrl), eq(extData))).thenReturn(manifestFile);
    File result = manager.generateManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, extData);
    assertEquals(manifestFile, result);
    verify(entitlementCurator).listByConsumer(eq(consumer));
    verify(exporter).getFullExport(eq(consumer), eq(cdn.getLabel()), eq(webAppPrefix), eq(apiUrl), eq(extData));
    verify(eventFactory).exportCreated(eq(consumer));
    verify(eventSink).queueEvent(eq(event));
    verifyZeroInteractions(fileService);
}
Also used : Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Event(org.candlepin.audit.Event) Cdn(org.candlepin.model.Cdn) Entitlement(org.candlepin.model.Entitlement) ManifestFile(org.candlepin.sync.file.ManifestFile) File(java.io.File) Test(org.junit.Test)

Example 8 with Cdn

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

the class ManifestManagerTest method ensureEventSentWhenManifestGeneratedAndStored.

@Test
public void ensureEventSentWhenManifestGeneratedAndStored() throws Exception {
    Consumer consumer = this.createMockConsumer(true);
    Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
    String webAppPrefix = "webapp-prefix";
    String apiUrl = "api-url";
    Event event = mock(Event.class);
    when(eventFactory.exportCreated(eq(consumer))).thenReturn(event);
    UserPrincipal principal = TestUtil.createOwnerPrincipal();
    when(principalProvider.get()).thenReturn(principal);
    ManifestFile manifest = mock(ManifestFile.class);
    when(fileService.store(eq(ManifestFileType.EXPORT), any(File.class), eq(principal.getName()), any(String.class))).thenReturn(manifest);
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
    manager.generateAndStoreManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, new HashMap<>());
    verify(eventFactory).exportCreated(eq(consumer));
    verify(eventSink).queueEvent(eq(event));
}
Also used : Consumer(org.candlepin.model.Consumer) Event(org.candlepin.audit.Event) Cdn(org.candlepin.model.Cdn) ManifestFile(org.candlepin.sync.file.ManifestFile) File(java.io.File) UserPrincipal(org.candlepin.auth.UserPrincipal) ManifestFile(org.candlepin.sync.file.ManifestFile) Test(org.junit.Test)

Example 9 with Cdn

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

the class ManifestManagerTest method ensureEventSentOnManifestGeneration.

@Test
public void ensureEventSentOnManifestGeneration() throws Exception {
    Consumer consumer = this.createMockConsumer(true);
    Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
    String webAppPrefix = "webapp-prefix";
    String apiUrl = "api-url";
    Event event = mock(Event.class);
    when(eventFactory.exportCreated(eq(consumer))).thenReturn(event);
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
    manager.generateManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, new HashMap<>());
    verify(eventFactory).exportCreated(eq(consumer));
    verify(eventSink).queueEvent(eq(event));
}
Also used : Consumer(org.candlepin.model.Consumer) Event(org.candlepin.audit.Event) Cdn(org.candlepin.model.Cdn) Test(org.junit.Test)

Example 10 with Cdn

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

the class ManifestManagerTest method verifyConsumerIsDistributorBeforeGeneratingManifest.

@Test
public void verifyConsumerIsDistributorBeforeGeneratingManifest() throws Exception {
    Consumer consumer = this.createMockConsumer(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.generateManifest(consumer.getUuid(), 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 : 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)

Aggregations

Cdn (org.candlepin.model.Cdn)26 Test (org.junit.Test)16 Consumer (org.candlepin.model.Consumer)11 HashMap (java.util.HashMap)7 Owner (org.candlepin.model.Owner)7 File (java.io.File)5 BadRequestException (org.candlepin.common.exceptions.BadRequestException)5 ArrayList (java.util.ArrayList)4 Event (org.candlepin.audit.Event)4 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)4 NotFoundException (org.candlepin.common.exceptions.NotFoundException)4 CertificateSerial (org.candlepin.model.CertificateSerial)4 ConsumerType (org.candlepin.model.ConsumerType)4 Entitlement (org.candlepin.model.Entitlement)4 ManifestFile (org.candlepin.sync.file.ManifestFile)3 ApiOperation (io.swagger.annotations.ApiOperation)2 Reader (java.io.Reader)2 Date (java.util.Date)2 Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2