Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MockDomain call providing fixture domain data not working, what am I missing? Grails 2.0.1
- @TestFor(MyService)
- @TestMixin(DomainClassUnitTestMixin)
- class MyServiceTests {
- void testMyThing() {
- defineBeans {anotherService(AnotherService)} //My service under test uses another service, unlikely relevant?
- MyUser.metaClass.isDirty = { //workaround for mockDomain not adding isDirty method.
- println("dirty check called");
- }
- mockDomain(MyUser, [
- [username: "email@gmail.com", accountType: UserType.STANDARD, id: 1L],
- [username: "user@gmail.com", accountType: UserType.STANDARD, id:3L],
- [username: "bizuser@domain.com", accountType: UserType.BUSINESS, id:2L]
- ])
- MyUser user1 = MyUser.get(1);
- System.out.println("user 1: ${user1}"); // output is 'user 1: null'
- MyUser user1byName = MyUser.findByUsername("email@gmail.com");
- System.out.println("user 1 by name: ${user1byName}"); // output is 'user 1 by name: null'
- ... the actual testing stuff which would love to have non null MyUser objects ...
- }
- }
- @Mock(MyUser)
- class MyServiceTests {
- ...
- void testMyThing() {
- new MyUser(username: "email@gmail.com",
- accountType: UserType.STANDARD,
- id: 1L).save(failOnError:true) //throws exception because MyUser requires password field to be non blank
- ...
- }
- }
Add Comment
Please, Sign In to add comment