JBossAssemblyDescriptorMetaData assembly = new JBossAssemblyDescriptorMetaData();
original.setAssemblyDescriptor(assembly);
SecurityRolesMetaData roles = new SecurityRolesMetaData();
assembly.setSecurityRoles(roles);
SecurityRoleMetaData role = new SecurityRoleMetaData();
role.setRoleName("original.only.Role");
role.setPrincipals(java.util.Collections.singleton("original"));
roles.add(role);
role = new SecurityRoleMetaData();
role.setRoleName("overriden.Role");
HashSet<String> principals = new HashSet<String>();
principals.add("original1");
principals.add("original2");
role.setPrincipals(principals);
roles.add(role);
// override
JBoss50MetaData override = new JBoss50MetaData();
assembly = new JBossAssemblyDescriptorMetaData();
override.setAssemblyDescriptor(assembly);
roles = new SecurityRolesMetaData();
assembly.setSecurityRoles(roles);
role = new SecurityRoleMetaData();
role.setRoleName("override.only.Role");
role.setPrincipals(java.util.Collections.singleton("override"));
roles.add(role);
role = new SecurityRoleMetaData();
role.setRoleName("overriden.Role");
principals = new HashSet<String>();
principals.add("original1");
principals.add("override1");
principals.add("override2");
role.setPrincipals(principals);
roles.add(role);
// merge
JBoss50MetaData merged = new JBoss50MetaData();
merged.merge(override, original);
assembly = merged.getAssemblyDescriptor();
assertNotNull(assembly);
roles = assembly.getSecurityRoles();
assertNotNull(roles);
assertEquals(3, roles.size());
role = roles.get("original.only.Role");
assertNotNull(role);
assertEquals("original.only.Role", role.getRoleName());
assertNotNull(role.getPrincipals());
assertEquals(1, role.getPrincipals().size());
assertTrue(role.getPrincipals().contains("original"));
role = roles.get("override.only.Role");
assertNotNull(role);
assertEquals("override.only.Role", role.getRoleName());
assertNotNull(role.getPrincipals());
assertEquals(1, role.getPrincipals().size());
assertTrue(role.getPrincipals().contains("override"));
role = roles.get("overriden.Role");
assertNotNull(role);
assertEquals("overriden.Role", role.getRoleName());
assertNotNull(role.getPrincipals());
// shouldn't there be 3? missing original2?
assertEquals(4, role.getPrincipals().size());
assertTrue(role.getPrincipals().contains("original1"));
assertTrue(role.getPrincipals().contains("original2"));
assertTrue(role.getPrincipals().contains("override1"));
assertTrue(role.getPrincipals().contains("override2"));
}