/* Copyright 2017 Telstra Open Source
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package org.openkilda.wfm;

import org.openkilda.wfm.config.ZookeeperConfig;

import com.google.common.io.Files;
import kafka.server.KafkaConfig;
import kafka.server.KafkaServerStartable;
import org.apache.curator.test.TestingServer;
import org.apache.storm.Config;

import java.io.File;
import java.io.IOException;
import java.util.Properties;

/**
 * Utility classes to facilitate testing.
 *
 * <p>Key Utilities:</p>
 */
public final class TestUtils {

    private TestUtils() {}

    public static Properties serverProperties(ZookeeperConfig config) {
        Properties props = new Properties();
        props.setProperty("zookeeper.connect", config.getHosts());
        props.setProperty("broker.id", "1");
        props.setProperty("delete.topic.enable", "true");
        return props;
    }

    public static Config stormConfig() {
        Config config = new Config();
        config.setDebug(false);
        config.setNumWorkers(1);
        return config;
    }

    public static class KafkaTestFixture {
        public TestingServer zk;
        public KafkaServerStartable kafka;
        public File tempDir = Files.createTempDir();
        private ZookeeperConfig zooKeeperConfig;

        public KafkaTestFixture(ZookeeperConfig zooKeeperConfig) {
            this.zooKeeperConfig = zooKeeperConfig;
        }

        public void start() throws Exception {
            Properties props = serverProperties(zooKeeperConfig);
            this.start(props);
        }

        public void start(Properties props) throws Exception {
            Integer port = getZkPort(props);

            zk = new TestingServer(port, tempDir); // this starts the zk server
            System.out.println("Started ZooKeeper: ");
            System.out.println("--> Temp Directory: " + zk.getTempDirectory());

            props.put("log.dirs", tempDir.getAbsolutePath());
            KafkaConfig kafkaConfig = new KafkaConfig(props);
            kafka = new KafkaServerStartable(kafkaConfig);
            kafka.startup();
            System.out.println("Started KAFKA: ");
        }

        public void stop() throws IOException {
            kafka.shutdown();
            zk.stop();
            zk.close();
            tempDir.delete();
        }

        private int getZkPort(Properties properties) {
            String url = (String) properties.get("zookeeper.connect");
            String port = url.split(":")[1];
            return Integer.valueOf(port);
        }
    }
}

@@ -849,40 +849,8 @@
 ver;
-%0Aimport org.apache.storm.Config;
 %0A%0Aim
@@ -1061,37 +1061,38 @@
 tils() %7B%7D%0A%0A    p
-ublic
+rivate
  static Properti
@@ -1364,170 +1364,78 @@
     
-return props;%0A    %7D%0A%0A    public static Config stormConfig() %7B%0A        Config config = new Config();%0A        config.setDebug(false);%0A        config.setNumWorkers(1
+props.setProperty(%22advertised.listeners%22, %22PLAINTEXT://localhost:9092%22
 );%0A 
@@ -1448,22 +1448,21 @@
  return 
-config
+props
 ;%0A    %7D%0A
@@ -1970,37 +1970,38 @@
     %7D%0A%0A        p
-ublic
+rivate
  void start(Prop
@@ -2561,32 +2561,148 @@
  %22);%0A        %7D%0A%0A
+        /**%0A         * Stop kafka and zookeeper.%0A         *%0A         * @throws IOException IO exception%0A         */%0A
         public v

Fix kafka test config