本文整理汇总了Java中org.springframework.mock.web.MockHttpServletResponse.getContentAsString方法的典型用法代码示例。如果您正苦于以下问题:Java MockHttpServletResponse.getContentAsString方法的具体用法?Java MockHttpServletResponse.getContentAsString怎么用?Java MockHttpServletResponse.getContentAsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.mock.web.MockHttpServletResponse
的用法示例。
在下文中一共展示了MockHttpServletResponse.getContentAsString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_jsonp
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void test_jsonp() throws Exception {
FastJsonJsonView view = new FastJsonJsonView();
Assert.assertNotNull(view.getFastJsonConfig());
view.setFastJsonConfig(new FastJsonConfig());
view.setExtractValueFromSingleKeyModel(true);
view.setDisableCaching(true);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("callback", "queryName");
MockHttpServletResponse response = new MockHttpServletResponse();
Assert.assertEquals(true, view.isExtractValueFromSingleKeyModel());
view.render(Collections.singletonMap("abc", "cde中文"), request, response);
String contentAsString = response.getContentAsString();
int contentLength = response.getContentLength();
Assert.assertEquals(contentLength, contentAsString.getBytes(view.getFastJsonConfig().getCharset().name()).length);
}
示例2: testAcceptPlainJson
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void testAcceptPlainJson() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setMethod("GET");
request.setContextPath("");
request.setServletPath("/api");
request.setPathInfo("/tasks/1");
request.setRequestURI("/api/tasks/1");
request.addHeader("Accept", "application/json");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
String responseContent = response.getContentAsString();
log.debug("responseContent: {}", responseContent);
assertNotNull(responseContent);
assertJsonPartEquals("tasks", responseContent, "data.type");
assertJsonPartEquals("\"1\"", responseContent, "data.id");
assertJsonPartEquals(SOME_TASK_ATTRIBUTES, responseContent, "data.attributes");
assertJsonPartEquals(FIRST_TASK_LINKS, responseContent, "data.links");
assertJsonPartEquals(PROJECT1_RELATIONSHIP_LINKS, responseContent, "data.relationships.project.links");
}
示例3: verifyManage
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void verifyManage() throws Exception{
final RegisteredServiceImpl r = new RegisteredServiceImpl();
r.setId(1200);
r.setName("name");
r.setDescription("uniqueDescription");
r.setServiceId("test");
r.setEvaluationOrder(2);
this.servicesManager.save(r);
final MockHttpServletResponse response = new MockHttpServletResponse();
final ModelAndView mv = this.controller.manage(response);
assertTrue(mv.getModel().containsKey("defaultServiceUrl"));
assertTrue(mv.getModel().containsKey("status"));
this.controller.getServices(response);
final String content = response.getContentAsString();
assertTrue(content.contains("services"));
assertTrue(content.contains("uniqueDescription"));
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:23,代码来源:ManageRegisteredServicesMultiActionControllerTests.java
示例4: testResponseWithoutAuthMethod
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void testResponseWithoutAuthMethod() throws Exception {
final Map<String, Object> model = new HashMap<String, Object>();
final Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("testAttribute", "testValue");
final SimplePrincipal principal = new SimplePrincipal("testPrincipal", attributes);
final Authentication primary = TestUtils.getAuthentication(principal);
final Assertion assertion = new ImmutableAssertion(
primary, Collections.singletonList(primary), TestUtils.getService(), true);
model.put("assertion", assertion);
final MockHttpServletResponse servletResponse = new MockHttpServletResponse();
this.response.renderMergedOutputModel(model, new MockHttpServletRequest(), servletResponse);
final String written = servletResponse.getContentAsString();
assertTrue(written.contains("testPrincipal"));
assertTrue(written.contains("testAttribute"));
assertTrue(written.contains("testValue"));
assertTrue(written.contains("urn:oasis:names:tc:SAML:1.0:am:unspecified"));
}
示例5: verifyManage
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void verifyManage() throws Exception {
final RegexRegisteredService r = new RegexRegisteredService();
r.setId(1200);
r.setName(NAME);
r.setDescription(UNIQUE_DESCRIPTION);
r.setServiceId("test");
r.setEvaluationOrder(2);
this.servicesManager.save(r);
final MockHttpServletResponse response = new MockHttpServletResponse();
final ModelAndView mv = this.controller.manage(response);
assertTrue(mv.getModel().containsKey("defaultServiceUrl"));
assertTrue(mv.getModel().containsKey("status"));
this.controller.getServices(response);
final String content = response.getContentAsString();
assertTrue(content.contains(SERVICES));
assertTrue(content.contains(UNIQUE_DESCRIPTION));
}
示例6: onSimpleResourceGetShouldReturnOneResource
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void onSimpleResourceGetShouldReturnOneResource() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setMethod("GET");
request.setContextPath("");
request.setServletPath("/api");
request.setPathInfo("/tasks/1");
request.setRequestURI("/api/tasks/1");
request.setContentType(HttpHeaders.JSONAPI_CONTENT_TYPE);
request.addHeader("Accept", "*/*");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
String responseContent = response.getContentAsString();
log.debug("responseContent: {}", responseContent);
assertNotNull(responseContent);
assertJsonPartEquals("tasks", responseContent, "data.type");
assertJsonPartEquals("\"1\"", responseContent, "data.id");
assertJsonPartEquals(SOME_TASK_ATTRIBUTES, responseContent, "data.attributes");
assertJsonPartEquals(FIRST_TASK_LINKS, responseContent, "data.links");
assertJsonPartEquals(PROJECT1_RELATIONSHIP_LINKS, responseContent, "data.relationships.project.links");
}
示例7: testAcceptJsonApi
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void testAcceptJsonApi() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setMethod("GET");
request.setContextPath("");
request.setServletPath("/api");
request.setPathInfo("/tasks/1");
request.setRequestURI("/api/tasks/1");
request.addHeader("Accept", HttpHeaders.JSONAPI_CONTENT_TYPE);
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
String responseContent = response.getContentAsString();
log.debug("responseContent: {}", responseContent);
assertNotNull(responseContent);
assertJsonPartEquals("tasks", responseContent, "data.type");
assertJsonPartEquals("\"1\"", responseContent, "data.id");
assertJsonPartEquals(SOME_TASK_ATTRIBUTES, responseContent, "data.attributes");
assertJsonPartEquals(FIRST_TASK_LINKS, responseContent, "data.links");
assertJsonPartEquals(PROJECT1_RELATIONSHIP_LINKS, responseContent, "data.relationships.project.links");
}
示例8: verifyResponseWithNoAttributes
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void verifyResponseWithNoAttributes() throws Exception {
final Map<String, Object> model = new HashMap<>();
final Principal principal = new DefaultPrincipalFactory().createPrincipal("testPrincipal");
final Map<String, Object> authAttributes = new HashMap<>();
authAttributes.put(
SamlAuthenticationMetaDataPopulator.ATTRIBUTE_AUTHENTICATION_METHOD,
SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT);
authAttributes.put("testSamlAttribute", "value");
final Authentication primary = org.jasig.cas.authentication.TestUtils.getAuthentication(principal, authAttributes);
final Assertion assertion = new ImmutableAssertion(
primary, Collections.singletonList(primary),
org.jasig.cas.authentication.TestUtils.getService(), true);
model.put("assertion", assertion);
final MockHttpServletResponse servletResponse = new MockHttpServletResponse();
this.response.renderMergedOutputModel(model, new MockHttpServletRequest(), servletResponse);
final String written = servletResponse.getContentAsString();
assertTrue(written.contains("testPrincipal"));
assertTrue(written.contains(SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT));
assertTrue(written.contains("AuthenticationMethod="));
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:29,代码来源:Saml10SuccessResponseViewTests.java
示例9: verifyResponse
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void verifyResponse() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
request.addParameter("TARGET", "service");
final String description = "Validation failed";
this.view.renderMergedOutputModel(
Collections.<String, Object>singletonMap("description", description), request, response);
final String responseText = response.getContentAsString();
assertTrue(responseText.contains("Status"));
assertTrue(responseText.contains(description));
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:Saml10FailureResponseViewTests.java
示例10: verifyCustomComponents
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void verifyCustomComponents() throws Exception {
// override the RegisteredServiceMapper
this.registeredServiceFactory.setRegisteredServiceMapper(new CustomRegisteredServiceMapper());
final RegisteredServiceImpl r = new RegisteredServiceImpl();
r.setId(1200);
r.setName("name");
r.setDescription("uniqueDescription");
r.setServiceId("test");
r.setEvaluationOrder(2);
this.servicesManager.save(r);
final MockHttpServletResponse response = new MockHttpServletResponse();
final ModelAndView mv = this.controller.manage(response);
assertTrue(mv.getModel().containsKey("defaultServiceUrl"));
assertTrue(mv.getModel().containsKey("status"));
this.controller.getServices(response);
final String content = response.getContentAsString();
assertTrue(content.contains("services"));
assertTrue(content.contains("uniqueDescription"));
assertTrue(content.contains("customComponent1"));
assertTrue(content.contains("key2"));
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:28,代码来源:ManageRegisteredServicesMultiActionControllerTests.java
示例11: verifyResponseWithoutAuthMethod
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void verifyResponseWithoutAuthMethod() throws Exception {
final Map<String, Object> model = new HashMap<>();
final Map<String, Object> attributes = new HashMap<>();
attributes.put("testAttribute", "testValue");
final Principal principal = new DefaultPrincipalFactory().createPrincipal("testPrincipal", attributes);
final Map<String, Object> authnAttributes = new HashMap<>();
authnAttributes.put("authnAttribute1", "authnAttrbuteV1");
authnAttributes.put("authnAttribute2", "authnAttrbuteV2");
authnAttributes.put(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME, Boolean.TRUE);
final Authentication primary =
org.jasig.cas.authentication.TestUtils.getAuthentication(principal, authnAttributes);
final Assertion assertion = new ImmutableAssertion(
primary, Collections.singletonList(primary),
org.jasig.cas.authentication.TestUtils.getService(), true);
model.put("assertion", assertion);
final MockHttpServletResponse servletResponse = new MockHttpServletResponse();
this.response.renderMergedOutputModel(model, new MockHttpServletRequest(), servletResponse);
final String written = servletResponse.getContentAsString();
assertTrue(written.contains("testPrincipal"));
assertTrue(written.contains("testAttribute"));
assertTrue(written.contains("testValue"));
assertTrue(written.contains("authnAttribute1"));
assertTrue(written.contains("authnAttribute2"));
assertTrue(written.contains(CasProtocolConstants.VALIDATION_REMEMBER_ME_ATTRIBUTE_NAME));
assertTrue(written.contains("urn:oasis:names:tc:SAML:1.0:am:unspecified"));
}
示例12: testResponse
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void testResponse() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
request.addParameter("TARGET", "service");
final String description = "Validation failed";
this.view.renderMergedOutputModel(
Collections.<String, Object>singletonMap("description", description), request, response);
final String responseText = response.getContentAsString();
assertTrue(responseText.contains("Status"));
assertTrue(responseText.contains(description));
}
示例13: onCollectionRequestWithParamsGetShouldReturnCollection
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void onCollectionRequestWithParamsGetShouldReturnCollection() throws Exception {
MockFilterChain filterChain = new MockFilterChain();
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setMethod("GET");
request.setContextPath("");
request.setServletPath(null);
request.setPathInfo(null);
request.setRequestURI("/api/tasks");
request.setContentType(HttpHeaders.JSONAPI_CONTENT_TYPE);
request.addHeader("Accept", "*/*");
request.addParameter("filter[name]", "John");
request.setQueryString(URLEncoder.encode("filter[name]", StandardCharsets.UTF_8.name()) + "=John");
MockHttpServletResponse response = new MockHttpServletResponse();
filter.doFilter(request, response, filterChain);
String responseContent = response.getContentAsString();
log.debug("responseContent: {}", responseContent);
assertNotNull(responseContent);
assertJsonPartEquals("tasks", responseContent, "data[0].type");
assertJsonPartEquals("\"1\"", responseContent, "data[0].id");
assertJsonPartEquals(FIRST_TASK_ATTRIBUTES, responseContent, "data[0].attributes");
assertJsonPartEquals(FIRST_TASK_LINKS, responseContent, "data[0].links");
assertJsonPartEquals(PROJECT1_RELATIONSHIP_LINKS, responseContent, "data[0].relationships.project.links");
}
示例14: loadServices
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void loadServices() throws Exception {
final MockHttpServletResponse response = this.mvc.perform(get("/getServices.html"))
.andExpect(status().isOk())
.andReturn().getResponse();
final String resp = response.getContentAsString();
assertTrue(resp.contains("services"));
assertTrue(resp.contains("status"));
}
示例15: testIncludeNestedWithDefault
import org.springframework.mock.web.MockHttpServletResponse; //导入方法依赖的package包/类
@Test
public void testIncludeNestedWithDefault() throws Exception {
Node root = new Node(1L, null, null);
Locale engLocale = new Locale(1L, java.util.Locale.ENGLISH);
Node child1 = new Node(2L, root, Collections.<Node>emptySet());
NodeComment child1Comment = new NodeComment(1L, "Child 1", child1, engLocale);
child1.setNodeComments(new LinkedHashSet<>(Collections.singleton(child1Comment)));
Node child2 = new Node(3L, root, Collections.<Node>emptySet(), Collections.<NodeComment>emptySet());
root.setChildren(new LinkedHashSet<>(Arrays.asList(child1, child2)));
nodeRepository.save(root);
nodeRepository.save(child1);
nodeRepository.save(child2);
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setMethod("GET");
request.setServletPath("/api");
request.setPathInfo("/nodes/1");
request.setRequestURI("/api/nodes/1");
request.setQueryString("include[nodes]=children.nodeComments");
request.setContentType(HttpHeaders.JSONAPI_CONTENT_TYPE);
Map<String, String> params = new HashMap<>();
params.put("include[nodes]", "children.nodeComments.langLocale");
request.setParameters(params);
request.addHeader("Accept", "*/*");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
String responseContent = response.getContentAsString();
assertTopLevelNodesCorrectWithChildren(responseContent);
}