|
This post has NOT been accepted by the mailing list yet.
Hi all,
i have some problems with grails unit tests and .save() method. Im using Build-Test-Data plugin. I have a simple DomainObject with around 5-6 members (all Strings or Ids)- In my Service (DomainObjectService) i have a method like this: DomainObject create(DomainObject object) { updateSomeInfos(object) if (object.save(flush:true)) { return object } else { throw new DomainObjectException() } } My test looks like this: @TestFor(DomainObjectService) @Build(DomainObject) class DomainObjectServiceTests { DomainObjectServiceService underTest = new DomainObjectServiceService() void setUp(){ grails.buildtestdata.TestDataConfigurationHolder.reset() } void testCreate(){ DomainObject object = new DomainObject() shouldFail(DomainObjectException) { underTest.create(object) } object = DomainObject.build() DomainObject result = underTest.create(object); //asserts } The step DomainObject result = underTest.create(object); will throw following exception: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 at java.util.ArrayList.RangeCheck(ArrayList.java:547) at java.util.ArrayList.remove(ArrayList.java:387) at org.grails.datastore.mapping.simple.engine.SimpleMapEntityPersister$1.deindex(SimpleMapEntityPersister.groovy:101) at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.updatePropertyIndices(NativeEntryEntityPersister.java:1183) at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.access$100(NativeEntryEntityPersister.java:55) at org.grails.datastore.mapping.engine.NativeEntryEntityPersister$4.run(NativeEntryEntityPersister.java:953) at org.grails.datastore.mapping.core.impl.PendingOperationExecution.executePendingOperation(PendingOperationExecution.java:36) at org.grails.datastore.mapping.core.AbstractSession.flushPendingOperations(AbstractSession.java:323) at org.grails.datastore.mapping.core.AbstractSession.flushPendingUpdates(AbstractSession.java:302) at org.grails.datastore.mapping.core.AbstractSession.flush(AbstractSession.java:240) at org.grails.datastore.gorm.GormInstanceApi.doSave(GormInstanceApi.groovy:168) at org.grails.datastore.gorm.GormInstanceApi$_save_closure4.doCall(GormInstanceApi.groovy:143) at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:301) at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:34) at org.grails.datastore.gorm.GormInstanceApi.save(GormInstanceApi.groovy:142) I think in that case i dont really need the flush:true but anyway i dont get it why it fails with flush:true. If i deploy the generated war to an appserver all works fine. so somehow this must be related to unit DB-mocking inside of grails. Any idea? Thx alot, cheers |
| Powered by Nabble | Edit this page |
