Spring Framework MockMultipartFile - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework MockMultipartFile class.

This code example shows how to use the following methods:
	final TracksController controller = new TracksController(trackRepository, this.tmpDir, this.gpsBabel.getAbsolutePath()); 
	 
	final MockMvc mockMvc = MockMvcBuilders.standaloneSetup(controller).build(); 
	 
	// Empty data 
	final MockMultipartFile multipartFile = new MockMultipartFile("trackData", new byte[0]);		 
	mockMvc 
		.perform( 
			fileUpload("http://biking.michael-simons.eu/api/tracks") 
			    .file(multipartFile) 
			    .param("name", "poef") 
			    .param("coveredOn", "2014-03-24T23:00:00.000Z") 
			    .param("description", "description") 
		)		 
		.andExpect(status().isBadRequest()); 
	 
	// No data 
	mockMvc 
	    .perform( 
		    fileUpload("http://biking.michael-simons.eu/api/tracks") 
3
CodeRank
This code example shows how to use the following methods:
                {new MockMultipartFile("test_image", "test_image", "text/plain", new byte[10])},
                {new MockMultipartFile("test_image", "test_image", "audio/mpeg", new byte[10])},
                {new MockMultipartFile("test_image", "test_image", "audio/x-wav", new byte[10])},
                {new MockMultipartFile("test_image", "test_image", "text/plain", new byte[10])},
                {new MockMultipartFile("test_image", "test_image", "text/html", new byte[10])},
                {new MockMultipartFile("test_image", "test_image", "video/mpeg", new byte[10])}
        }; 
    } 
 
    @Test(dataProvider = "validFormatValues")
    public void validateImageFormatShouldConsiderCorrectFormatsFromOperaAndIEAsValid(MultipartFile file)
            throws ImageFormatException { 
        imageService.validateImageFormat(file);
    } 
 
    @DataProvider 
    public Object[][] validFormatValues() {
        Set<String> validFormats = new HashSet<String>();
        validFormats.add("image/jpeg");
        validFormats.add("image/png");
4
CodeRank
This code example shows how to use the following methods:
 
  @Test
  public void shouldThrowErrorIfFileEmpty() throws Exception {
    expectedException.expect(DataException.class);
    expectedException.expectMessage("report.template.error.file.empty");
    MockMultipartFile file = new MockMultipartFile("report.jrxml", "report.jrxml", "", new byte[0]);
 
    service.validateFileAndInsertTemplate(new Template(), file);
  } 
 
  @Test
  public void shouldThrowErrorIfFileNotPresent() throws Exception {
    expectedException.expect(DataException.class);
    expectedException.expectMessage("report.template.error.file.missing");
 
    service.validateFileAndInsertTemplate(new Template(), null);
  } 
 
  @Test
  public void shouldThrowErrorIfFileIsInvalid() throws Exception {
3
CodeRank
This code example shows how to use the following methods:
    @Test(dataProvider = "parameterResizeImage")
    public void testResizeImage(int maxWidth, int maxHeight, int imageType, String format) throws IOException {
        int expectedWidth = 4;
        int expectedHeight = 4;
        imageConverter = new ImageConverter(format, imageType, maxWidth, maxHeight);
        BufferedImage originalImage = ImageIO.read(new MockMultipartFile("test_image", "test_image", "image/png",
                originalImageByteArray).getInputStream());
        Image modifiedImage = imageConverter.resizeImage(originalImage, imageType);
        assertEquals(modifiedImage.getWidth(null), expectedWidth);
        assertEquals(modifiedImage.getHeight(null), expectedHeight);
    } 
 
    @DataProvider(name = "parameterResizeImage") 
    public Object[][] parameterResizeImage() {
        int widthWithAspectRatioOne = 4;
        int heightWithAspectRatioOne = 4;
        int widthWithAspectRationMoreThatOne = 5;
        int heightWithAspectRatioMoreThatOne = 4;
        return new Object[][]{
                {widthWithAspectRatioOne, heightWithAspectRatioOne, BufferedImage.TYPE_INT_RGB, "jpeg"},
4
CodeRank