diff options
author | Shiwei Tian <tian.shiwei@zte.com.cn> | 2017-09-27 10:19:15 +0800 |
---|---|---|
committer | Shiwei Tian <tian.shiwei@zte.com.cn> | 2017-09-27 15:30:49 +0800 |
commit | c9ed775685b01f5622618216748eeac3000285c4 (patch) | |
tree | ae11132542e4266daee864cc6fe5c318ab58288d /holmes-actions/src/test | |
parent | 4eaf0290dd2572f40526da9cfd09a1ccee4da76d (diff) |
modify unit test and aai query
Issue-ID: HOLMES-44
Change-Id: I9d67fc26681dfb540ae4d011cde4d0cdc5f3d2a3
Signed-off-by: Shiwei Tian <tian.shiwei@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/test')
3 files changed, 79 insertions, 16 deletions
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java index f089881..59f8848 100644 --- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java +++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java @@ -301,4 +301,64 @@ public class AaiQueryTest { assertThat(actual.get("Authorization"), equalTo("Basic QUFJOkFBSQ==")); assertThat(actual.get("Accept"), equalTo("application/json")); } + + @Test + public void testAaiQuery_getBaseUrl_msb() throws Exception { + PowerMock.resetAll(); + aaiQuery = new AaiQuery(); + + PowerMockito.mockStatic(MicroServiceConfig.class); + when(MicroServiceConfig.getMsbServerAddr()).thenReturn("msb"); + when(MicroServiceConfig.getServiceAddrInfoFromCBS("nihao")).thenReturn(""); + + PowerMock.replayAll(); + String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "url"); + PowerMock.verifyAll(); + assertThat(actual, equalTo("msburl")); + } + + @Test + public void testAaiQuery_getBaseUrl_aaiurl() throws Exception { + PowerMock.resetAll(); + aaiQuery = new AaiQuery(); + + PowerMockito.mockStatic(MicroServiceConfig.class); + when(MicroServiceConfig.getMsbServerAddr()).thenThrow(new NullPointerException()); + when(MicroServiceConfig.getServiceAddrInfoFromCBS("aai_config")).thenReturn("aai"); + + PowerMock.replayAll(); + String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "url"); + System.out.println(actual); + PowerMock.verifyAll(); + assertThat(actual, equalTo("https:\\\\aaiurl")); + } + + @Test + public void testAaiQuery_getBaseUrl_exception() throws Exception { + PowerMock.resetAll(); + aaiQuery = new AaiQuery(); + + PowerMockito.mockStatic(MicroServiceConfig.class); + when(MicroServiceConfig.getMsbServerAddr()).thenThrow(new NullPointerException()); + when(MicroServiceConfig.getServiceAddrInfoFromCBS("aai_config")) + .thenThrow(new NullPointerException()); + + PowerMock.replayAll(); + String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "url"); + System.out.println(actual); + PowerMock.verifyAll(); + assertThat(actual, equalTo("")); + } + + @Test + public void testAaiQuery_getMsbSuffixAddr_Ok() throws Exception { + PowerMock.resetAll(); + String url = "/aai/v11/network/generic-vnfs/generic-vnf?"; + String expect = "/aai/network/v11/generic-vnfs/generic-vnf?"; + aaiQuery = new AaiQuery(); + PowerMock.replayAll(); + String actual = Whitebox.invokeMethod(aaiQuery, "getMsbSuffixAddr", url); + PowerMock.verifyAll(); + assertThat(actual, equalTo(expect)); + } } diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/CorrelationUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/CorrelationUtilTest.java index f5da5df..baf5205 100644 --- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/CorrelationUtilTest.java +++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/CorrelationUtilTest.java @@ -46,9 +46,10 @@ public class CorrelationUtilTest { @Before public void testCorrelationUtil() { - correlationUtil = CorrelationUtil.getInstance(); aaiQuery = PowerMock.createMock(AaiQuery.class); - Whitebox.setInternalState(correlationUtil, "aaiQuery", aaiQuery); + Whitebox.setInternalState(CorrelationUtil.class, "aaiQuery", aaiQuery); + correlationUtil = CorrelationUtil.getInstance(); + PowerMock.replayAll(); } @Test diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java index b6f57ce..7198ec8 100644 --- a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java +++ b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java @@ -51,13 +51,15 @@ public class DmaapServiceTest { private AaiQuery aaiQuery; + private DmaapService dmaapService; + @Before public void setUp() { + dmaapService = new DmaapService(); publisher = PowerMock.createMock(Publisher.class); - Whitebox.setInternalState(DmaapService.class, "publisher", publisher); + Whitebox.setInternalState(dmaapService, "publisher", publisher); aaiQuery = PowerMock.createMock(AaiQuery.class); - Whitebox.setInternalState(DmaapService.class, "aaiQuery", aaiQuery); - PowerMock.replayAll(); + Whitebox.setInternalState(dmaapService, "aaiQuery", aaiQuery); } @Test @@ -67,7 +69,7 @@ public class DmaapServiceTest { PowerMock.expectPrivate(publisher, "publish", anyObject(PolicyMsg.class)).andReturn(true) .anyTimes(); PowerMock.replayAll(); - Whitebox.invokeMethod(DmaapService.class, "publishPolicyMsg", policyMsg); + Whitebox.invokeMethod(dmaapService, "publishPolicyMsg", policyMsg); PowerMock.verifyAll(); } @@ -78,7 +80,7 @@ public class DmaapServiceTest { PowerMock.expectPrivate(publisher, "publish", policyMsg) .andThrow(new CorrelationException("")).anyTimes(); PowerMock.replayAll(); - Whitebox.invokeMethod(DmaapService.class, "publishPolicyMsg", policyMsg); + Whitebox.invokeMethod(dmaapService, "publishPolicyMsg", policyMsg); PowerMock.verifyAll(); } @@ -88,7 +90,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 +107,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 +119,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 +134,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 +146,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 +172,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 +184,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("")); @@ -200,12 +202,12 @@ public class DmaapServiceTest { vesAlarm.setEventId("11111"); vesAlarm.setEventName("3333"); - 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); PowerMock.verifyAll(); assertThat(actual.getPolicyName(), equalTo("vLoadBalancer")); |