Search in sources :

Example 6 with VehicleDetails

use of sample.test.service.VehicleDetails in project spring-boot by spring-projects.

the class UserVehicleControllerHtmlUnitTests method getVehicleWhenRequestingTextShouldReturnMakeAndModel.

@Test
public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception {
    given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic"));
    HtmlPage page = this.webClient.getPage("/sboot/vehicle.html");
    assertThat(page.getBody().getTextContent()).isEqualTo("Honda Civic");
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) VehicleDetails(sample.test.service.VehicleDetails) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 7 with VehicleDetails

use of sample.test.service.VehicleDetails in project spring-boot by spring-projects.

the class UserVehicleControllerTests method getVehicleWhenRequestingJsonShouldReturnMakeAndModel.

@Test
public void getVehicleWhenRequestingJsonShouldReturnMakeAndModel() throws Exception {
    given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic"));
    this.mvc.perform(get("/sboot/vehicle").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().json("{'make':'Honda','model':'Civic'}"));
}
Also used : VehicleDetails(sample.test.service.VehicleDetails) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 8 with VehicleDetails

use of sample.test.service.VehicleDetails in project spring-boot by spring-projects.

the class UserVehicleController method VehicleDetailsHtml.

@GetMapping(path = "/{username}/vehicle.html", produces = MediaType.TEXT_HTML_VALUE)
public String VehicleDetailsHtml(@PathVariable String username) {
    VehicleDetails details = this.userVehicleService.getVehicleDetails(username);
    String makeAndModel = details.getMake() + " " + details.getModel();
    return "<html><body><h1>" + makeAndModel + "</h1></body></html>";
}
Also used : VehicleDetails(sample.test.service.VehicleDetails) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

VehicleDetails (sample.test.service.VehicleDetails)8 Test (org.junit.Test)7 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)5 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 WebElement (org.openqa.selenium.WebElement)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 User (sample.test.domain.User)1