[SECIOTSRK-681] *Add health check for server MQ: fix unit test
authorm.dalakov <m.dalakov@samsung.com>
Mon, 6 Nov 2017 17:59:40 +0000 (19:59 +0200)
committerm.dalakov <m.dalakov@samsung.com>
Mon, 6 Nov 2017 18:01:23 +0000 (20:01 +0200)
servers/mq/src/main/java/com/samsung/servermq/ServerMQ.java
servers/mq/src/test/java/com/samsung/servermq/ServerMQTest.java

index ff02bce..11fb572 100644 (file)
@@ -36,10 +36,10 @@ public class ServerMQ {
 
     private static ConfigurableApplicationContext context;
 
-    private static final String  zookeeperHost;
-    private static final String kafkaHost;
+    private static String zookeeperHost;
+    private static String kafkaHost;
 
-    static {
+    private static void getHosts() {
         @SuppressWarnings("resource")
         AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
         ctx.register(ServerMQ.class);
@@ -57,6 +57,7 @@ public class ServerMQ {
 
     public static void main(String[] args) throws InterruptedException {
 
+        getHosts();
         while (!checkSocket(zookeeperHost)) {
             Thread.sleep(1000);
             System.out.println("can not connect to zookeeper...");
index 58f0c9b..ce78dd6 100644 (file)
@@ -5,6 +5,7 @@ import static org.junit.Assert.assertNotNull;
 
 import org.junit.Test;
 import org.springframework.boot.SpringApplication;
+import org.springframework.context.ConfigurableApplicationContext;
 
 /**
  * The type Server mq test.
@@ -15,11 +16,11 @@ public class ServerMQTest {
      * Test run
      */
     @Test
-    public void testRun() {
+    public void testRun() throws InterruptedException {
         String[] args = new String[0];
-        ServerMQ.main(args);
-        assertNotNull(getContext());
-        SpringApplication.exit(getContext(), () -> 0);
+        ConfigurableApplicationContext context = SpringApplication.run(ServerMQ.class, args);
+        assertNotNull(context);
+        SpringApplication.exit(context, () -> 0);
     }
 
 }