Search in sources :

Example 11 with Person

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

the class SampleTests method performGetWithResponseBodyFromFile.

@Test
public void performGetWithResponseBodyFromFile() {
    Resource responseBody = new ClassPathResource("ludwig.json", this.getClass());
    this.mockServer.expect(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);
    // hotel.getId() == 42
    // hotel.getName().equals("Holiday Inn")
    this.mockServer.verify();
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) Person(org.springframework.test.web.Person) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 12 with Person

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

the class XmlContentRequestMatchersIntegrationTests method setup.

@BeforeEach
public void setup() {
    List<Person> composers = Arrays.asList(new Person("Johann Sebastian Bach").setSomeDouble(21), new Person("Johannes Brahms").setSomeDouble(.0025), new Person("Edvard Grieg").setSomeDouble(1.6035), new Person("Robert Schumann").setSomeDouble(Double.NaN));
    this.people = new PeopleWrapper(composers);
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new Jaxb2RootElementHttpMessageConverter());
    this.restTemplate = new RestTemplate();
    this.restTemplate.setMessageConverters(converters);
    this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
Also used : Jaxb2RootElementHttpMessageConverter(org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) Jaxb2RootElementHttpMessageConverter(org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter) ArrayList(java.util.ArrayList) RestTemplate(org.springframework.web.client.RestTemplate) Person(org.springframework.test.web.Person) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 13 with Person

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

the class AsyncTests method deferredResultWithImmediateValue.

@Test
public void deferredResultWithImmediateValue() throws Exception {
    MvcResult mvcResult = this.mockMvc.perform(get("/1").param("deferredResultWithImmediateValue", "true")).andExpect(request().asyncStarted()).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 14 with Person

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

the class JavaConfigTests method setup.

@BeforeEach
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 15 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.mockMvc = MockMvcBuilders.webAppContextSetup(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)

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