@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); } }); }
@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())); } }); }
@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)); } }); }
@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); } }
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."))); }
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"))); }
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"))); }
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"))); }
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"))); }
static public ResultHandler myHandler() { return new MyResultHandler(); }
public static ResultHandler print() { return handler; }
@SuppressWarnings("unchecked") public final <T extends B> T alwaysDo(ResultHandler resultHandler) { this.globalResultHandlers.add(resultHandler); return (T) this; }
private ToggleableResultHandler(ResultHandler delegate) { this.delegate = delegate; }
/** * Print {@link MvcResult} details to the "standard" output stream. */ public static ResultHandler print() { return new ConsolePrintingResultHandler(); }
public static ResultHandler prepareJackson(ObjectMapper objectMapper) { return new JacksonPreparingResultHandler(objectMapper); }
private ResultHandler docs(String name) { return document(name, preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())); }
/** * 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);
/** * 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(); }
/** * 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); }
/** * 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)); }
/** * 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)); }
/** * 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; }