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"), params);
    ActionDoc doc = getCommentForMethod(result.getResponse().getContentAsString(), method);
    return doc;
  }
  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"), params);
    Assert.doesNotContain(
        "/**",
        result.getResponse().getContentAsString(),
        "generation of api.js should not contain method documentation");
  }
  @Test
  public void testMockGetUserByUsernameAndPassword1() throws Exception {
    MockHttpServletRequestBuilder requestBuilder =
        MockMvcRequestBuilders.get("/login/user/{username}/pwd/{password}");

    requestBuilder.param("username", "tholmes");
    requestBuilder.param("password", "pass1");

    this.mockMvc.perform(requestBuilder).andDo(print());
  }
Пример #4
0
  private void saveProfile(String editTeamUri) throws Exception {
    MockHttpServletRequestBuilder requestBuilder = put(editTeamUri).principal(principal);
    requestBuilder.param("name", "Some_ Guy_");
    requestBuilder.param("jobTitle", "Rock Star");
    requestBuilder.param("location", "London_");
    requestBuilder.param("bio", "I am just a guy_");
    requestBuilder.param("twitterUsername", "tw_some-guy_");
    requestBuilder.param("speakerdeckUsername", "sd_some-guy_");
    requestBuilder.param("lanyrdUsername", "ly_some-guy_");
    requestBuilder.param("geoLocation", "-12.5,45.3");
    requestBuilder.param(
        "videoEmbeds",
        "<iframe width=\"420\" height=\"315\" src=\"//www.youtube.com/embed/J---aiyznGQ\" frameborder=\"0\" allowfullscreen></iframe>");

    performRequestAndExpectRedirect(requestBuilder, editTeamUri);

    MemberProfile profile = teamRepository.findByUsername("some-guy");
    assertThat(profile, not(nullValue()));
    assertEquals("some-guy", profile.getUsername());
    assertEquals("gh-some-guy", profile.getGithubUsername());
    assertEquals("Some_ Guy_", profile.getName());
    assertEquals("Rock Star", profile.getJobTitle());
    assertEquals("London_", profile.getLocation());
    assertEquals("I am just a guy_", profile.getBio());
    assertEquals("tw_some-guy_", profile.getTwitterUsername());
    assertEquals("sd_some-guy_", profile.getSpeakerdeckUsername());
    assertEquals("ly_some-guy_", profile.getLanyrdUsername());
    assertEquals(
        "<iframe width=\"420\" height=\"315\" src=\"//www.youtube.com/embed/J---aiyznGQ\" frameborder=\"0\" allowfullscreen></iframe>",
        profile.getVideoEmbeds());

    assertThat(profile.getGeoLocation(), not(nullValue()));
    assertThat((double) profile.getGeoLocation().getLatitude(), closeTo(-12.5, 0.1));
    assertThat((double) profile.getGeoLocation().getLongitude(), closeTo(45.3, 0.1));
  }
Пример #5
0
  private MockHttpServletResponse getResponse(String url, Map<String, String> params)
      throws Exception {
    MockHttpServletRequestBuilder request = get(url);
    if (params != null && params.size() > 0) {
      for (String key : params.keySet()) {
        request.param(key, params.get(key));
      }
    }
    ResultActions result = this.mockMvc.perform(request);
    result.andExpect(MockMvcResultMatchers.status().is(this.HttpStatus));
    MvcResult mvcresult = result.andReturn();
    MockHttpServletResponse mockresponse = mvcresult.getResponse();

    return mockresponse;
  }