@Test
public void testRecursiveInterfaceMapping() throws Exception {
// prepare 2 Users in 1 UserGroup
User user1 = newInstance(UserImpl.class);
user1.setFirstName("first name 1");
user1.setLastName("last name 1");
User user2 = newInstance(UserImpl.class);
user2.setFirstName("first name 2");
user2.setLastName("last name 2");
UserGroup userGroup = newInstance(UserGroupImpl.class);
userGroup.setName("usergroup name");
userGroup.addUser(user1);
userGroup.addUser(user2);
// assert recursion
assertEquals("Two users in usergroup expected.", 2, userGroup.getUsers().size());
Iterator<?> iterator = userGroup.getUsers().iterator();
while (iterator.hasNext()) {
User user = (User) iterator.next();
assertNotNull(user);
assertNotNull(user.getUserGroup());
assertTrue(user.getUserGroup() == userGroup); // same reference
}
// get mapper
List<String> mappingFiles = new ArrayList<String>();
mappingFiles.add("interface-recursion-mappings.xml");