Package org.springframework.test.web.servlet

Examples of org.springframework.test.web.servlet.MvcResult


    }

    @Test
    public void test9() throws Exception {
        //异常处理
        MvcResult result = mockMvc.perform(get("/user/exception")) //执行请求
                .andExpect(status().isInternalServerError()) //验证服务器内部错误
                .andReturn();

        Assert.assertTrue(IllegalArgumentException.class.isAssignableFrom(result.getResolvedException().getClass()));
    }
View Full Code Here


    @Test
    public void test11() throws Exception {
        //异步测试

        //Callable
        MvcResult result = mockMvc.perform(get("/user/async1?id=1&name=zhang")) //执行请求
                .andExpect(request().asyncStarted())
                .andExpect(request().asyncResult(CoreMatchers.instanceOf(User.class))) //默认会等10秒超时
                .andReturn();

View Full Code Here

        mockMvc = standaloneSetup(userController).build();
    }

    @Test
    public void testView() throws Exception {
        MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get("/user/1"))
                .andExpect(MockMvcResultMatchers.view().name("user/view"))
                .andExpect(MockMvcResultMatchers.model().attributeExists("user"))
                .andDo(MockMvcResultHandlers.print())
                .andReturn();

        Assert.assertNotNull(result.getModelAndView().getModel().get("user"));
    }
View Full Code Here

        this.mockMvc = webAppContextSetup(this.wac).alwaysExpect(status().isOk()).build();
    }

    @Test
    void testDevice() throws Exception {
        MvcResult mvcResult =mockMvc.perform(get("/").param("device", "mobile")).andExpect(request().asyncStarted())
                .andExpect(request().asyncResult("index")).andReturn();
        mockMvc.perform(asyncDispatch(mvcResult)).andExpect(model().attribute("device", is(equalTo("mobile"))));
    }
View Full Code Here

                .andExpect(asyncJsonPath("$.total", is(equalTo(count)))).andDo(print());
    }

    @Test
    public void testMyinfo() throws Exception {
        MvcResult mvcResult = mockMvc.perform(post("/user/myinfo").principal(new TestingAuthenticationToken("admin", null)))
                .andExpect(request().asyncStarted()).andExpect(request().asyncResult(is(not(isEmptyOrNullString())))).andReturn();
        mvcResult = mockMvc.perform(asyncDispatch(mvcResult)).andReturn();
        Member member = (Member) mvcResult.getRequest().getAttribute("member");
        logger.debug("My account is \"{}\" and my name is {}", member.getId(), member.getName());
        assertThat("Test UserInfo error ", "admin", is(equalTo(member.getId())));
    }
View Full Code Here

        assertThat("Test UserInfo error ", "admin", is(equalTo(member.getId())));
    }

    @Test
    public void testUserInfo() throws Exception {
        MvcResult mvcResult = mockMvc.perform(post("/admin/user/{account}", "admin"))
                .andExpect(request().asyncStarted()).andExpect(request().asyncResult(is(not(isEmptyOrNullString())))).andReturn();
        mvcResult = mockMvc.perform(asyncDispatch(mvcResult)).andReturn();
        Member member = (Member) mvcResult.getRequest().getAttribute("member");
        logger.debug("account \"{}\" name is {}", member.getId(), member.getName());
        assertThat("Test UserInfo error ", "admin", is(equalTo(member.getId())));
    }
View Full Code Here

    assertThat(xpath.evaluate("/feed/icon", doc), is("http://www.example.com/favicon.ico"));
  }

  private Document doGetForDocument(String path) throws Exception {
    ResultActions resultActions = mockMvc.perform(get(path));
    MvcResult mvcResult = resultActions.andReturn();
    return getAtomFeedDocument(mvcResult);
  }
View Full Code Here

public class QuestionsIndexTests extends AbstractIntegrationTests {

    @Ignore
    @Test
    public void showsQuestionsIndex() throws Exception {
        MvcResult result = mockMvc.perform(get("/questions")).andExpect(status().isOk())
                .andExpect(content().contentTypeCompatibleWith("text/html")).andReturn();

        Document document = Jsoup.parse(result.getResponse().getContentAsString());
        String body = document.select("body").text();

    // header title
    assertThat(body, containsString("Spring at StackOverflow"));
View Full Code Here

        checkSnapshot(releases);
    }

    public List<Object> getAndCheckProjectReleases(String projectId, String expectedProjectName) throws Exception {
        MvcResult result = mockMvc.perform(
                MockMvcRequestBuilders.get("/project_metadata/" + projectId
                        + "?callback=a_function_name")).andReturn();

        String content = result.getResponse().getContentAsString();

        String functionNameRegex = "^([^(]*)\\((.*)\\);$";
        Matcher matcher = Pattern.compile(functionNameRegex).matcher(content);
        if (matcher.find()) {
            assertThat(matcher.group(1), equalTo("a_function_name"));
View Full Code Here

                .andExpect(content().contentTypeCompatibleWith("text/html"));
    }

    @Test
    public void showsAllStsGaDownloads() throws Exception {
        MvcResult mvcResult = mockMvc.perform(get("/tools/sts/all"))
                .andExpect(status().isOk())
                .andExpect(content().contentTypeCompatibleWith("text/html"))
                .andReturn();

        Document document = Jsoup.parse(mvcResult.getResponse().getContentAsString());
        assertThat(document.select("h1").text(), equalTo("Spring Tool Suite™ Downloads"));
        assertThat(document.select(".ga--release h2.tool-versions--version").text(), allOf(containsString("STS"),
                containsString("RELEASE")));
        assertThat(document.select(".platform h3").text(), containsString("Windows"));
View Full Code Here

TOP

Related Classes of org.springframework.test.web.servlet.MvcResult

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.