MethodPermissionsMetaData permissions = new MethodPermissionsMetaData();
assembly.setMethodPermissions(permissions);
// original only
MethodsMetaData methods = new MethodsMetaData();
MethodMetaData method = new MethodMetaData();
method.setEjbName("Original");
method.setMethodName("execute");
methods.add(method);
MethodPermissionMetaData permission = new MethodPermissionMetaData();
permission.setMethods(methods);
permission.setRoles(java.util.Collections.singleton("original"));
permissions.add(permission);
// mixed original part
methods = new MethodsMetaData();
method = new MethodMetaData();
method.setEjbName("Overriden");
method.setMethodName("execute");
method.setMethodIntf(MethodInterfaceType.Local);
methods.add(method);
permission = new MethodPermissionMetaData();
permission.setMethods(methods);
permission.setRoles(java.util.Collections.singleton("original"));
permissions.add(permission);
methods = new MethodsMetaData();
method = new MethodMetaData();
method.setEjbName("Overriden");
method.setMethodName("execute");
method.setMethodIntf(MethodInterfaceType.Remote);
methods.add(method);
permission = new MethodPermissionMetaData();
permission.setMethods(methods);
Set<String> roles = new HashSet<String>();
roles.add("original1");
roles.add("original2");
permission.setRoles(roles);
permissions.add(permission);
// override
JBoss50MetaData override = new JBoss50MetaData();
assembly = new JBossAssemblyDescriptorMetaData();
override.setAssemblyDescriptor(assembly);
permissions = new MethodPermissionsMetaData();
assembly.setMethodPermissions(permissions);
// override only
methods = new MethodsMetaData();
method = new MethodMetaData();
method.setEjbName("Override");
method.setMethodName("execute");
methods.add(method);
permission = new MethodPermissionMetaData();
permission.setMethods(methods);
permission.setRoles(java.util.Collections.singleton("override"));
permissions.add(permission);
// mixed override part
methods = new MethodsMetaData();
method = new MethodMetaData();
method.setEjbName("Overriden");
method.setMethodName("execute");
method.setMethodIntf(MethodInterfaceType.LocalHome);
methods.add(method);
permission = new MethodPermissionMetaData();
permission.setMethods(methods);
permission.setRoles(java.util.Collections.singleton("override"));
permissions.add(permission);
methods = new MethodsMetaData();
method = new MethodMetaData();
method.setEjbName("Overriden");
method.setMethodName("execute");
method.setMethodIntf(MethodInterfaceType.Remote);
methods.add(method);
permission = new MethodPermissionMetaData();
permission.setMethods(methods);
roles = new HashSet<String>();
roles.add("override1");
roles.add("override2");
permission.setRoles(roles);
permissions.add(permission);
// merge
JBoss50MetaData merged = new JBoss50MetaData();
merged.merge(override, original);
assembly = merged.getAssemblyDescriptor();
assertNotNull(assembly);
permissions = assembly.getMethodPermissions();
assertNotNull(permissions);
assertEquals(6, permissions.size());
for(MethodPermissionMetaData perm : permissions)
{
methods = perm.getMethods();
assertNotNull(methods);
assertEquals(1, methods.size());
method = methods.get(0);
assertNotNull(method);
assertEquals("execute", method.getMethodName());
roles = perm.getRoles();
assertNotNull(roles);
String ejbName = method.getEjbName();
if("Original".equals(ejbName))
{
assertEquals(1, roles.size());
assertTrue(roles.contains("original"));
}
else if("Override".equals(ejbName))
{
assertEquals(1, roles.size());
assertTrue(roles.contains("override"));
}
else if("Overriden".equals(ejbName))
{
MethodInterfaceType methodIntf = method.getMethodIntf();
if(MethodInterfaceType.Local == methodIntf)
{
assertEquals(1, roles.size());
assertTrue(roles.contains("original"));
}