Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Commit bde04b4

Browse files
committed
added test case for unmarshalling joda-time fields
1 parent 5a65f79 commit bde04b4

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

grails-app/conf/BuildConfig.groovy

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
grails.project.work.dir = 'target'
22
grails.project.docs.output.dir = 'docs' // for the gh-pages branch
33

4-
grails.project.dependency.distribution = {
5-
remoteRepository(id: 'snapshots-repo', url: 'http://noams.artifactoryonline.com/noams/grails-elasticsearch-plugin-snapshots/') {
6-
authentication username: System.getProperty('DEPLOYER_USERNAME'), password: System.getProperty('DEPLOYER_PASSWORD')
7-
}
8-
remoteRepository(id: 'rc-repo', url: 'http://noams.artifactoryonline.com/noams/grails-elasticsearch-plugin-rc/') {
9-
authentication username: System.getProperty('DEPLOYER_USERNAME'), password: System.getProperty('DEPLOYER_PASSWORD')
10-
}
11-
}
4+
//grails.project.dependency.distribution = {
5+
//// remoteRepository(id: 'snapshots-repo', url: 'http://noams.artifactoryonline.com/noams/grails-elasticsearch-plugin-snapshots/') {
6+
//// authentication username: System.getProperty('DEPLOYER_USERNAME'), password: System.getProperty('DEPLOYER_PASSWORD')
7+
//// }
8+
//// remoteRepository(id: 'rc-repo', url: 'http://noams.artifactoryonline.com/noams/grails-elasticsearch-plugin-rc/') {
9+
//// authentication username: System.getProperty('DEPLOYER_USERNAME'), password: System.getProperty('DEPLOYER_PASSWORD')
10+
//// }
11+
// remoteRepository(id: 'stainless-repo', url: 'http://frink.stainlesscode.com:8081/artifactory/libs-snapshot-local') {
12+
// authentication username: System.getProperty('DEPLOYER_USERNAME'), password: System.getProperty('DEPLOYER_PASSWORD')
13+
// }
14+
//}
1215
grails.project.dependency.resolver = 'maven' // or ivy
1316
grails.project.dependency.resolution = {
1417

@@ -49,6 +52,7 @@ grails.project.dependency.resolution = {
4952
compile 'com.vividsolutions:jts:1.13'
5053

5154
test 'com.googlecode.json-simple:json-simple:1.1.1'
55+
test 'org.jadira.usertype:usertype.jodatime:1.9'
5256
}
5357

5458
plugins {
@@ -59,5 +63,7 @@ grails.project.dependency.resolution = {
5963
test(':hibernate:3.6.10.16', ':tomcat:7.0.54') {
6064
export = false
6165
}
66+
67+
test ":joda-time:1.5"
6268
}
6369
}

grails-app/domain/test/Store.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
package test
22

3+
import org.jadira.usertype.dateandtime.joda.PersistentDateTime
4+
import org.joda.time.DateTime
5+
36
class Store {
47

58
String name
69
String description = "A description of a store"
710
String owner = "Owner of the store"
11+
DateTime openingDate
812

913
static searchable = true
1014

1115
static constraints = {
1216
name blank: false
1317
description nullable: true
1418
owner nullable: false
19+
openingDate nullable: true
1520
}
1621

1722
static mapping = {
1823
autoImport(false)
24+
openingDate type: PersistentDateTime
1925
}
2026

2127
public String toString() {

test/integration/org/grails/plugins/elasticsearch/ElasticSearchServiceIntegrationSpec.groovy

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.elasticsearch.search.builder.SearchSourceBuilder
2626
import org.elasticsearch.search.sort.FieldSortBuilder
2727
import org.elasticsearch.search.sort.SortBuilders
2828
import org.elasticsearch.search.sort.SortOrder
29+
import org.joda.time.DateTime
2930
import test.*
3031
import test.custom.id.Toy
3132

@@ -182,6 +183,26 @@ class ElasticSearchServiceIntegrationSpec extends IntegrationSpec {
182183
searchResults[0].date == product.date
183184
}
184185
186+
void 'a joda-time date value should be marshalled and de-marshalled correctly'() {
187+
def date = new DateTime()
188+
given:
189+
def store = new Store(name:'The Mapple Store',
190+
openingDate: date
191+
).save(failOnError: true)
192+
193+
elasticSearchService.index(store)
194+
elasticSearchAdminService.refresh()
195+
196+
when:
197+
def result = elasticSearchService.search(store.name, [indices: Store, types: Store])
198+
199+
then:
200+
result.total == 1
201+
List<Product> searchResults = result.searchResults
202+
searchResults[0].name == store.name
203+
searchResults[0].openingDate == store.openingDate
204+
}
205+
185206
void 'a geo point location is marshalled and de-marshalled correctly'() {
186207
given:
187208
def location = new GeoPoint(

0 commit comments

Comments
 (0)