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:com.cisco.ca.cstg.pdi.controllers.license.LicenseControllerTest.java
@Test public void licenseUpload_methodNameCheck() throws Exception { MockMultipartFile file = new MockMultipartFile("data", "filename.txt", "text/plain", "some xml".getBytes()); this.mockMvc.perform(MockMvcRequestBuilders.fileUpload("/licenseUpload.html").file(file)) .andExpect(handler().methodName("licenseUpload")); }
From source file:org.unidle.service.QuestionServiceImplTest.java
@Test public void testCreateQuestion() throws Exception { final Question question = subject.createQuestion("this is a question", "#tag1, #tag2 , ,, tag3,#tag4", asList(new MockMultipartFile("test.txt", "test.txt", "text/plain", "this is a text file".getBytes()))); assertThat(questionRepository.count()).isEqualTo(2L); // 1 in setUp() assertThat(attachmentRepository.count()).isEqualTo(1L); assertThat(question.getQuestion()).isEqualTo("this is a question"); assertThat(question.getTags()).containsOnly("tag1", "tag2", "tag3", "tag4"); assertThat(question.getAttachments()).hasSize(1); assertThat(question.getAttachments().get(0).getContent()).isEqualTo("this is a text file".getBytes()); assertThat(question.getAttachments().get(0).getContentType()).isEqualTo("text/plain"); assertThat(question.getAttachments().get(0).getTitle()).isEqualTo("test.txt"); }
From source file:org.chimi.s4s.controller.FileUploadControllerMockTest.java
@Test public void uploadSuccessfully() throws IllegalStateException, IOException { MockHttpServletRequest mockRequest = new MockHttpServletRequest(); MockMultipartFile uploadFile = new MockMultipartFile("file", "C:\\temp\\" + FILENAME, null, new byte[100]); String serviceId = "SVC01"; ModelMap modelMap = new ModelMap(); String viewName = controller.upload(uploadFile, serviceId, mockRequest, modelMap); assertEquals(SUCCESS_VIEWNAME, viewName); UploadResultResponse result = (UploadResultResponse) modelMap.get("uploadResult"); assertEquals(UploadResultCode.SUCCESS, result.getCode()); assertTrue(result.isSuccess());/*ww w . j a va 2 s .c o m*/ assertFalse(result.isImage()); assertEquals(FILENAME, result.getFileName()); assertEquals(FILEID01, result.getFileId()); assertEquals(METAID01, result.getMetadataId()); assertEquals(MIME_TYPE, result.getMimeType()); assertEquals(100L, result.getLength()); }
From source file:org.jtalks.common.web.validation.ImageDimensionValidatorTest.java
@Test public void testValidatorBigDimension() { Set<ConstraintViolation<TestObject>> constraintViolations = validator.validate(new TestObject( new MockMultipartFile("test_avatar", "test_avatar", "image/png", bigAvatarByteArray))); Assert.assertEquals(constraintViolations.size(), 1, "Validation without errors"); Assert.assertNotNull(constraintViolations.iterator().next().getMessage()); }
From source file:com.projectx.mvc.controller.completeregister.DocumentDetailsWACTest.java
@Test public void save() throws Exception { QuickRegisterSavedEntityDTO quickRegisterSavedEntityDTO = quickRegisterService .addNewCustomer(standardCustomerQuickRegisterEntity()); MockMultipartFile file = new MockMultipartFile("file", "filename.txt", "text/plain", "some xml".getBytes()); customerDetailsService// www . j a v a2 s .com .createCustomerDetailsFromQuickRegisterEntity(quickRegisterSavedEntityDTO.getCustomer()); customerDetailsService .merge(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity())); this.mockMvc.perform(fileUpload("/document/save").file(file) .param("customerId", Long.toString(quickRegisterSavedEntityDTO.getCustomer().getCustomerId())) .param("customerType", Long.toString(ENTITY_TYPE_CUSTOMER)).param("documentName", "DrivingLicense") ).andDo(print()).andExpect(view().name("showCustomerDetails")) .andExpect(model().attributeExists("documentDetails")) // .andExpect(model().attribute("documentDetails",hasProperty("key", is(standardDocumentKey())))) .andExpect(model().attribute("documentDetails", hasProperty("document", is("some xml".getBytes())))) .andExpect(model().attribute("documentDetails", hasProperty("contentType", is("text/plain")))) .andExpect(model().attribute("documentDetails", hasProperty("verificationStatus", is(standardDocumentDetails().getVerificationStatus())))) .andExpect(model().attribute("documentDetails", hasProperty("verificationRemark", is(standardDocumentDetails().getVerificationRemark())))) .andExpect(model().attribute("documentDetails", hasProperty("updatedBy", is(standardDocumentDetails().getUpdatedBy())))) .andExpect(model().attributeExists("customerDetails")) //.andExpect(model().attribute("customerDetails",hasProperty("customerId", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()).getCustomerId())))) .andExpect(model().attribute("customerDetails", hasProperty("firstName", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()) .getFirstName())))) .andExpect(model().attribute("customerDetails", hasProperty("lastName", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()) .getLastName())))) .andExpect(model().attribute("customerDetails", hasProperty("email", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()) .getEmail())))) .andExpect(model().attribute("customerDetails", hasProperty("mobile", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()) .getMobile())))) .andExpect(model().attribute("customerDetails", hasProperty("isEmailVerified", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()) .getIsEmailVerified())))) .andExpect(model().attribute("customerDetails", hasProperty("isMobileVerified", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()) .getIsMobileVerified())))) .andExpect(model().attribute("customerDetails", hasProperty("isSecondaryMobileVerified", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()) .getIsSecondaryMobileVerified())))); // .andExpect(model().attribute("customerDetails",hasProperty("homeAddressId", is(standardAddress())))) // .andExpect(model().attribute("customerDetails",hasProperty("language", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()).getLanguage())))) // .andExpect(model().attribute("customerDetails",hasProperty("businessDomain", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()).getBusinessDomain())))) // .andExpect(model().attribute("customerDetails",hasProperty("nameOfFirm", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()).getNameOfFirm())))) // .andExpect(model().attribute("customerDetails",hasProperty("firmAddressId", is(standardAddress())))) // .andExpect(model().attribute("customerDetails",hasProperty("secondaryMobile", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()).getSecondaryMobile())))) // .andExpect(model().attribute("customerDetails",hasProperty("isSecondaryMobileVerified", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()).getIsSecondaryMobileVerified())))) // .andExpect(model().attribute("customerDetails",hasProperty("secondaryEmail", is(standardCustomerDetails(standardCustomerDetailsCopiedFromQuickRegisterEntity()).getSecondaryEmail())))); }
From source file:alpha.portal.webapp.controller.CardFileUploadControllerTest.java
/** * Test on submit./* w w w .jav a2 s . c om*/ */ @Test public void testOnSubmit() { final String caseId = "550e4713-e22b-11d4-a716-446655440000"; final String cardId = "440e4816-e01b-74d4-a716-449955440092"; final String fileName = "doesnotcompute.file"; final String mimeType = "text/plain"; final byte[] content = "roflcopter".getBytes(); final MockHttpServletRequest request = this.newGet("/cardfileupload"); request.setRemoteUser("admin"); request.addParameter("case", caseId); request.addParameter("card", cardId); final FileUpload fileUpload = this.ctrl.showForm(request); fileUpload.setFile(content); final MockMultipartHttpServletRequest upload = new MockMultipartHttpServletRequest(); upload.setRemoteUser("admin"); final MockMultipartFile file = new MockMultipartFile("file", fileName, mimeType, content); upload.addFile(file); upload.addParameter("case", caseId); upload.addParameter("card", cardId); /* * Sadly enough we would need a flush() within the * PayloadManagerImpl.saveNewPayload() function for this test to succeed * since we moved to saving the payload via its own manager/dao. */ // BindingResult errors = new DataBinder(fileUpload).getBindingResult(); // String result = ""; // try { // result = ctrl.onSubmit(fileUpload, errors, upload); // } catch (IOException e) { // fail("Should not fail on fail upload"); // } // // assertFalse(errors.hasErrors()); // assertNotNull(upload.getSession().getAttribute("successMessages")); // // AlphaCard myCard = alphaCardManager.get(new // AlphaCardIdentifier(caseId, cardId)); // assertNotNull(myCard); // assertNotNull(myCard.getPayload()); // Assert.assertArrayEquals(content, myCard.getPayload().getContent()); // Assert.assertEquals(fileName, myCard.getPayload().getFilename()); // Assert.assertEquals(mimeType, myCard.getPayload().getMimeType()); // Assert.assertEquals("redirect:/caseform?caseId=" + caseId + // "&activeCardId=" + cardId, result); }