X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=holmes-actions%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fholmes%2Fcommon%2Fconfig%2FMicroServiceConfigTest.java;h=1fdc3355498ab689ac03c192128fc42cd255951e;hb=6cc976de165087178e784c40423242bc7f1b07ee;hp=a87ba674faec47d6c494dc9ed2cf75f3c8b7688b;hpb=3e5ddaee6984869b67dda89b7f8e1932a2b27045;p=holmes%2Fcommon.git diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java index a87ba67..1fdc335 100644 --- a/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java +++ b/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java @@ -40,26 +40,29 @@ public class MicroServiceConfigTest { private static String ACTUAL_HOSTNAME = System.getenv(HOSTNAME); - @Test public void getMsbServerAddrTest() { - System.setProperty(MSB_ADDR, "test:80"); - assertThat("http://test:80", equalTo(getMsbServerAddrWithHttpPrefix())); - System.clearProperty(MicroServiceConfig.MSB_ADDR); + System.setProperty(MSB_IAG_SERVICE_HOST, "test"); + System.setProperty(MSB_IAG_SERVICE_PORT, "443"); + assertThat("http://test:443", equalTo(getMsbServerAddrWithHttpPrefix())); + System.clearProperty(MicroServiceConfig.MSB_IAG_SERVICE_PORT); + System.clearProperty(MicroServiceConfig.MSB_IAG_SERVICE_HOST); } @Test public void getMsbServerIpTest() { - System.setProperty(MSB_ADDR, "10.54.23.79:80"); + System.setProperty(MSB_IAG_SERVICE_HOST, "10.54.23.79"); + System.setProperty(MSB_IAG_SERVICE_PORT, "443"); System.setProperty(HOSTNAME, "rule-mgmt"); PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class); EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME))) - .andReturn("{\"msb.hostname\": \"10.54.23.79:80\"}").times(2); + .andReturn("{\"msb.hostname\": \"10.54.23.79:443\"}").times(2); PowerMock.replayAll(); assertThat("10.54.23.79", equalTo(getMsbIpAndPort()[0])); - assertThat("80", equalTo(getMsbIpAndPort()[1])); + assertThat("443", equalTo(getMsbIpAndPort()[1])); System.clearProperty(MicroServiceConfig.HOSTNAME); - System.clearProperty(MSB_ADDR); + System.clearProperty(MicroServiceConfig.MSB_IAG_SERVICE_PORT); + System.clearProperty(MicroServiceConfig.MSB_IAG_SERVICE_HOST); } @Test @@ -115,7 +118,26 @@ public class MicroServiceConfigTest { } @Test - public void getConfigBindingServiceAddrInfoTest_consul_exists_propertie_not_exist() throws Exception { + public void getConfigBindingServiceAddrInfoTest_consul_return_empty_array() throws Exception { + System.setProperty(CONFIG_BINDING_SERVICE, "config_binding_service"); + PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class); + PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject()) + .andReturn("[]"); + System.setProperty(CONSUL_HOST, "127.0.0.1"); + + PowerMock.replayAll(); + + assertThat(getServiceAddrInfoFromDcaeConsulByHostName(System.getProperty(CONFIG_BINDING_SERVICE)), + is(nullValue())); + + PowerMock.verifyAll(); + + System.clearProperty(CONSUL_HOST); + System.clearProperty(CONFIG_BINDING_SERVICE); + } + + @Test + public void getConfigBindingServiceAddrInfoTest_consul_exists_property_not_exist() throws Exception { System.setProperty(CONFIG_BINDING_SERVICE, "config_binding_service"); PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class); PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject()) @@ -159,7 +181,8 @@ public class MicroServiceConfigTest { @Ignore public void getMsbAddrInfo_msb_registered() throws Exception { - System.setProperty(MSB_ADDR, "10.74.5.8:1545"); + System.setProperty(MSB_IAG_SERVICE_HOST, "10.74.5.8"); + System.setProperty(MSB_IAG_SERVICE_PORT, "1545"); System.setProperty(HOSTNAME, "rule-mgmt"); PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class); EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME))) @@ -173,12 +196,14 @@ public class MicroServiceConfigTest { assertThat(msbInfo[1], equalTo("5432")); System.clearProperty(HOSTNAME); - System.clearProperty(MSB_ADDR); + System.clearProperty(MSB_IAG_SERVICE_PORT); + System.clearProperty(MSB_IAG_SERVICE_HOST); } @Ignore public void getMsbAddrInfo_msb_not_registered() throws Exception { - System.setProperty(MSB_ADDR, "10.74.5.8:1545"); + System.setProperty(MSB_IAG_SERVICE_HOST, "10.74.5.8"); + System.setProperty(MSB_IAG_SERVICE_PORT, "1545"); System.setProperty(HOSTNAME, "rule-mgmt"); PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class); EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME))) @@ -192,7 +217,8 @@ public class MicroServiceConfigTest { assertThat(msbInfo[1], equalTo("1545")); System.clearProperty(HOSTNAME); - System.clearProperty(MSB_ADDR); + System.clearProperty(MSB_IAG_SERVICE_PORT); + System.clearProperty(MSB_IAG_SERVICE_HOST); } @Test @@ -249,7 +275,7 @@ public class MicroServiceConfigTest { assertThat(msbInfo[0], equalTo(ip)); assertThat(msbInfo[1], equalTo(port)); - System.clearProperty(MSB_ADDR); + System.clearProperty(HOSTNAME); } @Test @@ -268,7 +294,7 @@ public class MicroServiceConfigTest { assertThat(msbInfo[0], equalTo(ip)); assertThat(msbInfo[1], equalTo("80")); - System.clearProperty(MSB_ADDR); + System.clearProperty(HOSTNAME); } @Test @@ -287,7 +313,7 @@ public class MicroServiceConfigTest { assertThat(msbInfo[0], equalTo(ip)); assertThat(msbInfo[1], equalTo("80")); - System.clearProperty(MSB_ADDR); + System.clearProperty(HOSTNAME); } @Test @@ -307,54 +333,6 @@ public class MicroServiceConfigTest { assertThat(msbInfo[0], equalTo(ip)); assertThat(msbInfo[1], equalTo(port)); - System.clearProperty(MSB_ADDR); - } - - @Test - public void isValidIpAddress_with_port() throws Exception { - boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "10.75.13.21:90"); - assertThat(res, is(true)); - } - - @Test - public void isValidIpAddress_without_port() throws Exception { - boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "10.75.13.21"); - assertThat(res, is(true)); - } - - @Test - public void isValidIpAddress_with_port_with_http_prefix() throws Exception { - boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "http://10.75.13.21:90"); - assertThat(res, is(true)); - } - - @Test - public void isValidIpAddress_without_port_with_https_prefix() throws Exception { - boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "https://10.75.13.21"); - assertThat(res, is(true)); - } - - @Test - public void isValidIpAddress_invalid_ip_without_port() throws Exception { - boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "holmes-rule-mgmt"); - assertThat(res, is(false)); - } - - @Test - public void isValidIpAddress_invalid_ip_with_port() throws Exception { - boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "holmes-rule-mgmt:80"); - assertThat(res, is(false)); - } - - @Test - public void isValidIpAddress_invalid_ip_without_port_with_http_prefix() throws Exception { - boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "http://holmes-rule-mgmt"); - assertThat(res, is(false)); - } - - @Test - public void isValidIpAddress_invalid_ip_with_port_with_https_prefix() throws Exception { - boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "https://holmes-rule-mgmt:80"); - assertThat(res, is(false)); + System.clearProperty(HOSTNAME); } } \ No newline at end of file