Created
June 9, 2011 14:32
-
-
Save emedina/1016842 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package unittestfailwithobjectid | |
import grails.test.* | |
import grails.datastore.test.DatastoreUnitTestMixin | |
import org.bson.types.ObjectId | |
import org.springframework.core.convert.converter.Converter | |
@Mixin(DatastoreUnitTestMixin) | |
class SampleTests extends GrailsUnitTestCase { | |
protected void setUp() { | |
super.setUp() | |
connect() | |
} | |
protected void tearDown() { | |
disconnect() | |
super.tearDown() | |
} | |
void testSomething() { | |
mockDomain(Sample) | |
Sample.withSession { session -> | |
session.datastore.mappingContext.converterRegistry.addConverter(new | |
Converter<ObjectId, Long>() { | |
Long convert(ObjectId id) { | |
return 1.toLong() | |
} | |
} | |
) | |
session.datastore.mappingContext.converterRegistry.addConverter(new | |
Converter<Long, ObjectId>() { | |
ObjectId convert(Long id) { | |
return new ObjectId(id.toString()) | |
} | |
} | |
) | |
} | |
def s = new Sample(name: 'Sample1') | |
s.save() | |
assert s.id != null | |
s = Sample.get(s.id) | |
assert s != null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment