當前位置: 首頁>>代碼示例>>Java>>正文


Java MockMvcRequestBuilders.fileUpload方法代碼示例

本文整理匯總了Java中org.springframework.test.web.servlet.request.MockMvcRequestBuilders.fileUpload方法的典型用法代碼示例。如果您正苦於以下問題:Java MockMvcRequestBuilders.fileUpload方法的具體用法?Java MockMvcRequestBuilders.fileUpload怎麽用?Java MockMvcRequestBuilders.fileUpload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.test.web.servlet.request.MockMvcRequestBuilders的用法示例。


在下文中一共展示了MockMvcRequestBuilders.fileUpload方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: postDocumentVersion

import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; //導入方法依賴的package包/類
public ResultActions postDocumentVersion(String urlTemplate, MockMultipartFile file) {

        MockMultipartHttpServletRequestBuilder builder =
                MockMvcRequestBuilders.fileUpload(urlTemplate);


        builder.with(request -> {
            request.setMethod("POST");
            return request;
        });

        return translateException(() -> mvc.perform(
                builder
                    .file(file)
                    .headers(httpHeaders)
        ));

    }
 
開發者ID:hmcts,項目名稱:document-management-store-app,代碼行數:19,代碼來源:RestActions.java

示例2: testCytobandsManagement

import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; //導入方法依賴的package包/類
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testCytobandsManagement() throws Exception {
    Chromosome chromosome;
    ResultActions actions;
    MockMultipartHttpServletRequestBuilder builder;

    // creates a corresponded test genome 'classpath:templates/reference/hp.genome.fa'
    final Reference reference = createGenome();

    // 1. tries to save cytobands corresponded to the reference registered above
    final Resource resource = getTemplateResource(FileTemplates.HP_CYTOBANDS.getPath());
    final MockMultipartFile multipartFile = new MockMultipartFile(UPLOAD_FILE_PARAM, resource.getFilename(),
            null, resource.getInputStream());
    builder = MockMvcRequestBuilders.fileUpload(SAVE_CYTOBANDS);
    actions = mvc()
            .perform(builder
                    .file(multipartFile)
                    .param(REFERENCE_ID_PARAM, String.valueOf(reference.getId()))
                    .contentType(MediaType.MULTIPART_FORM_DATA_VALUE))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentType(EXPECTED_CONTENT_TYPE))
            .andExpect(MockMvcResultMatchers.jsonPath(JPATH_PAYLOAD).exists())
            .andExpect(MockMvcResultMatchers.jsonPath(JPATH_STATUS).value(ResultStatus.OK.name()))
            .andExpect(MockMvcResultMatchers.jsonPath(JPATH_MESSAGE).value(getMessage("info.cytobands.upload.done",
                    resource.getFilename())));
    actions.andDo(MockMvcResultHandlers.print());

    // 2. tries to get a track with cytobands for a particular chromosome
    chromosome = reference.getChromosomes().stream().filter(e -> e.getName().equals(CHR_A1))
            .findAny().get();
    actions = mvc()
            .perform(get(String.format(LOAD_CYTOBANDS, chromosome.getId())))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentType(EXPECTED_CONTENT_TYPE))
            .andExpect(MockMvcResultMatchers.jsonPath(JPATH_PAYLOAD).exists())
            .andExpect(MockMvcResultMatchers.jsonPath(JPATH_STATUS).value(ResultStatus.OK.name()));
    ResponseResult<Track<Cytoband>> result = getObjectMapper()
            .readValue(actions.andReturn().getResponse().getContentAsByteArray(),
                    getTypeFactory().constructParametrizedType(ResponseResult.class, ResponseResult.class,
                            getTypeFactory().constructParametrizedType(Track.class, Track.class, Cytoband.class)));
    final Track<Cytoband> track = result.getPayload();
    Assert.assertTrue("Unexpected number of bands.", CHR_NUMBER_OF_BANDS == track.getBlocks().size());
    Assert.assertTrue("Unexpected a beginning position for a track.", 1 == track.getStartIndex());
    ReflectionAssert.assertReflectionEquals("Unexpected chromosome.", chromosome, track.getChromosome());
    Assert.assertTrue("Unexpected an ending position for a track.", track.getEndIndex().equals(
        chromosome.getSize()));
    actions.andDo(MockMvcResultHandlers.print());

    // 3. tries to get a track for a chromosome without cytobands
    chromosome = reference.getChromosomes().stream().filter(e -> e.getName().equals(CHR_A5))
            .findAny().get();
    actions = mvc()
            .perform(get(String.format(LOAD_CYTOBANDS, chromosome.getId())))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentType(EXPECTED_CONTENT_TYPE))
            .andExpect(MockMvcResultMatchers.jsonPath(JPATH_PAYLOAD).doesNotExist())
            .andExpect(MockMvcResultMatchers.jsonPath(JPATH_STATUS).value(ResultStatus.WARN.name()));
    actions.andDo(MockMvcResultHandlers.print());
}
 
開發者ID:react-dev26,項目名稱:NGB-master,代碼行數:61,代碼來源:CytobandControllerTest.java

示例3: postDocuments

import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; //導入方法依賴的package包/類
public ResultActions postDocuments(String urlTemplate, List<MultipartFile> files, Classifications classification, List<String> roles) {

        MockMultipartHttpServletRequestBuilder builder = MockMvcRequestBuilders.fileUpload(urlTemplate);

        builder.param("classification", classification.toString());

        files.forEach(f -> builder.file((MockMultipartFile) f));

        return translateException(() -> mvc.perform(
            builder.headers(httpHeaders)
        ));

    }
 
開發者ID:hmcts,項目名稱:document-management-store-app,代碼行數:14,代碼來源:RestActions.java


注:本文中的org.springframework.test.web.servlet.request.MockMvcRequestBuilders.fileUpload方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。