modify unique bug
[holmes/common.git] / holmes-actions / src / test / java / org / onap / holmes / common / dmaap / DmaapServiceTest.java
index b6f57ce..3f61813 100644 (file)
@@ -21,7 +21,9 @@ import static org.junit.Assert.assertThat;
 
 import java.util.ArrayList;
 import java.util.List;
+import org.easymock.EasyMock;
 import org.junit.runner.RunWith;
+import org.omg.CORBA.Any;
 import org.onap.holmes.common.aai.AaiQuery;
 import org.onap.holmes.common.aai.entity.RelationshipList.Relationship;
 import org.onap.holmes.common.aai.entity.RelationshipList.RelationshipData;
@@ -29,6 +31,7 @@ import org.onap.holmes.common.aai.entity.VmEntity;
 import org.onap.holmes.common.aai.entity.VnfEntity;
 import org.onap.holmes.common.api.stat.VesAlarm;
 import org.onap.holmes.common.exception.CorrelationException;
+import org.powermock.api.mockito.PowerMockito;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 
 import org.junit.Before;
@@ -47,39 +50,15 @@ public class DmaapServiceTest {
     @Rule
     public ExpectedException thrown = ExpectedException.none();
 
-    private Publisher publisher;
-
     private AaiQuery aaiQuery;
 
+    private DmaapService dmaapService;
+
     @Before
     public void setUp() {
-        publisher = PowerMock.createMock(Publisher.class);
-        Whitebox.setInternalState(DmaapService.class, "publisher", publisher);
+        dmaapService = new DmaapService();
         aaiQuery = PowerMock.createMock(AaiQuery.class);
-        Whitebox.setInternalState(DmaapService.class, "aaiQuery", aaiQuery);
-        PowerMock.replayAll();
-    }
-
-    @Test
-    public void testDmaapService_publish_ok() throws Exception {
-        PowerMock.resetAll();
-        PolicyMsg policyMsg = new PolicyMsg();
-        PowerMock.expectPrivate(publisher, "publish", anyObject(PolicyMsg.class)).andReturn(true)
-                .anyTimes();
-        PowerMock.replayAll();
-        Whitebox.invokeMethod(DmaapService.class, "publishPolicyMsg", policyMsg);
-        PowerMock.verifyAll();
-    }
-
-    @Test
-    public void testDmaapService_publish_exception() throws Exception {
-        PowerMock.resetAll();
-        final PolicyMsg policyMsg = new PolicyMsg();
-        PowerMock.expectPrivate(publisher, "publish", policyMsg)
-                .andThrow(new CorrelationException("")).anyTimes();
-        PowerMock.replayAll();
-        Whitebox.invokeMethod(DmaapService.class, "publishPolicyMsg", policyMsg);
-        PowerMock.verifyAll();
+        Whitebox.setInternalState(dmaapService, "aaiQuery", aaiQuery);
     }
 
     @Test
@@ -88,7 +67,7 @@ public class DmaapServiceTest {
 
         PowerMock.replayAll();
         PolicyMsg policyMsg = Whitebox
-                .invokeMethod(DmaapService.class, "getDefaultPolicyMsg", "tetss");
+                .invokeMethod(dmaapService, "getDefaultPolicyMsg", "tetss");
         PowerMock.verifyAll();
 
         assertThat(policyMsg.getTarget(), equalTo("vserver.vserver-name"));
@@ -105,7 +84,7 @@ public class DmaapServiceTest {
                 anyObject(String.class)).andReturn(expect).anyTimes();
         PowerMock.replayAll();
         VnfEntity actual = Whitebox
-                .invokeMethod(DmaapService.class, "getVnfEntity", "tset", "test");
+                .invokeMethod(dmaapService, "getVnfEntity", "tset", "test");
         PowerMock.verifyAll();
 
         assertThat(actual.getVnfName(), equalTo("test"));
@@ -117,7 +96,7 @@ public class DmaapServiceTest {
         PowerMock.expectPrivate(aaiQuery, "getAaiVnfData", anyObject(String.class),
                 anyObject(String.class)).andThrow(new CorrelationException("")).anyTimes();
         PowerMock.replayAll();
-        VnfEntity actual = Whitebox.invokeMethod(DmaapService.class, "getVnfEntity", "tset", "test");
+        VnfEntity actual = Whitebox.invokeMethod(dmaapService, "getVnfEntity", "tset", "test");
         PowerMock.verifyAll();
 
         assertThat(actual == null, equalTo(true));
@@ -132,7 +111,7 @@ public class DmaapServiceTest {
                 anyObject(String.class)).andReturn(expect).anyTimes();
         PowerMock.replayAll();
         VmEntity actual = Whitebox
-                .invokeMethod(DmaapService.class, "getVmEntity", "tset", "test");
+                .invokeMethod(dmaapService, "getVmEntity", "tset", "test");
         PowerMock.verifyAll();
 
         assertThat(actual.getVserverId(), equalTo("11111"));
@@ -144,7 +123,7 @@ public class DmaapServiceTest {
         PowerMock.expectPrivate(aaiQuery, "getAaiVmData", anyObject(String.class),
                 anyObject(String.class)).andThrow(new CorrelationException("")).anyTimes();
         PowerMock.replayAll();
-        VnfEntity actual = Whitebox.invokeMethod(DmaapService.class, "getVmEntity", "tset", "test");
+        VnfEntity actual = Whitebox.invokeMethod(dmaapService, "getVmEntity", "tset", "test");
         PowerMock.verifyAll();
 
         assertThat(actual == null, equalTo(true));
@@ -170,7 +149,7 @@ public class DmaapServiceTest {
         vnfEntity.getRelationshipList().setRelationships(relationships);
 
         PowerMock.replayAll();
-        String actual = Whitebox.invokeMethod(DmaapService.class, "getVserverInstanceId", vnfEntity);
+        String actual = Whitebox.invokeMethod(dmaapService, "getVserverInstanceId", vnfEntity);
         PowerMock.verifyAll();
 
         assertThat(actual, equalTo("USUCP0PCOIL0110UJZZ01"));
@@ -182,7 +161,7 @@ public class DmaapServiceTest {
         VnfEntity vnfEntity = null;
 
         PowerMock.replayAll();
-        String actual = Whitebox.invokeMethod(DmaapService.class, "getVserverInstanceId", vnfEntity);
+        String actual = Whitebox.invokeMethod(dmaapService, "getVserverInstanceId", vnfEntity);
         PowerMock.verifyAll();
 
         assertThat(actual, equalTo(""));
@@ -199,16 +178,17 @@ public class DmaapServiceTest {
         VesAlarm vesAlarm = new VesAlarm();
         vesAlarm.setEventId("11111");
         vesAlarm.setEventName("3333");
+        vesAlarm.setSourceId("111");
 
-        PowerMock.expectPrivate(DmaapService.class, "getVnfEntity", anyObject(String.class),
+        PowerMock.expectPrivate(dmaapService, "getVnfEntity", anyObject(String.class),
                 anyObject(String.class)).andReturn(null).anyTimes();
 
         PowerMock.replayAll();
         PolicyMsg actual = Whitebox
-                .invokeMethod(DmaapService.class, "getEnrichedPolicyMsg", vmEntity, vesAlarm);
+                .invokeMethod(dmaapService, "getEnrichedPolicyMsg", vmEntity, vesAlarm, vesAlarm, "loopName");
         PowerMock.verifyAll();
 
-        assertThat(actual.getPolicyName(), equalTo("vLoadBalancer"));
+        assertThat(actual.getClosedLoopControlName(), equalTo(null));
         assertThat(actual.getAai().get("vserver.prov-status"), equalTo("prov"));
         assertThat(actual.getAai().get("vserver.vserver-name2") == null, equalTo(true));
         assertThat(actual.getAai().get("generic-vnf.service-instance-id"), equalTo(""));