本文整理汇总了Java中org.springframework.test.web.servlet.RequestBuilder类的典型用法代码示例。如果您正苦于以下问题:Java RequestBuilder类的具体用法?Java RequestBuilder怎么用?Java RequestBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequestBuilder类属于org.springframework.test.web.servlet包,在下文中一共展示了RequestBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: siteSettingsUpdated_UpdatesSiteOptions
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@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"));
}
示例2: testHttpAddSuccess
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@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());
}
});
}
示例3: updatePostWithValidData_RedirectsToPermalinkPage
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@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));
}
示例4: updatedPostTitleInAzIncludeFile
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@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));
}
示例5: updatedPostContainsNewCategory
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@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));
}
示例6: updatedPostUpdatesTwitterCardInfo
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@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));
}
示例7: reindexResetsSolrPosts
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@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);
}
示例8: contextLoads
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@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\"}"));
}
示例9: registerForm_ForValidDataSucceeds
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@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));
}
示例10: registerForm_differentPasswordsFails
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@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());//
}
示例11: checkApplicationInfoTest
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@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());
}
示例12: preparePostForRegisterForm
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
/**
* Prepare post statement for registering user, prepopulates params with
* valid data and changes one parameter to given value
*
* @param paramName
* name of AppUserDTO property
* @param paramValue
* value of given property
* @return RequestBuilder
*/
private RequestBuilder preparePostForRegisterForm(String paramName, String paramValue) {
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.set("userName", "test1");
parameters.set("email", "[email protected]");
parameters.set("password", "123456");
parameters.set("passwordVerification", "123456");
// replace value for parameter given in arguments
parameters.set(paramName, paramValue);
return post("/register")//
.params(parameters);
}
示例13: invalidRegistrationEmail
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@Test
public void invalidRegistrationEmail() throws Exception {
RequestBuilder request = post("/register").param("username", "bobby").param("firstName", "Bob")
.param("lastName", "Crachet").param("email", "[email protected]").param("password", "password")
.param("repeatedPassword", "password").with(csrf());
mvc.perform(request).andExpect(invalidRegistration());
}
示例14: preExistingUsernameRegistration
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@Test
public void preExistingUsernameRegistration() throws Exception {
RequestBuilder request = post("/register").param("username", "user").param("firstName", "Bob")
.param("lastName", "Crachet").param("email", "[email protected]").param("password", "password")
.param("repeatedPassword", "password").with(csrf());
mvc.perform(request).andExpect(model().attributeHasErrors("userDTO")).andExpect(invalidRegistration());
}
示例15: unapprovedEmailDomainFails
import org.springframework.test.web.servlet.RequestBuilder; //导入依赖的package包/类
@Test
public void unapprovedEmailDomainFails() throws Exception {
RequestBuilder request = post("/register").param("username", "user143").param("firstName", "Bob")
.param("lastName", "Crachet").param("email", "[email protected]").param("password", "password")
.param("repeatedPassword", "password").with(csrf());
mvc.perform(request).andExpect(model().attributeHasErrors("userDTO")).andExpect(invalidRegistration());
}