Search in sources :

Example 16 with Cdn

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

the class EntitlementImporterTest method init.

@Before
public void init() {
    this.owner = new Owner();
    this.translator = new StandardTranslator(mockConsumerTypeCurator, mockEnvironmentCurator, ownerCurator);
    i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    this.importer = new EntitlementImporter(certSerialCurator, cdnCurator, i18n, mockProductCurator, ec, translator);
    ConsumerType ctype = TestUtil.createConsumerType();
    ctype.setId("test-ctype");
    consumer = TestUtil.createConsumer(ctype, owner);
    consumerDTO = this.translator.translate(consumer, ConsumerDTO.class);
    consumerDTO.setUrlWeb("");
    consumerDTO.setUrlApi("");
    when(this.mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    when(this.mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    cert = createEntitlementCertificate("my-test-key", "my-cert");
    cert.setId("test-id");
    reader = mock(Reader.class);
    meta = new Meta();
    meta.setCdnLabel("test-cdn");
    testCdn = new Cdn("test-cdn", "Test CDN", "https://test.url.com");
    when(cdnCurator.lookupByLabel("test-cdn")).thenReturn(testCdn);
}
Also used : Owner(org.candlepin.model.Owner) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) Reader(java.io.Reader) ConsumerType(org.candlepin.model.ConsumerType) Cdn(org.candlepin.model.Cdn) StandardTranslator(org.candlepin.dto.StandardTranslator) Before(org.junit.Before)

Example 17 with Cdn

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

the class CdnManagerTest method deleteCdnUpdatesPoolAssociation.

@Test
public void deleteCdnUpdatesPoolAssociation() {
    Cdn cdn = createCdn("MyTestCdn");
    Owner owner = TestUtil.createOwner();
    ownerCurator.create(owner);
    Product product = createProduct(owner);
    Pool pool = createPool(owner, product);
    pool.setCdn(cdn);
    poolCurator.create(pool);
    assertNotNull(pool.getCdn());
    manager.deleteCdn(cdn);
    assertNull(curator.lookupByLabel(cdn.getLabel()));
    poolCurator.clear();
    Pool updatedPool = poolCurator.find(pool.getId());
    assertNull(updatedPool.getCdn());
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Cdn(org.candlepin.model.Cdn) Test(org.junit.Test)

Example 18 with Cdn

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

the class ManifestManagerTest method testGenerateAndStoreManifest.

@Test
public void testGenerateAndStoreManifest() 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);
    UserPrincipal principal = TestUtil.createOwnerPrincipal();
    when(principalProvider.get()).thenReturn(principal);
    String exportId = "export-id";
    ManifestFile manifest = mock(ManifestFile.class);
    when(manifest.getId()).thenReturn(exportId);
    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);
    List<Entitlement> ents = new ArrayList<>();
    when(entitlementCurator.listByConsumer(eq(consumer))).thenReturn(ents);
    ExportResult result = manager.generateAndStoreManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, extData);
    assertEquals(consumer.getUuid(), result.getExportedConsumer());
    assertEquals(exportId, result.getExportId());
    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));
    verify(fileService).delete(eq(ManifestFileType.EXPORT), eq(consumer.getUuid()));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cdn(org.candlepin.model.Cdn) UserPrincipal(org.candlepin.auth.UserPrincipal) ManifestFile(org.candlepin.sync.file.ManifestFile) Consumer(org.candlepin.model.Consumer) Event(org.candlepin.audit.Event) Entitlement(org.candlepin.model.Entitlement) ManifestFile(org.candlepin.sync.file.ManifestFile) File(java.io.File) ExportResult(org.candlepin.sync.ExportResult) Test(org.junit.Test)

Example 19 with Cdn

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

the class ManifestManagerTest method verifyCdnExistsBeforeGeneratingManifest.

@Test
public void verifyCdnExistsBeforeGeneratingManifest() 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";
    Map<String, String> extData = new HashMap<>();
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(null);
    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("A CDN with label %s does not exist on this system.", cdn.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) 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 20 with Cdn

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

the class ManifestManagerTest method ensureGenerateManifestRefreshesEnitlements.

@Test
public void ensureGenerateManifestRefreshesEnitlements() 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<>();
    extData.put("version", "1.0");
    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);
    manager.generateManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, extData);
    verify(poolManager).regenerateDirtyEntitlements(eq(ents));
    verify(exporter).getFullExport(eq(consumer), eq(cdn.getLabel()), eq(webAppPrefix), eq(apiUrl), eq(extData));
}
Also used : Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cdn(org.candlepin.model.Cdn) Entitlement(org.candlepin.model.Entitlement) 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