Search in sources :

Example 1 with ManifestManager

use of org.candlepin.controller.ManifestManager in project candlepin by candlepin.

the class OwnerResourceTest method testImportManifestFailure.

@Test
public void testImportManifestFailure() throws IOException, ImporterException {
    ManifestManager manifestManager = mock(ManifestManager.class);
    EventSink es = mock(EventSink.class);
    OwnerResource thisOwnerResource = new OwnerResource(ownerCurator, productCurator, null, null, i18n, es, eventFactory, null, null, manifestManager, null, null, null, null, importRecordCurator, null, null, null, null, null, null, null, contentOverrideValidator, serviceLevelValidator, null, null, null, null, null, this.modelTranslator);
    MultipartInput input = mock(MultipartInput.class);
    InputPart part = mock(InputPart.class);
    File archive = mock(File.class);
    List<InputPart> parts = new ArrayList<>();
    parts.add(part);
    MultivaluedMap<String, String> mm = new MultivaluedMapImpl<>();
    List<String> contDis = new ArrayList<>();
    contDis.add("form-data; name=\"upload\"; filename=\"test_file.zip\"");
    mm.put("Content-Disposition", contDis);
    when(input.getParts()).thenReturn(parts);
    when(part.getHeaders()).thenReturn(mm);
    when(part.getBody(any(GenericType.class))).thenReturn(archive);
    ImporterException expectedException = new ImporterException("Bad import");
    when(manifestManager.importManifest(eq(owner), any(File.class), any(String.class), any(ConflictOverrides.class))).thenThrow(expectedException);
    try {
        thisOwnerResource.importManifest(owner.getKey(), new String[] {}, input);
        fail("Expected IseException was not thrown");
    } catch (IseException ise) {
    // expected, so we catch and go on.
    }
    verify(manifestManager).recordImportFailure(eq(owner), eq(expectedException), eq("test_file.zip"));
}
Also used : ImporterException(org.candlepin.sync.ImporterException) ConflictOverrides(org.candlepin.sync.ConflictOverrides) GenericType(org.jboss.resteasy.util.GenericType) MultipartInput(org.jboss.resteasy.plugins.providers.multipart.MultipartInput) ArrayList(java.util.ArrayList) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) Matchers.anyString(org.mockito.Matchers.anyString) ManifestManager(org.candlepin.controller.ManifestManager) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) IseException(org.candlepin.common.exceptions.IseException) EventSink(org.candlepin.audit.EventSink) File(java.io.File) Test(org.junit.Test)

Example 2 with ManifestManager

use of org.candlepin.controller.ManifestManager in project candlepin by candlepin.

the class OwnerResourceTest method testImportManifestSynchronousSuccess.

@Test
public void testImportManifestSynchronousSuccess() throws IOException, ImporterException {
    ManifestManager manifestManager = mock(ManifestManager.class);
    EventSink es = mock(EventSink.class);
    OwnerResource thisOwnerResource = new OwnerResource(ownerCurator, productCurator, null, null, i18n, es, eventFactory, null, null, manifestManager, null, null, null, null, importRecordCurator, null, null, null, null, null, null, null, contentOverrideValidator, serviceLevelValidator, null, null, null, null, null, this.modelTranslator);
    MultipartInput input = mock(MultipartInput.class);
    InputPart part = mock(InputPart.class);
    File archive = mock(File.class);
    List<InputPart> parts = new ArrayList<>();
    parts.add(part);
    MultivaluedMap<String, String> mm = new MultivaluedMapImpl<>();
    List<String> contDis = new ArrayList<>();
    contDis.add("form-data; name=\"upload\"; filename=\"test_file.zip\"");
    mm.put("Content-Disposition", contDis);
    when(input.getParts()).thenReturn(parts);
    when(part.getHeaders()).thenReturn(mm);
    when(part.getBody(any(GenericType.class))).thenReturn(archive);
    ImportRecord ir = new ImportRecord(owner);
    when(manifestManager.importManifest(eq(owner), any(File.class), eq("test_file.zip"), any(ConflictOverrides.class))).thenReturn(ir);
    ImportRecord response = thisOwnerResource.importManifest(owner.getKey(), new String[] {}, input);
    assertNotNull(response);
    assertEquals(ir, response);
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) GenericType(org.jboss.resteasy.util.GenericType) MultipartInput(org.jboss.resteasy.plugins.providers.multipart.MultipartInput) ArrayList(java.util.ArrayList) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) Matchers.anyString(org.mockito.Matchers.anyString) ManifestManager(org.candlepin.controller.ManifestManager) ImportRecord(org.candlepin.model.ImportRecord) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) EventSink(org.candlepin.audit.EventSink) File(java.io.File) Test(org.junit.Test)

Example 3 with ManifestManager

use of org.candlepin.controller.ManifestManager in project candlepin by candlepin.

the class ConsumerResourceTest method testNoDryBindWhenAutobindDisabledForOwner.

