当前位置: 首页>>代码示例>>Java>>正文


Java MockMvcResultHandlers类代码示例

本文整理汇总了Java中org.springframework.test.web.servlet.result.MockMvcResultHandlers的典型用法代码示例。如果您正苦于以下问题:Java MockMvcResultHandlers类的具体用法?Java MockMvcResultHandlers怎么用?Java MockMvcResultHandlers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MockMvcResultHandlers类属于org.springframework.test.web.servlet.result包,在下文中一共展示了MockMvcResultHandlers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addBiz

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
@Test
public void addBiz() throws Exception {
	Partner bizInfo = new Partner();
	bizInfo.setPartnerKey("account");
	bizInfo.setUseAuth(true);
	bizInfo.setRangeCount(10000);
	bizInfo.setStart(44900000);
	bizInfo.setPartnerSecret("Xr&[email protected]");
	System.out.println(JSONObject.toJSONString(bizInfo));
	mockMvc.perform(post("/api/snowflake/add-biz").content(JSONObject.toJSONBytes(bizInfo))
	                                              .header("Content-Type", "application/json;charset=UTF-8"))
	       .andDo(MockMvcResultHandlers.print())
	       .andExpect(status().isOk())
	       .andExpect(jsonPath("$.code").value(0))
	       .andExpect(jsonPath("$.data").value("ok"));
}
 
开发者ID:mm23504570,项目名称:snowflake,代码行数:17,代码来源:SnowflakeControllerTest.java

示例2: moreLikeThis_DisplaySetTrue

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
@Test
public void moreLikeThis_DisplaySetTrue() throws Exception {

    // MoreLikeThis Posts Enabled, returns an HTML Response

    applicationSettings.setMoreLikeThisDisplay(true);
    List<Post> posts = postService.getAllPosts();
    postDocService.reindexPosts(posts);

    mockMvc.perform(get("/post/" + MLT_POSTNAME))
            .andExpect(model().attributeExists(MORELIKETHIS_ATTRIBUTE));

    MvcResult mvcResult = mockMvc.perform(get("/json/posts/post/mlt/" + MLT_POSTID))
            .andExpect(status().isOk())
            .andDo(MockMvcResultHandlers.print())
            .andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML))
            .andReturn();

    assertThat(mvcResult.getResponse().getContentAsString(),
            containsString("<div class=\"mlt-item\">"));

}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:23,代码来源:PostsRestControllerTests.java

示例3: should_update_valid_book_and_return_ok_status

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
@Test
public void should_update_valid_book_and_return_ok_status() throws Exception {
    Book book = new Book("978-0321356680","Book updated","Publisher");
    book.setDescription("New description");

    Author author = new Author("John","Doe");
    book.addAuthor(author);

    mockMvc.perform(put("/api/books/978-0321356680")
            .contentType(MediaType.APPLICATION_JSON)
            .content(json(book)))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
            .andExpect(jsonPath("$.id", is(1)))
            .andExpect(jsonPath("$.title", is("Book updated")))
            .andExpect(jsonPath("$.description", is("New description")))
            .andExpect(jsonPath("$.publisher", is("Publisher")))
            .andExpect(jsonPath("$.authors[0].firstName", is("John")))
            .andExpect(jsonPath("$.authors[0].lastName", is("Doe")))
            .andDo(MockMvcResultHandlers.print());
}
 
开发者ID:sbouclier,项目名称:java-rest-books,代码行数:22,代码来源:BookControllerTest.java

示例4: should_not_update_unknown_book_and_return_not_found_status

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
@Test
public void should_not_update_unknown_book_and_return_not_found_status() throws Exception {
    Book book = new Book("978-0321356680","Book updated","Publisher");
    book.setDescription("New description");

    Author author = new Author("John","Doe");
    book.addAuthor(author);

    mockMvc.perform(put("/api/books/000-1234567890")
            .contentType(MediaType.APPLICATION_JSON)
            .content(json(book)))
            .andExpect(status().isNotFound())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
            .andExpect(jsonPath("$[0].logref", is("error")))
            .andExpect(jsonPath("$[0].message", containsString("could not find book with ISBN: '000-1234567890'")))
            .andDo(MockMvcResultHandlers.print());
}
 
