diff options
author | 2017-03-14 19:12:07 +0800 | |
---|---|---|
committer | 2017-03-14 19:12:07 +0800 | |
commit | 29bf80d11209d1c4294cd0738f288e65f1be4a41 (patch) | |
tree | ec9cfc60a3866c2837c02f9c0d7a89bd592cb68d /holmes-actions | |
parent | e9d903e5f0c762e11d443994eac2ced51afbe3e3 (diff) |
Add UT for actions
Issue-ID: HOLMES-50
Change-Id: I295a72e8a8b522e48e43b8ee32152bdf71656e4d
Signed-off-by: youbowu <wu.youbo@zte.com.cn>
Diffstat (limited to 'holmes-actions')
3 files changed, 112 insertions, 3 deletions
diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/MSBRegisterUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/MSBRegisterUtil.java index e18a15c..91e28a6 100644 --- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/MSBRegisterUtil.java +++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/MSBRegisterUtil.java @@ -19,7 +19,6 @@ package org.openo.holmes.common.utils; import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
-import org.glassfish.jersey.client.ClientConfig;
import org.jvnet.hk2.annotations.Service;
import org.openo.holmes.common.api.entity.ServiceRegisterEntity;
import org.openo.holmes.common.config.MicroServiceConfig;
@@ -49,12 +48,11 @@ public class MSBRegisterUtil { }
private boolean inner_register(ServiceRegisterEntity entity) {
- ClientConfig config = new ClientConfig();
try {
log.info("msbServerAddr:" + MicroServiceConfig.getMsbServerAddr());
log.info("entity:" + entity);
MicroserviceBusRest resourceserviceproxy = ConsumerFactory.createConsumer(
- MicroServiceConfig.getMsbServerAddr(), config, MicroserviceBusRest.class);
+ MicroServiceConfig.getMsbServerAddr(), MicroserviceBusRest.class);
resourceserviceproxy.registerServce("false", entity);
} catch (Exception error) {
log.error("microservice register failed!" + error.getMessage());
diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/config/MicroServiceConfigTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/config/MicroServiceConfigTest.java new file mode 100644 index 0000000..7ec7fe6 --- /dev/null +++ b/holmes-actions/src/test/java/org/openo/holmes/common/config/MicroServiceConfigTest.java @@ -0,0 +1,39 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.openo.holmes.common.config;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class MicroServiceConfigTest {
+
+ @Test
+ public void getMsbServerAddrTest() {
+ System.setProperty("MSB_ADDR", "test");
+ assertThat("http://test", equalTo(MicroServiceConfig.getMsbServerAddr()));
+ System.clearProperty("MSB_ADDR");
+ }
+
+ @Test
+ public void getServiceIpTest() {
+ System.setProperty("SERVICE_IP", "test");
+ assertThat("test", equalTo(MicroServiceConfig.getServiceIp()));
+ System.clearProperty("SERVICE_IP");
+ }
+}
\ No newline at end of file diff --git a/holmes-actions/src/test/java/org/openo/holmes/common/utils/MSBRegisterUtilTest.java b/holmes-actions/src/test/java/org/openo/holmes/common/utils/MSBRegisterUtilTest.java new file mode 100644 index 0000000..0845981 --- /dev/null +++ b/holmes-actions/src/test/java/org/openo/holmes/common/utils/MSBRegisterUtilTest.java @@ -0,0 +1,72 @@ +/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.openo.holmes.common.utils;
+
+import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
+import javax.ws.rs.QueryParam;
+import org.easymock.EasyMock;
+import org.junit.Rule;
+import org.junit.Test;
+import org.openo.holmes.common.api.entity.ServiceRegisterEntity;
+import org.openo.holmes.common.config.MicroServiceConfig;
+import org.openo.holmes.common.msb.MicroserviceBusRest;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.rule.PowerMockRule;
+
+@PrepareForTest(ConsumerFactory.class)
+public class MSBRegisterUtilTest {
+
+ @Rule
+ public PowerMockRule powerMockRule = new PowerMockRule();
+ private MSBRegisterUtil msbRegisterUtil = new MSBRegisterUtil();
+ private MicroserviceBusRest microserviceBusRest = new MicroserviceBusRestProxy();
+
+ @Test
+ public void registerTest() throws Exception {
+ ServiceRegisterEntity entity = initServiceEntity();
+ PowerMock.mockStatic(ConsumerFactory.class);
+ EasyMock.expect(ConsumerFactory
+ .createConsumer(EasyMock.anyObject(String.class), EasyMock.anyObject(Class.class)))
+ .andReturn(microserviceBusRest);
+ PowerMock.replayAll();
+
+ msbRegisterUtil.register(initServiceEntity());
+
+ PowerMock.verifyAll();
+ }
+
+ private ServiceRegisterEntity initServiceEntity() {
+ ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity();
+ serviceRegisterEntity.setServiceName("holmes-rule-mgmt");
+ serviceRegisterEntity.setProtocol("REST");
+ serviceRegisterEntity.setVersion("v1");
+ serviceRegisterEntity.setUrl("/openoapi/holmes-rule-mgmt/v1");
+ serviceRegisterEntity.setSingleNode(MicroServiceConfig.getServiceIp(), "9101", 0);
+ serviceRegisterEntity.setVisualRange("1|0");
+ return serviceRegisterEntity;
+ }
+
+ class MicroserviceBusRestProxy implements MicroserviceBusRest {
+
+ @Override
+ public ServiceRegisterEntity registerServce(@QueryParam("createOrUpdate") String createOrUpdate,
+ ServiceRegisterEntity entity) throws Exception {
+ return null;
+ }
+ }
+}
\ No newline at end of file |