DistributedConfigurationPublisher { public void publishConfiguration() throws Exception { logger.debug("Publishing properties files : {}", propertiesFiles); publishConfiguration(propertiesFiles, true); logger.info("Properties files published successfully"); logger.debug("Publishing config files : {}", configFiles); publishConfiguration(configFiles, false); logger.info("Config files published successfully"); } DistributedConfigurationPublisher(Component component);  DistributedConfigurationPublisher(Component component, String project); void destroy(); void publishConfiguration(); boolean verifyPublishedConfiguration(); void clearConfiguration(); void notifyConfigEvent(ConfigEventType type); Map<String, String> getPropertiesFiles(); void setPropertiesFiles(Map<String, String> propertiesFiles); Map<String, String> getConfigFiles(); void setConfigFiles(Map<String, String> configFiles); ZNodePaths getZNodePaths(); Component getComponent(); String getProject();  }
@Test public void publishConfigurationTest() throws Exception { ConfigPublisher.main(new String[]{ "-connectString", zookeeper.getConnectString(), "-config", CONFIG_PUBLISHER_XML, "-a", "publish" }); ApplicationContext applicationContext = new ClassPathXmlApplicationContext(CONFIG_PUBLISHER_XML); Map distributedConfigurationPublishers = applicationContext.getBeansOfType(DistributedConfigurationPublisher.class); List<DistributedConfigurationPublisher> publishers = new ArrayList<>(distributedConfigurationPublishers.values().size()); for (Object bean : distributedConfigurationPublishers.values()) { publishers.add((DistributedConfigurationPublisher) bean); } for (DistributedConfigurationPublisher publisher : publishers) { Assert.assertTrue(publisher.verifyPublishedConfiguration()); ZNodePaths zNodePaths = publisher.getZNodePaths(); for (Map.Entry<String, String> entry : publisher.getPropertiesFiles().entrySet()) { String zNodePath = zNodePaths.getPropertiesZNodePath(entry.getValue()); Assert.assertNotNull(client.checkExists().forPath(zNodePath)); String storedContent = new String(client.getData().forPath(zNodePath)); String fileContent = FileUtils.readFileToString(new File(entry.getKey())); Assert.assertEquals(fileContent, storedContent); } for (Map.Entry<String, String> entry : publisher.getConfigFiles().entrySet()) { String zNodePath = zNodePaths.getConfigurationZNodePath(entry.getValue()); Assert.assertNotNull(client.checkExists().forPath(zNodePath)); String storedContent = new String(client.getData().forPath(zNodePath)); String fileContent = FileUtils.readFileToString(new File(entry.getKey())); Assert.assertEquals(fileContent, storedContent); } } ConfigPublisher.main(new String[]{ "-connectString", zookeeper.getConnectString(), "-config", CONFIG_PUBLISHER_XML, "-a", "clear" }); for (DistributedConfigurationPublisher publisher : publishers) { Assert.assertFalse(publisher.verifyPublishedConfiguration()); ZNodePaths zNodePaths = publisher.getZNodePaths(); for (Map.Entry<String, String> entry : publisher.getPropertiesFiles().entrySet()) { String zNodePath = zNodePaths.getPropertiesZNodePath(entry.getValue()); Assert.assertNull(client.checkExists().forPath(zNodePath)); } for (Map.Entry<String, String> entry : publisher.getConfigFiles().entrySet()) { String zNodePath = zNodePaths.getConfigurationZNodePath(entry.getValue()); Assert.assertNull(client.checkExists().forPath(zNodePath)); } } for (DistributedConfigurationPublisher publisher : publishers) { publisher.destroy(); } }