开发者ID:sbouclier,项目名称:java-rest-books,代码行数:18,代码来源:BookControllerTest.java

示例5: testAddBook

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
@Test
public void testAddBook() {
	try {
		mockMVC.perform(MockMvcRequestBuilders.post("/addBook.htm")
				
						.contentType(MediaType.APPLICATION_FORM_URLENCODED)
						.param("bookName", "Book_test")
						.param("author", "author_test")
						.param("description", "adding book for test")
						.param("ISBN", "1234")
						.param("price", "9191")
						.param("publication", "This is the test publication")
						.requestAttr("book", new Book()))
				.andExpect(MockMvcResultMatchers.view().name("display"))
				.andExpect(MockMvcResultMatchers.model().attribute("auth_name","author_test"))
				.andDo(MockMvcResultHandlers.print());
		;
	} catch (Exception e) {
		// TODO: handle exception
		fail(e.getMessage());

	}

}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:25,代码来源:TestAddBookController_Integration.java

示例6: testAddBook_Form_validation

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
@Test
public void testAddBook_Form_validation() {
	try {

		mockMVC.perform(MockMvcRequestBuilders.post("/addBook.htm")
				
				.contentType(MediaType.APPLICATION_FORM_URLENCODED)
				.param("bookName", "Book_test")
				.param("author", "author_test")
				.param("description", "adding book for test")
				.param("ISBN", "1234")
				.param("price", "9191")
				.param("publication", "This is the test publication")
				.requestAttr("book", new Book()))
				.andExpect(MockMvcResultMatchers.view().name("bookForm"))
				.andExpect(
						MockMvcResultMatchers
								.model()
								.attributeHasErrors("book"))
				
				.andDo(MockMvcResultHandlers.print());
	} catch (Exception e) {
		// TODO: handle exception
		fail(e.getMessage());
		e.printStackTrace();
	}
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:28,代码来源:TestAddBookController.java

示例7: loadMy

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
private List<ProjectVO> loadMy() throws Exception {
    ResultActions actions = mvc()
        .perform(get(URL_LOAD_MY_PROJECTS)
                     .contentType(EXPECTED_CONTENT_TYPE))
        .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()));
    actions.andDo(MockMvcResultHandlers.print());

    ResponseResult<List<ProjectVO>> myProjects = getObjectMapper()
        .readValue(actions.andReturn().getResponse().getContentAsByteArray(),
                   getTypeFactory().constructParametrizedType(ResponseResult.class, ResponseResult.class,
                                                              getTypeFactory().constructParametrizedType(List.class,
                                                                                     List.class, ProjectVO.class)));

    Assert.assertNotNull(myProjects.getPayload());
    Assert.assertFalse(myProjects.getPayload().isEmpty());

    return myProjects.getPayload();
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:22,代码来源:ProjectControllerTest.java

示例8: loadProject

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
private ProjectVO loadProject(long projcetId) throws Exception {
    ResultActions actions = mvc()
        .perform(get(String.format(URL_LOAD_PROJECT, projcetId)).contentType(EXPECTED_CONTENT_TYPE))
        .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()));
    actions.andDo(MockMvcResultHandlers.print());

    ResponseResult<ProjectVO> res = getObjectMapper()
        .readValue(actions.andReturn().getResponse().getContentAsByteArray(),
                   getTypeFactory().constructParametrizedType(ResponseResult.class, ResponseResult.class,
                                                              ProjectVO.class));

    ProjectVO loadedProject = res.getPayload();
    Assert.assertNotNull(loadedProject);
    return loadedProject;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:19,代码来源:ProjectControllerTest.java

