Package org.springframework.mock.web

Examples of org.springframework.mock.web.MockMultipartFile


    }

    @DataProvider
    public Object[][] invalidFormatValues() {
        return new Object[][]{
                {new MockMultipartFile("test_image", "test_image", "image/bmp", new byte[10])},
                {new MockMultipartFile("test_image", "test_image", "image/tiff", new byte[10])},
                {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])}
        };
    }
View Full Code Here


        validFormats.add("image/jpeg");
        validFormats.add("image/png");
        validFormats.add("image/gif");
        List<MultipartFile> files = new ArrayList<MultipartFile>(validFormats.size());
        for (String contentType : validFormats) {
            files.add(new MockMultipartFile("test_image", "test_image", contentType, new byte[10]));
        }
        Object[][] result = new Object[files.size()][];
        for (int i = 0; i < result.length; i++) {
            result[i] = new Object[]{files.get(i)};
        }
View Full Code Here

    @Test
    @SuppressWarnings("unchecked")
    public void uploadAvatarForOperaAndIEShouldReturnPreviewInResponce()
            throws IOException, ImageProcessException {
        MultipartFile file = new MockMultipartFile("qqfile", validAvatar);
        String expectedBody = "{\"srcPrefix\":\"data:image/jpeg;base64,\",\"srcImage\":\"srcImage\",\"success\":\"true\"}";
        when(imageService.preProcessAndEncodeInString64(validAvatar)).thenReturn(IMAGE_BYTE_ARRAY_IN_BASE_64_STRING);
        when(imageControllerUtils.getResponceJSONString(Matchers.anyMap())).thenReturn(expectedBody);
        Map<String, String> responseContent = new HashMap<String, String>();
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(MediaType.TEXT_HTML);

        ResponseEntity<String> actualResponseEntity = imageControllerUtils.prepareResponse(file, responseHeaders, responseContent);

        verify(imageService).validateImageFormat(file);
        verify(imageService).validateImageSize(file.getBytes());
        assertEquals(actualResponseEntity.getStatusCode(), HttpStatus.OK);
        assertEquals(actualResponseEntity.getBody(), expectedBody);
        HttpHeaders headers = actualResponseEntity.getHeaders();
        assertEquals(headers.getContentType(), MediaType.TEXT_HTML);
    }
View Full Code Here

        StringBuilder csvBuilder = new StringBuilder();
        csvBuilder.append("Name,Given Name,Additional Name,Family Name,Yomi Name,Given Name Yomi,Additional Name Yomi,Family Name Yomi,Name Prefix,Name Suffix,Initials,Nickname,Short Name,Maiden Name,Birthday,Gender,Location,Billing Information,Directory Server,Mileage,Occupation,Hobby,Sensitivity,Priority,Subject,Notes,Group Membership,E-mail 1 - Type,E-mail 1 - Value,Phone 1 - Type,Phone 1 - Value\n");
        csvBuilder.append("John Doe,John,,Doe,,,,,,,,,,,,,,,,,,,,,,,,* Other,john.doe@sparcedge.com,Work,843-555-5555");
        InputStream is = new ByteArrayInputStream(csvBuilder.toString().getBytes());

        MultipartFile mockFile = new MockMultipartFile("googleContacts", "googleContacts.csv", "plain/text", is);
        List<Contact> contacts = invitationService.parseContactsGoogle(mockFile);
        assertTrue(contacts.size() == 1);
        assertTrue(contacts.get(0).getEmail().equals("john.doe@sparcedge.com"));
    }
