Details
Description
i create a demo project to repeat this problem(i can't add Attachment,so i paste code below):
==========domain========================
class Book {
String title
String isbn
static constraints = {
}
}
==================service============================
class BookService {
boolean transactional = true
def add(String title,String isbn) {
def books = Book.list()
//======test case will fire exception====================================
Book book = Book.find(" from Book as b where b.isbn=:isbn",[isbn:isbn])
//=======================================================================
if(!book){
book = new Book()
book.title = title
book.isbn = isbn
book.save()
}
return book
}
def test(){
return Book.count()
}
}
=================testcase======================
import grails.test.*
class BookServiceTests extends GrailsUnitTestCase {
protected void setUp() {
super.setUp()
}
protected void tearDown() { super.tearDown() }
void testAddBook() {
mockDomain(Book)
Book b1 = new Book()
b1.title="Groovy in action"
b1.isbn ="332-2342"
b1.save(flush:true)
def bookService = new BookService()
def b2 = bookService.add("Groovy in action","332-2342")
def books = Book.list()
assertTrue books.size()==1
}
}
================================================
then the testcase will throw MissingMethodException:
No signature of method: org.bookcrm.Book.find() is applicable for argument types: (java.lang.String, java.util.LinkedHashMap) values: [ from Book as b where b.isbn=:isbn, [isbn:332-2342]]
groovy.lang.MissingMethodException: No signature of method: org.bookcrm.Book.find() is applicable for argument types: (java.lang.String, java.util.LinkedHashMap) values: [ from Book as b where b.isbn=:isbn, [isbn:332-2342]]
at grails.test.MockUtils$_addDynamicFinders_closure54.doCall(MockUtils.groovy:636)
at org.bookcrm.BookService.add(BookService.groovy:11)
at org.bookcrm.BookService$add.call(Unknown Source)
at org.bookcrm.BookServiceTests.testAddBook(BookServiceTests.groovy:23)
at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:262)
at _GrailsTest_groovy$_run_closure4.call(_GrailsTest_groovy)
at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:221)
at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:181)
at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:168)
at TestApp$_run_closure1.doCall(TestApp.groovy:102)
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:344)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:334)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.processTargets(Gant.groovy:495)
at gant.Gant.processTargets(Gant.groovy:480)
Is the test in your test/unit or test/integration directory?