示例9: assertSortRequest

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
private void assertSortRequest(FeatureFileSortRequest request, ArgumentMatcher payloadMatcher) throws Exception {
    ResultActions actions = mvc()
            .perform(post(URL_SORT).content(getObjectMapper().writeValueAsString(request))
                    .contentType(EXPECTED_CONTENT_TYPE))
            .andExpect(status().isOk())
            .andExpect(content().contentType(EXPECTED_CONTENT_TYPE))
            .andExpect(jsonPath(JPATH_PAYLOAD).value(payloadMatcher))
            .andExpect(jsonPath(JPATH_STATUS).value(ResultStatus.OK.name()));
    actions.andDo(MockMvcResultHandlers.print());

    final ResponseResult<String> res = getObjectMapper()
            .readValue(actions.andReturn().getResponse().getContentAsByteArray(),
                    getTypeFactory().constructParametrizedType(ResponseResult.class, ResponseResult.class,
                            String.class));

    Assert.assertNotNull(res.getPayload());
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:18,代码来源:ToolsControllerTest.java

示例10: testLoadHistogram

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
private void testLoadHistogram(long fileId) throws Exception {
    TrackQuery histogramQuery = initTrackQuery(fileId);
    ResultActions actions = mvc().perform(post(URL_LOAD_GENES_HISTOGRAM).content(getObjectMapper()
                                                                       .writeValueAsString(histogramQuery))
                                .contentType(EXPECTED_CONTENT_TYPE))
        .andExpect(status().isOk())
        .andExpect(content().contentType(EXPECTED_CONTENT_TYPE))
        .andExpect(jsonPath(JPATH_PAYLOAD).exists())
        .andExpect(jsonPath(JPATH_STATUS).value(ResultStatus.OK.name()));
    actions.andDo(MockMvcResultHandlers.print());

    ResponseResult<Track<Wig>> histogram = getObjectMapper()
        .readValue(actions.andReturn().getResponse().getContentAsByteArray(),
                   getTypeFactory().constructParametrizedType(ResponseResult.class, ResponseResult.class,
                                                          getTypeFactory().constructParametrizedType(Track.class,
                                                                                                     Track.class,
                                                                                                     Wig.class)));

    Assert.assertFalse(histogram.getPayload().getBlocks().isEmpty());
    Assert.assertTrue(histogram.getPayload().getBlocks()
                      .stream()
                      .allMatch(b -> b.getStartIndex() != null && b.getEndIndex() != null && b.getValue() != null));
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:24,代码来源:GeneControllerTest.java

示例11: testSearchGenesInProject

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
@Test
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
public void testSearchGenesInProject() throws Exception {
    GeneSearchQuery geneSearchQuery = new GeneSearchQuery();
    geneSearchQuery.setSearch("ENS");
    geneSearchQuery.setVcfIds(Collections.singletonList(vcfFile.getId()));

    ResultActions actions = mvc()
        .perform(post(URL_FILTER_SEARCH_GENES).content(
            getObjectMapper().writeValueAsString(geneSearchQuery)).contentType(EXPECTED_CONTENT_TYPE))
        .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()))
        .andDo(MockMvcResultHandlers.print());

    ResponseResult<Set<String>> geneNamesAvailable = getObjectMapper()
        .readValue(actions.andReturn().getResponse().getContentAsByteArray(),
                   getTypeFactory().constructParametrizedType(ResponseResult.class, ResponseResult.class,
                                                              getTypeFactory().constructParametrizedType(Set.class,
                                                                                         Set.class, String.class)));

    Assert.assertFalse(geneNamesAvailable.getPayload().isEmpty());
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:25,代码来源:FilterControllerTest.java

示例12: testGetFieldInfo

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
@Test
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
public void testGetFieldInfo() throws Exception {
    ResultActions actions = mvc()
        .perform(post(URL_FILTER_INFO).content(getObjectMapper().writeValueAsBytes(
            Collections.singletonList(vcfFile.getId()))).contentType(EXPECTED_CONTENT_TYPE))
        .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()));
    actions.andDo(MockMvcResultHandlers.print());

    ResponseResult<VcfFilterInfo> infoRes = getObjectMapper().readValue(
        actions.andReturn().getResponse().getContentAsByteArray(),
        getTypeFactory().constructParametrizedType(ResponseResult.class,
                                                   ResponseResult.class, VcfFilterInfo.class));

    Assert.assertNotNull(infoRes.getPayload());
    Assert.assertFalse(infoRes.getPayload().getAvailableFilters().isEmpty());
    Assert.assertNull(infoRes.getPayload().getInfoItemMap());
    Assert.assertFalse(infoRes.getPayload().getInfoItems().isEmpty());
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:23,代码来源:FilterControllerTest.java

