Grails JIRA

  • Log In Access more options
    • Online Help
    • GreenHopper Help
    • Agile Answers
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Agile
Grails
  • Grails
  • GRAILS-787 Top level task: Improve Grails unit t...
  • GRAILS-4568

Can't test POJO domain class with mockDomain

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Sub-task Sub-task
  • Status: Resolved Resolved
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.1
  • Fix Version/s: 1.2 final
  • Component/s: Testing
  • Labels:
    None
  • Environment:
    Windows Vista
    Grails 1.1
    Maven 2.1.0

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.

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Hide
    Zip Archive
    grails-test-pojo.zip
    14/Nov/09 7:51 PM
    236 kB
    Felipe Cypriano
    1. File
      grails-test-pojo/.classpath 6 kB
    2. File
      grails-test-pojo/.project 0.5 kB
    3. File
      grails-test-pojo/.../org.codehaus.groovy.eclipse.preferences.prefs 0.1 kB
    4. File
      grails-test-pojo/application.properties 0.1 kB
    5. XML File
      grails-test-pojo/build.xml 5 kB
    6. File
      grails-test-pojo/.../BootStrap.groovy 0.1 kB
    7. File
      grails-test-pojo/.../Config.groovy 3 kB
    8. File
      grails-test-pojo/.../DataSource.groovy 0.8 kB
    9. XML File
      grails-test-pojo/.../hibernate.cfg.xml 0.3 kB
    10. File
      grails-test-pojo/.../resources.groovy 0.0 kB
    11. File
      grails-test-pojo/.../UrlMappings.groovy 0.2 kB
    12. File
      grails-test-pojo/.../messages.properties 3 kB
    13. File
      grails-test-pojo/.../messages_de.properties 3 kB
    14. File
      grails-test-pojo/.../messages_es.properties 3 kB
    15. File
      grails-test-pojo/.../messages_fr.properties 2 kB
    16. File
      grails-test-pojo/.../messages_it.properties 2 kB
    17. File
      grails-test-pojo/.../messages_ja.properties 2 kB
    18. File
      grails-test-pojo/.../messages_nl.properties 3 kB
    19. File
      grails-test-pojo/.../messages_pt_BR.properties 3 kB
    20. File
      grails-test-pojo/.../messages_ru.properties 4 kB
    21. File
      grails-test-pojo/.../messages_th.properties 5 kB
    22. File
      grails-test-pojo/.../messages_zh_CN.properties 2 kB
    23. File
      grails-test-pojo/.../MagazineService.groovy 0.3 kB
    24. File
      grails-test-pojo/grails-app/.../error.gsp 2 kB
    25. File
      grails-test-pojo/grails-app/.../index.gsp 0.9 kB
    26. File
      grails-test-pojo/grails-app/.../main.gsp 0.7 kB
    27. File
      grails-test-pojo/grails-test-pojo-test.launch 0.8 kB
    28. File
      grails-test-pojo/grails-test-pojo.iml 3 kB
    29. File
      grails-test-pojo/grails-test-pojo.ipr 9 kB
    30. File
      grails-test-pojo/grails-test-pojo.iws 31 kB
    Showing 30 of 75 items Download Zip
    Show
    Zip Archive
    grails-test-pojo.zip
    14/Nov/09 7:51 PM
    236 kB
    Felipe Cypriano

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
  • Git Commits
Hide
Permalink
Peter Ledbrook added a comment - 14/Nov/09 3:18 AM

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.

Show
Peter Ledbrook added a comment - 14/Nov/09 3:18 AM 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.
Hide
Permalink
Felipe Cypriano added a comment - 14/Nov/09 7:51 PM

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.

Show
Felipe Cypriano added a comment - 14/Nov/09 7:51 PM 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.
Hide
Permalink
Felipe Cypriano added a comment - 14/Nov/09 7:52 PM

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.

Show
Felipe Cypriano added a comment - 14/Nov/09 7:52 PM 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.
Hide
Permalink
Scott Cleland added a comment - 23/Dec/09 12:21 PM

This appears to be fixed in 1.2. Thank you.

Show
Scott Cleland added a comment - 23/Dec/09 12:21 PM This appears to be fixed in 1.2. Thank you.

People

  • Assignee:
    Unassigned
    Reporter:
    Felipe Cypriano
Vote (3)
Watch (4)

Dates

  • Created:
    18/May/09 6:25 AM
    Updated:
    20/Jan/12 2:59 AM
    Resolved:
    21/Sep/11 8:28 AM
    Last Reviewed:
    01/Jan/10

Agile

  • View on Board
  • Atlassian JIRA (v5.2.1#813-sha1:277a546)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Grails project. Try JIRA - bug tracking software for your team.