Package org.springframework.test.web.servlet.request

Examples of org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder


       
        Resource r = catalog.getResourceLoader().get("workspaces/cite/styles/STYLE.PROPERTIES");
        assertEquals("created", Resource.Type.RESOURCE, r.getType() );
       
        // test delete
        MockHttpServletRequestBuilder delete = delete("/api/icons/foo/icon.png");
        boolean removed = ctrl.delete("cite","STYLE.PROPERTIES");
        assertEquals( true, removed );
    }
View Full Code Here


    configurationService.afterPropertiesSet();
  }

  @Test
  public void testCallExistsFormPostMethod() throws Exception {
    MockHttpServletRequestBuilder request = post("/router").accept(MediaType.ALL)
        .contentType(MediaType.APPLICATION_JSON).characterEncoding("UTF-8");

    request.param("extTID", "12");
    request.param("extAction", "formInfoController");
    request.param("extMethod", "updateInfo");
    request.param("extType", "rpc");
    request.param("name", "Ralph");
    request.param("age", "20");
    request.param("admin", "true");
    request.param("salary", "12.3");
    request.param("result", "theResult");

    mockMvc.perform(request).andExpect(status().isOk())
        .andExpect(forwardedUrl("updateInfo"));
  }
View Full Code Here

    mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
  }

  @Test
  public void testCallExistsFormPostMethod() throws Exception {
    MockHttpServletRequestBuilder request = post("/router").accept(MediaType.ALL)
        .contentType(MediaType.APPLICATION_JSON).characterEncoding("UTF-8");

    request.param("extTID", "14");
    request.param("extAction", "formInfoController3");
    request.param("extMethod", "updateInfoJson");
    request.param("extType", "rpc");

    mockMvc.perform(request).andExpect(status().isOk());
  }
