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