我正在尝试测试服务中的一种方法,但是我不断收到错误消息
GORM的此实现当前不支持基于字符串的查询,例如[findAll]。请改用条件。
我的服务:
class MyService { ListcolorShade (String shade) { def shadeId = Shade.findByName(shade).id return ColorShade.get(shadeId) } }
我的班级Shade
和Color
领域
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 get (long shadeId) { ColorShade.findAll 'from ColorShade where shade.id = :shadeId', [shadeId: shadeId] } static mapping = { table 'color_shade' version false id composite: ['color', 'shade'] } }
我的规格:test\unit\MyServiceSpec.groovy
我也尝试将其添加到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 also tried: mockDomain(ColorShade, [[color: color, shade: shade]]) but I get the same error */ } def cleanup () { } def "test colorShade" () { expect: 1 == service.colorShade("dark").size() } }
当我运行此测试时,出现错误:
String-based queries like [findAll] are currently not supported in this implementation of GORM. Use criteria instead.
题
我该如何测试?我在grails 2.2.4上
注意:这只是我针对该问题而创建的示例测试方案。我的实际测试有所不同,但在其中我遇到了与此问题相同的问题。