@Test void testPopulate() { ApplicationContext applicationContext = mock(ApplicationContext.class); ObjectIdentity objectIdentity0 = new ObjectIdentityImpl("type", "id0"); PermissionRegistry permissionRegistry0 = mock(PermissionRegistry.class); Multimap<ObjectIdentity, Pair<PermissionSet, Sid>> registry0Permissions = ArrayListMultimap.create(); Sid sid0 = mock(Sid.class); registry0Permissions.put(objectIdentity0, new Pair<>(PermissionSet.COUNT, sid0)); when(permissionRegistry0.getPermissions()).thenReturn(registry0Permissions); ObjectIdentity objectIdentity1 = new ObjectIdentityImpl("type", "id1"); Multimap<ObjectIdentity, Pair<PermissionSet, Sid>> registry1Permissions = ArrayListMultimap.create(); Sid sid1 = mock(Sid.class); registry1Permissions.put(objectIdentity1, new Pair<>(PermissionSet.READ, sid1)); PermissionRegistry permissionRegistry1 = mock(PermissionRegistry.class); when(permissionRegistry1.getPermissions()).thenReturn(registry1Permissions); Map<String, PermissionRegistry> registryMap = new LinkedHashMap<>(); registryMap.put("registry0", permissionRegistry0); registryMap.put("registry1", permissionRegistry1); when(applicationContext.getBeansOfType(PermissionRegistry.class)).thenReturn(registryMap); permissionPopulator.populate(applicationContext); verify(permissionService) .createPermission(Permission.create(objectIdentity0, sid0, PermissionSet.COUNT)); verify(permissionService) .createPermission(Permission.create(objectIdentity1, sid1, PermissionSet.READ)); }
@Transactional public void populate(ApplicationContext applicationContext) { Collection<PermissionRegistry> registries = applicationContext.getBeansOfType(PermissionRegistry.class).values(); registries.forEach(this::populate); }
PermissionPopulator { @Transactional public void populate(ApplicationContext applicationContext) { Collection<PermissionRegistry> registries = applicationContext.getBeansOfType(PermissionRegistry.class).values(); registries.forEach(this::populate); } }
PermissionPopulator { @Transactional public void populate(ApplicationContext applicationContext) { Collection<PermissionRegistry> registries = applicationContext.getBeansOfType(PermissionRegistry.class).values(); registries.forEach(this::populate); } PermissionPopulator(PermissionService permissionService); }
PermissionPopulator { @Transactional public void populate(ApplicationContext applicationContext) { Collection<PermissionRegistry> registries = applicationContext.getBeansOfType(PermissionRegistry.class).values(); registries.forEach(this::populate); } PermissionPopulator(PermissionService permissionService); @Transactional void populate(ApplicationContext applicationContext); }
PermissionPopulator { @Transactional public void populate(ApplicationContext applicationContext) { Collection<PermissionRegistry> registries = applicationContext.getBeansOfType(PermissionRegistry.class).values(); registries.forEach(this::populate); } PermissionPopulator(PermissionService permissionService); @Transactional void populate(ApplicationContext applicationContext);  }