modify listeners to only start when props present
[appc.git] / appc-event-listener / appc-event-listener-bundle / src / test / java / org / onap / appc / listener / TestAppcDmaapListenerActivator.java
index 6bb96b9..f8cbdb3 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
@@ -27,18 +27,25 @@ package org.onap.appc.listener;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
 import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.mockito.Mockito.doReturn;
+
 import org.onap.appc.listener.AppcEventListenerActivator;
 
 public class TestAppcDmaapListenerActivator {
 
     @Test
-    public void testStartStop() {
-        // TODO - How do we tests activators
+    public void testStartStopDefaultProperties() {
         AppcEventListenerActivator appc = new AppcEventListenerActivator();
         try {
             appc.start(null);
-            Thread.sleep(2000);
+            Thread.sleep(1000);
             appc.stop(null);
         } catch (Exception e) {
             e.printStackTrace();
@@ -46,4 +53,29 @@ public class TestAppcDmaapListenerActivator {
         }
         assertNotNull(appc.getName());
     }
+    
+    @Test
+    public void testStartStopEmptyProperties() {
+        InputStream input = getClass().getResourceAsStream("/org/onap/appc/empty.properties");
+        Properties props = new Properties();
+         try {
+             props.load(input);
+         } catch (IOException e) {
+             e.printStackTrace();
+         }
+
+        AppcEventListenerActivator appc = new AppcEventListenerActivator();
+        AppcEventListenerActivator spyAppc = Mockito.spy(appc);
+        doReturn(props).when(spyAppc).getProperties();
+        
+        try {
+            spyAppc.start(null);
+            Thread.sleep(1000);
+            spyAppc.stop(null);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+        assertNotNull(spyAppc.getName());
+    }
 }