Search in sources :

Example 21 with MockServerHttpResponse

use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.

the class JRubyScriptTemplateTests method renderTemplate.

@Test
public void renderTemplate() throws Exception {
    Map<String, Object> model = new HashMap<>();
    model.put("title", "Layout example");
    model.put("body", "This is the body");
    MockServerHttpResponse response = renderViewWithModel("org/springframework/web/reactive/result/view/script/jruby/template.erb", model);
    assertEquals("<html><head><title>Layout example</title></head><body><p>This is the body</p></body></html>", response.getBodyAsString().block());
}
Also used : HashMap(java.util.HashMap) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) Test(org.junit.Test)

Example 22 with MockServerHttpResponse

use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.

the class SessionAttributeMethodArgumentResolverTests method setup.

@Before
public void setup() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.refresh();
    ReactiveAdapterRegistry adapterRegistry = new ReactiveAdapterRegistry();
    this.resolver = new SessionAttributeMethodArgumentResolver(context.getBeanFactory(), adapterRegistry);
    this.session = mock(WebSession.class);
    WebSessionManager sessionManager = new MockWebSessionManager(this.session);
    ServerHttpRequest request = MockServerHttpRequest.get("/").build();
    this.exchange = new DefaultServerWebExchange(request, new MockServerHttpResponse(), sessionManager);
    this.handleMethod = ReflectionUtils.findMethod(getClass(), "handleWithSessionAttribute", (Class<?>[]) null);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DefaultServerWebExchange(org.springframework.web.server.adapter.DefaultServerWebExchange) WebSession(org.springframework.web.server.WebSession) MockWebSessionManager(org.springframework.web.server.session.MockWebSessionManager) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) MockWebSessionManager(org.springframework.web.server.session.MockWebSessionManager) WebSessionManager(org.springframework.web.server.session.WebSessionManager) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) Before(org.junit.Before)

Example 23 with MockServerHttpResponse

use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.

the class JythonScriptTemplateTests method renderTemplate.

@Test
public void renderTemplate() throws Exception {
    Map<String, Object> model = new HashMap<>();
    model.put("title", "Layout example");
    model.put("body", "This is the body");
    MockServerHttpResponse response = renderViewWithModel("org/springframework/web/reactive/result/view/script/jython/template.html", model);
    assertEquals("<html><head><title>Layout example</title></head><body><p>This is the body</p></body></html>", response.getBodyAsString().block());
}
Also used : HashMap(java.util.HashMap) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) Test(org.junit.Test)

Example 24 with MockServerHttpResponse

use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.

the class NashornScriptTemplateTests method renderTemplate.

@Test
public void renderTemplate() throws Exception {
    Map<String, Object> model = new HashMap<>();
    model.put("title", "Layout example");
    model.put("body", "This is the body");
    MockServerHttpResponse response = renderViewWithModel("org/springframework/web/reactive/result/view/script/nashorn/template.html", model, ScriptTemplatingConfiguration.class);
    assertEquals("<html><head><title>Layout example</title></head><body><p>This is the body</p></body></html>", response.getBodyAsString().block());
}
Also used : HashMap(java.util.HashMap) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) Test(org.junit.Test)

Example 25 with MockServerHttpResponse

use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.

the class WebHttpHandlerBuilderTests method orderedWebExceptionHandlerBeans.

// SPR-15074
@Test
public void orderedWebExceptionHandlerBeans() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(OrderedExceptionHandlerBeanConfig.class);
    context.refresh();
    HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(context).build();
    MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
    MockServerHttpResponse response = new MockServerHttpResponse();
    httpHandler.handle(request, response).blockMillis(5000);
    assertEquals("ExceptionHandlerB", response.getBodyAsString().blockMillis(5000));
}
Also used : HttpHandler(org.springframework.http.server.reactive.HttpHandler) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) Test(org.junit.Test)

Aggregations

MockServerHttpResponse (org.springframework.mock.http.server.reactive.test.MockServerHttpResponse)42 Test (org.junit.Test)37 MockServerHttpRequest (org.springframework.mock.http.server.reactive.test.MockServerHttpRequest)14 HttpHandler (org.springframework.http.server.reactive.HttpHandler)9 HttpHeaders (org.springframework.http.HttpHeaders)8 HttpStatus (org.springframework.http.HttpStatus)8 ServerWebExchange (org.springframework.web.server.ServerWebExchange)8 Mono (reactor.core.publisher.Mono)8 StepVerifier (reactor.test.StepVerifier)8 MediaType (org.springframework.http.MediaType)7 Assert (org.junit.Assert)6 Mockito (org.mockito.Mockito)6 ReactiveHttpOutputMessage (org.springframework.http.ReactiveHttpOutputMessage)6 ResponseStatusException (org.springframework.web.server.ResponseStatusException)6 HashMap (java.util.HashMap)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)4 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)4 Flux (reactor.core.publisher.Flux)4 Before (org.junit.Before)3 DataBuffer (org.springframework.core.io.buffer.DataBuffer)3