Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
8fcf355d
Commit
8fcf355d
authored
Sep 30, 2014
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gh-1627' into 1.1.x
parents
d0990c06
61e90f5b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
3 deletions
+51
-3
pom.xml
spring-boot-samples/spring-boot-sample-data-rest/pom.xml
+5
-0
CityRepository.java
...src/main/java/sample/data/jpa/service/CityRepository.java
+6
-3
SampleDataRestApplicationTests.java
.../java/sample/data/jpa/SampleDataRestApplicationTests.java
+21
-0
CityRepositoryIntegrationTests.java
...mple/data/jpa/service/CityRepositoryIntegrationTests.java
+19
-0
No files found.
spring-boot-samples/spring-boot-sample-data-rest/pom.xml
View file @
8fcf355d
...
...
@@ -37,6 +37,11 @@
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.jayway.jsonpath
</groupId>
<artifactId>
json-path
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
...
...
spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CityRepository.java
View file @
8fcf355d
...
...
@@ -19,6 +19,7 @@ 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.repository.query.Param
;
import
org.springframework.data.rest.core.annotation.RepositoryRestResource
;
import
sample.data.jpa.domain.City
;
...
...
@@ -26,9 +27,11 @@ import sample.data.jpa.domain.City;
@RepositoryRestResource
(
collectionResourceRel
=
"citys"
,
path
=
"cities"
)
interface
CityRepository
extends
PagingAndSortingRepository
<
City
,
Long
>
{
Page
<
City
>
findByNameContainingAndCountryContainingAllIgnoringCase
(
String
name
,
String
country
,
Pageable
pageable
);
Page
<
City
>
findByNameContainingAndCountryContainingAllIgnoringCase
(
@Param
(
"name"
)
String
name
,
@Param
(
"country"
)
String
country
,
Pageable
pageable
);
City
findByNameAndCountryAllIgnoringCase
(
String
name
,
String
country
);
City
findByNameAndCountryAllIgnoringCase
(
@Param
(
"name"
)
String
name
,
@Param
(
"country"
)
String
country
);
}
spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/SampleDataRestApplicationTests.java
View file @
8fcf355d
...
...
@@ -29,14 +29,17 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import
org.springframework.web.context.WebApplicationContext
;
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
.
result
.
MockMvcResultMatchers
.
content
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
jsonPath
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
/**
* Integration test to run the application.
*
* @author Oliver Gierke
* @author Andy Wilkinson
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
SampleDataRestApplication
.
class
)
...
...
@@ -61,4 +64,22 @@ public class SampleDataRestApplicationTests {
this
.
mvc
.
perform
(
get
(
"/"
)).
andExpect
(
status
().
isOk
())
.
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
)));
}
}
spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java
View file @
8fcf355d
...
...
@@ -27,14 +27,17 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
sample.data.jpa.SampleDataRestApplication
;
import
sample.data.jpa.domain.City
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
greaterThan
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
* Integration tests for {@link CityRepository}.
*
* @author Oliver Gierke
* @author Andy Wilkinson
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
SampleDataRestApplication
.
class
)
...
...
@@ -49,4 +52,20 @@ public class CityRepositoryIntegrationTests {
Page
<
City
>
cities
=
this
.
repository
.
findAll
(
new
PageRequest
(
0
,
10
));
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
)));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment