ClassLoaderDomain defaultDomain = system.getDefaultDomain();
ClassLoaderDomain domain = system.createAndRegisterDomain("test", ParentPolicy.BEFORE_BUT_JAVA_ONLY, defaultDomain);
MockClassLoaderPolicy a1 = createMockClassLoaderPolicy("a1");
a1.setPathsAndPackageNames(A.class);
RealClassLoader clA1 = (RealClassLoader) system.registerClassLoaderPolicy(domain, a1);
MockClassLoaderPolicy a2 = createMockClassLoaderPolicy("a2");
a2.setPathsAndPackageNames(A.class);
RealClassLoader clA2 = (RealClassLoader) system.registerClassLoaderPolicy(domain, a2);
MockClassLoaderPolicy b1 = createMockClassLoaderPolicy("b1");
b1.setPathsAndPackageNames(B.class);
RealClassLoader clB1 = (RealClassLoader) system.registerClassLoaderPolicy(domain, b1);
MockClassLoaderPolicy b2 = createMockClassLoaderPolicy("b2");
b2.setPaths(B.class);
RealClassLoader clB2 = (RealClassLoader) system.registerClassLoaderPolicy(domain, b2);
ObjectName testDomain = domain.getObjectName();
List<ObjectName> classLoaders = (List) server.invoke(testDomain, "listClassLoaders", null, null);
List<ObjectName> expected = Arrays.asList(clA1.getObjectName(), clA2.getObjectName(), clB1.getObjectName(), clB2.getObjectName());
assertEquals(expected, classLoaders);
Map<String, List<ObjectName>> packageClassLoaders = (Map) server.invoke(testDomain, "listExportingClassLoaders", null, null);
Map<String, List<ObjectName>> expectedMap = new HashMap<String, List<ObjectName>>();
expectedMap.put(A.class.getPackage().getName(), Arrays.asList(clA1.getObjectName(), clA2.getObjectName()));