0

I am looking for a mapping framework for my Spring/Groovy application. I found Nomin - it looks like something that fits my need. But I have the following issue: it doesn't find my mapping rules script in my test class.

in src/main/groovy/mypackage/entity2entitydto.groovy:

import org.nomin.entity.*

mappingFor a: Entity,  b: EntityDto
a.name      =       b.name

in src/test/groovy/mypackage/Entity2EntityDtoTest.groovy:

public class CoinMarketCap2CoinTest {
    NominMapper nomin = new Nomin("entity2entitydto.groovy");

    // also tried entity2entitydto, Entity2entitydto, Entity2entitydto.groovy
    // also tried with full package name
    // also tried File Name Entity2entitydto.groovy

    @Test
    public void test() {
        // Testing ...
    }

}

Result after gradle clean build --stacktrace

org.nomin.core.NominException: Specified resource entity2entitydto.groovy isn't found!
...

Someone any idea or suggestions about mapping frameworks which works fine with groovy. Thanks in advance.

Szymon Stepniak
  • 40,216
  • 10
  • 104
  • 131
Michael Hegner
  • 5,555
  • 9
  • 38
  • 64

1 Answers1

3

Nomin throws this exception, because your script is not in the classpath. Move your entity2entitydto.groovy file to src/main/resources so Nomin can load your mapping script from the classpath correctly.

Secondly, make sure you import correct classes in your mapping script. For example, if I have mypackage.Entity and mypackage.EntityDto class then I can import both of them like:

import mypackage.Entity
import mypackage.EntityDto

mappingFor a: Entity,  b: EntityDto
a.name      =       b.name

Instead you have to use full canonical names like:

mappingFor a: mypackage.Entity,  b: mypackage.EntityDto
a.name      =       b.name

You can also take a look at this very basic and simple example created basing on your question - https://github.com/wololock/nomin-example

Hope it helps.

Szymon Stepniak
  • 40,216
  • 10
  • 104
  • 131
  • Thank you very much for your example and explanation. I checked out your project and it works fine. When I copy your classes into my project then I get same issue as I have... But I know now how the files needs to be organized and need to find the root cause of my problem. – Michael Hegner Jan 12 '18 at 17:55
  • Do you still face this `Specified resource entity2entitydto.groovy isn't found!` error? Have you copied `entity2entitydto.groovy` to `src/main/resources/entity2entitydto.groovy`? – Szymon Stepniak Jan 12 '18 at 18:04
  • I copied your files in exactly same folder than in my project, and then I get same error. The difference between your project and my is, that I am using gradle instead of maven .... – Michael Hegner Jan 12 '18 at 18:08
  • if you like check it out, it is just a mini project: https://github.com/MichaelHegner/CCM You will also find your classes there – Michael Hegner Jan 12 '18 at 18:27
  • Oh, I just see on console it works already, it seems to be an Eclipse issue. When running the tests on Eclipse I still have the issue ... But thank you, your project helped a lot – Michael Hegner Jan 12 '18 at 18:33
  • Awesome, I'm glad I could help you :) – Szymon Stepniak Jan 12 '18 at 18:42
  • Hi Szymon, in case you have a deep understanding in Nomin, I would highly appreciate you could have a look on https://stackoverflow.com/questions/48234524/nomin-mapper-automap-causes-nominexception-inifite-loop – Michael Hegner Jan 12 '18 at 22:18