Search in sources :

Example 61 with Consumer

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));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) Event(org.candlepin.audit.Event) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 62 with Consumer

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();
}
Also used : Consumer(org.candlepin.model.Consumer) ServletOutputStream(javax.servlet.ServletOutputStream) InputStream(java.io.InputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) ManifestFile(org.candlepin.sync.file.ManifestFile) Test(org.junit.Test)

Example 63 with Consumer

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());
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) Cdn(org.candlepin.model.Cdn) Test(org.junit.Test)

Example 64 with Consumer

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);
}
Also used : Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Event(org.candlepin.audit.Event) Cdn(org.candlepin.model.Cdn) Entitlement(org.candlepin.model.Entitlement) ManifestFile(org.candlepin.sync.file.ManifestFile) File(java.io.File) Test(org.junit.Test)

Example 65 with Consumer

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));
}
Also used : Consumer(org.candlepin.model.Consumer) Event(org.candlepin.audit.Event) Cdn(org.candlepin.model.Cdn) ManifestFile(org.candlepin.sync.file.ManifestFile) File(java.io.File) UserPrincipal(org.candlepin.auth.UserPrincipal) ManifestFile(org.candlepin.sync.file.ManifestFile) Test(org.junit.Test)

Aggregations

Consumer (org.candlepin.model.Consumer)470 Test (org.junit.Test)345 Entitlement (org.candlepin.model.Entitlement)162 Owner (org.candlepin.model.Owner)126 Pool (org.candlepin.model.Pool)114 Product (org.candlepin.model.Product)112 Date (java.util.Date)102 ConsumerType (org.candlepin.model.ConsumerType)94 LinkedList (java.util.LinkedList)73 ArrayList (java.util.ArrayList)71 HashSet (java.util.HashSet)69 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)69 HashMap (java.util.HashMap)48 ApiOperation (io.swagger.annotations.ApiOperation)43 Produces (javax.ws.rs.Produces)43 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)40 ApiResponses (io.swagger.annotations.ApiResponses)38 GuestId (org.candlepin.model.GuestId)37 Path (javax.ws.rs.Path)36 List (java.util.List)35