use of org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest in project alfresco-remote-api by Alfresco.
the class SerializeTests method testInvokeMultiPartEntity.
@Test
public void testInvokeMultiPartEntity() throws IOException {
ResourceWithMetadata entityResource = locator.locateEntityResource(api, "multiparttest", HttpMethod.POST);
assertNotNull(entityResource);
MultiPartResourceAction.Create<?> resource = (MultiPartResourceAction.Create<?>) entityResource.getResource();
File file = TempFileProvider.createTempFile("ParamsExtractorTests-", ".txt");
PrintWriter writer = new PrintWriter(file);
writer.println("Multipart Mock test2.");
writer.close();
MultiPartRequest reqBody = MultiPartBuilder.create().setFileData(new FileData(file.getName(), file, MimetypeMap.MIMETYPE_TEXT_PLAIN)).build();
MockHttpServletRequest mockRequest = new MockHttpServletRequest("POST", "");
mockRequest.setContent(reqBody.getBody());
mockRequest.setContentType(reqBody.getContentType());
String out = writeResponse(helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, NOT_USED, resource.create(new FormData(mockRequest), NOT_USED, callBack)));
assertTrue("There must be json output", StringUtils.startsWith(out, "{\"entry\":"));
}
use of org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest in project alfresco-remote-api by Alfresco.
the class ParamsExtractorTests method testMultiPartPostExtractor.
@Test
public void testMultiPartPostExtractor() throws Exception {
ResourceWebScriptPost extractor = new ResourceWebScriptPost();
extractor.setAssistant(assistant);
extractor.setLocator(locator);
Map<String, String> templateVars = new HashMap<String, String>();
WebScriptRequest request = mock(WebScriptRequest.class);
when(request.getServiceMatch()).thenReturn(new Match(null, templateVars, null));
File file = TempFileProvider.createTempFile("ParamsExtractorTests-", ".txt");
PrintWriter writer = new PrintWriter(file);
writer.println("Multipart Mock test.");
writer.close();
MultiPartRequest reqBody = MultiPartBuilder.create().setFileData(new FileData(file.getName(), file, MimetypeMap.MIMETYPE_TEXT_PLAIN)).build();
MockHttpServletRequest mockRequest = new MockHttpServletRequest("POST", "");
mockRequest.setContent(reqBody.getBody());
mockRequest.setContentType(reqBody.getContentType());
when(request.getContentType()).thenReturn("multipart/form-data");
when(request.parseContent()).thenReturn(new FormData(mockRequest));
Params params = extractor.extractParams(mockEntity(), request);
assertNotNull(params);
Object passed = params.getPassedIn();
assertNotNull(passed);
assertTrue(FormData.class.isAssignableFrom(passed.getClass()));
FormData formData = (FormData) passed;
assertTrue(formData.getIsMultiPart());
// No entity id for POST
templateVars.put(ResourceLocator.ENTITY_ID, "1234");
try {
params = extractor.extractParams(mockEntity(), request);
fail("Should not get here. No entity id for POST");
} catch (UnsupportedResourceOperationException uoe) {
assertNotNull(uoe);
}
params = extractor.extractParams(mockRelationship(), request);
assertNotNull(params);
assertEquals("1234", params.getEntityId());
passed = params.getPassedIn();
assertNotNull(passed);
assertTrue(FormData.class.isAssignableFrom(passed.getClass()));
formData = (FormData) passed;
assertTrue(formData.getIsMultiPart());
}
Aggregations