diff options
Diffstat (limited to 'holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java')
-rw-r--r-- | holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java | 127 |
1 files changed, 49 insertions, 78 deletions
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 23dd075..59af9d3 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 @@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue; import static org.onap.holmes.common.config.MicroServiceConfig.*;
import org.easymock.EasyMock;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.powermock.api.easymock.PowerMock;
@@ -41,14 +42,7 @@ public class MicroServiceConfigTest { @Test
public void getMsbServerAddrTest() {
System.setProperty(MSB_ADDR, "test:80");
- System.setProperty(HOSTNAME, "rule-mgmt");
- PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);
- EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))
- .andReturn("{\"msb.hostname\": \"test:80\"}");
- PowerMock.replayAll();
- assertThat("http://test:80", equalTo(getMsbServerAddr()));
- PowerMock.verifyAll();
- System.clearProperty(MicroServiceConfig.HOSTNAME);
+ assertThat("http://test:80", equalTo(getMsbServerAddrWithHttpPrefix()));
System.clearProperty(MicroServiceConfig.MSB_ADDR);
}
@@ -56,12 +50,12 @@ public class MicroServiceConfigTest { public void getMsbServerIpTest() {
System.setProperty(MSB_ADDR, "10.54.23.79:80");
System.setProperty(HOSTNAME, "rule-mgmt");
- PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);
- EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))
+ PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class);
+ EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME)))
.andReturn("{\"msb.hostname\": \"10.54.23.79:80\"}").times(2);
PowerMock.replayAll();
- assertThat("10.54.23.79", equalTo(getMsbAddrInfo()[0]));
- assertThat("80", equalTo(getMsbAddrInfo()[1]));
+ assertThat("10.54.23.79", equalTo(getMsbIpAndPort()[0]));
+ assertThat("80", equalTo(getMsbIpAndPort()[1]));
System.clearProperty(MicroServiceConfig.HOSTNAME);
System.clearProperty(MSB_ADDR);
}
@@ -69,33 +63,37 @@ public class MicroServiceConfigTest { @Test
public void getServiceIpTest() {
System.setProperty(HOSTNAME, "127.0.0.1");
- assertThat("127.0.0.1", equalTo(getServiceAddrInfo()[0]));
- assertThat("80", equalTo(getServiceAddrInfo()[1]));
+ assertThat("127.0.0.1", equalTo(getMicroServiceIpAndPort()[0]));
+ assertThat("80", equalTo(getMicroServiceIpAndPort()[1]));
System.clearProperty(HOSTNAME);
}
@Test
public void getConsulAddrInfoTest() {
System.setProperty(CONSUL_HOST, "127.0.0.1");
- assertThat("127.0.0.1:8500/v1/catalog/service/", equalTo(getConsulAddrInfo()));
+ assertThat("http://127.0.0.1:8500/v1/catalog/service/", equalTo(getConsulAddrInfo()));
System.clearProperty(CONSUL_HOST);
}
@Test
public void getConfigBindingServiceAddrInfoTest_consul_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())
.andThrow(new RuntimeException("Invalid URL."));
PowerMock.replayAll();
- assertThat(getConfigBindingServiceAddrInfo(), is(nullValue()));
+ assertThat(getServiceAddrInfoFromDcaeConsulByHostName(System.getProperty(CONFIG_BINDING_SERVICE))
+ , is(nullValue()));
PowerMock.verifyAll();
+ System.clearProperty(CONFIG_BINDING_SERVICE);
}
@Test
- public void getConfigBindingServiceAddrInfoTest_consul_exists() throws Exception {
+ public void getServiceAddrInfoFromDcaeConsulByHostName_consul_exists() 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("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
@@ -103,15 +101,18 @@ public class MicroServiceConfigTest { PowerMock.replayAll();
- assertThat(getConfigBindingServiceAddrInfo(), equalTo("127.0.0.2:8080"));
+ assertThat(getServiceAddrInfoFromDcaeConsulByHostName(System.getProperty(CONFIG_BINDING_SERVICE)),
+ equalTo("http://127.0.0.2:8080"));
PowerMock.verifyAll();
System.clearProperty(CONSUL_HOST);
+ System.clearProperty(CONFIG_BINDING_SERVICE);
}
@Test
public void getConfigBindingServiceAddrInfoTest_consul_exists_propertie_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())
.andReturn("[{\"ServiceAddress\": \"127.0.0.2\"}]");
@@ -119,11 +120,13 @@ public class MicroServiceConfigTest { PowerMock.replayAll();
- assertThat(getConfigBindingServiceAddrInfo(), is(nullValue()));
+ assertThat(getServiceAddrInfoFromDcaeConsulByHostName(System.getProperty(CONFIG_BINDING_SERVICE)),
+ is(nullValue()));
PowerMock.verifyAll();
System.clearProperty(CONSUL_HOST);
+ System.clearProperty(CONFIG_BINDING_SERVICE);
}
@Test
@@ -134,52 +137,32 @@ public class MicroServiceConfigTest { PowerMock.replayAll();
- assertThat(getServiceAddrInfoFromCBS(HOSTNAME), is(nullValue()));
+ assertThat(getServiceConfigInfoFromCBS(HOSTNAME), is(nullValue()));
PowerMock.verifyAll();
}
@Test
- public void getServiceAddrInfoFromCBS_consul_exists_service_not_exist() throws Exception {
+ public void getServiceAddrInfoFromDcaeConsulByHostName_consul_exists_service_not_exist() throws Exception {
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("{}");
+ .andReturn("[]");
PowerMock.replayAll();
- assertThat(getServiceAddrInfoFromCBS(HOSTNAME), is(nullValue()));
- PowerMock.verifyAll();
- }
-
- @Test
- public void getServiceAddrInfoFromCBS_normal() throws Exception {
- System.setProperty(HOSTNAME, "rule-mgmt");
- PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("{\"rule-mgmt\": \"[\\\"127.0.0.3:5432\\\"]\"}");
-
- PowerMock.replayAll();
-
- assertThat(getServiceAddrInfoFromCBS("rule-mgmt"), equalTo("127.0.0.3:5432"));
-
+ assertThat(getServiceAddrInfoFromDcaeConsulByHostName(HOSTNAME), is(nullValue()));
PowerMock.verifyAll();
-
- System.clearProperty(HOSTNAME);
}
- @Test
+ @Ignore
public void getMsbAddrInfo_msb_registered() throws Exception {
System.setProperty(MSB_ADDR, "10.74.5.8:1545");
System.setProperty(HOSTNAME, "rule-mgmt");
- PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);
- EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))
+ PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class);
+ EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME)))
.andReturn("{\"msb.hostname\": \"127.0.0.3:5432\"}");
PowerMock.replayAll();
- String[] msbInfo = getMsbAddrInfo();
+ String[] msbInfo = getMsbIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("127.0.0.3"));
@@ -189,16 +172,16 @@ public class MicroServiceConfigTest { System.clearProperty(MSB_ADDR);
}
- @Test
+ @Ignore
public void getMsbAddrInfo_msb_not_registered() throws Exception {
System.setProperty(MSB_ADDR, "10.74.5.8:1545");
System.setProperty(HOSTNAME, "rule-mgmt");
- PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);
- EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))
+ PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class);
+ EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME)))
.andReturn("{}");
PowerMock.replayAll();
- String[] msbInfo = getMsbAddrInfo();
+ String[] msbInfo = getMsbIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("10.74.5.8"));
@@ -209,16 +192,14 @@ public class MicroServiceConfigTest { }
@Test
- public void getServiceAddrInfo_msb_registered() throws Exception {
+ public void getMicroServiceIpAndPort_service_registered_to_consul() throws Exception {
System.setProperty(HOSTNAME, "rule-mgmt");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("{\"rule-mgmt\": \"[\\\"127.0.0.3:5432\\\"]\"}");
+ .andReturn("[{\"ServiceAddress\": \"127.0.0.3\", \"ServicePort\": \"5432\"}]");
PowerMock.replayAll();
- String[] msbInfo = getServiceAddrInfo();
+ String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("127.0.0.3"));
@@ -228,16 +209,14 @@ public class MicroServiceConfigTest { }
@Test
- public void getServiceAddrInfo_msb_not_registered() throws Exception {
+ public void getMicroServiceIpAndPort_service_not_registered_to_consul() throws Exception {
System.setProperty(HOSTNAME, "10.74.5.8:1545");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("{}");
+ .andReturn("[]");
PowerMock.replayAll();
- String[] msbInfo = getServiceAddrInfo();
+ String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("10.74.5.8"));
@@ -247,16 +226,14 @@ public class MicroServiceConfigTest { }
@Test
- public void getServiceAddrInfo_msb_not_registered_full_addr() throws Exception {
+ public void getMicroServiceIpAndPort_service_not_registered_full_addr() throws Exception {
System.setProperty(HOSTNAME, "http://10.74.5.8:1545");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
.andReturn("{}");
PowerMock.replayAll();
- String[] msbInfo = getServiceAddrInfo();
+ String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("10.74.5.8"));
@@ -266,16 +243,14 @@ public class MicroServiceConfigTest { }
@Test
- public void getServiceAddrInfo_msb_not_registered_no_port() throws Exception {
+ public void getMicroServiceIpAndPort_service_not_registered_no_port() throws Exception {
System.setProperty(HOSTNAME, "http://10.74.5.8");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
.andReturn("{}");
PowerMock.replayAll();
- String[] msbInfo = getServiceAddrInfo();
+ String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("10.74.5.8"));
@@ -285,16 +260,14 @@ public class MicroServiceConfigTest { }
@Test
- public void getServiceAddrInfo_msb_not_registered_only_ip() throws Exception {
+ public void getMicroServiceIpAndPort_service_not_registered_only_ip() throws Exception {
System.setProperty(HOSTNAME, "10.74.5.8");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
.andReturn("{}");
PowerMock.replayAll();
- String[] msbInfo = getServiceAddrInfo();
+ String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("10.74.5.8"));
@@ -304,16 +277,14 @@ public class MicroServiceConfigTest { }
@Test
- public void getServiceAddrInfo_msb_not_registered_full_addr_https() throws Exception {
+ public void getMicroServiceIpAndPort_service_not_registered_full_addr_https() throws Exception {
System.setProperty(HOSTNAME, "https://10.74.5.8:5432");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("{}");
+ .andReturn("[]");
PowerMock.replayAll();
- String[] msbInfo = getServiceAddrInfo();
+ String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("10.74.5.8"));
|