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.
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.