Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails Unit Test "CreateAlias" doesn´t work

I am trying to make a unit test over a namedquery method and it´s not working as I am using the method grails.orm.HibernateCriteriaBuilder.createAlias which doesn´t seem to be found by Grails: " No signature of method: grails.gorm.CriteriaBuilder.createAlias()"

I guess the problem is that when making a unit test and mocking the class, it´s trying to find the method around "grails.gorm.CriteriaBuilder" class and not grails.orm.HibernateCriteriaBuilder class, why ?? any ideas to solve it?

class Book{
  static namedQueries = {     
      testMethod()
      {
         createAlias('name', 'james')
      }
   }
}



@Mock([Book])
class BookTests{
  @Test
  void myTest() {
      Book.testMethod();
   }
}

Error : No signature of method: grails.gorm.CriteriaBuilder.createAlias()

like image 619
alvaro.rmfg Avatar asked Oct 23 '12 07:10

alvaro.rmfg


1 Answers

We couldn't figure this out either; we suspect it's just missing from the GORM UnitTest implementation. But if you just want to query an association, in Grails you don't need an alias. Observe:

Book.createCriteria {
    eq("title", "One Hundred Years of Solitude")
    author {
        eq("name", "Gabriel García Márquez")
    }
}
like image 101
David Seiler Avatar answered Oct 21 '22 13:10

David Seiler