SyncConfigTracker extends ServiceTracker { @NotNull Map<String, String[]> getAutoMembership() { Map<String, String[]> autoMembership = new HashMap<>(); for (ServiceReference ref : enablingRefs) { String syncHandlerName = PropertiesUtil.toString(ref.getProperty(DefaultSyncConfigImpl.PARAM_NAME), DefaultSyncConfigImpl.PARAM_NAME_DEFAULT); String[] userAuthMembership = PropertiesUtil.toStringArray(ref.getProperty(DefaultSyncConfigImpl.PARAM_USER_AUTO_MEMBERSHIP), new String[0]); String[] groupAuthMembership = PropertiesUtil.toStringArray(ref.getProperty(DefaultSyncConfigImpl.PARAM_GROUP_AUTO_MEMBERSHIP), new String[0]); String[] membership = ObjectArrays.concat(userAuthMembership, groupAuthMembership, String.class); for (String idpName : mappingTracker.getIdpNames(syncHandlerName)) { String[] previous = autoMembership.put(idpName, membership); if (previous != null) { String msg = (Arrays.equals(previous, membership)) ? "Duplicate" : "Colliding"; String prev = Arrays.toString(previous); String mbrs = Arrays.toString(membership); log.debug("{} auto-membership configuration for IDP '{}'; replacing previous values {} by {} defined by SyncHandler '{}'", msg, idpName, prev, mbrs, syncHandlerName); } } } return autoMembership; } SyncConfigTracker(@NotNull BundleContext context, @NotNull SyncHandlerMappingTracker mappingTracker); @Override Object addingService(ServiceReference reference); @Override void modifiedService(ServiceReference reference, Object service); @Override void removedService(ServiceReference reference, Object service);  }
@Test public void testGetAutoMembership() { assertTrue(tracker.getAutoMembership().isEmpty()); String[] gam = new String[] {"g1", "g2"}; String[] uam = new String[] {"g3", "g4"}; when(ref.getProperty(PARAM_NAME)).thenReturn("sh"); when(ref.getProperty(PARAM_GROUP_AUTO_MEMBERSHIP)).thenReturn(gam); when(ref.getProperty(PARAM_USER_AUTO_MEMBERSHIP)).thenReturn(uam); when(ref.getProperty(PARAM_USER_DYNAMIC_MEMBERSHIP)).thenReturn(true); tracker.addingService(ref); ServiceReference mappingRef = mock(ServiceReference.class); when(mappingRef.getProperty(PARAM_IDP_NAME)).thenReturn("idp"); when(mappingRef.getProperty(PARAM_SYNC_HANDLER_NAME)).thenReturn("sh"); mappingTracker.addingService(mappingRef); Map<String,String[]> automembership = tracker.getAutoMembership(); assertEquals(1, automembership.size()); assertArrayEquals(ObjectArrays.concat(uam,gam,String.class), automembership.get("idp")); }