ClientsAndResourcesInitializer implements InitializingBean { @SuppressWarnings("unchecked") protected List<ClientDetailsEntity> applicationEvent() throws IOException { Yaml yaml = new Yaml(); final List<ClientDetailsEntity> clientDetails = new ArrayList<>(); Map<String, List<Map<String, Object>>> config = (Map<String, List<Map<String, Object>>>) yaml.load(clientConfLocation.getInputStream()); List<Map<String, Object>> clients = config.get("clients"); for (int i = 0; i < clients.size(); i++) { clientDetails.add(client(clients.get(i))); } List<Map<String, Object>> resourceServers = config.get("resourceServers"); for (int i = 0; i < resourceServers.size(); i++) { ClientDetailsEntity entity = resourceServer(resourceServers.get(i)); ClientDetailsEntity clientDetailsEntity = configuredClient(entity, clientDetails); if (clientDetailsEntity != null) { clientDetailsEntity.setAllowIntrospection(true); } else { clientDetails.add(entity); } } return transactionTemplate.execute(new TransactionCallback<List<ClientDetailsEntity>>() { @Override public List<ClientDetailsEntity> doInTransaction(TransactionStatus transactionStatus) { for (int i = 0; i < clientDetails.size(); i++) { ClientDetailsEntity entity = clientDetails.get(i); entity.setSubjectType(ClientDetailsEntity.SubjectType.PAIRWISE); ClientDetailsEntity existing = clientRepository.getClientByClientId(entity.getClientId()); if (existing == null) { LOG.debug("Inserting new default client {}", entity.getClientId()); clientRepository.saveClient(entity); } else { LOG.debug("Updating new default client {}", entity.getClientId()); clientRepository.updateClient(existing.getId(), entity); } } return clientDetails; } }); } @Autowired  ClientsAndResourcesInitializer(@Value("${client.conf.location}") Resource clientConfLocation, PlatformTransactionManager transactionManager, OAuth2ClientRepository clientRepository); @Override void afterPropertiesSet();  }
@Test public void testApplicationEvent() throws Exception { PlatformTransactionManager transactionManager = mock(PlatformTransactionManager.class); OAuth2ClientRepository clientRepository = mock(OAuth2ClientRepository.class); ClientsAndResourcesInitializer subject = new ClientsAndResourcesInitializer(new ClassPathResource("clientsAndResources.yml"),transactionManager, clientRepository); List<ClientDetailsEntity> entities = subject.applicationEvent(); assertEquals(3, entities.size()); ClientDetailsEntity entity = byClientId(entities, "https@ assertFalse(entity.isAllowIntrospection()); assertEquals(4, entity.getGrantTypes().size()); entity = byClientId(entities, "https@ assertTrue(entity.isAllowIntrospection()); assertEquals(entity.getScope().size(), 1); entity = byClientId(entities, "https@ assertTrue(entity.isAllowIntrospection()); assertEquals(entity.getScope().size(), 2); }