@Test
public void publishConfigurationTest() throws Exception {

    // Publishing configuration through CLI and verifying whether they were stored correctly
    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();
        // Checking for configuration files
        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);
        }
        // Checking for configuration files
        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);
        }
    }
    // Clearing configuration through CLI and checking whether the configuration has actually been gone
    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();
        // Checking for configuration files
        for (Map.Entry<String, String> entry : publisher.getPropertiesFiles().entrySet()) {
            String zNodePath = zNodePaths.getPropertiesZNodePath(entry.getValue());
            Assert.assertNull(client.checkExists().forPath(zNodePath));
        }
        // Checking for configuration files
        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();
    }
}