Details
Description
I need to test my app which has domain classes as POJOs and when I try to use mockDomain with my POJO I get this error:
java.lang.ClassCastException: br.com.litoraltextil.vc.entity.Transportadora cannot be cast to groovy.lang.GroovyObject
at grails.test.MockUtils.mockDomain(MockUtils.groovy:432)
The class Transportadora is a java class mapped by hibernate.cfg.xml, when running the app all dynamic methods works fine but using mockDomain I get that error. I know a java class isn't a GroovyObject and I can't make my pojo extends it.
Transportadora.java
@Entity @Table(name = "TRANSP") @SequenceGenerator(name = "SequenceTransportadora", sequenceName = "GEN_TRANSP", allocationSize = 1) public class Transportadora implements Serializable{ @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SequenceTransportadora") @Min(0) private int id; @Transient // I can't have version activated, because legacy app, and the mockDomain always searchs for this property private long version;
Hibernate.cfg.xml:
<hibernate-configuration> <session-factory> <mapping package="br.com.litoraltextil.vc.entity" /> <mapping class="br.com.litoraltextil.vc.entity.Transportadora" /> </session-factory> </hibernate-configuration>
Because of it I can't test my services. Is there a workaround for this?
The POJO support should be implemented.
-
Hide
- grails-test-pojo.zip
- 14/Nov/09 7:51 PM
- 236 kB
- Felipe Cypriano
-
- grails-test-pojo/.classpath 6 kB
- grails-test-pojo/.project 0.5 kB
- grails-test-pojo/.../org.codehaus.groovy.eclipse.preferences.prefs 0.1 kB
- grails-test-pojo/application.properties 0.1 kB
- grails-test-pojo/build.xml 5 kB
- grails-test-pojo/.../BootStrap.groovy 0.1 kB
- grails-test-pojo/.../Config.groovy 3 kB
- grails-test-pojo/.../DataSource.groovy 0.8 kB
- grails-test-pojo/.../hibernate.cfg.xml 0.3 kB
- grails-test-pojo/.../resources.groovy 0.0 kB
- grails-test-pojo/.../UrlMappings.groovy 0.2 kB
- grails-test-pojo/.../messages.properties 3 kB
- grails-test-pojo/.../messages_de.properties 3 kB
- grails-test-pojo/.../messages_es.properties 3 kB
- grails-test-pojo/.../messages_fr.properties 2 kB
- grails-test-pojo/.../messages_it.properties 2 kB
- grails-test-pojo/.../messages_ja.properties 2 kB
- grails-test-pojo/.../messages_nl.properties 3 kB
- grails-test-pojo/.../messages_pt_BR.properties 3 kB
- grails-test-pojo/.../messages_ru.properties 4 kB
- grails-test-pojo/.../messages_th.properties 5 kB
- grails-test-pojo/.../messages_zh_CN.properties 2 kB
- grails-test-pojo/.../MagazineService.groovy 0.3 kB
- grails-test-pojo/grails-app/.../error.gsp 2 kB
- grails-test-pojo/grails-app/.../index.gsp 0.9 kB
- grails-test-pojo/grails-app/.../main.gsp 0.7 kB
- grails-test-pojo/grails-test-pojo-test.launch 0.8 kB
- grails-test-pojo/grails-test-pojo.iml 3 kB
- grails-test-pojo/grails-test-pojo.ipr 9 kB
- grails-test-pojo/grails-test-pojo.iws 31 kB
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
Hello Peter,
I've attached a sample project, just run grails test-app to see the error.
Also remove the need to have the version attribute in the class, if possible.
I forget to comment about but this in this test case there's no Maven, I'm using Mac OS X and Grails 1.1.1
Just to update the environment.
This needs a reproducible example attached so we can track down the issue. Inspection of the code doesn't show any requirement for the class to be a GroovyObject. Could you also please attach the full stack trace.