View Full Code Here

        StringBuilder csvBuilder = new StringBuilder();
        csvBuilder.append("First Name,Middle Name,Last Name,Title,Suffix,Initials,Web Page,Gender,Birthday,Anniversary,Location,Language,Internet Free Busy,Notes,E-mail Address,E-mail 2 Address,E-mail 3 Address,Primary Phone,Home Phone,Home Phone 2,Mobile Phone,Pager,Home Fax,Home Address,Home Street,Home Street 2,Home Street 3,Home Address PO Box,Home City,Home State,Home Postal Code,Home Country,Spouse,Children,Manager's Name,Assistant's Name,Referred By,Company Main Phone,Business Phone,Business Phone 2,Business Fax,Assistant's Phone,Company,Job Title,Department,Office Location,Organizational ID Number,Profession,Account,Business Address,Business Street,Business Street 2,Business Street 3,Business Address PO Box,Business City,Business State,Business Postal Code,Business Country,Other Phone,Other Fax,Other Address,Other Street,Other Street 2,Other Street 3,Other Address PO Box,Other City,Other State,Other Postal Code,Other Country,Callback,Car Phone,ISDN,Radio Phone,TTY/TDD Phone,Telex,User 1,User 2,User 3,User 4,Keywords,Mileage,Hobby,Billing Information,Directory Server,Sensitivity,Priority,Private,Categories\n");
        csvBuilder.append("John,,Doe,,,,,,,,,,,,john.doe@sparcedge.com,,,,,,,,,,,,,,,,,,,,,,,,843-55-5555,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Normal,,Most Contacted,");
        InputStream is = new ByteArrayInputStream(csvBuilder.toString().getBytes());

        MultipartFile mockFile = new MockMultipartFile("outlookContacts", "outlookContacts.csv", "plain/text", is);
        List<Contact> contacts = invitationService.parseContactsOutlook(mockFile);
        assertTrue(contacts.size() == 1);
        assertTrue(contacts.get(0).getEmail().equals("john.doe@sparcedge.com"));
    }
View Full Code Here

    }

    private static void initIcons() {
        try {
            InputStream inputStream = ctx.getResource("resources/img/icon_entertainment.png").getInputStream();
            entertainmentIcon = new MockMultipartFile("defaultCategory1", "icon_entertainment.png", "image/png", IOUtils.toByteArray(inputStream));
        } catch (IOException e) {
            log.warn("Error loading entertainment icon for default categories", e);
        }

        try {
            InputStream inputStream = ctx.getResource("resources/img/icon_productivity.png").getInputStream();
            productivityIcon = new MockMultipartFile("defaultCategory2", "icon_productivity.png", "image/png", IOUtils.toByteArray(inputStream));
        } catch (IOException e) {
            log.warn("Error loading productivity icon for default categories", e);
        }

        try {
            InputStream inputStream = ctx.getResource("resources/img/icon_utilities.png").getInputStream();
            utilitiesIcon = new MockMultipartFile("defaultCategory3", "icon_utilities.png", "image/png", IOUtils.toByteArray(inputStream));
        } catch (IOException e) {
            log.warn("Error loading utilities icon for default categories", e);
        }
    }
View Full Code Here

    ModelMap model = new ModelMap();
    String path = "test-upload-path";
    scriptController.addFolder(getTestUser(), "", path, model);

    String upFileName = "Uploaded";
    MultipartFile upFile = new MockMultipartFile("Uploaded.py", "Uploaded.py", null, "#test content...".getBytes());
    path = path + "/" + upFileName;
    scriptController.upload(getTestUser(), path, "Uploaded file desc.", upFile, model);
    model.clear();
    scriptController.search(getTestUser(), "Uploaded", model);
    Collection<FileEntry> searchResult = (Collection<FileEntry>) model.get("files");
View Full Code Here

   * Create a new MockMultipartFile with the given content.
   * @param name the name of the file
   * @param content the content of the file
   */
  public MockMultipartHttpServletRequestBuilder file(String name, byte[] content) {
    this.files.add(new MockMultipartFile(name, content));
    return this;
  }
View Full Code Here

*/
public class FileUploadControllerTests {

  @Test
  public void readString() throws Exception {
    MockMultipartFile file = new MockMultipartFile("file", "orig", null, "bar".getBytes());
    standaloneSetup(new FileUploadController()).build()
        .perform(fileUpload("/fileupload").file(file))
        .andExpect(model().attribute("message", "File 'orig' uploaded successfully"));
  }
View Full Code Here

    FileUtils.deleteDirectory(new File(System.getProperty("java.io.tmpdir", "/tmp"), "batch/files"));
  }

  @Test
  public void testUpload() throws Exception {
    MockMultipartFile file = new MockMultipartFile("foo", "foo.properties", "text/plain", "bar".getBytes());
    ExtendedModelMap model = new ExtendedModelMap();
    Date date = new Date();
    controller.upload("spam", file, model, 0, 20, date, new BindException(date, "date"));
    String uploaded = (String) model.get("uploaded");
    // System.err.println(uploaded);
View Full Code Here

TOP

Related Classes of org.springframework.mock.web.MockMultipartFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.