import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\r
import java.io.IOException;\r
import lombok.extern.slf4j.Slf4j;\r
-import org.glassfish.jersey.client.ClientConfig;\r
import org.jvnet.hk2.annotations.Service;\r
import org.openo.holmes.common.api.entity.ServiceRegisterEntity;\r
import org.openo.holmes.common.config.MicroServiceConfig;\r
}\r
\r
private boolean inner_register(ServiceRegisterEntity entity) {\r
- ClientConfig config = new ClientConfig();\r
try {\r
log.info("msbServerAddr:" + MicroServiceConfig.getMsbServerAddr());\r
log.info("entity:" + entity);\r
MicroserviceBusRest resourceserviceproxy = ConsumerFactory.createConsumer(\r
- MicroServiceConfig.getMsbServerAddr(), config, MicroserviceBusRest.class);\r
+ MicroServiceConfig.getMsbServerAddr(), MicroserviceBusRest.class);\r
resourceserviceproxy.registerServce("false", entity);\r
} catch (Exception error) {\r
log.error("microservice register failed!" + error.getMessage());\r
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\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
+ * 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
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.openo.holmes.common.config;\r
+\r
+import static org.hamcrest.core.IsEqual.equalTo;\r
+import static org.junit.Assert.assertThat;\r
+\r
+import org.junit.Test;\r
+\r
+public class MicroServiceConfigTest {\r
+\r
+ @Test\r
+ public void getMsbServerAddrTest() {\r
+ System.setProperty("MSB_ADDR", "test");\r
+ assertThat("http://test", equalTo(MicroServiceConfig.getMsbServerAddr()));\r
+ System.clearProperty("MSB_ADDR");\r
+ }\r
+\r
+ @Test\r
+ public void getServiceIpTest() {\r
+ System.setProperty("SERVICE_IP", "test");\r
+ assertThat("test", equalTo(MicroServiceConfig.getServiceIp()));\r
+ System.clearProperty("SERVICE_IP");\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\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
+ * 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
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.openo.holmes.common.utils;\r
+\r
+import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\r
+import javax.ws.rs.QueryParam;\r
+import org.easymock.EasyMock;\r
+import org.junit.Rule;\r
+import org.junit.Test;\r
+import org.openo.holmes.common.api.entity.ServiceRegisterEntity;\r
+import org.openo.holmes.common.config.MicroServiceConfig;\r
+import org.openo.holmes.common.msb.MicroserviceBusRest;\r
+import org.powermock.api.easymock.PowerMock;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.rule.PowerMockRule;\r
+\r
+@PrepareForTest(ConsumerFactory.class)\r
+public class MSBRegisterUtilTest {\r
+\r
+ @Rule\r
+ public PowerMockRule powerMockRule = new PowerMockRule();\r
+ private MSBRegisterUtil msbRegisterUtil = new MSBRegisterUtil();\r
+ private MicroserviceBusRest microserviceBusRest = new MicroserviceBusRestProxy();\r
+\r
+ @Test\r
+ public void registerTest() throws Exception {\r
+ ServiceRegisterEntity entity = initServiceEntity();\r
+ PowerMock.mockStatic(ConsumerFactory.class);\r
+ EasyMock.expect(ConsumerFactory\r
+ .createConsumer(EasyMock.anyObject(String.class), EasyMock.anyObject(Class.class)))\r
+ .andReturn(microserviceBusRest);\r
+ PowerMock.replayAll();\r
+\r
+ msbRegisterUtil.register(initServiceEntity());\r
+\r
+ PowerMock.verifyAll();\r
+ }\r
+\r
+ private ServiceRegisterEntity initServiceEntity() {\r
+ ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity();\r
+ serviceRegisterEntity.setServiceName("holmes-rule-mgmt");\r
+ serviceRegisterEntity.setProtocol("REST");\r
+ serviceRegisterEntity.setVersion("v1");\r
+ serviceRegisterEntity.setUrl("/openoapi/holmes-rule-mgmt/v1");\r
+ serviceRegisterEntity.setSingleNode(MicroServiceConfig.getServiceIp(), "9101", 0);\r
+ serviceRegisterEntity.setVisualRange("1|0");\r
+ return serviceRegisterEntity;\r
+ }\r
+\r
+ class MicroserviceBusRestProxy implements MicroserviceBusRest {\r
+\r
+ @Override\r
+ public ServiceRegisterEntity registerServce(@QueryParam("createOrUpdate") String createOrUpdate,\r
+ ServiceRegisterEntity entity) throws Exception {\r
+ return null;\r
+ }\r
+ }\r
+}
\ No newline at end of file