Modify the Service Addr Query Logic 73/21973/1
authorGuangrong Fu <fu.guangrong@zte.com.cn>
Fri, 3 Nov 2017 06:17:20 +0000 (14:17 +0800)
committerGuangrong Fu <fu.guangrong@zte.com.cn>
Fri, 3 Nov 2017 06:17:20 +0000 (14:17 +0800)
Change-Id: I9e97a301bc5ba85e366bddbfda2f0ad721470c5f
Issue-ID: HOLMES-81
Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java
holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java
holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java
holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java
holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java

index cee6236..b80c40e 100644 (file)
@@ -95,17 +95,17 @@ public class AaiQuery {
     private String getBaseUrl(String suffixUrl) {
         String url = "";
         try {
-            String[] msbUrl = MicroServiceConfig.getMsbServerAddr().split(":");
+            String[] msbUrl = MicroServiceConfig.getMsbServerAddrWithHttpPrefix().split(":");
             url = msbUrl[0] + ":" + msbUrl[1] + suffixUrl;
         } catch (Exception e) {
             log.info("Failed to get msb address");
         }
         if ("".equals(url)) {
             try {
-                url = "https://" + MicroServiceConfig.getServiceAddrInfoFromCBS("aai_config")
+                url = "https://" + MicroServiceConfig.getServiceConfigInfoFromCBS("aai_config").replace("http://", "")
                         + suffixUrl;
             } catch (Exception e) {
-                log.info("Failed to get aai address");
+                log.info("Failed to get the address of A&AI.", e);
             }
         }
         return url;
index d86f56c..2be8824 100644 (file)
@@ -43,22 +43,22 @@ public class MicroServiceConfig {
     }\r
 \r
     public static String getConsulAddrInfo() {\r
-        return getEnv(CONSUL_HOST) + CONSUL_ADDR_SUF;\r
+        return "http://" + getEnv(CONSUL_HOST) + CONSUL_ADDR_SUF;\r
     }\r
 \r
-    public static String getConfigBindingServiceAddrInfo() {\r
+    public static String getServiceAddrInfoFromDcaeConsulByHostName(String hostname) {\r
         String ret = null;\r
-        String queryString = getConsulAddrInfo() + CONFIG_BINDING_SERVICE;\r
-        log.info("Query the CBS address using the URL: " + queryString);\r
+        String queryString = getConsulAddrInfo() + hostname;\r
+        log.info("Query the " + hostname + " address using the URL: " + queryString);\r
         try {\r
             JSONObject addrJson = (JSONObject) JSONArray.fromObject(execQuery(queryString)).get(0);\r
             if (addrJson.has("ServiceAddress") && addrJson.has("ServicePort")) {\r
-                ret = addrJson.getString("ServiceAddress") + ":" + addrJson.getString("ServicePort");\r
+                ret = "http://" + addrJson.getString("ServiceAddress") + ":" + addrJson.getString("ServicePort");\r
             }\r
         } catch (Exception e) {\r
             log.warn(e.getMessage(), e);\r
         }\r
-        log.info("The CBS address is " + ret);\r
+        log.info("The " + hostname + " address is " + ret);\r
         return ret;\r
     }\r
 \r
@@ -68,23 +68,20 @@ public class MicroServiceConfig {
         return response.readEntity(String.class);\r
     }\r
 \r
-    public static String getServiceAddrInfoFromCBS(String serviceName) {\r
+    public static String getServiceConfigInfoFromCBS(String hostname) {\r
         String ret = null;\r
-        String url = getConfigBindingServiceAddrInfo() + "/service_component/" +serviceName;\r
+        String url = getServiceAddrInfoFromDcaeConsulByHostName(getEnv(CONFIG_BINDING_SERVICE)) + "/service_component/" + hostname;\r
         try {\r
-            JSONObject jsonObject = JSONObject.fromObject(execQuery(url));\r
-            log.info("The origin configurations (" + url + ") returned by DCAE is: " + jsonObject.toString());\r
-            if (jsonObject.has(serviceName)) {\r
-                ret = (String) jsonObject.getJSONArray(serviceName).get(0);\r
-            }\r
+            ret = execQuery(url);\r
         } catch (Exception e) {\r
             log.warn(e.getMessage(), e);\r
         }\r
+        log.info("The query url is: " + url + ". The corresponding configurations are " + ret);\r
         return ret;\r
     }\r
 \r
-    public static String getMsbServerAddr() {\r
-        String[] addrInfo = getMsbAddrInfo();\r
+    public static String getMsbServerAddrWithHttpPrefix() {\r
+        String[] addrInfo = getMsbIpAndPort();\r
         String ret = addrInfo[0] + ":" + addrInfo[1];\r
         if (!ret.startsWith(AlarmConst.HTTP) || !ret.startsWith(AlarmConst.HTTPS)){\r
             ret = AlarmConst.HTTP + ret;\r
@@ -92,33 +89,15 @@ public class MicroServiceConfig {
         return ret;\r
     }\r
 \r
-    public static String[] getMsbAddrInfo() {\r
-        String[] msbServerInfo = null;\r
-\r
-        //String info = getServiceAddrInfoFromCBS(MSB_ADDR);\r
-        String info = getServiceAddrInfoFromCBS(getEnv(HOSTNAME));\r
-        log.info("Got the service information of \"" + getEnv(HOSTNAME) + "\" from CBS. The response is " + info + ".");\r
-\r
-        if (info != null){\r
-            JSONObject infoObj = JSONObject.fromObject(info);\r
-            String msbInfoTmp = infoObj.has("msb.hostname") ? infoObj.getString("msb.hostname") : null;\r
-            if (msbInfoTmp != null) {\r
-                msbServerInfo = split(msbInfoTmp);\r
-            } else {\r
-                msbServerInfo = split(getEnv(MSB_ADDR));\r
-            }\r
-        } else {\r
-            msbServerInfo = split(getEnv(MSB_ADDR));\r
-        }\r
-\r
-        return msbServerInfo;\r
+    public static String[] getMsbIpAndPort() {\r
+        return split(getEnv(MSB_ADDR));\r
     }\r
 \r
-    public static String[] getServiceAddrInfo() {\r
+    public static String[] getMicroServiceIpAndPort() {\r
         String[] serviceAddrInfo = null;\r
-        String info = getServiceAddrInfoFromCBS(getEnv(HOSTNAME));\r
-        log.info("Got the service information of \"" + getEnv(HOSTNAME) + "\" from CBS. The response is " + info + ".");\r
-        if (info != null){\r
+        String info = getServiceAddrInfoFromDcaeConsulByHostName(getEnv(HOSTNAME));\r
+        log.info("Got the service information of \"" + getEnv(HOSTNAME) + "\" from Consul. The response is " + info + ".");\r
+        if (info != null && !info.isEmpty()){\r
             serviceAddrInfo = split(info);\r
         } else {\r
             serviceAddrInfo = split(getEnv(HOSTNAME));\r
index 897f689..a0bb943 100644 (file)
@@ -19,7 +19,6 @@ import javax.ws.rs.client.Client;
 import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.client.WebTarget;
 import org.glassfish.jersey.client.ClientConfig;
-import org.jvnet.hk2.annotations.Service;
 import org.onap.holmes.common.config.MicroServiceConfig;
 import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
 import org.onap.holmes.common.dcae.utils.DcaeConfigurationParser;
@@ -29,7 +28,7 @@ public class DcaeConfigurationQuery {
 
     public static DcaeConfigurations getDcaeConfigurations(String hostname)
             throws CorrelationException {
-        String serviceAddrInfo = MicroServiceConfig.getServiceAddrInfoFromCBS(hostname);
+        String serviceAddrInfo = MicroServiceConfig.getServiceConfigInfoFromCBS(hostname);
         String response;
         try {
             response = getDcaeResponse(serviceAddrInfo);
index 1cd481e..877a824 100644 (file)
@@ -18,14 +18,10 @@ package org.onap.holmes.common.utils;
 \r
 import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;\r
 \r
-import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\r
-import java.io.IOException;\r
 import lombok.extern.slf4j.Slf4j;\r
 import org.jvnet.hk2.annotations.Service;\r
-import org.onap.holmes.common.api.entity.ServiceRegisterEntity;\r
 import org.onap.holmes.common.config.MicroServiceConfig;\r
 import org.onap.holmes.common.exception.CorrelationException;\r
-import org.onap.holmes.common.msb.MicroserviceBusRest;\r
 import org.onap.msb.sdk.discovery.common.RouteException;\r
 import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;\r
 import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;\r
@@ -36,7 +32,7 @@ import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
 public class MSBRegisterUtil {\r
 \r
     public void register2Msb(MicroServiceInfo msinfo) throws CorrelationException {\r
-        String[] msbAddrInfo = MicroServiceConfig.getMsbAddrInfo();\r
+        String[] msbAddrInfo = MicroServiceConfig.getMsbIpAndPort();\r
         MSBServiceClient msbClient = new MSBServiceClient(msbAddrInfo[0],\r
                 Integer.parseInt(msbAddrInfo[1]));\r
 \r
index 7872f2b..b3f1eb6 100644 (file)
@@ -97,7 +97,7 @@ public class AaiQueryTest {
         when(HttpsUtils.get(url, headers)).thenReturn("{}");
 
         PowerMockito.mockStatic(MicroServiceConfig.class);
-        when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
+        when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("http://10.96.33.33:80");
 
         PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
                 .andReturn("/aai/v11/cloud-infrastructure");
@@ -131,7 +131,7 @@ public class AaiQueryTest {
         when(HttpsUtils.get(url, headers)).thenReturn("");
 
         PowerMockito.mockStatic(MicroServiceConfig.class);
-        when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
+        when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("http://10.96.33.33:80");
 
         PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
                 .andReturn("/aai/v11/cloud-infrastructure");
@@ -162,7 +162,7 @@ public class AaiQueryTest {
         when(HttpsUtils.get(url, headers)).thenThrow(new CorrelationException(""));
 
         PowerMockito.mockStatic(MicroServiceConfig.class);
-        when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
+        when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("http://10.96.33.33:80");
 
         PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
                 .andReturn("/aai/v11/cloud-infrastructure");
@@ -216,7 +216,7 @@ public class AaiQueryTest {
         Whitebox.setInternalState(aaiQuery, "aaiResponseUtil", aaiResponseUtil);
 
         PowerMockito.mockStatic(MicroServiceConfig.class);
-        when(MicroServiceConfig.getMsbServerAddr()).thenReturn("host_url");
+        when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("host_url");
 
         PowerMock.expectPrivate(aaiQuery, "getResponse", anyObject(String.class)).andReturn("").anyTimes();
         PowerMock.replayAll();
@@ -235,7 +235,7 @@ public class AaiQueryTest {
         Whitebox.setInternalState(aaiQuery, "aaiResponseUtil", aaiResponseUtil);
 
         PowerMockito.mockStatic(MicroServiceConfig.class);
-        when(MicroServiceConfig.getMsbServerAddr()).thenReturn("host_url");
+        when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("host_url");
 
         PowerMock.expectPrivate(aaiQuery, "getResponse", anyObject(String.class)).andReturn("").anyTimes();
         PowerMock.replayAll();
@@ -307,8 +307,8 @@ public class AaiQueryTest {
         aaiQuery = new AaiQuery();
 
         PowerMockito.mockStatic(MicroServiceConfig.class);
-        when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
-        when(MicroServiceConfig.getServiceAddrInfoFromCBS("nihao")).thenReturn("");
+        when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("http://10.96.33.33:80");
+        when(MicroServiceConfig.getServiceConfigInfoFromCBS("nihao")).thenReturn("");
 
         PowerMock.replayAll();
         String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "/url");
@@ -322,8 +322,8 @@ public class AaiQueryTest {
         aaiQuery = new AaiQuery();
 
         PowerMockito.mockStatic(MicroServiceConfig.class);
-        when(MicroServiceConfig.getMsbServerAddr()).thenThrow(new NullPointerException());
-        when(MicroServiceConfig.getServiceAddrInfoFromCBS("aai_config")).thenReturn("aai");
+        when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenThrow(new NullPointerException());
+        when(MicroServiceConfig.getServiceConfigInfoFromCBS("aai_config")).thenReturn("aai");
 
         PowerMock.replayAll();
         String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "url");
@@ -338,8 +338,8 @@ public class AaiQueryTest {
         aaiQuery = new AaiQuery();
 
         PowerMockito.mockStatic(MicroServiceConfig.class);
-        when(MicroServiceConfig.getMsbServerAddr()).thenThrow(new NullPointerException());
-        when(MicroServiceConfig.getServiceAddrInfoFromCBS("aai_config"))
+        when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenThrow(new NullPointerException());
+        when(MicroServiceConfig.getServiceConfigInfoFromCBS("aai_config"))
                 .thenThrow(new NullPointerException());
 
         PowerMock.replayAll();
index 23dd075..59af9d3 100644 (file)
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
 import static org.onap.holmes.common.config.MicroServiceConfig.*;\r
 \r
 import org.easymock.EasyMock;\r
+import org.junit.Ignore;\r
 import org.junit.Rule;\r
 import org.junit.Test;\r
 import org.powermock.api.easymock.PowerMock;\r
@@ -41,14 +42,7 @@ public class MicroServiceConfigTest {
     @Test\r
     public void getMsbServerAddrTest() {\r
         System.setProperty(MSB_ADDR, "test:80");\r
-        System.setProperty(HOSTNAME, "rule-mgmt");\r
-        PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);\r
-        EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))\r
-                .andReturn("{\"msb.hostname\": \"test:80\"}");\r
-        PowerMock.replayAll();\r
-        assertThat("http://test:80", equalTo(getMsbServerAddr()));\r
-        PowerMock.verifyAll();\r
-        System.clearProperty(MicroServiceConfig.HOSTNAME);\r
+        assertThat("http://test:80", equalTo(getMsbServerAddrWithHttpPrefix()));\r
         System.clearProperty(MicroServiceConfig.MSB_ADDR);\r
     }\r
 \r
@@ -56,12 +50,12 @@ public class MicroServiceConfigTest {
     public void getMsbServerIpTest() {\r
         System.setProperty(MSB_ADDR, "10.54.23.79:80");\r
         System.setProperty(HOSTNAME, "rule-mgmt");\r
-        PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);\r
-        EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))\r
+        PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class);\r
+        EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME)))\r
                 .andReturn("{\"msb.hostname\": \"10.54.23.79:80\"}").times(2);\r
         PowerMock.replayAll();\r
-        assertThat("10.54.23.79", equalTo(getMsbAddrInfo()[0]));\r
-        assertThat("80", equalTo(getMsbAddrInfo()[1]));\r
+        assertThat("10.54.23.79", equalTo(getMsbIpAndPort()[0]));\r
+        assertThat("80", equalTo(getMsbIpAndPort()[1]));\r
         System.clearProperty(MicroServiceConfig.HOSTNAME);\r
         System.clearProperty(MSB_ADDR);\r
     }\r
@@ -69,33 +63,37 @@ public class MicroServiceConfigTest {
     @Test\r
     public void getServiceIpTest() {\r
         System.setProperty(HOSTNAME, "127.0.0.1");\r
-        assertThat("127.0.0.1", equalTo(getServiceAddrInfo()[0]));\r
-        assertThat("80", equalTo(getServiceAddrInfo()[1]));\r
+        assertThat("127.0.0.1", equalTo(getMicroServiceIpAndPort()[0]));\r
+        assertThat("80", equalTo(getMicroServiceIpAndPort()[1]));\r
         System.clearProperty(HOSTNAME);\r
     }\r
 \r
     @Test\r
     public void getConsulAddrInfoTest() {\r
         System.setProperty(CONSUL_HOST, "127.0.0.1");\r
-        assertThat("127.0.0.1:8500/v1/catalog/service/", equalTo(getConsulAddrInfo()));\r
+        assertThat("http://127.0.0.1:8500/v1/catalog/service/", equalTo(getConsulAddrInfo()));\r
         System.clearProperty(CONSUL_HOST);\r
     }\r
 \r
     @Test\r
     public void getConfigBindingServiceAddrInfoTest_consul_not_exist() throws Exception {\r
+        System.setProperty(CONFIG_BINDING_SERVICE, "config_binding_service");\r
         PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);\r
         PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
                 .andThrow(new RuntimeException("Invalid URL."));\r
 \r
         PowerMock.replayAll();\r
 \r
-        assertThat(getConfigBindingServiceAddrInfo(), is(nullValue()));\r
+        assertThat(getServiceAddrInfoFromDcaeConsulByHostName(System.getProperty(CONFIG_BINDING_SERVICE))\r
+                , is(nullValue()));\r
 \r
         PowerMock.verifyAll();\r
+        System.clearProperty(CONFIG_BINDING_SERVICE);\r
     }\r
 \r
     @Test\r
-    public void getConfigBindingServiceAddrInfoTest_consul_exists() throws Exception {\r
+    public void getServiceAddrInfoFromDcaeConsulByHostName_consul_exists() throws Exception {\r
+        System.setProperty(CONFIG_BINDING_SERVICE, "config_binding_service");\r
         PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);\r
         PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
                 .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");\r
@@ -103,15 +101,18 @@ public class MicroServiceConfigTest {
 \r
         PowerMock.replayAll();\r
 \r
-        assertThat(getConfigBindingServiceAddrInfo(), equalTo("127.0.0.2:8080"));\r
+        assertThat(getServiceAddrInfoFromDcaeConsulByHostName(System.getProperty(CONFIG_BINDING_SERVICE)),\r
+                equalTo("http://127.0.0.2:8080"));\r
 \r
         PowerMock.verifyAll();\r
 \r
         System.clearProperty(CONSUL_HOST);\r
+        System.clearProperty(CONFIG_BINDING_SERVICE);\r
     }\r
 \r
     @Test\r
     public void getConfigBindingServiceAddrInfoTest_consul_exists_propertie_not_exist() throws Exception {\r
+        System.setProperty(CONFIG_BINDING_SERVICE, "config_binding_service");\r
         PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);\r
         PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
                 .andReturn("[{\"ServiceAddress\": \"127.0.0.2\"}]");\r
@@ -119,11 +120,13 @@ public class MicroServiceConfigTest {
 \r
         PowerMock.replayAll();\r
 \r
-        assertThat(getConfigBindingServiceAddrInfo(), is(nullValue()));\r
+        assertThat(getServiceAddrInfoFromDcaeConsulByHostName(System.getProperty(CONFIG_BINDING_SERVICE)),\r
+                is(nullValue()));\r
 \r
         PowerMock.verifyAll();\r
 \r
         System.clearProperty(CONSUL_HOST);\r
+        System.clearProperty(CONFIG_BINDING_SERVICE);\r
     }\r
 \r
     @Test\r
@@ -134,52 +137,32 @@ public class MicroServiceConfigTest {
 \r
         PowerMock.replayAll();\r
 \r
-        assertThat(getServiceAddrInfoFromCBS(HOSTNAME), is(nullValue()));\r
+        assertThat(getServiceConfigInfoFromCBS(HOSTNAME), is(nullValue()));\r
 \r
         PowerMock.verifyAll();\r
     }\r
 \r
     @Test\r
-    public void getServiceAddrInfoFromCBS_consul_exists_service_not_exist() throws Exception {\r
+    public void getServiceAddrInfoFromDcaeConsulByHostName_consul_exists_service_not_exist() throws Exception {\r
         PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);\r
         PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
-                .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");\r
-        PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
-                .andReturn("{}");\r
+                .andReturn("[]");\r
 \r
         PowerMock.replayAll();\r
-        assertThat(getServiceAddrInfoFromCBS(HOSTNAME), is(nullValue()));\r
-        PowerMock.verifyAll();\r
-    }\r
-\r
-    @Test\r
-    public void getServiceAddrInfoFromCBS_normal() throws Exception {\r
-        System.setProperty(HOSTNAME, "rule-mgmt");\r
-        PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);\r
-        PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
-                .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");\r
-        PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
-                .andReturn("{\"rule-mgmt\": \"[\\\"127.0.0.3:5432\\\"]\"}");\r
-\r
-        PowerMock.replayAll();\r
-\r
-        assertThat(getServiceAddrInfoFromCBS("rule-mgmt"), equalTo("127.0.0.3:5432"));\r
-\r
+        assertThat(getServiceAddrInfoFromDcaeConsulByHostName(HOSTNAME), is(nullValue()));\r
         PowerMock.verifyAll();\r
-\r
-        System.clearProperty(HOSTNAME);\r
     }\r
 \r
-    @Test\r
+    @Ignore\r
     public void getMsbAddrInfo_msb_registered() throws Exception {\r
         System.setProperty(MSB_ADDR, "10.74.5.8:1545");\r
         System.setProperty(HOSTNAME, "rule-mgmt");\r
-        PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);\r
-        EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))\r
+        PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class);\r
+        EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME)))\r
                 .andReturn("{\"msb.hostname\": \"127.0.0.3:5432\"}");\r
 \r
         PowerMock.replayAll();\r
-        String[] msbInfo = getMsbAddrInfo();\r
+        String[] msbInfo = getMsbIpAndPort();\r
         PowerMock.verifyAll();\r
 \r
         assertThat(msbInfo[0], equalTo("127.0.0.3"));\r
@@ -189,16 +172,16 @@ public class MicroServiceConfigTest {
         System.clearProperty(MSB_ADDR);\r
     }\r
 \r
-    @Test\r
+    @Ignore\r
     public void getMsbAddrInfo_msb_not_registered() throws Exception {\r
         System.setProperty(MSB_ADDR, "10.74.5.8:1545");\r
         System.setProperty(HOSTNAME, "rule-mgmt");\r
-        PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);\r
-        EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))\r
+        PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class);\r
+        EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME)))\r
                 .andReturn("{}");\r
 \r
         PowerMock.replayAll();\r
-        String[] msbInfo = getMsbAddrInfo();\r
+        String[] msbInfo = getMsbIpAndPort();\r
         PowerMock.verifyAll();\r
 \r
         assertThat(msbInfo[0], equalTo("10.74.5.8"));\r
@@ -209,16 +192,14 @@ public class MicroServiceConfigTest {
     }\r
 \r
     @Test\r
-    public void getServiceAddrInfo_msb_registered() throws Exception {\r
+    public void getMicroServiceIpAndPort_service_registered_to_consul() throws Exception {\r
         System.setProperty(HOSTNAME, "rule-mgmt");\r
         PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);\r
         PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
-                .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");\r
-        PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
-                .andReturn("{\"rule-mgmt\": \"[\\\"127.0.0.3:5432\\\"]\"}");\r
+                .andReturn("[{\"ServiceAddress\": \"127.0.0.3\", \"ServicePort\": \"5432\"}]");\r
 \r
         PowerMock.replayAll();\r
-        String[] msbInfo = getServiceAddrInfo();\r
+        String[] msbInfo = getMicroServiceIpAndPort();\r
         PowerMock.verifyAll();\r
 \r
         assertThat(msbInfo[0], equalTo("127.0.0.3"));\r
@@ -228,16 +209,14 @@ public class MicroServiceConfigTest {
     }\r
 \r
     @Test\r
-    public void getServiceAddrInfo_msb_not_registered() throws Exception {\r
+    public void getMicroServiceIpAndPort_service_not_registered_to_consul() throws Exception {\r
         System.setProperty(HOSTNAME, "10.74.5.8:1545");\r
         PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);\r
         PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
-                .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");\r
-        PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
-                .andReturn("{}");\r
+                .andReturn("[]");\r
 \r
         PowerMock.replayAll();\r
-        String[] msbInfo = getServiceAddrInfo();\r
+        String[] msbInfo = getMicroServiceIpAndPort();\r
         PowerMock.verifyAll();\r
 \r
         assertThat(msbInfo[0], equalTo("10.74.5.8"));\r
@@ -247,16 +226,14 @@ public class MicroServiceConfigTest {
     }\r
 \r
     @Test\r
-    public void getServiceAddrInfo_msb_not_registered_full_addr() throws Exception {\r
+    public void getMicroServiceIpAndPort_service_not_registered_full_addr() throws Exception {\r
         System.setProperty(HOSTNAME, "http://10.74.5.8:1545");\r
         PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);\r
-        PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
-                .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");\r
         PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
                 .andReturn("{}");\r
 \r
         PowerMock.replayAll();\r
-        String[] msbInfo = getServiceAddrInfo();\r
+        String[] msbInfo = getMicroServiceIpAndPort();\r
         PowerMock.verifyAll();\r
 \r
         assertThat(msbInfo[0], equalTo("10.74.5.8"));\r
@@ -266,16 +243,14 @@ public class MicroServiceConfigTest {
     }\r
 \r
     @Test\r
-    public void getServiceAddrInfo_msb_not_registered_no_port() throws Exception {\r
+    public void getMicroServiceIpAndPort_service_not_registered_no_port() throws Exception {\r
         System.setProperty(HOSTNAME, "http://10.74.5.8");\r
         PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);\r
-        PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
-                .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");\r
         PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
                 .andReturn("{}");\r
 \r
         PowerMock.replayAll();\r
-        String[] msbInfo = getServiceAddrInfo();\r
+        String[] msbInfo = getMicroServiceIpAndPort();\r
         PowerMock.verifyAll();\r
 \r
         assertThat(msbInfo[0], equalTo("10.74.5.8"));\r
@@ -285,16 +260,14 @@ public class MicroServiceConfigTest {
     }\r
 \r
     @Test\r
-    public void getServiceAddrInfo_msb_not_registered_only_ip() throws Exception {\r
+    public void getMicroServiceIpAndPort_service_not_registered_only_ip() throws Exception {\r
         System.setProperty(HOSTNAME, "10.74.5.8");\r
         PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);\r
-        PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
-                .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");\r
         PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
                 .andReturn("{}");\r
 \r
         PowerMock.replayAll();\r
-        String[] msbInfo = getServiceAddrInfo();\r
+        String[] msbInfo = getMicroServiceIpAndPort();\r
         PowerMock.verifyAll();\r
 \r
         assertThat(msbInfo[0], equalTo("10.74.5.8"));\r
@@ -304,16 +277,14 @@ public class MicroServiceConfigTest {
     }\r
 \r
     @Test\r
-    public void getServiceAddrInfo_msb_not_registered_full_addr_https() throws Exception {\r
+    public void getMicroServiceIpAndPort_service_not_registered_full_addr_https() throws Exception {\r
         System.setProperty(HOSTNAME, "https://10.74.5.8:5432");\r
         PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);\r
         PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
-                .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");\r
-        PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())\r
-                .andReturn("{}");\r
+                .andReturn("[]");\r
 \r
         PowerMock.replayAll();\r
-        String[] msbInfo = getServiceAddrInfo();\r
+        String[] msbInfo = getMicroServiceIpAndPort();\r
         PowerMock.verifyAll();\r
 \r
         assertThat(msbInfo[0], equalTo("10.74.5.8"));\r
index ab2554f..e1b79bf 100644 (file)
 \r
 package org.onap.holmes.common.utils;\r
 \r
-import static org.onap.holmes.common.config.MicroServiceConfig.HOSTNAME;\r
-\r
 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\r
 import javax.ws.rs.QueryParam;\r
-import org.easymock.EasyMock;\r
 import org.junit.Rule;\r
-import org.junit.Test;\r
 import org.onap.holmes.common.msb.MicroserviceBusRest;\r
 import org.onap.holmes.common.api.entity.ServiceRegisterEntity;\r
 import org.onap.holmes.common.config.MicroServiceConfig;\r
-import org.powermock.api.easymock.PowerMock;\r
 import org.powermock.core.classloader.annotations.PowerMockIgnore;\r
 import org.powermock.core.classloader.annotations.PrepareForTest;\r
 import org.powermock.modules.junit4.rule.PowerMockRule;\r
@@ -41,7 +36,7 @@ public class MSBRegisterUtilTest {
     private MicroserviceBusRest microserviceBusRest = new MicroserviceBusRestProxy();\r
 \r
     private ServiceRegisterEntity initServiceEntity() {\r
-        String[] serviceAddrInfo = MicroServiceConfig.getServiceAddrInfo();\r
+        String[] serviceAddrInfo = MicroServiceConfig.getMicroServiceIpAndPort();\r
         ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity();\r
         serviceRegisterEntity.setServiceName("holmes-rule-mgmt");\r
         serviceRegisterEntity.setProtocol("REST");\r