Remove Class: HttpsUtils & MicroserviceBusRest
[holmes/common.git] / holmes-actions / src / test / java / org / onap / holmes / common / config / MicroServiceConfigTest.java
index aea9d96..1fdc335 100644 (file)
@@ -1,12 +1,12 @@
 /**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
+ * Copyright 2017-2020 ZTE Corporation.\r
+ * <p>\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
@@ -19,12 +19,12 @@ package org.onap.holmes.common.config;
 import org.apache.commons.lang3.StringUtils;\r
 import org.easymock.EasyMock;\r
 import org.junit.Ignore;\r
-import org.junit.Rule;\r
 import org.junit.Test;\r
+import org.junit.runner.RunWith;\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
+import org.powermock.modules.junit4.PowerMockRunner;\r
 import org.powermock.reflect.internal.WhiteboxImpl;\r
 \r
 import static org.hamcrest.core.Is.is;\r
@@ -35,32 +35,34 @@ import static org.onap.holmes.common.config.MicroServiceConfig.*;
 \r
 @PrepareForTest(MicroServiceConfig.class)\r
 @PowerMockIgnore({"javax.ws.*"})\r
+@RunWith(PowerMockRunner.class)\r
 public class MicroServiceConfigTest {\r
 \r
     private static String ACTUAL_HOSTNAME = System.getenv(HOSTNAME);\r
 \r
-    @Rule\r
-    public PowerMockRule powerMockRule = new PowerMockRule();\r
-\r
     @Test\r
     public void getMsbServerAddrTest() {\r
-        System.setProperty(MSB_ADDR, "test:80");\r
-        assertThat("http://test:80", equalTo(getMsbServerAddrWithHttpPrefix()));\r
-        System.clearProperty(MicroServiceConfig.MSB_ADDR);\r
+        System.setProperty(MSB_IAG_SERVICE_HOST, "test");\r
+        System.setProperty(MSB_IAG_SERVICE_PORT, "443");\r
+        assertThat("http://test:443", equalTo(getMsbServerAddrWithHttpPrefix()));\r
+        System.clearProperty(MicroServiceConfig.MSB_IAG_SERVICE_PORT);\r
+        System.clearProperty(MicroServiceConfig.MSB_IAG_SERVICE_HOST);\r
     }\r
 \r
     @Test\r
     public void getMsbServerIpTest() {\r
-        System.setProperty(MSB_ADDR, "10.54.23.79:80");\r
+        System.setProperty(MSB_IAG_SERVICE_HOST, "10.54.23.79");\r
+        System.setProperty(MSB_IAG_SERVICE_PORT, "443");\r
         System.setProperty(HOSTNAME, "rule-mgmt");\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
+                .andReturn("{\"msb.hostname\": \"10.54.23.79:443\"}").times(2);\r
         PowerMock.replayAll();\r
         assertThat("10.54.23.79", equalTo(getMsbIpAndPort()[0]));\r
-        assertThat("80", equalTo(getMsbIpAndPort()[1]));\r
+        assertThat("443", equalTo(getMsbIpAndPort()[1]));\r
         System.clearProperty(MicroServiceConfig.HOSTNAME);\r
-        System.clearProperty(MSB_ADDR);\r
+        System.clearProperty(MicroServiceConfig.MSB_IAG_SERVICE_PORT);\r
+        System.clearProperty(MicroServiceConfig.MSB_IAG_SERVICE_HOST);\r
     }\r
 \r
     @Test\r
@@ -116,7 +118,26 @@ public class MicroServiceConfigTest {
     }\r
 \r
     @Test\r
-    public void getConfigBindingServiceAddrInfoTest_consul_exists_propertie_not_exist() throws Exception {\r
+    public void getConfigBindingServiceAddrInfoTest_consul_return_empty_array() 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("[]");\r
+        System.setProperty(CONSUL_HOST, "127.0.0.1");\r
+\r
+        PowerMock.replayAll();\r
+\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
+    public void getConfigBindingServiceAddrInfoTest_consul_exists_property_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
@@ -160,7 +181,8 @@ public class MicroServiceConfigTest {
 \r
     @Ignore\r
     public void getMsbAddrInfo_msb_registered() throws Exception {\r
-        System.setProperty(MSB_ADDR, "10.74.5.8:1545");\r
+        System.setProperty(MSB_IAG_SERVICE_HOST, "10.74.5.8");\r
+        System.setProperty(MSB_IAG_SERVICE_PORT, "1545");\r
         System.setProperty(HOSTNAME, "rule-mgmt");\r
         PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class);\r
         EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME)))\r
@@ -174,12 +196,14 @@ public class MicroServiceConfigTest {
         assertThat(msbInfo[1], equalTo("5432"));\r
 \r
         System.clearProperty(HOSTNAME);\r
-        System.clearProperty(MSB_ADDR);\r
+        System.clearProperty(MSB_IAG_SERVICE_PORT);\r
+        System.clearProperty(MSB_IAG_SERVICE_HOST);\r
     }\r
 \r
     @Ignore\r
     public void getMsbAddrInfo_msb_not_registered() throws Exception {\r
-        System.setProperty(MSB_ADDR, "10.74.5.8:1545");\r
+        System.setProperty(MSB_IAG_SERVICE_HOST, "10.74.5.8");\r
+        System.setProperty(MSB_IAG_SERVICE_PORT, "1545");\r
         System.setProperty(HOSTNAME, "rule-mgmt");\r
         PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class);\r
         EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME)))\r
@@ -193,7 +217,8 @@ public class MicroServiceConfigTest {
         assertThat(msbInfo[1], equalTo("1545"));\r
 \r
         System.clearProperty(HOSTNAME);\r
-        System.clearProperty(MSB_ADDR);\r
+        System.clearProperty(MSB_IAG_SERVICE_PORT);\r
+        System.clearProperty(MSB_IAG_SERVICE_HOST);\r
     }\r
 \r
     @Test\r
@@ -250,7 +275,7 @@ public class MicroServiceConfigTest {
         assertThat(msbInfo[0], equalTo(ip));\r
         assertThat(msbInfo[1], equalTo(port));\r
 \r
-        System.clearProperty(MSB_ADDR);\r
+        System.clearProperty(HOSTNAME);\r
     }\r
 \r
     @Test\r
@@ -269,7 +294,7 @@ public class MicroServiceConfigTest {
         assertThat(msbInfo[0], equalTo(ip));\r
         assertThat(msbInfo[1], equalTo("80"));\r
 \r
-        System.clearProperty(MSB_ADDR);\r
+        System.clearProperty(HOSTNAME);\r
     }\r
 \r
     @Test\r
@@ -288,7 +313,7 @@ public class MicroServiceConfigTest {
         assertThat(msbInfo[0], equalTo(ip));\r
         assertThat(msbInfo[1], equalTo("80"));\r
 \r
-        System.clearProperty(MSB_ADDR);\r
+        System.clearProperty(HOSTNAME);\r
     }\r
 \r
     @Test\r
@@ -308,54 +333,6 @@ public class MicroServiceConfigTest {
         assertThat(msbInfo[0], equalTo(ip));\r
         assertThat(msbInfo[1], equalTo(port));\r
 \r
-        System.clearProperty(MSB_ADDR);\r
-    }\r
-\r
-    @Test\r
-    public void isValidIpAddress_with_port() throws Exception {\r
-        boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "10.75.13.21:90");\r
-        assertThat(res, is(true));\r
-    }\r
-\r
-    @Test\r
-    public void isValidIpAddress_without_port() throws Exception {\r
-        boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "10.75.13.21");\r
-        assertThat(res, is(true));\r
-    }\r
-\r
-    @Test\r
-    public void isValidIpAddress_with_port_with_http_prefix() throws Exception {\r
-        boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "http://10.75.13.21:90");\r
-        assertThat(res, is(true));\r
-    }\r
-\r
-    @Test\r
-    public void isValidIpAddress_without_port_with_https_prefix() throws Exception {\r
-        boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "https://10.75.13.21");\r
-        assertThat(res, is(true));\r
-    }\r
-\r
-    @Test\r
-    public void isValidIpAddress_invalid_ip_without_port() throws Exception {\r
-        boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "holmes-rule-mgmt");\r
-        assertThat(res, is(false));\r
-    }\r
-\r
-    @Test\r
-    public void isValidIpAddress_invalid_ip_with_port() throws Exception {\r
-        boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "holmes-rule-mgmt:80");\r
-        assertThat(res, is(false));\r
-    }\r
-\r
-    @Test\r
-    public void isValidIpAddress_invalid_ip_without_port_with_http_prefix() throws Exception {\r
-        boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "http://holmes-rule-mgmt");\r
-        assertThat(res, is(false));\r
-    }\r
-\r
-    @Test\r
-    public void isValidIpAddress_invalid_ip_with_port_with_https_prefix() throws Exception {\r
-        boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "https://holmes-rule-mgmt:80");\r
-        assertThat(res, is(false));\r
+        System.clearProperty(HOSTNAME);\r
     }\r
 }
\ No newline at end of file