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);
}
}
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()));
}
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);
}
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);
}
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));
}
Aggregations