Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some test coverage for passing GStrings to gorm query methods
- Loading branch information
Jeff Brown
committed
Aug 15, 2011
1 parent
1ee3b55
commit a99b9dc
Showing
3 changed files
with
89 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
.../src/test/groovy/org/codehaus/groovy/grails/orm/hibernate/CharSequenceAndGormTests.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.codehaus.groovy.grails.orm.hibernate | ||
|
||
import grails.util.GrailsWebUtil | ||
|
||
import org.codehaus.groovy.grails.web.util.StreamCharBuffer | ||
import org.springframework.web.context.request.RequestContextHolder | ||
|
||
/** | ||
* @author Graeme Rocher | ||
* @since 1.1 | ||
*/ | ||
class CharSequenceAndGormTests extends AbstractGrailsHibernateTests { | ||
|
||
protected void onSetUp() { | ||
gcl.parseClass ''' | ||
import grails.persistence.* | ||
@Entity | ||
class SomeDomainClass { | ||
String name | ||
} | ||
''' | ||
|
||
gcl.parseClass ''' | ||
class StreamCharTagLib { | ||
Closure callMe = { attrs, body -> | ||
out << "hello" | ||
} | ||
} | ||
''' | ||
} | ||
|
||
void testGormWithStreamCharBuffer() { | ||
GrailsWebUtil.bindMockWebRequest(appCtx) | ||
|
||
try { | ||
def someDomainClass = ga.getDomainClass('SomeDomainClass').clazz | ||
|
||
assertNotNull "should have saved instance", someDomainClass.newInstance(name:"hello").save(flush:true) | ||
session.clear() | ||
|
||
def taglib = appCtx.getBean("StreamCharTagLib") | ||
def result = taglib.callMe() | ||
assertTrue result instanceof StreamCharBuffer | ||
|
||
testQueryMethods result | ||
} | ||
finally { | ||
RequestContextHolder.setRequestAttributes(null) | ||
} | ||
} | ||
|
||
void testGormWithGString() { | ||
GrailsWebUtil.bindMockWebRequest(appCtx) | ||
|
||
try { | ||
def someDomainClass = ga.getDomainClass('SomeDomainClass').clazz | ||
|
||
assertNotNull "should have saved instance", someDomainClass.newInstance(name:"hello").save(flush:true) | ||
session.clear() | ||
|
||
def value = 'hello' | ||
def queryArg = "${value}" | ||
assertTrue queryArg instanceof GString | ||
testQueryMethods queryArg | ||
} | ||
finally { | ||
RequestContextHolder.setRequestAttributes(null) | ||
} | ||
} | ||
|
||
private testQueryMethods(queryArg) { | ||
def someDomainClass = ga.getDomainClass('SomeDomainClass').clazz | ||
assert someDomainClass.findByName(queryArg) : "should have found a result when passing a ${queryArg.getClass()} value" | ||
assert someDomainClass.findByNameLike(queryArg) : "should have found a result when passing a ${queryArg.getClass()} value" | ||
assert someDomainClass.countByName(queryArg) : "should have found a result when passing a ${queryArg.getClass()} value" | ||
assert someDomainClass.countByNameLike(queryArg) : "should have found a result when passing a ${queryArg.getClass()} value" | ||
assert someDomainClass.findAllByName(queryArg) : "should have found a result when passing a ${queryArg.getClass()} value" | ||
assert someDomainClass.findAllByNameLike(queryArg) : "should have found a result when passing a ${queryArg.getClass()} value" | ||
assert someDomainClass.findWhere(name:queryArg) : "should have found a result when passing a ${queryArg.getClass()} value" | ||
assert someDomainClass.findAllWhere(name:queryArg) : "should have found a result when passing a ${queryArg.getClass()} value" | ||
assert someDomainClass.withCriteria{ eq 'name',queryArg } : "should have found a result when passing a ${queryArg.getClass()} value" | ||
assert someDomainClass.find("from SomeDomainClass s where s.name = ?", [queryArg]) : "should have found a result when passing a ${queryArg.getClass()} value" | ||
assert someDomainClass.findAll("from SomeDomainClass s where s.name = ?", [queryArg]) : "should have found a result when passing a ${queryArg.getClass()} value" | ||
assert someDomainClass.executeQuery("from SomeDomainClass s where s.name = ?", [queryArg]) : "should have found a result when passing a ${queryArg.getClass()} value" | ||
|
||
} | ||
} |
63 changes: 0 additions & 63 deletions
63
.../test/groovy/org/codehaus/groovy/grails/orm/hibernate/StreamCharBufferAndGormTests.groovy
This file was deleted.
Oops, something went wrong.