@Test
public void testNoDryBindWhenAutobindDisabledForOwner() throws Exception {
    Owner owner = createOwner();
    owner.setId(TestUtil.randomString());
    Consumer consumer = createConsumer(owner);
    owner.setAutobindDisabled(true);
    when(mockConsumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    ManifestManager manifestManager = mock(ManifestManager.class);
    when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
    ConsumerResource consumerResource = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, null, null, null, manifestManager, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    try {
        consumerResource.dryBind(consumer.getUuid(), "some-sla");
        fail("Should have thrown a BadRequestException.");
    } catch (BadRequestException e) {
        assertEquals("Owner has autobind disabled.", e.getMessage());
    }
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ManifestManager(org.candlepin.controller.ManifestManager) Test(org.junit.Test)

Example 4 with ManifestManager

use of org.candlepin.controller.ManifestManager in project candlepin by candlepin.

the class ConsumerResourceTest method testAsyncExport.

@Test
public void testAsyncExport() {
    CdnCurator mockCdnCurator = mock(CdnCurator.class);
    ManifestManager manifestManager = mock(ManifestManager.class);
    ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, mockCdnCurator, null, null, manifestManager, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    List<KeyValueParameter> extParams = new ArrayList<>();
    Owner owner = this.createOwner();
    owner.setId(TestUtil.randomString());
    when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN));
    Consumer consumer = this.createConsumer(owner, ctype);
    Cdn cdn = new Cdn("cdn-label", "test", "url");
    when(mockCdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
    cr.exportDataAsync(null, consumer.getUuid(), cdn.getLabel(), "prefix", cdn.getUrl(), extParams);
    verify(manifestManager).generateManifestAsync(eq(consumer.getUuid()), eq(owner.getKey()), eq(cdn.getLabel()), eq("prefix"), eq(cdn.getUrl()), any(Map.class));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) KeyValueParameter(org.candlepin.resteasy.parameter.KeyValueParameter) CdnCurator(org.candlepin.model.CdnCurator) ManifestManager(org.candlepin.controller.ManifestManager) ConsumerType(org.candlepin.model.ConsumerType) Cdn(org.candlepin.model.Cdn) Map(java.util.Map) Test(org.junit.Test)

Example 5 with ManifestManager

use of org.candlepin.controller.ManifestManager in project candlepin by candlepin.

the class OwnerResourceTest method testImportManifestAsyncSuccess.

@Test
public void testImportManifestAsyncSuccess() throws IOException, ImporterException {
    ManifestManager manifestManager = mock(ManifestManager.class);
    EventSink es = mock(EventSink.class);
    OwnerResource thisOwnerResource = new OwnerResource(ownerCurator, productCurator, null, null, i18n, es, eventFactory, null, null, manifestManager, null, null, null, null, importRecordCurator, null, null, null, null, null, null, null, contentOverrideValidator, serviceLevelValidator, null, null, null, null, null, this.modelTranslator);
    MultipartInput input = mock(MultipartInput.class);
    InputPart part = mock(InputPart.class);
    File archive = mock(File.class);
    List<InputPart> parts = new ArrayList<>();
    parts.add(part);
    MultivaluedMap<String, String> mm = new MultivaluedMapImpl<>();
    List<String> contDis = new ArrayList<>();
    contDis.add("form-data; name=\"upload\"; filename=\"test_file.zip\"");
    mm.put("Content-Disposition", contDis);
    JobDetail job = mock(JobDetail.class);
    when(input.getParts()).thenReturn(parts);
    when(part.getHeaders()).thenReturn(mm);
    when(part.getBody(any(GenericType.class))).thenReturn(archive);
    when(manifestManager.importManifestAsync(eq(owner), any(File.class), eq("test_file.zip"), any(ConflictOverrides.class))).thenReturn(job);
    JobDetail response = thisOwnerResource.importManifestAsync(owner.getKey(), new String[] {}, input);
    assertNotNull(response);
    assertEquals(job, response);
    verify(manifestManager, never()).importManifest(eq(owner), any(File.class), any(String.class), any(ConflictOverrides.class));
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) GenericType(org.jboss.resteasy.util.GenericType) MultipartInput(org.jboss.resteasy.plugins.providers.multipart.MultipartInput) ArrayList(java.util.ArrayList) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) Matchers.anyString(org.mockito.Matchers.anyString) ManifestManager(org.candlepin.controller.ManifestManager) JobDetail(org.quartz.JobDetail) InputPart(org.jboss.resteasy.plugins.providers.multipart.InputPart) EventSink(org.candlepin.audit.EventSink) File(java.io.File) Test(org.junit.Test)

Aggregations

ManifestManager (org.candlepin.controller.ManifestManager)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 File (java.io.File)3 EventSink (org.candlepin.audit.EventSink)3 ConflictOverrides (org.candlepin.sync.ConflictOverrides)3 InputPart (org.jboss.resteasy.plugins.providers.multipart.InputPart)3 MultipartInput (org.jboss.resteasy.plugins.providers.multipart.MultipartInput)3 MultivaluedMapImpl (org.jboss.resteasy.specimpl.MultivaluedMapImpl)3 GenericType (org.jboss.resteasy.util.GenericType)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Consumer (org.candlepin.model.Consumer)2 Owner (org.candlepin.model.Owner)2 Map (java.util.Map)1 BadRequestException (org.candlepin.common.exceptions.BadRequestException)1 IseException (org.candlepin.common.exceptions.IseException)1 Cdn (org.candlepin.model.Cdn)1 CdnCurator (org.candlepin.model.CdnCurator)1 ConsumerType (org.candlepin.model.ConsumerType)1 ImportRecord (org.candlepin.model.ImportRecord)1