List of usage examples for org.springframework.mock.web MockMultipartFile MockMultipartFile
public MockMultipartFile(String name, @Nullable String originalFilename, @Nullable String contentType, InputStream contentStream) throws IOException
From source file:apiserver.services.image.controllers.filters.ImageLensBlurTests.java
@Test public void testLensBlurByIdRESTPost() throws Exception { InputStream fileStream = this.getClass().getClassLoader().getResourceAsStream("IMG_5932.JPG"); MockMultipartFile file = new MockMultipartFile("file", "IMG_5932.JPG", "image/jpeg", fileStream); MvcResult result = MockMvcBuilders.webAppContextSetup((WebApplicationContext) context).build() .perform(fileUpload(rootUrl + "/image/filter/lensblur.jpg").file(file).param("radius", "10") .param("sides", "5").param("bloom", "2")) .andExpect(status().is(200)).andExpect(content().contentType("image/jpeg")).andReturn(); Assert.assertEquals(823872, result.getResponse().getContentLength()); saveFileToLocalDisk("lensblur-post.jpg", result.getResponse().getContentAsByteArray()); }
From source file:apiserver.services.image.controllers.filters.ImageMotionBlurTests.java
@Test public void testLensBlurByIdRESTPost() throws Exception { InputStream fileStream = this.getClass().getClassLoader().getResourceAsStream("IMG_5932.JPG"); MockMultipartFile file = new MockMultipartFile("file", "IMG_5932.JPG", "image/jpeg", fileStream); MvcResult result = MockMvcBuilders.webAppContextSetup((WebApplicationContext) context).build() .perform(fileUpload(rootUrl + "/image/filter/motionblur.jpg").file(file).param("angle", "0") .param("distance", "1").param("rotation", "0").param("wrapEdges", "false") .param("zoom", "0")) .andExpect(status().is(200)).andExpect(content().contentType("image/jpeg")).andReturn(); Assert.assertEquals(1507837, result.getResponse().getContentLength()); saveFileToLocalDisk("motionblur-post.jpg", result.getResponse().getContentAsByteArray()); }
From source file:com.ccserver.digital.controller.CreditCardApplicationDocumentControllerTest.java
@Test public void modifySubmittedDocumentTest() throws IOException { // Arrange//from w w w.ja va 2 s . c o m long id = 1l; long docId = 1l; CreditCardApplicationDocumentDTO doc = new CreditCardApplicationDocumentDTO(); doc.setId(docId); File ifile = new File("./src/main/resources/sample"); Path idDocPath = FileSystems.getDefault().getPath(ifile.getAbsolutePath(), "IdDoc.pdf"); byte[] idDocByteArray = Files.readAllBytes(idDocPath); MockMultipartFile idDocMultipartFile = new MockMultipartFile("IdDoc", "IdDoc.pdf", "application/pdf", idDocByteArray); Mockito.when(ccAppService.isSubmittedDocument(id)).thenReturn(true); Mockito.when(mockDocService.documentIsBelongToApp(id, docId)).thenReturn(true); // Act ResponseEntity<?> response = mockDocController.saveAll(new MockMultipartFile[] { idDocMultipartFile }, null, id, docId, request); // Assert Assert.assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(Constants.MODIFYING_SUBMITTED_DOCUMENT, ((ErrorObject) response.getBody()).getId()); }
From source file:org.bonitasoft.web.designer.controller.ImportControllerTest.java
@Test public void should_respond_404_for_an_unknown_artifact_type() throws Exception { MockMultipartFile file = new MockMultipartFile("file", "myfile.zip", "application/zip", "foo".getBytes()); mockMvc.perform(fileUpload("/import/unknown").file(file)).andExpect(status().isNotFound()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ModuleController1_8Test.java
@Test public void shouldUploadModule() throws Exception { byte[] fileData = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("mockModule.omod")); MockMultipartFile toUpload = new MockMultipartFile("file", "mockModule.omod", "archive/zip", fileData); MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); request.setRequestURI(getBaseRestURI() + getURI()); request.setMethod(RequestMethod.POST.name()); request.addHeader("Content-Type", "multipart/form-data"); request.addFile(toUpload);/*ww w.j av a 2s . c o m*/ mockModuleFactory.loadModuleMock = mockModuleToLoad; MockHttpServletResponse response = handle(request); assertThat(mockModuleFactory.loadedModules, hasItem(mockModuleToLoad)); assertThat(mockModuleFactory.startedModules, hasItem(mockModuleToLoad)); }
From source file:org.bonitasoft.web.designer.controller.asset.AssetServiceTest.java
@Test public void should_return_error_when_uploading_file_empty() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage(is("Part named [file] is needed to successfully import a component")); //We construct a mockfile (the first arg is the name of the property expected in the controller MockMultipartFile file = new MockMultipartFile("file", "myfile.js", "application/js", "".getBytes()); assetService.upload(file, aPage().build(), "js"); }
From source file:org.openlmis.fulfillment.service.TemplateServiceTest.java
@Test public void shouldThrowErrorIfFileEmpty() throws Exception { expectedException.expect(ReportingException.class); expectedException.expectMessage(REPORTING_FILE_EMPTY); MockMultipartFile file = new MockMultipartFile(NAME_OF_FILE, NAME_OF_FILE, "", new byte[0]); templateService.validateFileAndInsertTemplate(new Template(), file); }
From source file:eionet.webq.converter.MultipartFileToUserFileConverterTest.java
@Test public void whenConvertingMultipartFile_ifAttachmentFileNameExtensionIsZip_unpackAllFiles() throws Exception { Collection<UserFile> files = fileConverter.convert( new MockMultipartFile("xmlFileUpload", "file.zip", "some-other-zip-attachment-content-type", FileUtils.readFileToByteArray(new File(TEST_XML_FILES_ZIP)))); verifyContentExtractedFromTestZipFile(files); }
From source file:org.bonitasoft.web.designer.controller.asset.AssetServiceTest.java
@Test public void should_return_error_when_uploadind_type_invalid() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage(is("Part named [file] is needed to successfully import a component")); //We construct a mockfile (the first arg is the name of the property expected in the controller MockMultipartFile file = new MockMultipartFile("file", "myfile.js", "application/js", "".getBytes()); assetService.upload(file, aPage().build(), "INVALID"); }
From source file:org.bonitasoft.web.designer.controller.ImportControllerTest.java
private MockMultipartFile aFile(String contentType) { return new MockMultipartFile("file", "myfile.zip", contentType, "foo".getBytes()); }