From 2845b101a1fe476e4ae0e53eb5036ba4cfa0213b Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 27 Feb 2014 10:33:44 +0000 Subject: [PATCH] Add spring-data-rest sample --- spring-boot-samples/pom.xml | 1 + .../spring-boot-sample-data-rest/pom.xml | 43 ++++++ .../data/jpa/SampleDataRestApplication.java | 35 +++++ .../java/sample/data/jpa/domain/City.java | 76 +++++++++++ .../java/sample/data/jpa/domain/Hotel.java | 75 +++++++++++ .../data/jpa/service/CityRepository.java | 34 +++++ .../data/jpa/service/CitySearchCriteria.java | 44 +++++++ .../data/jpa/service/HotelRepository.java | 30 +++++ .../src/main/resources/import.sql | 123 ++++++++++++++++++ .../jpa/SampleDataRestApplicationTests.java | 48 +++++++ .../CityRepositoryIntegrationTests.java | 51 ++++++++ .../resources/application-scratch.properties | 1 + .../spring-boot-starter-parent/pom.xml | 5 + 13 files changed, 566 insertions(+) create mode 100644 spring-boot-samples/spring-boot-sample-data-rest/pom.xml create mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/SampleDataRestApplication.java create mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/City.java create mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/Hotel.java create mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CityRepository.java create mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CitySearchCriteria.java create mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/HotelRepository.java create mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/main/resources/import.sql create mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/SampleDataRestApplicationTests.java create mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java create mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/test/resources/application-scratch.properties diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml index aa7f449c21..e9d2f38bcb 100644 --- a/spring-boot-samples/pom.xml +++ b/spring-boot-samples/pom.xml @@ -24,6 +24,7 @@ spring-boot-sample-data-jpa spring-boot-sample-data-mongodb spring-boot-sample-data-redis + spring-boot-sample-data-rest spring-boot-sample-integration spring-boot-sample-jetty spring-boot-sample-profile diff --git a/spring-boot-samples/spring-boot-sample-data-rest/pom.xml b/spring-boot-samples/spring-boot-sample-data-rest/pom.xml new file mode 100644 index 0000000000..bfad96617d --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-rest/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-samples + 1.0.0.BUILD-SNAPSHOT + + spring-boot-sample-data-rest + jar + + ${basedir}/../.. + + + + ${project.groupId} + spring-boot-starter-data-jpa + + + ${project.groupId} + spring-boot-starter-data-rest + + + org.hsqldb + hsqldb + runtime + + + ${project.groupId} + spring-boot-starter-test + test + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/SampleDataRestApplication.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/SampleDataRestApplication.java new file mode 100644 index 0000000000..49b0d5dcfc --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/SampleDataRestApplication.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.data.jpa; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; + +@Configuration +@ComponentScan +@EnableAutoConfiguration +@Import(RepositoryRestMvcConfiguration.class) +public class SampleDataRestApplication { + + public static void main(String[] args) throws Exception { + SpringApplication.run(SampleDataRestApplication.class, args); + } +} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/City.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/City.java new file mode 100644 index 0000000000..55ebea8582 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/City.java @@ -0,0 +1,76 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.data.jpa.domain; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class City implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue + private Long id; + + @Column(nullable = false) + private String name; + + @Column(nullable = false) + private String state; + + @Column(nullable = false) + private String country; + + @Column(nullable = false) + private String map; + + protected City() { + } + + public City(String name, String country) { + super(); + this.name = name; + this.country = country; + } + + public String getName() { + return this.name; + } + + public String getState() { + return this.state; + } + + public String getCountry() { + return this.country; + } + + public String getMap() { + return this.map; + } + + @Override + public String toString() { + return getName() + "," + getState() + "," + getCountry(); + } +} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/Hotel.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/Hotel.java new file mode 100644 index 0000000000..bb904a10d7 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/Hotel.java @@ -0,0 +1,75 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.data.jpa.domain; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +import org.hibernate.annotations.NaturalId; + +@Entity +public class Hotel implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue + private Long id; + + @ManyToOne(optional = false) + @NaturalId + private City city; + + @Column(nullable = false) + @NaturalId + private String name; + + @Column(nullable = false) + private String address; + + @Column(nullable = false) + private String zip; + + protected Hotel() { + } + + public Hotel(City city, String name) { + this.city = city; + this.name = name; + } + + public City getCity() { + return this.city; + } + + public String getName() { + return this.name; + } + + public String getAddress() { + return this.address; + } + + public String getZip() { + return this.zip; + } +} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CityRepository.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CityRepository.java new file mode 100644 index 0000000000..e6ee6ecf78 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CityRepository.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.data.jpa.service; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +import sample.data.jpa.domain.City; + +@RepositoryRestResource(collectionResourceRel = "citys", path = "cities") +interface CityRepository extends PagingAndSortingRepository { + + Page findByNameContainingAndCountryContainingAllIgnoringCase(String name, + String country, Pageable pageable); + + City findByNameAndCountryAllIgnoringCase(String name, String country); + +} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CitySearchCriteria.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CitySearchCriteria.java new file mode 100644 index 0000000000..cd74f536cd --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CitySearchCriteria.java @@ -0,0 +1,44 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.data.jpa.service; + +import java.io.Serializable; + +import org.springframework.util.Assert; + +public class CitySearchCriteria implements Serializable { + + private static final long serialVersionUID = 1L; + + private String name; + + public CitySearchCriteria() { + } + + public CitySearchCriteria(String name) { + Assert.notNull(name, "Name must not be null"); + this.name = name; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/HotelRepository.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/HotelRepository.java new file mode 100644 index 0000000000..91737222d5 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/HotelRepository.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.data.jpa.service; + +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +import sample.data.jpa.domain.City; +import sample.data.jpa.domain.Hotel; + +@RepositoryRestResource(collectionResourceRel = "hotels", path = "hotels") +interface HotelRepository extends PagingAndSortingRepository { + + Hotel findByCityAndName(City city, String name); + +} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/resources/import.sql b/spring-boot-samples/spring-boot-sample-data-rest/src/main/resources/import.sql new file mode 100644 index 0000000000..6f2753bda3 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/resources/import.sql @@ -0,0 +1,123 @@ +-- +-- Sample dataset containing a number of Hotels in various Cities across the world. +-- + +-- ================================================================================================= +-- AUSTRALIA + +-- Brisbane +insert into city(country, name, state, map) values ('Australia', 'Brisbane', 'Queensland', '-27.470933, 153.023502') +insert into hotel(city_id, name, address, zip) values (1, 'Conrad Treasury Place', 'William & George Streets', '4001') + +-- Melbourne +insert into city(country, name, state, map) values ('Australia', 'Melbourne', 'Victoria', '-37.813187, 144.96298') +insert into hotel(city_id, name, address, zip) values (2, 'The Langham', '1 Southgate Ave, Southbank', '3006') + +-- Sydney +insert into city(country, name, state, map) values ('Australia', 'Sydney', 'New South Wales', '-33.868901, 151.207091') +insert into hotel(city_id, name, address, zip) values (3, 'Swissotel', '68 Market Street', '2000') + + +-- ================================================================================================= +-- CANADA + +-- Montreal +insert into city(country, name, state, map) values ('Canada', 'Montreal', 'Quebec', '45.508889, -73.554167') +insert into hotel(city_id, name, address, zip) values (4, 'Ritz Carlton', '1228 Sherbrooke St', 'H3G1H6') + + +-- ================================================================================================= +-- ISRAEL + +-- Tel Aviv +insert into city(country, name, state, map) values ('Israel', 'Tel Aviv', '', '32.066157, 34.777821') +insert into hotel(city_id, name, address, zip) values (5, 'Hilton Tel Aviv', 'Independence Park', '63405') + + +-- ================================================================================================= +-- JAPAN + +-- Tokyo +insert into city(country, name, state, map) values ('Japan', 'Tokyo', '', '35.689488, 139.691706') +insert into hotel(city_id, name, address, zip) values (6, 'InterContinental Tokyo Bay', 'Takeshiba Pier', '105') + + +-- ================================================================================================= +-- SPAIN + +-- Barcelona +insert into city(country, name, state, map) values ('Spain', 'Barcelona', 'Catalunya', '41.387917, 2.169919') +insert into hotel(city_id, name, address, zip) values (7, 'Hilton Diagonal Mar', 'Passeig del Taulat 262-264', '08019') + +-- ================================================================================================= +-- SWITZERLAND + +-- Neuchatel +insert into city(country, name, state, map) values ('Switzerland', 'Neuchatel', '', '46.992979, 6.931933') +insert into hotel(city_id, name, address, zip) values (8, 'Hotel Beaulac', ' Esplanade Leopold-Robert 2', '2000') + + +-- ================================================================================================= +-- UNITED KINGDOM + +-- Bath +insert into city(country, name, state, map) values ('UK', 'Bath', 'Somerset', '51.381428, -2.357454') +insert into hotel(city_id, name, address, zip) values (9, 'The Bath Priory Hotel', 'Weston Road', 'BA1 2XT') +insert into hotel(city_id, name, address, zip) values (9, 'Bath Travelodge', 'Rossiter Road, Widcombe Basin', 'BA2 4JP') + +-- London +insert into city(country, name, state, map) values ('UK', 'London', '', '51.500152, -0.126236') +insert into hotel(city_id, name, address, zip) values (10, 'Melia White House', 'Albany Street', 'NW1 3UP') + +-- Southampton +insert into city(country, name, state, map) values ('UK', 'Southampton', 'Hampshire', '50.902571, -1.397238') +insert into hotel(city_id, name, address, zip) values (11, 'Chilworth Manor', 'The Cottage, Southampton Business Park', 'SO16 7JF') + + +-- ================================================================================================= +-- USA + +-- Atlanta +insert into city(country, name, state, map) values ('USA', 'Atlanta', 'GA', '33.748995, -84.387982') +insert into hotel(city_id, name, address, zip) values (12, 'Marriott Courtyard', 'Tower Place, Buckhead', '30305') +insert into hotel(city_id, name, address, zip) values (12, 'Ritz Carlton', 'Peachtree Rd, Buckhead', '30326') +insert into hotel(city_id, name, address, zip) values (12, 'Doubletree', 'Tower Place, Buckhead', '30305') + +-- Chicago +insert into city(country, name, state, map) values ('USA', 'Chicago', 'IL', '41.878114, -87.629798') +insert into hotel(city_id, name, address, zip) values (13, 'Hotel Allegro', '171 West Randolph Street', '60601') + +-- Eau Claire +insert into city(country, name, state, map) values ('USA', 'Eau Claire', 'WI', '44.811349, -91.498494') +insert into hotel(city_id, name, address, zip) values (14, 'Sea Horse Inn', '2106 N Clairemont Ave', '54703') +insert into hotel(city_id, name, address, zip) values (14, 'Super 8 Eau Claire Campus Area', '1151 W Macarthur Ave', '54701') + +-- Hollywood +insert into city(country, name, state, map) values ('USA', 'Hollywood', 'FL', '26.011201, -80.14949') +insert into hotel(city_id, name, address, zip) values (15, 'Westin Diplomat', '3555 S. Ocean Drive', '33019') + +-- Miami +insert into city(country, name, state, map) values ('USA', 'Miami', 'FL', '25.788969, -80.226439') +insert into hotel(city_id, name, address, zip) values (16, 'Conrad Miami', '1395 Brickell Ave', '33131') + +-- Melbourne +insert into city(country, name, state, map) values ('USA', 'Melbourne', 'FL', '28.083627, -80.608109') +insert into hotel(city_id, name, address, zip) values (17, 'Radisson Suite Hotel Oceanfront', '3101 North Hwy', '32903') + +-- New York +insert into city(country, name, state, map) values ('USA', 'New York', 'NY', '40.714353, -74.005973') +insert into hotel(city_id, name, address, zip) values (18, 'W Union Hotel', 'Union Square, Manhattan', '10011') +insert into hotel(city_id, name, address, zip) values (18, 'W Lexington Hotel', 'Lexington Ave, Manhattan', '10011') +insert into hotel(city_id, name, address, zip) values (18, '70 Park Avenue Hotel', '70 Park Avenue', '10011') + +-- Palm Bay +insert into city(country, name, state, map) values ('USA', 'Palm Bay', 'FL', '28.034462, -80.588665') +insert into hotel(city_id, name, address, zip) values (19, 'Jameson Inn', '890 Palm Bay Rd NE', '32905') + +-- San Francisco +insert into city(country, name, state, map) values ('USA', 'San Francisco', 'CA', '37.77493, -122.419415') +insert into hotel(city_id, name, address, zip) values (20, 'Marriot Downtown', '55 Fourth Street', '94103') + +-- Washington +insert into city(country, name, state, map) values ('USA', 'Washington', 'DC', '38.895112, -77.036366') +insert into hotel(city_id, name, address, zip) values (21, 'Hotel Rouge', '1315 16th Street NW', '20036') diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/SampleDataRestApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/SampleDataRestApplicationTests.java new file mode 100644 index 0000000000..567d554a31 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/SampleDataRestApplicationTests.java @@ -0,0 +1,48 @@ +package sample.data.jpa; + +import static org.hamcrest.Matchers.containsString; +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.status; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +/** + * Integration test to run the application. + * + * @author Oliver Gierke + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SampleDataRestApplication.class) +@WebAppConfiguration +@ActiveProfiles("scratch") +// Separate profile for web tests to avoid clashing databases +public class SampleDataRestApplicationTests { + + @Autowired + private WebApplicationContext context; + + private MockMvc mvc; + + @Before + public void setUp() { + this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); + } + + @Test + public void testHome() throws Exception { + + this.mvc.perform(get("/")).andExpect(status().isOk()) + .andExpect(content().string(containsString("hotels"))); + } +} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java new file mode 100644 index 0000000000..7a8608fb9a --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package sample.data.jpa.service; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import sample.data.jpa.SampleDataRestApplication; +import sample.data.jpa.domain.City; + +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +/** + * Integration tests for {@link CityRepository}. + * + * @author Oliver Gierke + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SampleDataRestApplication.class) +public class CityRepositoryIntegrationTests { + + @Autowired + CityRepository repository; + + @Test + public void findsFirstPageOfCities() { + + Page cities = this.repository.findAll(new PageRequest(0, 10)); + assertThat(cities.getTotalElements(), is(greaterThan(20L))); + } +} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/test/resources/application-scratch.properties b/spring-boot-samples/spring-boot-sample-data-rest/src/test/resources/application-scratch.properties new file mode 100644 index 0000000000..1d31022540 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/test/resources/application-scratch.properties @@ -0,0 +1 @@ +spring.datasource.url: jdbc:hsqldb:mem:restdb diff --git a/spring-boot-starters/spring-boot-starter-parent/pom.xml b/spring-boot-starters/spring-boot-starter-parent/pom.xml index 12faa6b1c8..33294be771 100644 --- a/spring-boot-starters/spring-boot-starter-parent/pom.xml +++ b/spring-boot-starters/spring-boot-starter-parent/pom.xml @@ -72,6 +72,11 @@ spring-boot-starter-data-mongodb ${spring-boot.version} + + org.springframework.boot + spring-boot-starter-data-rest + ${spring-boot.version} + org.springframework.boot spring-boot-starter-integration