Skip to content

Commit 8fcf355

Browse files
committed
Merge branch 'gh-1627' into 1.1.x
2 parents d0990c0 + 61e90f5 commit 8fcf355

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

spring-boot-samples/spring-boot-sample-data-rest/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
<artifactId>spring-boot-starter-test</artifactId>
3838
<scope>test</scope>
3939
</dependency>
40+
<dependency>
41+
<groupId>com.jayway.jsonpath</groupId>
42+
<artifactId>json-path</artifactId>
43+
<scope>test</scope>
44+
</dependency>
4045
</dependencies>
4146
<build>
4247
<plugins>

spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CityRepository.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@
1919
import org.springframework.data.domain.Page;
2020
import org.springframework.data.domain.Pageable;
2121
import org.springframework.data.repository.PagingAndSortingRepository;
22+
import org.springframework.data.repository.query.Param;
2223
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
2324

2425
import sample.data.jpa.domain.City;
2526

2627
@RepositoryRestResource(collectionResourceRel = "citys", path = "cities")
2728
interface CityRepository extends PagingAndSortingRepository<City, Long> {
2829

29-
Page<City> findByNameContainingAndCountryContainingAllIgnoringCase(String name,
30-
String country, Pageable pageable);
30+
Page<City> findByNameContainingAndCountryContainingAllIgnoringCase(
31+
@Param("name") String name, @Param("country") String country,
32+
Pageable pageable);
3133

32-
City findByNameAndCountryAllIgnoringCase(String name, String country);
34+
City findByNameAndCountryAllIgnoringCase(@Param("name") String name,
35+
@Param("country") String country);
3336

3437
}

spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/SampleDataRestApplicationTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@
2929
import org.springframework.web.context.WebApplicationContext;
3030

3131
import static org.hamcrest.Matchers.containsString;
32+
import static org.hamcrest.Matchers.hasSize;
3233
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
3334
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
35+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
3436
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
3537

3638
/**
3739
* Integration test to run the application.
3840
*
3941
* @author Oliver Gierke
42+
* @author Andy Wilkinson
4043
*/
4144
@RunWith(SpringJUnit4ClassRunner.class)
4245
@SpringApplicationConfiguration(classes = SampleDataRestApplication.class)
@@ -61,4 +64,22 @@ public void testHome() throws Exception {
6164
this.mvc.perform(get("/")).andExpect(status().isOk())
6265
.andExpect(content().string(containsString("hotels")));
6366
}
67+
68+
@Test
69+
public void findByNameAndCountry() throws Exception {
70+
71+
this.mvc.perform(
72+
get("/cities/search/findByNameAndCountryAllIgnoringCase?name=Melbourne&country=Australia"))
73+
.andExpect(status().isOk())
74+
.andExpect(jsonPath("_embedded.citys", hasSize(1)));
75+
}
76+
77+
@Test
78+
public void findByContaining() throws Exception {
79+
80+
this.mvc.perform(
81+
get("/cities/search/findByNameContainingAndCountryContainingAllIgnoringCase?name=&country=UK"))
82+
.andExpect(status().isOk())
83+
.andExpect(jsonPath("_embedded.citys", hasSize(3)));
84+
}
6485
}

spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@
2727
import sample.data.jpa.SampleDataRestApplication;
2828
import sample.data.jpa.domain.City;
2929

30+
import static org.hamcrest.Matchers.equalTo;
3031
import static org.hamcrest.Matchers.greaterThan;
3132
import static org.hamcrest.Matchers.is;
33+
import static org.hamcrest.Matchers.notNullValue;
3234
import static org.junit.Assert.assertThat;
3335

3436
/**
3537
* Integration tests for {@link CityRepository}.
3638
*
3739
* @author Oliver Gierke
40+
* @author Andy Wilkinson
3841
*/
3942
@RunWith(SpringJUnit4ClassRunner.class)
4043
@SpringApplicationConfiguration(classes = SampleDataRestApplication.class)
@@ -49,4 +52,20 @@ public void findsFirstPageOfCities() {
4952
Page<City> cities = this.repository.findAll(new PageRequest(0, 10));
5053
assertThat(cities.getTotalElements(), is(greaterThan(20L)));
5154
}
55+
56+
@Test
57+
public void findByNameAndCountry() {
58+
City city = this.repository.findByNameAndCountryAllIgnoringCase("Melbourne",
59+
"Australia");
60+
assertThat(city, notNullValue());
61+
assertThat(city.getName(), is(equalTo("Melbourne")));
62+
}
63+
64+
@Test
65+
public void findContaining() {
66+
Page<City> cities = this.repository
67+
.findByNameContainingAndCountryContainingAllIgnoringCase("", "UK",
68+
new PageRequest(0, 10));
69+
assertThat(cities.getTotalElements(), is(equalTo(3L)));
70+
}
5271
}

0 commit comments

Comments
 (0)