Mocking domain objects with a collection mappedBy "none" fails

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Mocking domain objects with a collection mappedBy "none" fails

joemccall86
This post was updated on .
According to the docs here: http://grails.org/doc/2.2.4/guide/GORM.html#manyToOneAndOneToOne

I should be able to have a domain class that has multiple references to the same type, as long as the `mappedBy` entry specifies "none" as the value for all but one.

So for the attached sample, I have 2 domain objects: Person, and SoftballTeamPreference.

class Person {
    String name
    static hasOne = [softballTeampreference: SoftballTeamPreference]
}


class SoftballTeamPreference {
    static belongsTo = [owner: Person]
    static hasMany = [players: Person]
    static mappedBy = [players: "none"]
}

I have a very simple unit test that tries to @Mock these and asserts true:

@Mock([Person, SoftballTeamPreference])
class PersonServiceTests {

    void testSomething() {
        assert true, 'The unit tests compiled'
    }
}

However in my sample when I try to run my unit test, I get the following output:

org.grails.datastore.mapping.model.IllegalMappingException: Non-existent mapping property [none] specified for property [players] in class [grails22test.SoftballTeamPreference]

(whole stack trace is here: https://gist.github.com/joemccall86/9943666)

Attached is the grails project. This may be related to GRAILS-10115, which has been fixed. The same fix may apply to GormMappingConfigurationStrategy.java, but I don't know enough about the code to comment.

Should I raise an issue in Jira?

grails22test.zip
Reply | Threaded
Open this post in threaded view
|

Re: Mocking domain objects with a collection mappedBy "none" fails

joemccall86
I updated the test to use grails 2.3.7 (the latest as of this writing) and the same thing happens. Attached is the modified project. grails23test.zip
Reply | Threaded
Open this post in threaded view
|

Re: Mocking domain objects with a collection mappedBy "none" fails

gordcurrie
Did you find a workaround? Running into the same issue and hate the idea of not being able to test this class.
Reply | Threaded
Open this post in threaded view
|

Re: Mocking domain objects with a collection mappedBy "none" fails

mbpakla
Hi,

is there a Jira for this ? or an explanation ?
Reply | Threaded
Open this post in threaded view
|

Re: Mocking domain objects with a collection mappedBy "none" fails

joemccall86
The jira is https://jira.grails.org/browse/GRAILS-11285 and I couldn't find an explanation for it. No workaround just yet (other than to test without mocks through integration testing).

On Fri, Sep 26, 2014 at 10:59 AM, mbpakla [via Grails] <[hidden email]> wrote:
Hi,

is there a Jira for this ? or an explanation ?


If you reply to this email, your message will be added to the discussion below:
http://grails.1312388.n4.nabble.com/Mocking-domain-objects-with-a-collection-mappedBy-none-fails-tp4655685p4657979.html
To unsubscribe from Mocking domain objects with a collection mappedBy "none" fails, click here.
NAML



--

Joe McCall

Software Engineer - Intrepid Networks