Add tests to Data REST sample for search operations
Closes gh-1627
This commit is contained in:
parent
b798d001d7
commit
61e90f5b6e
|
@ -37,6 +37,11 @@
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.jayway.jsonpath</groupId>
|
||||||
|
<artifactId>json-path</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
|
@ -29,14 +29,17 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration test to run the application.
|
* Integration test to run the application.
|
||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringApplicationConfiguration(classes = SampleDataRestApplication.class)
|
@SpringApplicationConfiguration(classes = SampleDataRestApplication.class)
|
||||||
|
@ -61,4 +64,22 @@ public class SampleDataRestApplicationTests {
|
||||||
this.mvc.perform(get("/")).andExpect(status().isOk())
|
this.mvc.perform(get("/")).andExpect(status().isOk())
|
||||||
.andExpect(content().string(containsString("hotels")));
|
.andExpect(content().string(containsString("hotels")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByNameAndCountry() throws Exception {
|
||||||
|
|
||||||
|
this.mvc.perform(
|
||||||
|
get("/cities/search/findByNameAndCountryAllIgnoringCase?name=Melbourne&country=Australia"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("_embedded.citys", hasSize(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByContaining() throws Exception {
|
||||||
|
|
||||||
|
this.mvc.perform(
|
||||||
|
get("/cities/search/findByNameContainingAndCountryContainingAllIgnoringCase?name=&country=UK"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("_embedded.citys", hasSize(3)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,17 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import sample.data.jpa.SampleDataRestApplication;
|
import sample.data.jpa.SampleDataRestApplication;
|
||||||
import sample.data.jpa.domain.City;
|
import sample.data.jpa.domain.City;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.greaterThan;
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests for {@link CityRepository}.
|
* Integration tests for {@link CityRepository}.
|
||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringApplicationConfiguration(classes = SampleDataRestApplication.class)
|
@SpringApplicationConfiguration(classes = SampleDataRestApplication.class)
|
||||||
|
@ -49,4 +52,20 @@ public class CityRepositoryIntegrationTests {
|
||||||
Page<City> cities = this.repository.findAll(new PageRequest(0, 10));
|
Page<City> cities = this.repository.findAll(new PageRequest(0, 10));
|
||||||
assertThat(cities.getTotalElements(), is(greaterThan(20L)));
|
assertThat(cities.getTotalElements(), is(greaterThan(20L)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByNameAndCountry() {
|
||||||
|
City city = this.repository.findByNameAndCountryAllIgnoringCase("Melbourne",
|
||||||
|
"Australia");
|
||||||
|
assertThat(city, notNullValue());
|
||||||
|
assertThat(city.getName(), is(equalTo("Melbourne")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findContaining() {
|
||||||
|
Page<City> cities = this.repository
|
||||||
|
.findByNameContainingAndCountryContainingAllIgnoringCase("", "UK",
|
||||||
|
new PageRequest(0, 10));
|
||||||
|
assertThat(cities.getTotalElements(), is(equalTo(3L)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue