unit testing - findAll not supported in this implementation of GORM -
i'm trying test method in service maintain getting error that
string-based queries [findall] not supported in implementation of gorm. utilize criteria instead.
my service:
class myservice { list<color> colorshade (string shade) { def shadeid = shade.findbyname(shade).id homecoming colorshade.get(shadeid) } } my class joins shade , color domains
class colorshade extends serializable { color color shade shade static colorshade create (color color, shade shade, boolean flush = false) { if (get(shade.id) == null) new colornetwork(color: color, shade: shade).save(flush: flush) } static colorshade (long shadeid) { colorshade.findall 'from colorshade shade.id = :shadeid', [shadeid: shadeid] } static mapping = { table 'color_shade' version false id composite: ['color', 'shade'] } } my spec: test\unit\myservicespec.groovy i've tried adding test\integration\myservicespec.groovy
@testfor(myservicespec) @mock([color, shade, colornetwork]) @testmixin(domainclassunittestmixin) class myservicespec extends specification { def shade def color def setup(){ color = new color(name: "red") shade = new shade(name: "dark") color.save(flush: true) shade.save(flush: true) colorshade.create(color, shade) /* i've tried: mockdomain(colorshade, [[color: color, shade: shade]]) same error */ } def cleanup () { } def "test colorshade" () { expect: 1 == service.colorshade("dark").size() } } when run test error:
string-based queries [findall] not supported in implementation of gorm. utilize criteria instead. question
how can test ? on grails 2.2.4note: sample test scenario i've created purpose of question. actual tests different in them have same problem question.
if using version 4.3.5.4 or later of hibernate4 plugin can utilize grails.test.mixin.hibernate.hibernatetestmixin, supports total hibernate gorm in unit test environment. need add together dependency in grails-app/conf/buildconfig.groovy.
dependencies { test "org.grails:grails-datastore-test-support:1.0-grails-2.4" } then annotate test grails.test.mixin.hibernate.hibernatetestmixin annotation.
unit-testing grails spock
No comments:
Post a Comment