use of org.jboss.resteasy.plugins.providers.multipart.MultipartInput 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"));
}
use of org.jboss.resteasy.plugins.providers.multipart.MultipartInput 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);
}
use of org.jboss.resteasy.plugins.providers.multipart.MultipartInput 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));
}
Aggregations