Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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

Aaron graemerocher Lari Hotari
Aaron
Collaborator

... tests

Basically test cases for:

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

Seemed more complete to test them in this context.

Aaron 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

Aaron
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.

Lari Hotari
Owner

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

Lari Hotari 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. Aaron
This page is out of date. Refresh to see the latest.
126 grails-test-suite-uber/src/test/groovy/grails/test/mixin/UnitTestEmbeddedPropertyQuery.groovy
View
@@ -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.