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