use of org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder in project ArachneCentralAPI by OHDSI.
the class AnalysisControllerTests method testUpdateCodeFile.
@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study-with-contributor.xml"), @DatabaseSetup("/data/analysis/analysis-list.xml"), @DatabaseSetup("/data/analysis/code-file-before-deleting.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study-with-contributor.xml", assertionMode = NON_STRICT), @ExpectedDatabase(value = "/data/analysis/code-file-after-updating.xml", assertionMode = NON_STRICT) })
public void testUpdateCodeFile() throws Exception {
String uuid = "68b75ac9-ab29-49a6-8edb-95142456f5fc";
String path = this.getClass().getResource("/test.jpg").getPath();
FileInputStream fileInputStream = new FileInputStream(path);
MockMultipartFile multipartFile = new MockMultipartFile("file", "test_updated.jpg", "image/jpeg", fileInputStream);
MockMultipartHttpServletRequestBuilder builder = fileUpload("/api/v1/analysis-management/analyses/{analysisId}/files/{fileUuid}", ANALYSIS_ID, uuid);
builder.with(request -> {
request.setMethod("PUT");
return request;
});
mvc.perform(builder.file(multipartFile).param("label", "labelUploadedFile").param("file", path).contentType(MULTIPART_FORM_DATA)).andExpect(NO_ERROR_CODE).andExpect(TRUE_RESULT);
}
use of org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder in project TOSCAna by StuPro-TOSCAna.
the class CsarControllerTest method uploadTestArchiveAlreadyExists.
@Test
public void uploadTestArchiveAlreadyExists() throws Exception {
// Generate 10 KiB of random data
byte[] data = generateRandomByteArray(rnd, 10);
String path = CSAR_BASE_URL + "apache";
MockMultipartHttpServletRequestBuilder builder = buildMockedMultipartUploadRequest(data, path);
ResultActions resultActions = mvc.perform(builder).andDo(print()).andExpect(status().is(201));
resultActions.andReturn();
}
use of org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder in project TOSCAna by StuPro-TOSCAna.
the class CsarControllerTest method buildMockedMultipartUploadRequest.
public MockMultipartHttpServletRequestBuilder buildMockedMultipartUploadRequest(byte[] data, String path) {
MockMultipartFile mockMultipartFile = new MockMultipartFile(MULTIPART_FILE_UPLOAD_KEY, MULTIPART_FILE_ORIGINAL_FILENAME, MediaType.APPLICATION_OCTET_STREAM_VALUE, data);
MockMultipartHttpServletRequestBuilder builder = fileUpload(path);
builder.with(request -> {
request.setMethod("PUT");
return request;
});
builder = (MockMultipartHttpServletRequestBuilder) builder.file(mockMultipartFile).contentType(MediaType.MULTIPART_FORM_DATA);
return builder;
}
use of org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder in project thingsboard by thingsboard.
the class AbstractOtaLwM2MIntegrationTest method savaData.
protected OtaPackageInfo savaData(String urlTemplate, MockMultipartFile content, String... params) throws Exception {
MockMultipartHttpServletRequestBuilder postRequest = MockMvcRequestBuilders.multipart(urlTemplate, params);
postRequest.file(content);
setJwtToken(postRequest);
return readResponse(mockMvc.perform(postRequest).andExpect(status().isOk()), OtaPackageInfo.class);
}
use of org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder in project vorto by eclipse.
the class IntegrationTestBase method addAttachment.
protected ResultActions addAttachment(String modelId, SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor user, String fileName, MediaType mediaType, Integer size) throws Exception {
MockMultipartFile file = new MockMultipartFile("file", fileName, mediaType.toString(), size == null ? "{\"test\":123}".getBytes() : new byte[size]);
MockMultipartHttpServletRequestBuilder builder = MockMvcRequestBuilders.fileUpload("/api/v1/attachments/" + modelId);
return repositoryServer.perform(builder.file(file).with(request -> {
request.setMethod("PUT");
return request;
}).contentType(MediaType.MULTIPART_FORM_DATA).with(user));
}
Aggregations