Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

GRAILS-10166 - Add test case for embedded property query support in unit... #359

Closed
wants to merge 1 commit into from

3 participants

@longwa
Collaborator

... tests

Basically test cases for:

https://github.com/SpringSource/grails-data-mapping/pull/128

Seemed more complete to test them in this context.

@longwa longwa referenced this pull request in spring-projects/grails-data-mapping
Merged

GRAILS-10166 - Add support for querying embedded properties #128

@graemerocher
Owner

I can't merge this until we publish a new version

@longwa
Collaborator

I added more tests directly to the data-mapping project to cover this scenario. It doesn't hurt to have the tests in grails-core as well but it would be some duplication.

@lhotari
Collaborator

cherry picked commit as 8d17eec to 2.3.x branch since 2.2.x isn't maintained anymore. Thanks for the pull request!

@lhotari lhotari closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 6, 2013
  1. @longwa
This page is out of date. Refresh to see the latest.
View
126 ...ls-test-suite-uber/src/test/groovy/grails/test/mixin/UnitTestEmbeddedPropertyQuery.groovy
@@ -0,0 +1,126 @@
+package grails.test.mixin
+
+import grails.persistence.Entity
+
+@TestFor(Book2)
+@Mock([Author2, Book2])
+class UnitTestEmbeddedPropertyQuery {
+ void setUp() {
+ def author = new Author2(name: 'George')
+
+ def book = new Book2(
+ name: 'Game of Thrones',
+ publishPeriod: new Period(
+ startDate: new Date(2012, 1, 1),
+ endDate: new Date(2013, 1, 1)
+ )
+ )
+
+ author.addToBooks(book)
+ author.save(flush: true, failOnError: true)
+ }
+
+ void testQueryEmbedded() {
+
+ assert Book2.withCriteria {
+ gt 'publishPeriod.startDate', new Date(2011, 1, 1)
+ }.size() == 1
+
+ assert Book2.withCriteria {
+ ge 'publishPeriod.startDate', new Date(2012, 1, 1)
+ }.size() == 1
+
+ assert Book2.withCriteria {
+ lt 'publishPeriod.startDate', new Date(2014, 1, 1)
+ }.size() == 1
+
+ assert Book2.withCriteria {
+ le 'publishPeriod.startDate', new Date(2012, 1, 1)
+ }.size() == 1
+
+ assert Book2.withCriteria {
+ eq 'publishPeriod.startDate', new Date(2012, 1, 1)
+ }.size() == 1
+
+ assert Book2.withCriteria {
+ ne 'publishPeriod.startDate', new Date(2017, 1, 1)
+ }.size() == 1
+
+ assert Book2.withCriteria {
+ isNotNull 'publishPeriod.startDate'
+ }.size() == 1
+ }
+
+ void testAssociated() {
+ assert Author2.withCriteria {
+ books {
+ gt 'publishPeriod.startDate', new Date(2011, 1, 1)
+ }
+ }.size() == 1
+
+ assert Author2.withCriteria {
+ books {
+ ge 'publishPeriod.startDate', new Date(2012, 1, 1)
+ }
+ }.size() == 1
+
+ assert Author2.withCriteria {
+ books {
+ lt 'publishPeriod.startDate', new Date(2014, 1, 1)
+ }
+ }.size() == 1
+
+ assert Author2.withCriteria {
+ books {
+ le 'publishPeriod.startDate', new Date(2012, 1, 1)
+ }
+ }.size() == 1
+
+ assert Author2.withCriteria {
+ books {
+ eq 'publishPeriod.startDate', new Date(2012, 1, 1)
+ }
+ }.size() == 1
+
+ assert Author2.withCriteria {
+ books {
+ ne 'publishPeriod.startDate', new Date(2017, 1, 1)
+ }
+ }.size() == 1
+
+ assert Author2.withCriteria {
+ books {
+ isNotNull 'publishPeriod.startDate'
+ }
+ }.size() == 1
+ }
+
+ void testQueryToOne() {
+ assert Book2.withCriteria {
+ gt 'publishPeriod.startDate', new Date(2011, 1, 1)
+ author {
+ eq 'name', 'George'
+ }
+ }.size() == 1
+ }
+}
+
+@Entity
+class Book2 {
+ String name
+ Period publishPeriod
+
+ static belongsTo = [author: Author2]
+ static embedded = ['publishPeriod']
+}
+
+@Entity
+class Author2 {
+ String name
+ static hasMany = [books: Book2]
+}
+
+class Period {
+ Date startDate
+ Date endDate
+}
Something went wrong with that request. Please try again.