Here are the examples of the java api org.springframework.mock.web.MockHttpServletResponse taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
848 Examples
19
View Source File : DefaultErrorViewResolverTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
private MockHttpServletResponse render(ModelAndView modelAndView) throws Exception {
MockHttpServletResponse response = new MockHttpServletResponse();
modelAndView.getView().render(this.model, this.request, response);
return response;
}
19
View Source File : GroovyTemplateAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
@Test
public void customSuffix() throws Exception {
registerAndRefreshContext("spring.groovy.template.suffix:.groovytemplate");
MockHttpServletResponse response = render("suffixed");
String result = response.getContentreplacedtring();
replacedertThat(result).contains("suffixed");
}
19
View Source File : GroovyTemplateAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
@Test
public void customContentType() throws Exception {
registerAndRefreshContext("spring.groovy.template.contentType:application/json");
MockHttpServletResponse response = render("home");
String result = response.getContentreplacedtring();
replacedertThat(result).contains("home");
replacedertThat(response.getContentType()).isEqualTo("application/json;charset=UTF-8");
}
19
View Source File : GroovyTemplateAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
@Test
public void customTemplateLoaderPath() throws Exception {
registerAndRefreshContext("spring.groovy.template.resource-loader-path:clreplacedpath:/custom-templates/");
MockHttpServletResponse response = render("custom");
String result = response.getContentreplacedtring();
replacedertThat(result).contains("custom");
}
19
View Source File : GroovyTemplateAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
@Test
public void defaultViewResolution() throws Exception {
registerAndRefreshContext();
MockHttpServletResponse response = render("home");
String result = response.getContentreplacedtring();
replacedertThat(result).contains("home");
replacedertThat(response.getContentType()).isEqualTo("text/html;charset=UTF-8");
}
19
View Source File : GroovyTemplateAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
@Test
public void customPrefix() throws Exception {
registerAndRefreshContext("spring.groovy.template.prefix:prefix/");
MockHttpServletResponse response = render("prefixed");
String result = response.getContentreplacedtring();
replacedertThat(result).contains("prefixed");
}
19
View Source File : GroovyTemplateAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
@Test
public void includesViewResolution() throws Exception {
registerAndRefreshContext();
MockHttpServletResponse response = render("includes");
String result = response.getContentreplacedtring();
replacedertThat(result).contains("here");
replacedertThat(response.getContentType()).isEqualTo("text/html;charset=UTF-8");
}
19
View Source File : FreeMarkerAutoConfigurationServletIntegrationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
@Test
public void customSuffix() throws Exception {
load("spring.freemarker.suffix:.freemarker");
MockHttpServletResponse response = render("suffixed");
String result = response.getContentreplacedtring();
replacedertThat(result).contains("suffixed");
}
19
View Source File : FreeMarkerAutoConfigurationServletIntegrationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
@Test
public void customTemplateLoaderPath() throws Exception {
load("spring.freemarker.templateLoaderPath:clreplacedpath:/custom-templates/");
MockHttpServletResponse response = render("custom");
String result = response.getContentreplacedtring();
replacedertThat(result).contains("custom");
}
19
View Source File : FreeMarkerAutoConfigurationServletIntegrationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
@Test
public void customPrefix() throws Exception {
load("spring.freemarker.prefix:prefix/");
MockHttpServletResponse response = render("prefixed");
String result = response.getContentreplacedtring();
replacedertThat(result).contains("prefixed");
}
19
View Source File : FreeMarkerAutoConfigurationServletIntegrationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
@Test
public void customContentType() throws Exception {
load("spring.freemarker.contentType:application/json");
MockHttpServletResponse response = render("home");
String result = response.getContentreplacedtring();
replacedertThat(result).contains("home");
replacedertThat(response.getContentType()).isEqualTo("application/json;charset=UTF-8");
}
19
View Source File : FreeMarkerAutoConfigurationServletIntegrationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
@Test
public void defaultViewResolution() throws Exception {
load();
MockHttpServletResponse response = render("home");
String result = response.getContentreplacedtring();
replacedertThat(result).contains("home");
replacedertThat(response.getContentType()).isEqualTo("text/html;charset=UTF-8");
}
19
View Source File : StubMvcResult.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
public void setResponse(MockHttpServletResponse response) {
this.response = response;
}
19
View Source File : XpathResultMatchers.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Get the response encoding if explicitly defined in the response, {code null} otherwise.
*/
@Nullable
private String getDefinedEncoding(MockHttpServletResponse response) {
return (response.isCharset() ? response.getCharacterEncoding() : null);
}
19
View Source File : RedissonWebSessionManagerTest.java
License : MIT License
Project Creator : streamone
License : MIT License
Project Creator : streamone
@Test
public void testSessionIdUrlRewritingEnabled() {
RedissonWebSessionManager cloneSessionManager = spy(this.webSessionManager);
replacedertEquals(true, cloneSessionManager.isSessionIdUrlRewritingEnabled());
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
WebSessionKey sessionKey = new WebSessionKey(request, response);
cloneSessionManager.getSession(sessionKey);
replacedertTrue((Boolean) request.getAttribute(ShiroHttpServletRequest.SESSION_ID_URL_REWRITING_ENABLED));
cloneSessionManager.setSessionIdUrlRewritingEnabled(false);
replacedertFalse(cloneSessionManager.isSessionIdUrlRewritingEnabled());
cloneSessionManager.getSession(sessionKey);
replacedertFalse((Boolean) request.getAttribute(ShiroHttpServletRequest.SESSION_ID_URL_REWRITING_ENABLED));
}
19
View Source File : SebConnectionTest.java
License : Mozilla Public License 2.0
Project Creator : SafeExamBrowser
License : Mozilla Public License 2.0
Project Creator : SafeExamBrowser
@Test
@Sql(scripts = { "clreplacedpath:schema-test.sql", "clreplacedpath:data-test.sql", "clreplacedpath:data-test-additional.sql" })
public void testCreateConnectionNoInsreplacedutionId() throws Exception {
final String accessToken = super.obtainAccessToken("test", "test", "SEBClient");
replacedertNotNull(accessToken);
final MockHttpServletResponse createConnection = super.createConnection(accessToken, null, null);
replacedertNotNull(createConnection);
// expecting error status
replacedertTrue(createConnection.getStatus() != HttpStatus.OK.value());
final String contentreplacedtring = createConnection.getContentreplacedtring();
final Collection<APIMessage> errorMessage = this.jsonMapper.readValue(contentreplacedtring, new TypeReference<Collection<APIMessage>>() {
});
final APIMessage error = errorMessage.iterator().next();
replacedertEquals(ErrorMessage.ILLEGAL_API_ARGUMENT.messageCode, error.messageCode);
}
19
View Source File : SebConnectionTest.java
License : Mozilla Public License 2.0
Project Creator : SafeExamBrowser
License : Mozilla Public License 2.0
Project Creator : SafeExamBrowser
@Test
@Sql(scripts = { "clreplacedpath:schema-test.sql", "clreplacedpath:data-test.sql", "clreplacedpath:data-test-additional.sql" })
public void testCreateConnectionWithWrongExamId() throws Exception {
final String accessToken = super.obtainAccessToken("test", "test", "SEBClient");
replacedertNotNull(accessToken);
final MockHttpServletResponse createConnection = super.createConnection(accessToken, 1L, 1L);
replacedertNotNull(createConnection);
// expecting error status
replacedertTrue(createConnection.getStatus() != HttpStatus.OK.value());
final String contentreplacedtring = createConnection.getContentreplacedtring();
final Collection<APIMessage> errorMessage = this.jsonMapper.readValue(contentreplacedtring, new TypeReference<Collection<APIMessage>>() {
});
final APIMessage error = errorMessage.iterator().next();
replacedertEquals(ErrorMessage.UNEXPECTED.messageCode, error.messageCode);
replacedertEquals("The exam 1 is not running", error.details);
}
19
View Source File : SebConnectionTest.java
License : Mozilla Public License 2.0
Project Creator : SafeExamBrowser
License : Mozilla Public License 2.0
Project Creator : SafeExamBrowser
@Test
@Sql(scripts = { "clreplacedpath:schema-test.sql", "clreplacedpath:data-test.sql", "clreplacedpath:data-test-additional.sql" })
public void testUpdateConnectionWithWrongConnectionToken() throws Exception {
final String accessToken = super.obtainAccessToken("test", "test", "SEBClient");
replacedertNotNull(accessToken);
final MockHttpServletResponse updatedConnection = super.updateConnection(accessToken, "", 2L, "userSessionId");
// expecting error status
replacedertTrue(HttpStatus.OK.value() != updatedConnection.getStatus());
final String contentreplacedtring = updatedConnection.getContentreplacedtring();
final Collection<APIMessage> errorMessage = this.jsonMapper.readValue(contentreplacedtring, new TypeReference<Collection<APIMessage>>() {
});
final APIMessage error = errorMessage.iterator().next();
replacedertEquals(ErrorMessage.RESOURCE_NOT_FOUND.messageCode, error.messageCode);
}
19
View Source File : SebConnectionTest.java
License : Mozilla Public License 2.0
Project Creator : SafeExamBrowser
License : Mozilla Public License 2.0
Project Creator : SafeExamBrowser
@Test
@Sql(scripts = { "clreplacedpath:schema-test.sql", "clreplacedpath:data-test.sql", "clreplacedpath:data-test-additional.sql" })
public void testSendEventToNoneExistingConnectionIsIgnored() throws Exception {
final String accessToken = super.obtainAccessToken("test", "test", "SEBClient");
replacedertNotNull(accessToken);
final MockHttpServletResponse sendEvent = super.sendEvent(accessToken, "someInvalidConnectionToken", "INFO_LOG", 1l, 100.0, "testEvent1");
// check correct response
replacedertTrue(HttpStatus.NO_CONTENT.value() == sendEvent.getStatus());
final List<ClientEventRecord> events = this.clientEventRecordMapper.selectByExample().build().execute();
replacedertTrue(events.isEmpty());
}
19
View Source File : SignatureResponseWrapperTest.java
License : Mozilla Public License 2.0
Project Creator : RadarCOVID
License : Mozilla Public License 2.0
Project Creator : RadarCOVID
/**
* @author bachmann created on 24.04.20
*/
public clreplaced SignatureResponseWrapperTest {
private MockHttpServletResponse response;
@Test
public void testSignaturResponseWrapper() throws IOException, NoSuchAlgorithmException {
response = new MockHttpServletResponse();
KeyPair keyPair = Keys.keyPairFor(SignatureAlgorithm.ES256);
List<String> protectedHeaders = new ArrayList<String>();
protectedHeaders.add("X-BATCH-RELEASE-TIME");
SignatureResponseWrapper signatureResponseWrapper = new SignatureResponseWrapper(response, keyPair, 21, protectedHeaders, true);
signatureResponseWrapper.getOutputStream().print("TEST");
signatureResponseWrapper.flushBuffer();
String digest = response.getHeader("Digest");
String rawJWT = response.getHeader("Signature");
replacedertNotNull(digest);
String expected = "sha-256=" + Hex.encodeHexString(MessageDigest.getInstance("SHA-256").digest("TEST".getBytes()));
replacedertEquals(expected, digest);
}
@Test
public void setSignatureOnlyFor200And204ButNotFor304() throws IOException {
response = new MockHttpServletResponse();
response.setStatus(200);
KeyPair keyPair = Keys.keyPairFor(SignatureAlgorithm.ES256);
List<String> protectedHeaders = new ArrayList<String>();
SignatureResponseWrapper signatureResponseWrapper = new SignatureResponseWrapper(response, keyPair, 21, protectedHeaders, true);
signatureResponseWrapper.getOutputStream().print("TEST");
signatureResponseWrapper.flushBuffer();
String rawJWT = response.getHeader("Signature");
replacedertNotNull(rawJWT);
response = new MockHttpServletResponse();
response.setStatus(204);
signatureResponseWrapper = new SignatureResponseWrapper(response, keyPair, 21, protectedHeaders, true);
signatureResponseWrapper.getOutputStream().print("TEST");
signatureResponseWrapper.flushBuffer();
rawJWT = response.getHeader("Signature");
replacedertNotNull(rawJWT);
response = new MockHttpServletResponse();
response.setStatus(304);
signatureResponseWrapper = new SignatureResponseWrapper(response, keyPair, 21, protectedHeaders, true);
signatureResponseWrapper.getOutputStream().print("TEST");
signatureResponseWrapper.flushBuffer();
rawJWT = response.getHeader("Signature");
replacedertNull(rawJWT);
}
@Test
public void testSignatureViaOutput() throws IOException, NoSuchAlgorithmException {
response = new MockHttpServletResponse();
KeyPair keyPair = Keys.keyPairFor(SignatureAlgorithm.ES256);
KeyPair wrongKey = Keys.keyPairFor(SignatureAlgorithm.ES256);
List<String> protectedHeaders = new ArrayList<String>();
protectedHeaders.add("X-BATCH-RELEASE-TIME");
SignatureResponseWrapper signatureResponseWrapper = new SignatureResponseWrapper(response, keyPair, 21, protectedHeaders, true);
signatureResponseWrapper.getOutputStream().print("TEST");
OutputStream stream = OutputStream.nullOutputStream();
signatureResponseWrapper.outputData(stream);
String digest = response.getHeader("Digest");
String rawJWT = response.getHeader("Signature");
replacedertNotNull(digest);
String expected = "sha-256=" + Hex.encodeHexString(MessageDigest.getInstance("SHA-256").digest("TEST".getBytes()));
replacedertEquals(expected, digest);
}
@Test
public void testBatchReleaseTime() throws IOException, NoSuchAlgorithmException {
response = new MockHttpServletResponse();
response.setHeader("X-BATCH-RELEASE-TIME", Long.toString(UTCInstant.now().getTimestamp()));
KeyPair keyPair = Keys.keyPairFor(SignatureAlgorithm.ES256);
KeyPair wrongKey = Keys.keyPairFor(SignatureAlgorithm.ES256);
List<String> protectedHeaders = new ArrayList<String>();
protectedHeaders.add("X-BATCH-RELEASE-TIME");
SignatureResponseWrapper signatureResponseWrapper = new SignatureResponseWrapper(response, keyPair, 21, protectedHeaders, true);
signatureResponseWrapper.getOutputStream().print("TEST");
signatureResponseWrapper.flushBuffer();
String digest = response.getHeader("Digest");
String rawJWT = response.getHeader("Signature");
JwtParser jwtParser = Jwts.parserBuilder().setSigningKey(keyPair.getPublic()).build();
Jwt jwt = jwtParser.parse(rawJWT);
replacedertTrue(response.containsHeader("X-BATCH-RELEASE-TIME"));
Claims claims = (Claims) jwt.getBody();
replacedertTrue(claims.containsKey("batch-release-time"));
}
@Test
public void testBatchReleaseTimeWithOutputStream() throws IOException, NoSuchAlgorithmException {
response = new MockHttpServletResponse();
response.setHeader("X-BATCH-RELEASE-TIME", Long.toString(UTCInstant.now().getTimestamp()));
KeyPair keyPair = Keys.keyPairFor(SignatureAlgorithm.ES256);
KeyPair wrongKey = Keys.keyPairFor(SignatureAlgorithm.ES256);
List<String> protectedHeaders = new ArrayList<String>();
protectedHeaders.add("X-BATCH-RELEASE-TIME");
SignatureResponseWrapper signatureResponseWrapper = new SignatureResponseWrapper(response, keyPair, 21, protectedHeaders, true);
signatureResponseWrapper.getOutputStream().print("TEST");
OutputStream stream = OutputStream.nullOutputStream();
signatureResponseWrapper.outputData(stream);
String digest = response.getHeader("Digest");
String rawJWT = response.getHeader("Signature");
JwtParser jwtParser = Jwts.parserBuilder().setSigningKey(keyPair.getPublic()).build();
Jwt jwt = jwtParser.parse(rawJWT);
replacedertTrue(response.containsHeader("X-BATCH-RELEASE-TIME"));
Claims claims = (Claims) jwt.getBody();
replacedertTrue(claims.containsKey("batch-release-time"));
}
@Test
public void testSignaturResponseWrapperWithDebugHeaders() throws IOException, NoSuchAlgorithmException {
response = new MockHttpServletResponse();
KeyPair keyPair = Keys.keyPairFor(SignatureAlgorithm.ES256);
List<String> protectedHeaders = new ArrayList<String>();
protectedHeaders.add("X-BATCH-RELEASE-TIME");
SignatureResponseWrapper signatureResponseWrapper = new SignatureResponseWrapper(response, keyPair, 21, protectedHeaders, true);
signatureResponseWrapper.getOutputStream().print("TEST");
signatureResponseWrapper.flushBuffer();
String digest = response.getHeader("Digest");
replacedertNotNull(digest);
String publicKey = response.getHeader("X-Public-Key");
replacedertNotNull(publicKey);
}
@Test
public void testSignaturResponseWrapperWithoutDebugHeaders() throws IOException, NoSuchAlgorithmException {
response = new MockHttpServletResponse();
KeyPair keyPair = Keys.keyPairFor(SignatureAlgorithm.ES256);
List<String> protectedHeaders = new ArrayList<String>();
protectedHeaders.add("X-BATCH-RELEASE-TIME");
SignatureResponseWrapper signatureResponseWrapper = new SignatureResponseWrapper(response, keyPair, 21, protectedHeaders, false);
signatureResponseWrapper.getOutputStream().print("TEST");
signatureResponseWrapper.flushBuffer();
String digest = response.getHeader("Digest");
replacedertNull(digest);
String publicKey = response.getHeader("X-Public-Key");
replacedertNull(publicKey);
}
}
19
View Source File : OAuth20AuthorizeControllerTests.java
License : Apache License 2.0
Project Creator : luotuo
License : Apache License 2.0
Project Creator : luotuo
@Test
public void testNoClientId() throws Exception {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.AUTHORIZE_URL);
mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
oauth20WrapperController.afterPropertiesSet();
final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
replacedertEquals(OAuthConstants.ERROR_VIEW, modelAndView.getViewName());
}
19
View Source File : OAuth20AuthorizeControllerTests.java
License : Apache License 2.0
Project Creator : luotuo
License : Apache License 2.0
Project Creator : luotuo
@Test
public void testNoRedirectUri() throws Exception {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.AUTHORIZE_URL);
mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
oauth20WrapperController.afterPropertiesSet();
final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
replacedertEquals(OAuthConstants.ERROR_VIEW, modelAndView.getViewName());
}
19
View Source File : OAuth20AccessTokenControllerTests.java
License : Apache License 2.0
Project Creator : luotuo
License : Apache License 2.0
Project Creator : luotuo
@Test
public void testNoClientSecret() throws Exception {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.ACCESS_TOKEN_URL);
mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setParameter(OAuthConstants.CODE, CODE);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
oauth20WrapperController.afterPropertiesSet();
oauth20WrapperController.handleRequest(mockRequest, mockResponse);
replacedertEquals(400, mockResponse.getStatus());
replacedertEquals("error=" + OAuthConstants.INVALID_REQUEST, mockResponse.getContentreplacedtring());
}
19
View Source File : OAuth20AccessTokenControllerTests.java
License : Apache License 2.0
Project Creator : luotuo
License : Apache License 2.0
Project Creator : luotuo
@Test
public void testNoRedirectUri() throws Exception {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.ACCESS_TOKEN_URL);
mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET);
mockRequest.setParameter(OAuthConstants.CODE, CODE);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
oauth20WrapperController.afterPropertiesSet();
oauth20WrapperController.handleRequest(mockRequest, mockResponse);
replacedertEquals(400, mockResponse.getStatus());
replacedertEquals("error=" + OAuthConstants.INVALID_REQUEST, mockResponse.getContentreplacedtring());
}
19
View Source File : OAuth20AccessTokenControllerTests.java
License : Apache License 2.0
Project Creator : luotuo
License : Apache License 2.0
Project Creator : luotuo
@Test
public void testNoClientId() throws Exception {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.ACCESS_TOKEN_URL);
mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET);
mockRequest.setParameter(OAuthConstants.CODE, CODE);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
oauth20WrapperController.afterPropertiesSet();
oauth20WrapperController.handleRequest(mockRequest, mockResponse);
replacedertEquals(400, mockResponse.getStatus());
replacedertEquals("error=" + OAuthConstants.INVALID_REQUEST, mockResponse.getContentreplacedtring());
}
19
View Source File : OAuth20AccessTokenControllerTests.java
License : Apache License 2.0
Project Creator : luotuo
License : Apache License 2.0
Project Creator : luotuo
@Test
public void testNoCode() throws Exception {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.ACCESS_TOKEN_URL);
mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
oauth20WrapperController.afterPropertiesSet();
oauth20WrapperController.handleRequest(mockRequest, mockResponse);
replacedertEquals(400, mockResponse.getStatus());
replacedertEquals("error=" + OAuthConstants.INVALID_REQUEST, mockResponse.getContentreplacedtring());
}
19
View Source File : XpathResultMatchers.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
/**
* Get the response encoding if explicitly defined in the response, {code null} otherwise.
*/
private String getDefinedEncoding(MockHttpServletResponse response) {
return response.isCharset() ? response.getCharacterEncoding() : null;
}
19
View Source File : Helper.java
License : MIT License
Project Creator : hmcts
License : MIT License
Project Creator : hmcts
public static String getBinaryUrlFromResponse(MockHttpServletResponse response) throws IOException {
final String path = "/_links/binary/href";
return getPathFromResponse(response, path);
}
19
View Source File : Helper.java
License : MIT License
Project Creator : hmcts
License : MIT License
Project Creator : hmcts
public static String getSelfUrlFromResponse(MockHttpServletResponse response) throws IOException {
final String path = "/_links/self/href";
return getPathFromResponse(response, path);
}
19
View Source File : Helper.java
License : MIT License
Project Creator : hmcts
License : MIT License
Project Creator : hmcts
public static String getThumbnailUrlFromResponse(MockHttpServletResponse response) throws IOException {
final String path = "/_links/thumbnail/href";
return getPathFromResponse(response, path);
}
19
View Source File : ApmFilterTest.java
License : Apache License 2.0
Project Creator : elastic
License : Apache License 2.0
Project Creator : elastic
@Test
void testNoHeaderRecording() throws IOException, ServletException {
when(coreConfiguration.isCaptureHeaders()).thenReturn(false);
filterChain = new MockFilterChain(new TestServlet());
final MockHttpServletRequest get = new MockHttpServletRequest("GET", "/foo");
get.addHeader("Elastic-Apm-Traceparent", "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01");
get.setCookies(new Cookie("foo", "bar"));
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
mockResponse.addHeader("foo", "bar");
mockResponse.addHeader("bar", "baz");
filterChain.doFilter(get, mockResponse);
replacedertThat(reporter.getTransactions()).hreplacedize(1);
replacedertThat(reporter.getFirstTransaction().getContext().getResponse().getHeaders().isEmpty()).isTrue();
replacedertThat(reporter.getFirstTransaction().getContext().getRequest().getHeaders().isEmpty()).isTrue();
replacedertThat(reporter.getFirstTransaction().getContext().getRequest().getCookies().isEmpty()).isTrue();
replacedertThat(reporter.getFirstTransaction().getTraceContext().getTraceId().toString()).isEqualTo("0af7651916cd43dd8448eb211c80319c");
replacedertThat(reporter.getFirstTransaction().getTraceContext().getParentId().toString()).isEqualTo("b9c7c989f97918e1");
}
19
View Source File : DeliverableControllerTest.java
License : Apache License 2.0
Project Creator : desarrolladorSLP
License : Apache License 2.0
Project Creator : desarrolladorSLP
@Test
public void givenAnExistentDeliverableId_whenDelete_then200Status() throws Exception {
// given
UUID deliverableId = UUID.randomUUID();
// when
MockHttpServletResponse response = mockMvc.perform(MockMvcRequestBuilders.delete(BASE_DELIVERABLE_URL + "/" + deliverableId)).andReturn().getResponse();
// then
replacedertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
verify(deliverableService).delete(deliverableId);
verifyNoMoreInteractions(deliverableService);
}
19
View Source File : ServletResponseResultWriterTest.java
License : Apache License 2.0
Project Creator : cloudendpoints
License : Apache License 2.0
Project Creator : cloudendpoints
private String writeToResponse(Object value) throws IOException {
MockHttpServletResponse response = new MockHttpServletResponse();
ServletResponseResultWriter writer = new ServletResponseResultWriter(response, null);
writer.write(value);
return response.getContentreplacedtring();
}
19
View Source File : CookieTestUtils.java
License : GNU Affero General Public License v3.0
Project Creator : ClimbAssist
License : GNU Affero General Public License v3.0
Project Creator : ClimbAssist
public static void verifySessionCookiesAreRemoved(@NonNull MockHttpServletResponse mockHttpServletResponse) {
verifyResponseContainsCookies(mockHttpServletResponse, buildEmptyCookie(ACCESS_TOKEN_COOKIE_NAME), buildEmptyCookie(REFRESH_TOKEN_COOKIE_NAME));
}
19
View Source File : CookieTestUtils.java
License : GNU Affero General Public License v3.0
Project Creator : ClimbAssist
License : GNU Affero General Public License v3.0
Project Creator : ClimbAssist
static void verifyJSessionIdCookieIsRemoved(@NonNull MockHttpServletResponse mockHttpServletResponse) {
verifyResponseContainsCookies(mockHttpServletResponse, buildEmptyCookie(J_SESSION_ID_COOKIE_NAME));
}
19
View Source File : MainControllerTest.java
License : Apache License 2.0
Project Creator : chaosblade-io
License : Apache License 2.0
Project Creator : chaosblade-io
@Test
public void testFetchChaostoolsOverview() throws Exception {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/api/FetchChaostoolsOverview/chaosblade/overview.yaml").contentType(MediaType.APPLICATION_JSON)).andReturn();
MockHttpServletResponse httpServletResponse = mvcResult.getResponse();
replacedert.replacedertEquals(httpServletResponse.getStatus(), 200);
Representer representer = new Representer();
representer.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(representer);
ToolsOverview toolsOverview = yaml.loadAs(new ByteArrayInputStream(httpServletResponse.getContentAsByteArray()), ToolsOverview.clreplaced);
replacedert.replacedertEquals(toolsOverview.getName(), "chaosblade");
}
19
View Source File : MainControllerTest.java
License : Apache License 2.0
Project Creator : chaosblade-io
License : Apache License 2.0
Project Creator : chaosblade-io
@Test
public void testFetchPublicChaostools() throws Exception {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/api/FetchPublicChaostools").contentType(MediaType.APPLICATION_JSON)).andReturn();
MockHttpServletResponse httpServletResponse = mvcResult.getResponse();
replacedert.replacedertEquals(httpServletResponse.getStatus(), 200);
String contentreplacedtring = httpServletResponse.getContentreplacedtring();
replacedert.replacedertTrue(contentreplacedtring.contains("chaosblade"));
}
19
View Source File : VenControllerTest.java
License : Apache License 2.0
Project Creator : avob
License : Apache License 2.0
Project Creator : avob
private <T> T convertMvcResultToDto(MvcResult result, Clreplaced<T> klreplaced) throws JsonParseException, JsonMappingException, IOException {
MockHttpServletResponse mockHttpServletResponse = result.getResponse();
byte[] contentAsByteArray = mockHttpServletResponse.getContentAsByteArray();
return mapper.readValue(contentAsByteArray, klreplaced);
}
19
View Source File : GroupControllerTest.java
License : Apache License 2.0
Project Creator : avob
License : Apache License 2.0
Project Creator : avob
private VenGroupDto convertMvcResultToVenGroupDto(MvcResult result) throws JsonParseException, JsonMappingException, IOException {
MockHttpServletResponse mockHttpServletResponse = result.getResponse();
byte[] contentAsByteArray = mockHttpServletResponse.getContentAsByteArray();
return mapper.readValue(contentAsByteArray, VenGroupDto.clreplaced);
}
19
View Source File : GroupControllerTest.java
License : Apache License 2.0
Project Creator : avob
License : Apache License 2.0
Project Creator : avob
private List<VenGroupDto> convertMvcResultToVenGroupDtoList(MvcResult result) throws JsonParseException, JsonMappingException, IOException {
MockHttpServletResponse mockHttpServletResponse = result.getResponse();
byte[] contentAsByteArray = mockHttpServletResponse.getContentAsByteArray();
return mapper.readValue(contentAsByteArray, new TypeReference<List<VenGroupDto>>() {
});
}
19
View Source File : AccountControllerTest.java
License : Apache License 2.0
Project Creator : avob
License : Apache License 2.0
Project Creator : avob
private <S> List<S> convertMvcResultToList(MvcResult result, TypeReference<List<S>> listType) throws JsonParseException, JsonMappingException, IOException {
MockHttpServletResponse mockHttpServletResponse = result.getResponse();
byte[] contentAsByteArray = mockHttpServletResponse.getContentAsByteArray();
return mapper.readValue(contentAsByteArray, listType);
}
19
View Source File : AccountControllerTest.java
License : Apache License 2.0
Project Creator : avob
License : Apache License 2.0
Project Creator : avob
private <S> S convertMvcResultToObject(MvcResult result, Clreplaced<S> klreplaced) throws JsonParseException, JsonMappingException, IOException {
MockHttpServletResponse mockHttpServletResponse = result.getResponse();
byte[] contentAsByteArray = mockHttpServletResponse.getContentAsByteArray();
return mapper.readValue(contentAsByteArray, klreplaced);
}
19
View Source File : AuthorizationRequestHandlerSpiImpl.java
License : Apache License 2.0
Project Creator : authlete
License : Apache License 2.0
Project Creator : authlete
private String render(View view, Map<String, Object> model) throws Exception {
// Prepare a dummy HttpServletResponse instance.
MockHttpServletResponse response = new MockHttpServletResponse();
// Render the authorization page.
view.render(model, mRequest, response);
// Extract the result (HTML) as a String.
return response.getContentreplacedtring();
}
19
View Source File : AuthenticationControllerTest.java
License : MIT License
Project Creator : auth0
License : MIT License
Project Creator : auth0
@Test
public void shouldSetSameSiteNoneCookiesAndLegacyCookieWhenIdTokenResponse() {
MockHttpServletResponse response = new MockHttpServletResponse();
AuthenticationController controller = AuthenticationController.newBuilder("domain", "clientId", "clientSecret").withResponseType("id_token").build();
controller.buildAuthorizeUrl(new MockHttpServletRequest(), response, "https://redirect.uri/here").withState("state").withNonce("nonce").build();
List<String> headers = response.getHeaders("Set-Cookie");
replacedertThat(headers.size(), is(4));
replacedertThat(headers, hasItem("com.auth0.state=state; HttpOnly; Max-Age=600; SameSite=None; Secure"));
replacedertThat(headers, hasItem("_com.auth0.state=state; HttpOnly; Max-Age=600"));
replacedertThat(headers, hasItem("com.auth0.nonce=nonce; HttpOnly; Max-Age=600; SameSite=None; Secure"));
replacedertThat(headers, hasItem("_com.auth0.nonce=nonce; HttpOnly; Max-Age=600"));
}
19
View Source File : AuthenticationControllerTest.java
License : MIT License
Project Creator : auth0
License : MIT License
Project Creator : auth0
@Test
public void shouldSetSameSiteNoneCookiesAndNoLegacyCookieWhenIdTokenResponse() {
MockHttpServletResponse response = new MockHttpServletResponse();
AuthenticationController controller = AuthenticationController.newBuilder("domain", "clientId", "clientSecret").withResponseType("id_token").withLegacySameSiteCookie(false).build();
controller.buildAuthorizeUrl(new MockHttpServletRequest(), response, "https://redirect.uri/here").withState("state").withNonce("nonce").build();
List<String> headers = response.getHeaders("Set-Cookie");
replacedertThat(headers.size(), is(2));
replacedertThat(headers, hasItem("com.auth0.state=state; HttpOnly; Max-Age=600; SameSite=None; Secure"));
replacedertThat(headers, hasItem("com.auth0.nonce=nonce; HttpOnly; Max-Age=600; SameSite=None; Secure"));
}
19
View Source File : AuthenticationControllerTest.java
License : MIT License
Project Creator : auth0
License : MIT License
Project Creator : auth0
@Test
public void shouldSetLaxCookiesAndNoLegacyCookieWhenCodeFlow() {
MockHttpServletResponse response = new MockHttpServletResponse();
AuthenticationController controller = AuthenticationController.newBuilder("domain", "clientId", "clientSecret").withResponseType("code").build();
controller.buildAuthorizeUrl(new MockHttpServletRequest(), response, "https://redirect.uri/here").withState("state").build();
List<String> headers = response.getHeaders("Set-Cookie");
replacedertThat(headers.size(), is(1));
replacedertThat(headers, everyItem(is("com.auth0.state=state; HttpOnly; Max-Age=600; SameSite=Lax")));
}
19
View Source File : SignatureFilterTest.java
License : Apache License 2.0
Project Creator : adorsys
License : Apache License 2.0
Project Creator : adorsys
private void mockResponseCode(MockHttpServletResponse mockResponse, int code) throws IOException {
doAnswer((i) -> {
mockResponse.setStatus(code);
return null;
}).when(tppErrorMessageWriter).writeError(eq(mockResponse), any(TppErrorMessage.clreplaced));
}
19
View Source File : TestMvcClient.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
/**
* For a given servlet response, verify that the provided rel exists in its hypermedia. If so, return the URI link.
*
* @param rel
* @param response
* @return {@link org.springframework.hateoas.Link} of the rel found in the response
* @throws Exception
*/
public Link replacedertHasLinkWithRel(String rel, MockHttpServletResponse response) throws Exception {
String content = response.getContentreplacedtring();
Optional<Link> link = getDiscoverer(response).findLinkWithRel(rel, content);
replacedertThat(link).describedAs("Expected to find link with rel " + rel + " but found none in " + content + "!").isPresent();
return link.get();
}
19
View Source File : AssertResponseContent.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
/**
* replacederts for response content
*/
public clreplaced replacedertResponseContent {
private static final String ATTACHMENT_CONTENT_DISPOSITION = "attachment;filename=";
private final MockHttpServletResponse response;
public replacedertResponseContent(MockHttpServletResponse response) {
this.response = response;
}
public replacedertFileContent isFile() {
replacedertThat(response).isNotNull();
replacedertThat(response.getContentType()).isNotNull();
replacedertThat(response.getContentAsByteArray()).isNotEmpty();
replacedertThat(response.getHeader(CONTENT_DISPOSITION)).isNotEmpty().startsWith(ATTACHMENT_CONTENT_DISPOSITION);
String filename = response.getHeader(CONTENT_DISPOSITION).substring(ATTACHMENT_CONTENT_DISPOSITION.length());
return new replacedertFileContent(new FileContent(filename, response.getContentType(), response.getContentAsByteArray()));
}
public static replacedertResponseContent replacedertThatResponseContent(MvcResult mvcResult) {
return replacedertThatResponseContent(mvcResult.getResponse());
}
public static replacedertResponseContent replacedertThatResponseContent(MockMvcResponse response) {
return replacedertThatResponseContent(response.mockHttpServletResponse());
}
public static replacedertResponseContent replacedertThatResponseContent(MockHttpServletResponse response) {
return new replacedertResponseContent(response);
}
}
19
View Source File : AssertResponseContent.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
public static replacedertResponseContent replacedertThatResponseContent(MockHttpServletResponse response) {
return new replacedertResponseContent(response);
}
See More Examples