Search in sources :

Example 6 with MockHttpOutputMessage

use of org.springframework.mock.http.MockHttpOutputMessage in project cas by apereo.

the class CasYamlHttpMessageConverterTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    val input = new CasYamlHttpMessageConverter();
    val outputMessage = new MockHttpOutputMessage();
    input.write(getService(), MediaType.APPLICATION_JSON, outputMessage);
    assertNotNull(outputMessage.getBodyAsString());
    input.write(List.of(getService()), MediaType.APPLICATION_JSON, outputMessage);
    assertNotNull(outputMessage.getBodyAsString());
}
Also used : lombok.val(lombok.val) CasYamlHttpMessageConverter(org.apereo.cas.web.CasYamlHttpMessageConverter) MockHttpOutputMessage(org.springframework.mock.http.MockHttpOutputMessage) Test(org.junit.jupiter.api.Test)

Example 7 with MockHttpOutputMessage

use of org.springframework.mock.http.MockHttpOutputMessage in project thingsboard by thingsboard.

the class AbstractWebTest method json.

@SuppressWarnings("unchecked")
protected String json(Object o) throws IOException {
    MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
    HttpMessageConverter converter = o instanceof String ? stringHttpMessageConverter : mappingJackson2HttpMessageConverter;
    converter.write(o, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
    return mockHttpOutputMessage.getBodyAsString();
}
Also used : MockHttpOutputMessage(org.springframework.mock.http.MockHttpOutputMessage) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)

Example 8 with MockHttpOutputMessage

use of org.springframework.mock.http.MockHttpOutputMessage in project springdatacouchbase by carlosCharz.

the class UserControllerTest method json.

@SuppressWarnings("unchecked")
protected String json(Object o) throws IOException {
    MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
    mappingJackson2HttpMessageConverter.write(o, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
    return mockHttpOutputMessage.getBodyAsString();
}
Also used : MockHttpOutputMessage(org.springframework.mock.http.MockHttpOutputMessage)

Example 9 with MockHttpOutputMessage

use of org.springframework.mock.http.MockHttpOutputMessage in project modesti by jlsalmon.

the class TaskControllerTest method json.

protected String json(Object o) throws IOException {
    MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
    this.mappingJackson2HttpMessageConverter.write(o, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
    return mockHttpOutputMessage.getBodyAsString();
}
Also used : MockHttpOutputMessage(org.springframework.mock.http.MockHttpOutputMessage)

Example 10 with MockHttpOutputMessage

use of org.springframework.mock.http.MockHttpOutputMessage in project spring-security by spring-projects.

the class OAuth2ErrorHttpMessageConverterTests method writeInternalWhenOAuth2ErrorThenWriteErrorResponse.

@Test
public void writeInternalWhenOAuth2ErrorThenWriteErrorResponse() throws Exception {
    OAuth2Error oauth2Error = new OAuth2Error("unauthorized_client", "The client is not authorized", "https://tools.ietf.org/html/rfc6749#section-5.2");
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    this.messageConverter.writeInternal(oauth2Error, outputMessage);
    String errorResponse = outputMessage.getBodyAsString();
    assertThat(errorResponse).contains("\"error\":\"unauthorized_client\"");
    assertThat(errorResponse).contains("\"error_description\":\"The client is not authorized\"");
    assertThat(errorResponse).contains("\"error_uri\":\"https://tools.ietf.org/html/rfc6749#section-5.2\"");
}
Also used : MockHttpOutputMessage(org.springframework.mock.http.MockHttpOutputMessage) OAuth2Error(org.springframework.security.oauth2.core.OAuth2Error) Test(org.junit.jupiter.api.Test)

Aggregations

MockHttpOutputMessage (org.springframework.mock.http.MockHttpOutputMessage)10 Test (org.junit.jupiter.api.Test)5 Converter (org.springframework.core.convert.converter.Converter)2 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)2 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)2 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)2 OAuth2Error (org.springframework.security.oauth2.core.OAuth2Error)2 OAuth2AccessTokenResponse (org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse)2 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 lombok.val (lombok.val)1 CasYamlHttpMessageConverter (org.apereo.cas.web.CasYamlHttpMessageConverter)1