grails / gorm-neo4j

GORM for Neo4j
Apache License 2.0
17 stars 10 forks source link

mockDomain fails when Domain is a relationship, so use a geb test instead #142

Closed nathandunn closed 4 years ago

nathandunn commented 4 years ago

I can provide better documentation, but at a glance:

class SomeServiceSpec extends Specification implements ServiceUnitTest<SomeService>, DataTest{

    def setup() {
        mockDomain Domain1
        mockDomain Domain2
        mockDomain Relationship
    }

   void "test1"(){
        when: "test"
        def d1 = new Domain1()
        def d2 = new Domain2()
        new Relationship(from:d1, to: d2).save()
   }

Where relationship is a relationship:

class Relationship implements Relationship<Domain1,Domain2>{}

I get an error that is:

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Relationship' with class 'org.grails.datastore.mapping.keyvalue.mapping.config.KeyValuePersistentEntity' to class 'org.grails.datastore.gorm.neo4j.RelationshipPersistentEntity'

Maybe there is a better way to do this, but it seems like there should be a mockRelationship or it should properly percieve that it is a RelationshipPersistentEntity instead of a KeyValuePersistentEntity.

nathandunn commented 4 years ago

Sorry, this is GORM 7.0.6 and Grails 4.0.4 (though also tried with 7.02 and 4.0.3 respecitively).

nathandunn commented 4 years ago

Ah, quick answer is:

  1. don't do mockDomain Relationship
  2. better if you can extend Neo4JSpec instead of Specification, but not necessary.

So should be:

class SomeServiceSpec extends Specification implements ServiceUnitTest<SomeService>, DataTest{

    def setup() {
        mockDomain Domain1
        mockDomain Domain2
//        mockDomain Relationship
    }

   void "test1"(){
        when: "test"
        def d1 = new Domain1().save(failOnError: true)
        def d2 = new Domain2().save(failOnError: true)
        new Relationship(from:d1, to: d2).save(failOnError: true)
   }

The it works fine.