summaryrefslogtreecommitdiffstats
path: root/holmes-actions/src/test/java
diff options
context:
space:
mode:
authorGuangrongFu <fu.guangrong@zte.com.cn>2020-10-22 16:56:16 +0800
committerGuangrongFu <fu.guangrong@zte.com.cn>2020-10-22 17:28:30 +0800
commit59d22c8f5ed81e1221ee6e9c5364a8baf5bc3a20 (patch)
tree9c0194c635f3047ccb262663e28e2c796db83f58 /holmes-actions/src/test/java
parent3cec62c66fa20ff781ace2c0bb5261f9fabbf0b1 (diff)
Fixed MSB Registration Failure
Issue-ID: HOLMES-368 Change-Id: I9a5b3275e7c58265992796bff3033acfa7b595db Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/test/java')
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java42
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/engine/dao/EngineEntityMapperTest.java10
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/JerseyClientTest.java47
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java64
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java93
5 files changed, 167 insertions, 89 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 a87ba67..fbc22e5 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
@@ -43,23 +43,27 @@ public class MicroServiceConfigTest {
@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
@@ -159,7 +163,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 +178,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 +199,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 +257,7 @@ public class MicroServiceConfigTest {
assertThat(msbInfo[0], equalTo(ip));
assertThat(msbInfo[1], equalTo(port));
- System.clearProperty(MSB_ADDR);
+ System.clearProperty(HOSTNAME);
}
@Test
@@ -268,7 +276,7 @@ public class MicroServiceConfigTest {
assertThat(msbInfo[0], equalTo(ip));
assertThat(msbInfo[1], equalTo("80"));
- System.clearProperty(MSB_ADDR);
+ System.clearProperty(HOSTNAME);
}
@Test
@@ -287,7 +295,7 @@ public class MicroServiceConfigTest {
assertThat(msbInfo[0], equalTo(ip));
assertThat(msbInfo[1], equalTo("80"));
- System.clearProperty(MSB_ADDR);
+ System.clearProperty(HOSTNAME);
}
@Test
@@ -307,7 +315,7 @@ public class MicroServiceConfigTest {
assertThat(msbInfo[0], equalTo(ip));
assertThat(msbInfo[1], equalTo(port));
- System.clearProperty(MSB_ADDR);
+ System.clearProperty(HOSTNAME);
}
@Test
@@ -342,7 +350,7 @@ public class MicroServiceConfigTest {
@Test
public void isValidIpAddress_invalid_ip_with_port() throws Exception {
- boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "holmes-rule-mgmt:80");
+ boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "holmes-rule-mgmt:443");
assertThat(res, is(false));
}
@@ -354,7 +362,7 @@ public class MicroServiceConfigTest {
@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");
+ boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "https://holmes-rule-mgmt:443");
assertThat(res, is(false));
}
} \ No newline at end of file
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/engine/dao/EngineEntityMapperTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/engine/dao/EngineEntityMapperTest.java
index ad684da..99b14ab 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/engine/dao/EngineEntityMapperTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/engine/dao/EngineEntityMapperTest.java
@@ -23,18 +23,12 @@ import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import java.io.InputStream;
-import java.io.Reader;
-import java.math.BigDecimal;
-import java.net.URL;
-import java.sql.*;
-import java.util.Calendar;
-import java.util.Map;
+import java.sql.ResultSet;
import static org.easymock.EasyMock.expect;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ResultSet.class})
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/JerseyClientTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/JerseyClientTest.java
new file mode 100644
index 0000000..6c95ccb
--- /dev/null
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/JerseyClientTest.java
@@ -0,0 +1,47 @@
+/**
+ * Copyright 2020 ZTE Corporation.
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.common.utils;
+
+import org.junit.Test;
+import org.powermock.reflect.internal.WhiteboxImpl;
+
+public class JerseyClientTest {
+
+ private JerseyClient jerseyClient = new JerseyClient();
+
+ @Test
+ public void http() {
+ jerseyClient.httpClient();
+ }
+
+ @Test
+ public void https() throws Exception {
+ WhiteboxImpl.invokeMethod(jerseyClient, "init");
+ jerseyClient.httpsClient();
+ }
+
+ @Test
+ public void clientHttp() {
+ jerseyClient.client(false);
+ }
+
+ @Test
+ public void clientHttps() throws Exception {
+ WhiteboxImpl.invokeMethod(jerseyClient, "init");
+ jerseyClient.client(true);
+ }
+} \ No newline at end of file
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java
deleted file mode 100644
index e6b6f9d..0000000
--- a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Copyright 2017-2020 ZTE Corporation.
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onap.holmes.common.utils;
-
-import org.easymock.EasyMock;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.onap.holmes.common.config.MicroServiceConfig;
-import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
-import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
-import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@PrepareForTest({MicroServiceConfig.class, MSBServiceClient.class, MSBRegisterUtil.class})
-@PowerMockIgnore({"javax.ws.*"})
-@RunWith(PowerMockRunner.class)
-public class MSBRegisterUtilTest {
-
- private MSBRegisterUtil msbRegisterUtil = new MSBRegisterUtil();
-
- @Test
- public void test_register2Msb_normal() throws Exception {
- MicroServiceInfo msi = new MicroServiceInfo();
- String[] msbAddrInfo = {"127.0.0.1", "80"};
-
- PowerMock.mockStatic(MicroServiceConfig.class);
- EasyMock.expect(MicroServiceConfig.getMsbIpAndPort()).andReturn(msbAddrInfo);
-
- MSBServiceClient client = PowerMock.createMock(MSBServiceClient.class);
- PowerMock.expectNew(MSBServiceClient.class, msbAddrInfo[0], Integer.parseInt(msbAddrInfo[1])).andReturn(client);
-
- EasyMock.expect(client.registerMicroServiceInfo(msi, false)).andReturn(null);
-
- EasyMock.expect(client.registerMicroServiceInfo(msi, false)).andReturn(new MicroServiceFullInfo());
-
- PowerMock.replayAll();
-
- try {
- msbRegisterUtil.register2Msb(msi);
- } catch (CorrelationException e) {
- // Do nothing
- }
-
- PowerMock.verifyAll();
- }
-} \ No newline at end of file
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java
new file mode 100644
index 0000000..0637586
--- /dev/null
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java
@@ -0,0 +1,93 @@
+/**
+ * Copyright 2017-2020 ZTE Corporation.
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.holmes.common.utils;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.holmes.common.config.MicroServiceConfig;
+import org.onap.holmes.common.exception.CorrelationException;
+import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import static org.easymock.EasyMock.expect;
+import static org.powermock.api.easymock.PowerMock.createMock;
+
+@PrepareForTest({MicroServiceConfig.class})
+@RunWith(PowerMockRunner.class)
+public class MsbRegisterTest {
+ @Test
+ public void test_register2Msb_normal() {
+ MicroServiceInfo msi = new MicroServiceInfo();
+ String[] msbAddrInfo = {"127.0.0.1", "80"};
+
+ PowerMock.mockStatic(MicroServiceConfig.class);
+ expect(MicroServiceConfig.getMsbIpAndPort()).andReturn(msbAddrInfo);
+
+ JerseyClient mockedJerseyClient = createMock(JerseyClient.class);
+
+ Client mockedClient = createMock(Client.class);
+ expect(mockedJerseyClient.client(false)).andReturn(mockedClient);
+
+ WebTarget mockedWebTarget = createMock(WebTarget.class);
+ expect(mockedClient.target("http://127.0.0.1:80/api/microservices/v1/services")).andReturn(mockedWebTarget);
+
+
+ expect(mockedWebTarget.queryParam("createOrUpdate", true)).andReturn(mockedWebTarget).times(2);
+
+ Invocation.Builder mockedBuilder = createMock(Invocation.Builder.class);
+ expect(mockedWebTarget.request(MediaType.APPLICATION_JSON)).andReturn(mockedBuilder).times(2);
+
+ Response mockedResponse = createMock(Response.class);
+ expect(mockedBuilder.post(Entity.entity(msi, MediaType.APPLICATION_JSON)))
+ .andReturn(mockedResponse);
+ expect(mockedResponse.getStatus()).andReturn(300);
+
+ expect(mockedBuilder.post(Entity.entity(msi, MediaType.APPLICATION_JSON)))
+ .andReturn(mockedResponse);
+ expect(mockedResponse.getStatus()).andReturn(201);
+ expect(mockedResponse.readEntity(String.class)).andReturn("Error");
+ expect(mockedResponse.readEntity(String.class)).andReturn("{\"serviceName\":\"holmes-engine-mgmt\"," +
+ "\"version\":\"v1\",\"url\":\"/api/holmes-engine-mgmt/v1\",\"protocol\":\"REST\"," +
+ "\"visualRange\":\"0|1\",\"lb_policy\":\"\",\"publish_port\":\"\",\"namespace\":\"\"," +
+ "\"network_plane_type\":\"\",\"host\":\"\",\"path\":\"/api/holmes-engine-mgmt/v1\"," +
+ "\"enable_ssl\":true,\"nodes\":[{\"ip\":\"127.0.0.1\",\"port\":\"9102\",\"checkType\":\"\"," +
+ "\"checkUrl\":\"\",\"tls_skip_verify\":true,\"ha_role\":\"\",\"nodeId\":\"_v1_holmes-engine-mgmt_127.0.0.1_9102\"," +
+ "\"status\":\"passing\"}],\"metadata\":[],\"labels\":[],\"status\":\"1\",\"is_manual\":false}");
+
+
+ MsbRegister msbRegister = new MsbRegister(mockedJerseyClient);
+
+ PowerMock.replayAll();
+
+ try {
+ msbRegister.register2Msb(msi);
+ } catch (CorrelationException e) {
+ // Do nothing
+ }
+
+ PowerMock.verifyAll();
+ }
+} \ No newline at end of file