示例13: testGroupVariations

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
@Test
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
public void testGroupVariations() throws Exception {
    VcfFilterForm vcfFilterForm = new VcfFilterForm();
    vcfFilterForm.setVcfFileIds(Collections.singletonList(vcfFile.getId()));

    ResultActions actions = mvc()
        .perform(post(URL_FILTER_GROUP).content(getObjectMapper().writeValueAsString(vcfFilterForm))
                     .param("groupBy", "VARIATION_TYPE")
                     .contentType(EXPECTED_CONTENT_TYPE))
        .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()));
    actions.andDo(MockMvcResultHandlers.print());

    ResponseResult<List<Group>> groupRes = getObjectMapper()
        .readValue(actions.andReturn().getResponse().getContentAsByteArray(),
                   getTypeFactory().constructParametrizedType(ResponseResult.class, ResponseResult.class,
                                      getTypeFactory().constructParametrizedType(List.class, List.class,
                                             Group.class)));

    Assert.assertFalse(groupRes.getPayload().isEmpty());
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:25,代码来源:FilterControllerTest.java

示例14: testValidate

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
@Test
public void testValidate() {
	String email = "[email protected]";
	String password = "********";
	Map<String, String> paramMap = Maps.newHashMap();
	paramMap.put("email", email);
	String pwd = Base64.getEncoder().encodeToString(EncryptUtil.encrypt(password, configProperties.getKey()));
	paramMap.put("password", pwd);
	try {
		mockMvc.perform(MockMvcRequestBuilders.post("/mail/validate")
				.contentType(MediaType.APPLICATION_JSON_UTF8)
				.content(SystemUtil.toJson(paramMap)))
				.andExpect(MockMvcResultMatchers.status().isOk())
				.andDo(MockMvcResultHandlers.print());
	} catch (Exception e) {
		LOG.error("Test Validate Error", e);
	}
}
 
开发者ID:Saisimon,项目名称:tip,代码行数:19,代码来源:MailTest.java

示例15: failedPutFileWithWrongUuid

import org.springframework.test.web.servlet.result.MockMvcResultHandlers; //导入依赖的package包/类
@Test
public void failedPutFileWithWrongUuid() throws Exception {
    final long previousRevision = revisionService.getLatest();
    final long previousSize = mediaService.getAll().size();

    final MediaType newMediaType = MediaType.IMAGE;

    final MediaType mediaType = MediaType.IMAGE;
    final MockMultipartFile jsonFile = new MockMultipartFile("file", "texte.jpeg", "sdfsdf", "{json:null}".getBytes());

    formMediaMetadataDto.setMediaType(newMediaType.toString());

    mockMvc.perform(fileUploadAuthenticated("/media/sdpfosdfiosd/file")
            .file(jsonFile)
    )
            .andDo(MockMvcResultHandlers.print())
            .andExpect(status().isNotFound())
            .andReturn();

    Assert.assertEquals(previousSize, mediaService.getAll().size());
    Assert.assertEquals(previousRevision, revisionService.getLatest());
}
 
开发者ID:resourcepool,项目名称:dashboard,代码行数:23,代码来源:MediaControllerMediaWebEditTest.java


注:本文中的org.springframework.test.web.servlet.result.MockMvcResultHandlers类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。