Search in sources :

Example 66 with Consumer

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

the class ManifestManagerTest method createMockConsumer.

protected Consumer createMockConsumer(Owner owner, boolean manifestDistributor) {
    ConsumerType type = manifestDistributor ? new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN) : new ConsumerType("test-consumer-type-" + TestUtil.randomInt());
    type.setId("test-ctype-" + TestUtil.randomInt());
    Consumer consumer = new Consumer("TestConsumer" + TestUtil.randomInt(), "User", owner, type);
    when(consumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(type);
    when(consumerTypeCurator.find(eq(type.getId()))).thenReturn(type);
    return consumer;
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType)

Example 67 with Consumer

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

the class ManifestManagerTest method ensureEventSentOnManifestGeneration.

@Test
public void ensureEventSentOnManifestGeneration() 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);
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
    manager.generateManifest(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) Test(org.junit.Test)

Example 68 with Consumer

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

the class ManifestManagerTest method testWriteStoredExportToResponseFailsWhenManifestFileNotFound.

@Test(expected = NotFoundException.class)
public void testWriteStoredExportToResponseFailsWhenManifestFileNotFound() throws Exception {
    HttpServletResponse response = mock(HttpServletResponse.class);
    Consumer exportedConsumer = this.createMockConsumer(true);
    String manifestId = "124";
    ManifestFile manifest = mock(ManifestFile.class);
    when(manifest.getTargetId()).thenReturn(exportedConsumer.getUuid());
    when(fileService.get(eq(manifestId))).thenReturn(null);
    manager.writeStoredExportToResponse(manifestId, exportedConsumer.getUuid(), response);
}
Also used : Consumer(org.candlepin.model.Consumer) HttpServletResponse(javax.servlet.http.HttpServletResponse) ManifestFile(org.candlepin.sync.file.ManifestFile) Test(org.junit.Test)

Example 69 with Consumer

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

the class ManifestManagerTest method verifyConsumerIsDistributorBeforeGeneratingManifest.

@Test
public void verifyConsumerIsDistributorBeforeGeneratingManifest() throws Exception {
    Consumer consumer = this.createMockConsumer(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.generateManifest(consumer.getUuid(), 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 : 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 70 with Consumer

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

the class ManifestManagerTest method testWriteStoredExportToResponseFailsWhenConsumerIdDoesntMatchManifest.

@Test(expected = BadRequestException.class)
public void testWriteStoredExportToResponseFailsWhenConsumerIdDoesntMatchManifest() throws Exception {
    HttpServletResponse response = mock(HttpServletResponse.class);
    Consumer exportedConsumer = this.createMockConsumer(true);
    String manifestId = "124";
    when(consumerCurator.verifyAndLookupConsumer(eq(exportedConsumer.getUuid()))).thenReturn(exportedConsumer);
    ManifestFile manifest = mock(ManifestFile.class);
    when(manifest.getTargetId()).thenReturn("another-consumer-uuid");
    when(fileService.get(eq(manifestId))).thenReturn(manifest);
    manager.writeStoredExportToResponse(manifestId, exportedConsumer.getUuid(), response);
}
Also used : Consumer(org.candlepin.model.Consumer) HttpServletResponse(javax.servlet.http.HttpServletResponse) 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