Search in sources :

Example 11 with Cdn

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

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

the class CdnManagerTest method deleteCdn.

@Test
public void deleteCdn() throws Exception {
    Cdn cdn = createCdn("test_cdn");
    manager.deleteCdn(cdn);
    assertNull(curator.lookupByLabel(cdn.getLabel()));
}
Also used : Cdn(org.candlepin.model.Cdn) Test(org.junit.Test)

Example 13 with Cdn

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

the class Importer method importContentDeliveryNetworks.

protected void importContentDeliveryNetworks(File[] cdnFiles) throws IOException {
    CdnImporter importer = new CdnImporter(cdnCurator);
    Set<Cdn> cdns = new HashSet<>();
    for (File cdnFile : cdnFiles) {
        Reader reader = null;
        try {
            reader = new FileReader(cdnFile);
            cdns.add(importer.createObject(mapper, reader));
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
    }
    importer.store(cdns);
}
Also used : Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) Cdn(org.candlepin.model.Cdn) ManifestFile(org.candlepin.sync.file.ManifestFile) File(java.io.File) HashSet(java.util.HashSet)

Example 14 with Cdn

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

the class CdnResource method create.

@ApiOperation(notes = "Creates a CDN @return a Cdn object", value = "create")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public CdnDTO create(@ApiParam(name = "cdn", required = true) CdnDTO cdnDTOInput, @Context Principal principal) {
    Cdn existing = curator.lookupByLabel(cdnDTOInput.getLabel());
    if (existing != null) {
        throw new BadRequestException(i18n.tr("A CDN with the label {0} already exists", cdnDTOInput.getLabel()));
    }
    Cdn cndToCreate = new Cdn();
    this.populateEntity(cndToCreate, cdnDTOInput);
    if (cdnDTOInput.getLabel() != null) {
        cndToCreate.setLabel(cdnDTOInput.getLabel());
    }
    return this.translator.translate(cdnManager.createCdn(cndToCreate), CdnDTO.class);
}
Also used : BadRequestException(org.candlepin.common.exceptions.BadRequestException) Cdn(org.candlepin.model.Cdn) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Example 15 with Cdn

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

the class ConsumerResourceTest method testAsyncExport.

@Test
public void testAsyncExport() {
    CdnCurator mockCdnCurator = mock(CdnCurator.class);
    ManifestManager manifestManager = mock(ManifestManager.class);
    ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, mockCdnCurator, null, null, manifestManager, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    List<KeyValueParameter> extParams = new ArrayList<>();
    Owner owner = this.createOwner();
    owner.setId(TestUtil.randomString());
    when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN));
    Consumer consumer = this.createConsumer(owner, ctype);
    Cdn cdn = new Cdn("cdn-label", "test", "url");
    when(mockCdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
    cr.exportDataAsync(null, consumer.getUuid(), cdn.getLabel(), "prefix", cdn.getUrl(), extParams);
    verify(manifestManager).generateManifestAsync(eq(consumer.getUuid()), eq(owner.getKey()), eq(cdn.getLabel()), eq("prefix"), eq(cdn.getUrl()), any(Map.class));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) KeyValueParameter(org.candlepin.resteasy.parameter.KeyValueParameter) CdnCurator(org.candlepin.model.CdnCurator) ManifestManager(org.candlepin.controller.ManifestManager) ConsumerType(org.candlepin.model.ConsumerType) Cdn(org.candlepin.model.Cdn) Map(java.util.Map) 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