Search in sources :

Example 1 with Person

use of org.springframework.test.web.Person in project spring-framework by spring-projects.

the class XmlConfigTests method setup.

@BeforeEach
public void setup() {
    this.testClient = MockMvcWebTestClient.bindToApplicationContext(this.wac).build();
    given(this.personDao.getPerson(5L)).willReturn(new Person("Joe"));
}
Also used : Person(org.springframework.test.web.Person) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Person

use of org.springframework.test.web.Person in project spring-framework by spring-projects.

the class AsyncTests method callable.

@Test
public void callable() throws Exception {
    MvcResult mvcResult = this.mockMvc.perform(get("/1").param("callable", "true")).andExpect(request().asyncStarted()).andExpect(request().asyncResult(equalTo(new Person("Joe")))).andExpect(request().asyncResult(new Person("Joe"))).andReturn();
    this.mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) Person(org.springframework.test.web.Person) Test(org.junit.jupiter.api.Test)

Example 3 with Person

use of org.springframework.test.web.Person in project spring-framework by spring-projects.

the class JavaConfigTests method setup.

@BeforeEach
public void setup() {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
    verifyRootWacSupport();
    given(this.personDao.getPerson(5L)).willReturn(new Person("Joe"));
}
Also used : Person(org.springframework.test.web.Person) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Person

use of org.springframework.test.web.Person in project spring-framework by spring-projects.

the class SseTests method sse.

@Test
public void sse() {
    FluxExchangeResult<Person> exchangeResult = this.testClient.get().uri("/persons").exchange().expectStatus().isOk().expectHeader().contentType("text/event-stream").returnResult(Person.class);
    StepVerifier.create(exchangeResult.getResponseBody()).expectNext(new Person("N0"), new Person("N1"), new Person("N2")).expectNextCount(4).consumeNextWith(person -> assertThat(person.getName()).endsWith("7")).thenCancel().verify();
}
Also used : Person(org.springframework.test.web.Person) Test(org.junit.jupiter.api.Test)

Example 5 with Person

use of org.springframework.test.web.Person in project spring-framework by spring-projects.

the class SampleTests method performGetManyTimes.

@Test
public void performGetManyTimes() {
    String responseBody = "{\"name\" : \"Ludwig van Beethoven\", \"someDouble\" : \"1.6035\"}";
    this.mockServer.expect(manyTimes(), requestTo("/composers/42")).andExpect(method(HttpMethod.GET)).andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));
    @SuppressWarnings("unused") Person ludwig = this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
    // We are only validating the request. The response is mocked out.
    // hotel.getId() == 42
    // hotel.getName().equals("Holiday Inn")
    this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
    this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
    this.restTemplate.getForObject("/composers/{id}", Person.class, 42);
    this.mockServer.verify();
}
Also used : Person(org.springframework.test.web.Person) Test(org.junit.jupiter.api.Test)

Aggregations

Person (org.springframework.test.web.Person)15 Test (org.junit.jupiter.api.Test)8 BeforeEach (org.junit.jupiter.api.BeforeEach)7 MvcResult (org.springframework.test.web.servlet.MvcResult)3 ArrayList (java.util.ArrayList)2 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)2 Jaxb2RootElementHttpMessageConverter (org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter)2 RestTemplate (org.springframework.web.client.RestTemplate)2 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1 MockMvc (org.springframework.test.web.servlet.MockMvc)1 ShallowEtagHeaderFilter (org.springframework.web.filter.ShallowEtagHeaderFilter)1