Java 类org.springframework.test.web.servlet.ResultHandler 实例源码

项目:java-fast-framework    文件:ArticleCtrlTest.java   
@Test
public void getListTest() throws Exception {
    //插入一条数据
    articleIo.insert(new Article(null, "测试数据", false));
    //检测接口
    getMockMvc().perform(MockMvcRequestBuilders.post(PATH + "getList")).andDo(new ResultHandler() {
        @Override
        public void handle(MvcResult result) throws Exception {
            JSONObject ret = JSON.parseObject(result.getResponse().getContentAsString());
            //ok
            Assert.assertTrue(ret.getInteger("code") == 0);
            //check list
            Assert.assertTrue(ret.getJSONArray("msg").size() > 0);
        }
    });
}
项目:java-fast-framework    文件:ArticleCtrlTest.java   
@Test
public void getTest() throws Exception {
    final Article article = new Article(null, "测试数据", false);
    //插入一条数据
    articleIo.insert(article);
    //检测接口
    getMockMvc().perform(MockMvcRequestBuilders.post(PATH + "get").param("id", article.getId())).andDo(new ResultHandler() {
        @Override
        public void handle(MvcResult result) throws Exception {
            JSONObject ret = JSON.parseObject(result.getResponse().getContentAsString());
            //ok
            Assert.assertTrue(ret.getInteger("code") == 0);
            //check
            Assert.assertTrue(ret.getJSONObject("msg").getString("id").equals(article.getId()));
        }
    });
}
项目:java-fast-framework    文件:ArticleCtrlTest.java   
@Test
public void putTest() throws Exception {
    final String content = UUID.randomUUID().toString();
    final String token = "darkfireworld";
    //检测接口
    getMockMvc().perform(MockMvcRequestBuilders.post(PATH + "put").param("token", token).param("content", content)).andDo(new ResultHandler() {
        @Override
        public void handle(MvcResult result) throws Exception {
            JSONObject ret = JSON.parseObject(result.getResponse().getContentAsString());
            //ok
            Assert.assertTrue(ret.getInteger("code") == 0);
            //check
            Assert.assertTrue(ret.getJSONObject("msg").getString("id") != null);
            Assert.assertTrue(ret.getJSONObject("msg").getString("content").equals(content));
        }
    });
}
项目:spring4-understanding    文件:MockMvcResultHandlers.java   
@Override
public void handle(MvcResult result) throws Exception {
    if (logger.isDebugEnabled()) {
        StringWriter stringWriter = new StringWriter();
        ResultHandler printingResultHandler =
                new PrintWriterPrintingResultHandler(new PrintWriter(stringWriter));
        printingResultHandler.handle(result);
        logger.debug("MvcResult details:\n" + stringWriter);
    }
}
项目:coderadar    文件:ProjectControllerTest.java   
private ResultHandler documentCreateProject() {
  ConstrainedFields fields = fields(ProjectResource.class);
  return document(
      "projects/create",
      links(
          halLinks(),
          linkWithRel("self").description("Link to the project."),
          linkWithRel("files").description("Link to the project's file patterns."),
          linkWithRel("analyzers").description("Link to the project's analyzer configurations."),
          linkWithRel("strategy").description("Link to the project's analyzing strategy.")),
      requestFields(
          fields.withPath("name").description("The name of the project to be analyzed."),
          fields
              .withPath("vcsUrl")
              .description(
                  "The URL to the version control repository where the project's source files are kept."),
          fields
              .withPath("vcsUser")
              .description(
                  "The user name used to access the version control system of your project. Needs read access only. Don't provide this field if anonymous access is possible."),
          fields
              .withPath("vcsPassword")
              .description(
                  "The password of the version control system user. This password has to be stored in plain text for coderadar to be usable, so make sure to provide a user with only reading permissions. Don't provide this field if anonymous access is possible."),
          fields
              .withPath("vcsOnline")
              .description(
                  "Set to false if you want no interaction with a remote repository for this project. True by default."),
          fields
              .withPath("startDate")
              .description(
                  "The start date of the range of commits which should be analyzed by coderadar. Leave empty to start at the first commit."),
          fields
              .withPath("endDate")
              .description(
                  "The end date of the range of commits which should be analyzed by coderadar. Leave empty to automatically process all new incoming commits.")));
}
项目:coderadar    文件:UserControllerTest.java   
private ResultHandler documentRegistration() {
  ConstrainedFields fields = fields(UserRegistrationDataResource.class);
  return document(
      "user/registration",
      links(halLinks(), linkWithRel("self").description("Link to the user.")),
      requestFields(
          fields.withPath("username").description("The name of the user to be registered."),
          fields
              .withCustomPath("password")
              .description("The password of the user as plaintext")));
}
项目:coderadar    文件:UserControllerTest.java   
private ResultHandler documentLogin() {
  ConstrainedFields fields = fields(UserLoginResource.class);
  return document(
      "user/auth",
      links(halLinks(), linkWithRel("self").description("Link to the user.")),
      requestFields(
          fields.withPath("username").description("The name of the user to be logged in."),
          fields.withPath("password").description("The password of the user as plaintext")));
}
项目:coderadar    文件:UserControllerTest.java   
private ResultHandler documentPasswordChange() {
  ConstrainedFields fields = fields(PasswordChangeResource.class);
  return document(
      "user/password/change",
      links(halLinks(), linkWithRel("self").description("Link to the user.")),
      requestFields(
          fields.withPath("refreshToken").description("the current refresh token of the user"),
          fields
              .withCustomPath("newPassword")
              .description("The password of the user as plaintext")));
}
项目:coderadar    文件:UserControllerTest.java   
private ResultHandler documentRefresh() {
  ConstrainedFields fields = fields(RefreshTokenResource.class);
  return document(
      "user/refresh",
      requestFields(
          fields.withPath("accessToken").description("The expired access token"),
          fields.withPath("refreshToken").description("The valid refresh token")));
}
项目:springrestdoc    文件:MyResultHandler.java   
static public ResultHandler myHandler() {
    return new MyResultHandler();
}
项目:loom    文件:LoomMvcClient.java   
public static ResultHandler print() {
    return handler;
}
项目:spring4-understanding    文件:AbstractMockMvcBuilder.java   
@SuppressWarnings("unchecked")
public final <T extends B> T alwaysDo(ResultHandler resultHandler) {
    this.globalResultHandlers.add(resultHandler);
    return (T) this;
}
项目:spring-cloud-dataflow    文件:BaseDocumentation.java   
private ToggleableResultHandler(ResultHandler delegate) {
    this.delegate = delegate;
}
项目:hawkbit    文件:MockMvcResultPrinter.java   
/**
 * Print {@link MvcResult} details to the "standard" output stream.
 */
