Search in sources :

Example 1 with VehicleDetails

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

the class UserVehicleControllerSeleniumTests method getVehicleWhenRequestingTextShouldReturnMakeAndModel.

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

Example 2 with VehicleDetails

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

the class UserVehicleControllerTests method getVehicleWhenRequestingTextShouldReturnMakeAndModel.

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

Example 3 with VehicleDetails

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

the class UserVehicleControllerTests method getVehicleWhenRequestingHtmlShouldReturnMakeAndModel.

@Test
public void getVehicleWhenRequestingHtmlShouldReturnMakeAndModel() throws Exception {
    given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic"));
    this.mvc.perform(get("/sboot/vehicle.html").accept(MediaType.TEXT_HTML)).andExpect(status().isOk()).andExpect(content().string(containsString("<h1>Honda Civic</h1>")));
}
Also used : VehicleDetails(sample.test.service.VehicleDetails) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 4 with VehicleDetails

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

the class UserVehicleServiceTests method getVehicleDetailsShouldReturnMakeAndModel.

@Test
public void getVehicleDetailsShouldReturnMakeAndModel() throws Exception {
    given(this.userRepository.findByUsername(anyString())).willReturn(new User("sboot", VIN));
    VehicleDetails details = new VehicleDetails("Honda", "Civic");
    given(this.vehicleDetailsService.getVehicleDetails(VIN)).willReturn(details);
    VehicleDetails actual = this.service.getVehicleDetails("sboot");
    assertThat(actual).isEqualTo(details);
}
Also used : User(sample.test.domain.User) VehicleDetails(sample.test.service.VehicleDetails) Test(org.junit.Test)

Example 5 with VehicleDetails

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

the class UserVehicleControllerApplicationTests method getVehicleWhenRequestingTextShouldReturnMakeAndModel.

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

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