Search in sources :

Example 1 with VehicleDetails

use of demo.service.VehicleDetails in project microservices by pwillhan.

the class UserVehicleControllerApplicationTest method getVehicleWhenRequestingTextShouldReturnMakeAndModel.

@Test
public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception {
    given(this.userVehicleService.getVehicleDetails("donald")).willReturn(new VehicleDetails("Honda", "Civic"));
    this.mvc.perform(get("/donald/vehicle").accept(MediaType.TEXT_PLAIN)).andExpect(status().isOk()).andExpect(content().string("Honda Civic"));
}
Also used : VehicleDetails(demo.service.VehicleDetails) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with VehicleDetails

use of demo.service.VehicleDetails in project microservices by pwillhan.

the class UserVehicleControllerSeleniumTest method getVehicleWhenRequestingTextShouldReturnMakeAndModel.

@Test
public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception {
    given(this.userVehicleService.getVehicleDetails("donald")).willReturn(new VehicleDetails("Honda", "Civic"));
    this.webDriver.get("/donald/vehicle.html");
    WebElement element = this.webDriver.findElement(By.tagName("h1"));
    assertThat(element.getText()).isEqualTo("Honda Civic");
}
Also used : WebElement(org.openqa.selenium.WebElement) VehicleDetails(demo.service.VehicleDetails) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 3 with VehicleDetails

use of demo.service.VehicleDetails in project microservices by pwillhan.

the class UserVehicleControllerTest method getVehicleWhenRequestingTextShouldReturnMakeAndModel.

@Test
public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception {
    given(this.userVehicleService.getVehicleDetails("donald")).willReturn(new VehicleDetails("Honda", "Civic"));
    this.mvc.perform(get("/donald/vehicle").accept(MediaType.TEXT_PLAIN)).andExpect(status().isOk()).andExpect(content().string("Honda Civic"));
}
Also used : VehicleDetails(demo.service.VehicleDetails) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 4 with VehicleDetails

use of demo.service.VehicleDetails in project microservices by pwillhan.

the class UserVehicleControllerHtmlUnitTest method getVehicleWhenRequestingTextShouldReturnMakeAndModel.

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

Example 5 with VehicleDetails

use of demo.service.VehicleDetails in project microservices by pwillhan.

the class UserVehicleControllerTest method getVehicleWhenRequestingJsonShouldReturnMakeAndModel.

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

Aggregations

VehicleDetails (demo.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 User (demo.domain.User)1 WebElement (org.openqa.selenium.WebElement)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1