use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class EntitlementCertificateGeneratorTest method testNonLazyRegenerate.
@Test
public void testNonLazyRegenerate() throws Exception {
Owner owner = TestUtil.createOwner("test-owner", "Test Owner");
Product product = TestUtil.createProduct();
Pool pool = TestUtil.createPool(owner, product);
pool.setSourceSubscription(new SourceSubscription("source-sub-id", "master"));
Map<String, EntitlementCertificate> entCerts = new HashMap<>();
entCerts.put(pool.getId(), new EntitlementCertificate());
when(this.mockEntCertAdapter.generateEntitlementCerts(any(Consumer.class), anyMapOf(String.class, PoolQuantity.class), anyMapOf(String.class, Entitlement.class), anyMapOf(String.class, Product.class), eq(true))).thenReturn(entCerts);
Consumer consumer = TestUtil.createConsumer(owner);
Entitlement entitlement = new Entitlement(pool, consumer, owner, 1);
entitlement.setDirty(true);
this.ecGenerator.regenerateCertificatesOf(entitlement, false);
assertFalse(entitlement.isDirty());
verify(this.mockEntCertAdapter).generateEntitlementCerts(eq(consumer), this.poolQuantityMapCaptor.capture(), this.entMapCaptor.capture(), this.productMapCaptor.capture(), eq(true));
assertEquals(entitlement, this.entMapCaptor.getValue().get(pool.getId()));
assertEquals(product, this.productMapCaptor.getValue().get(pool.getId()));
verify(this.mockEventSink, times(1)).queueEvent(any(Event.class));
}
use of org.candlepin.model.Consumer in project candlepin by candlepin.
the class ManifestManagerTest method testWriteStoredExportToResponse.
@Test
public void testWriteStoredExportToResponse() throws Exception {
HttpServletResponse response = mock(HttpServletResponse.class);
ServletOutputStream responseOutputStream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(responseOutputStream);
Consumer exportedConsumer = this.createMockConsumer(true);
when(consumerCurator.verifyAndLookupConsumer(eq(exportedConsumer.getUuid()))).thenReturn(exportedConsumer);
String manifestId = "124";
String manifestFilename = "manifest.zip";
ManifestFile manifest = mock(ManifestFile.class);
InputStream mockManifestInputStream = mock(InputStream.class);
when(manifest.getId()).thenReturn(manifestId);
when(manifest.getName()).thenReturn(manifestFilename);
when(manifest.getTargetId()).thenReturn(exportedConsumer.getUuid());
when(manifest.getInputStream()).thenReturn(mockManifestInputStream);
when(fileService.get(eq(manifestId))).thenReturn(manifest);
// Simulate no data for test.
when(mockManifestInputStream.read()).thenReturn(-1);
manager.writeStoredExportToResponse(manifestId, exportedConsumer.getUuid(), response);
verify(fileService).get(eq(manifestId));
verify(response).setContentType("application/zip");
verify(response).setHeader(eq("Content-Disposition"), eq("attachment; filename=" + manifestFilename));
verify(responseOutputStream).flush();
}
use of org.candlepin.model.Consumer 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());
}
use of org.candlepin.model.Consumer 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);
}
use of org.candlepin.model.Consumer 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));
}
Aggregations