X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=holmes-actions%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fholmes%2Fcommon%2Faai%2FAaiQueryTest.java;h=34a6c46e2ef1b7e17a25c6e3301c8d1bff47f2bc;hb=17a3500b535e9dd09a272c7428bdd9c9c945f1bb;hp=f0898818743ae3c69b88fdf4c32e67c776dd6a1b;hpb=4eaf0290dd2572f40526da9cfd09a1ccee4da76d;p=holmes%2Fcommon.git 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..34a6c46 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/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)); + } }