modify bug
[holmes/common.git] / holmes-actions / src / test / java / org / onap / holmes / common / aai / AaiQueryTest.java
index f089881..7872f2b 100644 (file)
@@ -93,13 +93,14 @@ public class AaiQueryTest {
         headers.put("X-FromAppId", AaiConfig.X_FROMAPP_ID);
         headers.put("Authorization", AaiConfig.getAuthenticationCredentials());
         headers.put("Accept", "application/json");
-        String url = "host_url";
+        String url = "http://10.96.33.33/api/aai-cloudInfrastructure/v11";
         when(HttpsUtils.get(url, headers)).thenReturn("{}");
 
         PowerMockito.mockStatic(MicroServiceConfig.class);
-        when(MicroServiceConfig.getMsbServerAddr()).thenReturn("host_url");
+        when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
 
-        PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2").andReturn("");
+        PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
+                .andReturn("/aai/v11/cloud-infrastructure");
         PowerMock.replayAll();
         VmEntity vmEntity = Whitebox.invokeMethod(aaiQuery, "getAaiVmData", "test1", "test2");
         PowerMock.verifyAll();
@@ -125,14 +126,15 @@ public class AaiQueryTest {
         headers.put("X-FromAppId", AaiConfig.X_FROMAPP_ID);
         headers.put("Authorization", AaiConfig.getAuthenticationCredentials());
         headers.put("Accept", "application/json");
-        String url = "host_url";
+        String url = "http://10.96.33.33/api/aai-cloudInfrastructure/v11";
 
         when(HttpsUtils.get(url, headers)).thenReturn("");
 
         PowerMockito.mockStatic(MicroServiceConfig.class);
-        when(MicroServiceConfig.getMsbServerAddr()).thenReturn("host_url");
+        when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
 
-        PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2").andReturn("");
+        PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
+                .andReturn("/aai/v11/cloud-infrastructure");
 
         PowerMock.replayAll();
         Whitebox.invokeMethod(aaiQuery, "getAaiVmData", "test1", "test2");
@@ -155,14 +157,15 @@ public class AaiQueryTest {
         headers.put("X-FromAppId", AaiConfig.X_FROMAPP_ID);
         headers.put("Authorization", AaiConfig.getAuthenticationCredentials());
         headers.put("Accept", "application/json");
-        String url = "host_url";
+        String url = "http://10.96.33.33/api/aai-cloudInfrastructure/v11";
 
         when(HttpsUtils.get(url, headers)).thenThrow(new CorrelationException(""));
 
         PowerMockito.mockStatic(MicroServiceConfig.class);
-        when(MicroServiceConfig.getMsbServerAddr()).thenReturn("host_url");
+        when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
 
-        PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2").andReturn("");
+        PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
+                .andReturn("/aai/v11/cloud-infrastructure");
         PowerMock.replayAll();
         Whitebox.invokeMethod(aaiQuery, "getAaiVmData", "test1", "test2");
         PowerMock.verifyAll();
@@ -277,15 +280,11 @@ public class AaiQueryTest {
         headers.put("Authorization", AaiConfig.getAuthenticationCredentials());
         headers.put("Accept", "application/json");
         String url = "host_url";
-
         when(HttpsUtils.get(url, headers)).thenThrow(new CorrelationException(""));
-
         PowerMock.replayAll();
         String resource = Whitebox.invokeMethod(aaiQuery, "getResponse", "host_url");
         PowerMock.verifyAll();
-
         assertThat(resource, equalTo(""));
-
     }
 
     @Test
@@ -301,4 +300,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("http://10.96.33.33:80");
+        when(MicroServiceConfig.getServiceAddrInfoFromCBS("nihao")).thenReturn("");
+
+        PowerMock.replayAll();
+        String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "/url");
+        PowerMock.verifyAll();
+        assertThat(actual, equalTo("http://10.96.33.33/url"));
+    }
+
+    @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 = "/api/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));
+    }
 }