View Full Code Here

  }

  public static ExtDirectPollResponse performPollRequest(MockMvc mockMvc, String bean,
      String method, String event, Map<String, String> params, HttpHeaders headers,
      List<Cookie> cookies, boolean withSession) throws Exception {
    MockHttpServletRequestBuilder request = post(
        "/poll/" + bean + "/" + method + "/" + event).accept(MediaType.ALL)
        .contentType(MediaType.APPLICATION_JSON).characterEncoding("UTF-8");

    if (cookies != null) {
      request.cookie(cookies.toArray(new Cookie[cookies.size()]));
    }

    if (withSession) {
      request.session(new MockHttpSession());
    }

    if (params != null) {
      for (String paramName : params.keySet()) {
        request.param(paramName, params.get(paramName));
      }
    }

    if (headers != null) {
      request.headers(headers);
    }

    MvcResult result = mockMvc.perform(request).andExpect(status().isOk())
        .andExpect(content().contentType("application/json;charset=UTF-8"))
        .andExpect(content().encoding("UTF-8")).andReturn();
View Full Code Here

  }

  public static List<SSEvent> performSseRequest(MockMvc mockMvc, String bean,
      String method, Map<String, String> params, HttpHeaders headers,
      List<Cookie> cookies, boolean withSession) throws Exception {
    MockHttpServletRequestBuilder request = post("/sse/" + bean + "/" + method)
        .accept(MediaType.ALL)
        .contentType(MediaType.parseMediaType("text/event-stream"))
        .characterEncoding("UTF-8");

    if (cookies != null) {
      request.cookie(cookies.toArray(new Cookie[cookies.size()]));
    }

    if (withSession) {
      request.session(new MockHttpSession());
    }

    if (params != null) {
      for (String paramName : params.keySet()) {
        request.param(paramName, params.get(paramName));
      }
    }

    if (headers != null) {
      request.headers(headers);
    }

    MvcResult result = mockMvc.perform(request).andExpect(status().isOk())
        .andExpect(content().contentType("text/event-stream;charset=UTF-8"))
        .andExpect(content().encoding("UTF-8")).andReturn();
View Full Code Here

  public static MvcResult performRouterRequest(MockMvc mockMvc, String content,
      Map<String, String> params, HttpHeaders headers, List<Cookie> cookies,
      boolean withSession) throws Exception {

    MockHttpServletRequestBuilder request = post("/router").accept(MediaType.ALL)
        .contentType(MediaType.APPLICATION_JSON).characterEncoding("UTF-8");

    if (cookies != null) {
      request.cookie(cookies.toArray(new Cookie[cookies.size()]));
    }

    if (withSession) {
      request.session(new MockHttpSession());
    }

    if (content != null) {
      request.content(content);
    }

    if (params != null) {
      for (String paramName : params.keySet()) {
        request.param(paramName, params.get(paramName));
      }

    }

    if (headers != null) {
      request.headers(headers);
    }

    return mockMvc.perform(request).andExpect(status().isOk())
        .andExpect(content().contentType("application/json;charset=UTF-8"))
        .andExpect(content().encoding("UTF-8")).andReturn();
View Full Code Here

  private void doRequestWithoutDocs(String url) throws Exception {
    ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns")
        .actionNs("actionns").group("doc")
        .configuration(configurationService.getConfiguration()).build();
    MockHttpServletRequestBuilder request = get(url).accept(MediaType.ALL)
        .characterEncoding("UTF-8");
    request.param("apiNs", params.getApiNs());
    request.param("actionNs", params.getActionNs());
    request.param("group", params.getGroup());

    MvcResult result = mockMvc.perform(request).andExpect(status().isOk())
        .andExpect(content().contentType("application/javascript")).andReturn();

    ApiControllerTest.compare(result, ApiControllerTest.groupApisWithDoc("actionns"),
View Full Code Here

  private ActionDoc callApi(String method) throws Exception {
    ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns")
        .actionNs("actionns").group("doc")
        .configuration(configurationService.getConfiguration()).build();
    MockHttpServletRequestBuilder request = get("/api-debug-doc.js").accept(
        MediaType.ALL).characterEncoding("UTF-8");
    request.param("apiNs", params.getApiNs());
    request.param("actionNs", params.getActionNs());
    request.param("group", params.getGroup());

    MvcResult result = mockMvc.perform(request).andExpect(status().isOk())
        .andExpect(content().contentType("application/javascript")).andReturn();

    ApiControllerTest.compare(result, ApiControllerTest.groupApisWithDoc("actionns"),
View Full Code Here

    return doTest(mockMvc, url, params, expectedApi);
  }

  private static MvcResult doTest(MockMvc mockMvc, String url, ApiRequestParams params,
      RemotingApi expectedApi) throws Exception {
    MockHttpServletRequestBuilder request = get(url).accept(MediaType.ALL)
        .characterEncoding("UTF-8");

    if (params.getApiNs() != null) {
      request.param("apiNs", params.getApiNs());
    }
    if (params.getActionNs() != null) {
      request.param("actionNs", params.getActionNs());
    }
    if (params.getFormat() != null) {
      request.param("format", params.getFormat());
    }
    if (params.getGroup() != null) {
      request.param("group", params.getGroup());
    }
    if (params.getPollingUrlsVar() != null) {
      request.param("pollingUrlsVar", params.getPollingUrlsVar());
    }
    if (params.getRemotingApiVar() != null) {
      request.param("remotingApiVar", params.getRemotingApiVar());
    }
    if (params.getSseVar() != null) {
      request.param("sseVar", params.getSseVar());
    }
    if (params.isFullRouterUrl() != null && params.isFullRouterUrl()) {
      request.param("fullRouterUrl", "true");
    }
    if (params.getBaseRouterUrl() != null) {
      request.param("baseRouterUrl", params.getBaseRouterUrl());
    }

    String contentType = "application/javascript";
    if ("json".equals(params.getFormat())) {
      contentType = "application/json;charset=UTF-8";
View Full Code Here

    return doTest(mockMvc, url, params, expectedApi);
  }

  private static MvcResult doTest(MockMvc mockMvc, String url, ApiRequestParams params,
      RemotingApi expectedApi) throws Exception {
    MockHttpServletRequestBuilder request = get(url).accept(MediaType.ALL)
        .characterEncoding("UTF-8");

    if (params.getFormat() != null) {
      request.param("format", params.getFormat());
    }
    if (params.getGroup() != null) {
      request.param("group", params.getGroup());
    }

    String contentType = "application/javascript";
    if ("json".equals(params.getFormat())) {
      contentType = "application/json;charset=UTF-8";
View Full Code Here

TOP

Related Classes of org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder

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.