public static ResultHandler print() {
    return new ConsolePrintingResultHandler();
}
项目:spring-auto-restdocs    文件:JacksonResultHandlers.java   
public static ResultHandler prepareJackson(ObjectMapper objectMapper) {
    return new JacksonPreparingResultHandler(objectMapper);
}
项目:class-guard    文件:MockMvcResultHandlers.java   
/**
 * Print {@link MvcResult} details to the "standard" output stream.
 */
public static ResultHandler print() {
    return new ConsolePrintingResultHandler();
}
项目:sagan    文件:ProjectsMetadataApiTests.java   
private ResultHandler docs(String name) {
    return document(name,
            preprocessRequest(prettyPrint()),
            preprocessResponse(prettyPrint()));
}
项目:spring4-understanding    文件:ConfigurableMockMvcBuilder.java   
/**
 * Define a global action that should <em>always</em> be applied to every
 * response. For example, writing detailed information about the performed
 * request and resulting response to {@code System.out}.
 *
 * @param resultHandler a ResultHandler; see static factory methods in
 * {@link org.springframework.test.web.servlet.result.MockMvcResultHandlers}
 */
<T extends B> T alwaysDo(ResultHandler resultHandler);
项目:spring4-understanding    文件:MockMvcResultHandlers.java   
/**
 * Log {@link MvcResult} details as a {@code DEBUG} log message via
 * Apache Commons Logging using the log category
 * {@code org.springframework.test.web.servlet.result}.
 * @since 4.2
 * @see #print()
 * @see #print(OutputStream)
 * @see #print(Writer)
 */
public static ResultHandler log() {
    return new LoggingResultHandler();
}
项目:spring4-understanding    文件:MockMvcResultHandlers.java   
/**
 * Print {@link MvcResult} details to the "standard" output stream.
 * @see System#out
 * @see #print(OutputStream)
 * @see #print(Writer)
 * @see #log()
 */
public static ResultHandler print() {
    return print(System.out);
}
项目:spring4-understanding    文件:MockMvcResultHandlers.java   
/**
 * Print {@link MvcResult} details to the supplied {@link OutputStream}.
 * @since 4.2
 * @see #print()
 * @see #print(Writer)
 * @see #log()
 */
public static ResultHandler print(OutputStream stream) {
    return new PrintWriterPrintingResultHandler(new PrintWriter(stream, true));
}
项目:spring4-understanding    文件:MockMvcResultHandlers.java   
/**
 * Print {@link MvcResult} details to the supplied {@link Writer}.
 * @since 4.2
 * @see #print()
 * @see #print(OutputStream)
 * @see #log()
 */
public static ResultHandler print(Writer writer) {
    return new PrintWriterPrintingResultHandler(new PrintWriter(writer, true));
}
项目:class-guard    文件:DefaultMockMvcBuilder.java   
/**
 * Define a global action that should <em>always</em> be applied to every
 * response. For example, writing detailed information about the performed
 * request and resulting response to {@code System.out}.
 *
 * @param resultHandler a ResultHandler; see static factory methods in
 * {@link org.springframework.test.web.servlet.result.MockMvcResultHandlers}
 */
@SuppressWarnings("unchecked")
public final <T extends Self> T alwaysDo(ResultHandler resultHandler) {
    this.globalResultHandlers.add(resultHandler);
    return (T) this;
}