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

项目:nixmash-blog    文件:AdminControllerTests.java   
@Test
@WithAdminUser
public void siteSettingsUpdated_UpdatesSiteOptions() throws Exception {

    RequestBuilder request = post("/admin/site/settings")
            .param(ISiteOption.SITE_NAME, siteOptionMapDTO.getSiteName())
            .param(ISiteOption.SITE_DESCRIPTION, siteOptionMapDTO.getSiteDescription())
            .param(ISiteOption.ADD_GOOGLE_ANALYTICS, String.valueOf(siteOptionMapDTO.getAddGoogleAnalytics()))
            .param(ISiteOption.GOOGLE_ANALYTICS_TRACKING_ID, siteOptionMapDTO.getGoogleAnalyticsTrackingId())
            .param(ISiteOption.USER_REGISTRATION, String.valueOf(siteOptionMapDTO.getUserRegistration()))
            .with(csrf());

    mvc.perform(request)
            .andExpect(model().attributeHasNoErrors())
            .andExpect(MockMvcResultMatchers.flash().attributeExists("feedbackMessage"))
            .andExpect(redirectedUrl("/admin/site/settings"));
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void updatePostWithValidData_RedirectsToPermalinkPage() throws Exception {

    String newTitle = "New Title for updatePostWithValidData_RedirectsToPermalinkPage Test";

    Post post = postService.getPostById(1L);
    RequestBuilder request = post("/admin/posts/update")
            .param("postId", "1")
            .param("displayType", String.valueOf(post.getDisplayType()))
            .param("postContent", post.getPostContent())
            .param("twitterCardType", post.getPostMeta().getTwitterCardType().name())
            .param("postTitle", newTitle)
            .param("tags", "updatePostWithValidData1, updatePostWithValidData2")
            .with(csrf());

    mvc.perform(request)
            .andExpect(model().hasNoErrors())
            .andExpect(MockMvcResultMatchers.flash().attributeExists("feedbackMessage"))
            .andExpect(redirectedUrl("/admin/posts"));

    Post updatedPost = postService.getPostById(1L);
    assert (updatedPost.getPostTitle().equals(newTitle));
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void updatedPostTitleInAzIncludeFile() throws Exception {

    String newTitle = "New Title for updatedPostTitleInAzIncludeFile Test";

    Post post = postService.getPostById(1L);
    RequestBuilder request = post("/admin/posts/update")
            .param("postId", "1")
            .param("displayType", String.valueOf(post.getDisplayType()))
            .param("postContent", post.getPostContent())
            .param("postTitle", newTitle)
            .param("twitterCardType", TWITTER_SUMMARY)
            .param("tags", "one, two")
            .with(csrf());

    mvc.perform(request);

    File azFile = new File(azTestFileName);
    String contents = FileUtils.readFileToString(azFile);
    assertTrue(contents.contains(newTitle));
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void updatedPostContainsNewCategory() throws Exception {

    Post post = postService.getPostById(1L);
    post.setCategory(PostTestUtils.getUncategorizedCategory());
    assert(post.getCategory().getCategoryId().equals(1L));

    RequestBuilder request = post("/admin/posts/update")
            .param("postId", "1")
            .param("displayType", String.valueOf(post.getDisplayType()))
            .param("postContent", post.getPostContent())
            .param("postTitle", post.getPostTitle())
            .param("twitterCardType", post.getPostMeta().getTwitterCardType().name())
            .param("tags", "one, two")
            .param("categoryId", "3")
            .with(csrf());

    mvc.perform(request);

    post = postService.getPostById(1L);
    assert(post.getCategory().getCategoryId().equals(3L));

}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void updatedPostUpdatesTwitterCardInfo() throws Exception {
    Post post = postService.getPostById(1L);
    assert(post.getPostMeta().getTwitterCardType().equals(TwitterCardType.SUMMARY));

    RequestBuilder request = post("/admin/posts/update")
            .param("postId", "1")
            .param("displayType", String.valueOf(post.getDisplayType()))
            .param("postContent", post.getPostContent())
            .param("postTitle", post.getPostTitle())
            .param("twitterCardType", TwitterCardType.SUMMARY_LARGE_IMAGE.name())
            .param("tags", "one, two")
            .param("categoryId", "3")
            .with(csrf());

    mvc.perform(request);

    post = postService.getPostById(1L);
    assert(post.getPostMeta().getTwitterCardType().equals(TwitterCardType.SUMMARY_LARGE_IMAGE));
}
项目:nixmash-blog    文件:AdminSolrPostsControllerTests.java   
@Test
public void reindexResetsSolrPosts() throws Exception {
    RequestBuilder request = get("/admin/posts/solr/reindex")
            .param("reindex", "doit")
            .with(csrf());

    int originalPostDocCount = postDocService.getAllPostDocuments().size();
    postDocService.removeFromIndex(postDocService.getPostDocByPostId(1L));
   assertThat(postDocService.getAllPostDocuments().size(), is(lessThan(originalPostDocCount)));

    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(model().attributeExists("hasPostDocCount"))
            .andExpect(view().name(ADMIN_POSTS_REINDEX_VIEW));

    assertEquals(postDocService.getAllPostDocuments().size(), originalPostDocCount);
}
项目:cloud-s4-sdk-examples    文件:CostCenterServiceIntegrationTest.java   
@Test
public void testHttpAddSuccess() throws Exception {
    final SapClient sapClient = mockSdk.getErpSystem().getSapClient();

    final String newCostCenterJson = getNewCostCenterAsJson(DEMO_COSTCENTER_ID);

    final RequestBuilder newCostCenterRequest = MockMvcRequestBuilders
            .request(HttpMethod.POST, "/api/v1/rest/client/"+sapClient+"/controllingarea/"+DEMO_CONTROLLING_AREA+"/costcenters")
            .param("testRun", "true")
            .contentType(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_JSON)
            .content(newCostCenterJson);

    mockSdk.requestContextExecutor().execute(new Executable() {
        @Override
        public void execute() throws Exception {
            mockMvc.perform(newCostCenterRequest).andExpect(MockMvcResultMatchers.status().isOk());
        }
    });
}
项目:Robin_Java    文件:SpringBootDemo21ApplicationTests.java   
@Test
public void contextLoads() throws Exception {
    RequestBuilder request = get("/index");
    mvc.perform(request).andExpect(status().isOk()).andExpect(content().string("hello world"));

    request = get("/index/get").param("name", "无境");
    mvc.perform(request).andExpect(status().isOk()).andExpect(content().string("{\"name\":\"无境\",\"title\":\"hello world\"}"));
}
项目:Smart-Shopping    文件:MvcControllerRegistrationTest.java   
@Test
public void registerForm_ForValidDataSucceeds() throws Exception {
    RequestBuilder request = preparePostForRegisterForm("userName", "validUserName");
    request = performPostRedirect(request);
    mockMvc.perform(request)//
            .andDo(print())//
            .andExpect(status().isOk())//
            .andExpect(model().attributeHasNoErrors("newUser"))//
            .andExpect(model().attributeExists("registered"))//
            .andExpect(model().attribute("registered", true));
}
项目:Smart-Shopping    文件:MvcControllerRegistrationTest.java   
@Test
public void registerForm_differentPasswordsFails() throws Exception {
    // preparePostForRegisterForm sets passwordValidation to 123456 so
    // setting another valid value
    RequestBuilder request = preparePostForRegisterForm("password", "01234567");
    request = performPostRedirect(request);
    mockMvc.perform(request)//
            .andDo(print())//
            .andExpect(status().isOk())//
            .andExpect(globalBindingErrors().hasGlobalErrorCode("newUser", "FieldsVerification"))
            //field and its verification field have different values
            .andExpect(model().hasErrors());//
}
项目:service-hive    文件:ServiceProviderTests.java   
@Test
public void checkApplicationInfoTest() throws Exception {
    RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/info").contentType(MediaType.ALL)
            .param("p1", "1").param("p2", "2")
            .accept(MediaType.ALL);

    mvc.perform(requestBuilder).andExpect(MockMvcResultMatchers.status().isOk());
}
项目:nixmash-blog    文件:AdminControllerTests.java   
@Test
@WithAdminUser
public void adminUserCanAccessAdmin() throws Exception {
    RequestBuilder request = get("/admin").with(csrf());
    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(view().name(ADMIN_HOME_VIEW));
}
项目:nixmash-blog    文件:AdminControllerTests.java   
@Test
@WithPostUser
public void postUserCanAccessAdmin() throws Exception {
    RequestBuilder request = get("/admin").with(csrf());
    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(view().name(ADMIN_HOME_VIEW));
}
项目:service-hive    文件:ServiceProviderTests.java   
@Test
public void checkMetricsTest() throws Exception {
    RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/metrics").contentType(MediaType.ALL)
            .accept(MediaType.ALL);

    mvc.perform(requestBuilder).andExpect(MockMvcResultMatchers.status().isOk());
}
项目:nixmash-blog    文件:AdminControllerTests.java   
@Test
@WithAnonymousUser
public void anonymousCannotAccessAdmin() throws Exception {

    // Whereas Erwin is forbidden, anonymous users redirected to login page
    RequestBuilder request = get("/admin").with(csrf());
    mvc.perform(request)
            .andExpect(status().is3xxRedirection())
            .andExpect(loginPage());
}
项目:nixmash-blog    文件:AdminControllerTests.java   
@Test
@WithAdminUser
public void adminUserCanAccessAdminUsersList() throws Exception {
    RequestBuilder request = get("/admin/users").with(csrf());
    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(view().name(ADMIN_USERS_VIEW));
}
项目:nixmash-blog    文件:AdminControllerTests.java   
@Test
@WithAdminUser
public void retrieveSiteOptionsForSiteGeneralSettingsPage() throws Exception {
    RequestBuilder request = get("/admin/site/settings").with(csrf());
    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(model().attributeExists("siteOptionMapDTO"))
            .andExpect(view().name(AdminController.ADMIN_SITESETTINGS_VIEW));
}
项目:nixmash-blog    文件:AdminControllerTests.java   
@Test
@WithAdminUser
public void siteSettingsWithEmptySiteName_ErrorResult() throws Exception {

    RequestBuilder request = post("/admin/site/settings")
            .param(ISiteOption.SITE_NAME, StringUtils.EMPTY)
            .param(ISiteOption.SITE_DESCRIPTION, siteOptionMapDTO.getSiteDescription())
            .param(ISiteOption.ADD_GOOGLE_ANALYTICS, String.valueOf(siteOptionMapDTO.getAddGoogleAnalytics()))
            .param(ISiteOption.GOOGLE_ANALYTICS_TRACKING_ID, siteOptionMapDTO.getGoogleAnalyticsTrackingId()).with(csrf());

    mvc.perform(request)
            .andExpect(model().attributeHasFieldErrors("siteOptionMapDTO", "siteName"))
            .andExpect(view().name(AdminController.ADMIN_SITESETTINGS_VIEW));
}
项目:nixmash-blog    文件:AdminControllerTests.java   
@Test
@WithAdminUser
public void getSetUserPasswordPage() throws Exception {
    RequestBuilder request = get("/admin/users/password/3").with(csrf());
    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(model().attributeExists("userPasswordDTO"))
            .andExpect(model().attributeExists("userDescription"))
            .andExpect(view().name(ADMIN_USERPASSWORD_VIEW));
}
项目:nixmash-blog    文件:AdminControllerTests.java   
@Test
@WithAdminUser
public void resetPasswordMatchingPasswords_RedirectsToUserList() throws Exception {
    RequestBuilder request = post("/admin/users/password")
            .param("userId", "4").param("password", "password").param("repeatedPassword", "password").with(csrf());

    mvc.perform(request)
            .andExpect(redirectedUrl("/admin/users"));

}
项目:nixmash-blog    文件:AdminControllerTests.java   
@Test
@WithAdminUser
public void resetPassword3CharPasswords_ReturnsToView() throws Exception {
    RequestBuilder request = post("/admin/users/password")
            .param("userId", "4").param("password", "one").param("repeatedPassword", "one").with(csrf());

    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(model().attributeExists("userPasswordDTO"))
            .andExpect(model().attributeExists("userDescription"))
            .andExpect(view().name(ADMIN_USERPASSWORD_VIEW));

}
项目:nixmash-blog    文件:AdminControllerTests.java   
@Test
@WithAdminUser
public void resetNonMatchingPasswords_ReturnsToView() throws Exception {
    RequestBuilder request = post("/admin/users/password")
            .param("userId", "4").param("password", "firstpassword").param("repeatedPassword", "secondpassword").with(csrf());

    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(model().attributeExists("userPasswordDTO"))
            .andExpect(model().attributeExists("userDescription"))
            .andExpect(view().name(ADMIN_USERPASSWORD_VIEW));

}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void postsList_page_loads() throws Exception {
    RequestBuilder request = get("/admin/posts").with(csrf());
    MvcResult result = mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(view().name(ADMIN_POSTS_LIST_VIEW)).andReturn();

    assertThat(result.getModelAndView().getModel().get("posts"),
            is(instanceOf(ArrayList.class)));
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void postsList_allPosts_present() throws Exception {
    RequestBuilder request = get("/admin/posts?allposts=true")
            .with(csrf());
    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(model().attributeExists("allposts"))
            .andExpect(view().name(ADMIN_POSTS_LIST_VIEW));
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void postsList_allPosts_isNotPresent() throws Exception {
    RequestBuilder request = get("/admin/posts")
            .with(csrf());
    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(model().attributeExists("posts"))
            .andExpect(model().attributeDoesNotExist("allposts"))
            .andExpect(view().name(ADMIN_POSTS_LIST_VIEW));
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void addPost_page_loads() throws Exception {
    RequestBuilder request = get("/admin/posts/add/post").with(csrf());
    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(model().attributeExists("postDTO"))
            .andExpect(model().attributeExists("categories"))
            .andExpect(view().name(ADMIN_POST_ADD_VIEW));

}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void updatePostWithMissingTitle_ReturnsToPage() throws Exception {
    RequestBuilder request = post("/admin/posts/update")
            .param("postContent", "postContent").with(csrf());

    mvc.perform(request)
            .andExpect(model().attributeHasFieldErrors("postDTO", "postTitle"))
            .andExpect(view().name(ADMIN_POSTLINK_UPDATE_VIEW));
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void postMetaPageLoads() throws Exception {
    RequestBuilder request = get("/admin/posts/postmeta").with(csrf());
    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(view().name(ADMIN_POSTMETA_UPDATE_VIEW));
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void updatePostMetas() throws Exception {
    RequestBuilder request = get("/admin/posts/postmeta")
            .param("update", "doit")
            .with(csrf());

    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(model().attributeExists("hasPostMetaCount"))
            .andExpect(view().name(ADMIN_POSTMETA_UPDATE_VIEW));

    List<Post> posts = postService.getAllPublishedPosts();

}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void addLink_page_loads() throws Exception {
    RequestBuilder request = get("/admin/posts/add/link").with(csrf());
    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(model().attributeExists("postDTO"))
            .andExpect(model().attributeExists("categories"))
            .andExpect(view().name(ADMIN_LINK_ADD_VIEW));
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void updatePostLink_page_loads() throws Exception {
    RequestBuilder request = get("/admin/posts/update/1").with(csrf());
    mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(model().attributeExists("postDTO"))
            .andExpect(view().name(ADMIN_POSTLINK_UPDATE_VIEW));
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void categoriesList_page_loads() throws Exception {
    RequestBuilder request = get("/admin/posts/categories").with(csrf());
    MvcResult result = mvc.perform(request)
            .andExpect(status().isOk())
            .andExpect(view().name(ADMIN_CATEGORIES_VIEW)).andReturn();

    assertThat(result.getModelAndView().getModel().get("categories"),
            is(instanceOf(ArrayList.class)));
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
@Test
public void tagsList_page_loads() throws Exception {
    RequestBuilder request = get("/admin/posts/tags").with(csrf());
    MvcResult result = mvc.perform(request)
            .andExpect(status().isOk())
            .andDo(MockMvcResultHandlers.print())
            .andExpect(view().name(ADMIN_TAGS_VIEW)).andReturn();

    assertThat(result.getModelAndView().getModel().get("tags"),
            is(instanceOf(ArrayList.class)));
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
private RequestBuilder addTwitterCardPostRequest(String s, TwitterCardType twitterCardType, PostDisplayType postDisplayType) {
    return post("/admin/posts/add/post")
            .param("post", POST_PUBLISH )
            .param("postTitle", "my title " + s)
            .param("hasPost", "true")
            .param("postLink", StringUtils.EMPTY)
            .param("postType", POST_CONSTANT)
            .param("twitterCardType", twitterCardType.name())
            .param("displayType", postDisplayType.name())
            .param("postContent", "My Post Content must be longer so I don't trigger a new contraint addition!")
            .param("isPublished", "true")
            .param("tags", String.format("req%s, req%s%s", s, s, 1))
            .param("categoryId", "1")
            .with(csrf());
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
private RequestBuilder addPostRequest(String s, Boolean isPublished, Boolean addSolrCategory, TwitterCardType twitterCardType) {
    return post("/admin/posts/add/post")
            .param("post", isPublished ? POST_PUBLISH : POST_DRAFT)
            .param("postTitle", "my title " + s)
            .param("hasPost", "true")
            .param("postLink", StringUtils.EMPTY)
            .param("postType", POST_CONSTANT)
            .param("twitterCardType", twitterCardType.name())
            .param("displayType", POST_CONSTANT)
            .param("postContent", "My Post Content must be longer so I don't trigger a new contraint addition!")
            .param("isPublished", isPublished.toString())
            .param("tags", String.format("req%s, req%s%s", s, s, 1))
            .param("categoryId", addSolrCategory ? "3" : "1")
            .with(csrf());
}
项目:nixmash-blog    文件:AdminPostsControllerTests.java   
private RequestBuilder addLinkRequest(String s) {
    return post("/admin/posts/add/link")
            .param("post", POST_PUBLISH )
            .param("postTitle", "my title " + s)
            .param("hasPost", "true")
            .param("postLink", "http://some.link/some/path")
            .param("postDescription", "my description")
            .param("postType", LINK_CONSTANT)
            .param("displayType", LINK_CONSTANT)
            .param("twitterCardType", TWITTER_SUMMARY)
            .param("postContent", "My Post Content must be longer so I don't trigger a new contraint addition!")
            .param("isPublished", "true")
            .param("tags", String.format("req%s, req%s%s", s, s, 1))
            .with(csrf());
}