mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 14:55:51 +00:00
Fixed tests
This commit is contained in:
parent
55dae5ac8d
commit
0d17a00cf5
2 changed files with 32 additions and 40 deletions
|
@ -28,16 +28,11 @@ public class MainPageIT {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void googleTitleIT() {
|
||||
public void petclinicTitleIT() {
|
||||
WebDriver driver = config.getDriver();
|
||||
driver.get(url);
|
||||
assertEquals("Title not as expected: ", "PetClinic :: a Spring Framework demonstration", getTitle());
|
||||
// Save the random value from the page.
|
||||
String welcomeText = driver.findElement(By.id("welcome")).getText();
|
||||
// Reload the page and get a new random value.
|
||||
driver.get(url);
|
||||
String value2 = driver.findElement(By.id("random-value")).getText();
|
||||
// Values should not be the same.
|
||||
assertEquals("Wrong welcome text.", "Welcome to the Pet Clinic!", welcomeText);
|
||||
System.out.println("Text extracted: " + welcomeText);
|
||||
}
|
||||
|
|
|
@ -43,43 +43,40 @@ import org.springframework.test.web.servlet.ResultActions;
|
|||
@WebMvcTest(VetController.class)
|
||||
public class VetControllerTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
private VetRepository vets;
|
||||
@MockBean
|
||||
private VetRepository vets;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Vet james = new Vet();
|
||||
james.setFirstName("James");
|
||||
james.setLastName("Carter");
|
||||
james.setId(1);
|
||||
Vet helen = new Vet();
|
||||
helen.setFirstName("Helen");
|
||||
helen.setLastName("Leary");
|
||||
helen.setId(2);
|
||||
Specialty radiology = new Specialty();
|
||||
radiology.setId(1);
|
||||
radiology.setName("radiology");
|
||||
helen.addSpecialty(radiology);
|
||||
given(this.vets.findAll()).willReturn(Lists.newArrayList(james, helen));
|
||||
}
|
||||
@Before
|
||||
public void setup() {
|
||||
Vet james = new Vet();
|
||||
james.setFirstName("James");
|
||||
james.setLastName("Carter");
|
||||
james.setId(1);
|
||||
Vet helen = new Vet();
|
||||
helen.setFirstName("Helen");
|
||||
helen.setLastName("Leary");
|
||||
helen.setId(2);
|
||||
Specialty radiology = new Specialty();
|
||||
radiology.setId(1);
|
||||
radiology.setName("radiology");
|
||||
helen.addSpecialty(radiology);
|
||||
given(this.vets.findAll()).willReturn(Lists.newArrayList(james, helen));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowVetListHtml() throws Exception {
|
||||
mockMvc.perform(get("/vets.html"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(model().attributeExists("vets"))
|
||||
.andExpect(view().name("vets/vetList"));
|
||||
}
|
||||
@Test
|
||||
public void testShowVetListHtml() throws Exception {
|
||||
mockMvc.perform(get("/vets.html")).andExpect(status().isOk()).andExpect(model().attributeExists("vets"))
|
||||
.andExpect(view().name("vets/vetList"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowResourcesVetList() throws Exception {
|
||||
ResultActions actions = mockMvc.perform(get("/vets")
|
||||
.accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
|
||||
actions.andExpect(content().contentType("application/json;charset=UTF-8"))
|
||||
.andExpect(jsonPath("$.vetList[0].id").value(1));
|
||||
}
|
||||
@Test
|
||||
public void testShowResourcesVetList() throws Exception {
|
||||
ResultActions actions = mockMvc.perform(get("/vets").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
actions.andExpect(content().contentType("application/json")).andExpect(jsonPath("$.vetList[0].id").value(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue