当前位置: 首页>>代码示例>>Java>>正文


Java RequestBuilder类代码示例

本文整理汇总了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"));
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:18,代码来源:AdminControllerTests.java

示例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());
        }
    });
}
 
开发者ID:SAP,项目名称:cloud-s4-sdk-examples,代码行数:21,代码来源:CostCenterServiceIntegrationTest.java

示例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));
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:24,代码来源:AdminPostsControllerTests.java

示例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));
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:22,代码来源:AdminPostsControllerTests.java

示例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));

}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:24,代码来源:AdminPostsControllerTests.java

示例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));
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:21,代码来源:AdminPostsControllerTests.java

示例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);
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:18,代码来源:AdminSolrPostsControllerTests.java

示例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\"}"));
}
 
开发者ID:ruobingding,项目名称:Robin_Java,代码行数:9,代码来源:SpringBootDemo21ApplicationTests.java

示例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));
}
 
开发者ID:Azanx,项目名称:Smart-Shopping,代码行数:12,代码来源:MvcControllerRegistrationTest.java

示例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());//
}
 
开发者ID:Azanx,项目名称:Smart-Shopping,代码行数:14,代码来源:MvcControllerRegistrationTest.java

示例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());
}
 
开发者ID:kenly333,项目名称:service-hive,代码行数:9,代码来源:ServiceProviderTests.java

示例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);
}
 
开发者ID:Azanx,项目名称:Smart-Shopping,代码行数:24,代码来源:MvcControllerRegistrationTest.java

示例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());
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:8,代码来源:SecurityTests.java

示例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());
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:8,代码来源:SecurityTests.java

示例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());
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:8,代码来源:SecurityTests.java


注:本文中的org.springframework.test.web.servlet.RequestBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。