use of cn.taketoday.web.handler.method.RequestBodyAdvice in project today-framework by TAKETODAY.
the class RequestResponseBodyAdviceChainTests method responseBodyAdvice.
@SuppressWarnings("unchecked")
@Test
public void responseBodyAdvice() {
RequestBodyAdvice requestAdvice = Mockito.mock(RequestBodyAdvice.class);
ResponseBodyAdvice<String> responseAdvice = Mockito.mock(ResponseBodyAdvice.class);
List<Object> advice = Arrays.asList(requestAdvice, responseAdvice);
RequestResponseBodyAdviceChain chain = new RequestResponseBodyAdviceChain(advice);
String expected = "body++";
given(responseAdvice.supports(this.returnType, this.converterType)).willReturn(true);
given(responseAdvice.beforeBodyWrite(eq(this.body), eq(this.returnType), eq(this.contentType), eq(this.converterType), same(requestContext))).willReturn(expected);
String actual = (String) chain.beforeBodyWrite(this.body, this.returnType, this.contentType, this.converterType, requestContext);
assertThat(actual).isEqualTo(expected);
}
use of cn.taketoday.web.handler.method.RequestBodyAdvice in project today-framework by TAKETODAY.
the class RequestResponseBodyAdviceChainTests method requestBodyAdvice.
@SuppressWarnings("unchecked")
@Test
public void requestBodyAdvice() throws IOException {
RequestBodyAdvice requestAdvice = Mockito.mock(RequestBodyAdvice.class);
ResponseBodyAdvice<String> responseAdvice = Mockito.mock(ResponseBodyAdvice.class);
List<Object> advice = Arrays.asList(requestAdvice, responseAdvice);
RequestResponseBodyAdviceChain chain = new RequestResponseBodyAdviceChain(advice);
HttpInputMessage wrapped = new ServletServerHttpRequest(new MockHttpServletRequest());
given(requestAdvice.supports(this.paramType, String.class, this.converterType)).willReturn(true);
given(requestAdvice.beforeBodyRead(eq(this.request), eq(this.paramType), eq(String.class), eq(this.converterType))).willReturn(wrapped);
assertThat(chain.beforeBodyRead(this.request, this.paramType, String.class, this.converterType)).isSameAs(wrapped);
String modified = "body++";
given(requestAdvice.afterBodyRead(eq(this.body), eq(this.request), eq(this.paramType), eq(String.class), eq(this.converterType))).willReturn(modified);
assertThat(chain.afterBodyRead(this.body, this.request, this.paramType, String.class, this.converterType)).isEqualTo(modified);
}
Aggregations