/**\r
- * Copyright 2017 ZTE Corporation.\r
- *\r
+ * Copyright 2017-2020 ZTE Corporation.\r
+ * <p>\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
+ * <p>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p>\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
\r
package org.onap.holmes.common.utils;\r
\r
-import static org.onap.holmes.common.config.MicroServiceConfig.HOSTNAME;\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.onap.holmes.common.msb.MicroserviceBusRest;\r
-import org.onap.holmes.common.api.entity.ServiceRegisterEntity;\r
+import org.junit.runner.RunWith;\r
import org.onap.holmes.common.config.MicroServiceConfig;\r
+import org.onap.holmes.common.exception.CorrelationException;\r
+import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;\r
+import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;\r
+import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;\r
import org.powermock.api.easymock.PowerMock;\r
import org.powermock.core.classloader.annotations.PowerMockIgnore;\r
import org.powermock.core.classloader.annotations.PrepareForTest;\r
-import org.powermock.modules.junit4.rule.PowerMockRule;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
\r
-@PrepareForTest({ConsumerFactory.class, MicroServiceConfig.class})\r
+@PrepareForTest({MicroServiceConfig.class, MSBServiceClient.class, MSBRegisterUtil.class})\r
@PowerMockIgnore({"javax.ws.*"})\r
+@RunWith(PowerMockRunner.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
- private ServiceRegisterEntity initServiceEntity() {\r
- String[] serviceAddrInfo = MicroServiceConfig.getServiceAddrInfo();\r
- ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity();\r
- serviceRegisterEntity.setServiceName("holmes-rule-mgmt");\r
- serviceRegisterEntity.setProtocol("REST");\r
- serviceRegisterEntity.setVersion("v1");\r
- serviceRegisterEntity.setUrl("/api/holmes-rule-mgmt/v1");\r
- serviceRegisterEntity.setSingleNode(serviceAddrInfo[0], serviceAddrInfo[1], 0);\r
- serviceRegisterEntity.setVisualRange("1|0");\r
- return serviceRegisterEntity;\r
- }\r
\r
- class MicroserviceBusRestProxy implements MicroserviceBusRest {\r
+ @Test\r
+ public void test_register2Msb_normal() throws Exception {\r
+ MicroServiceInfo msi = new MicroServiceInfo();\r
+ String[] msbAddrInfo = {"127.0.0.1", "80"};\r
+\r
+ PowerMock.mockStatic(MicroServiceConfig.class);\r
+ EasyMock.expect(MicroServiceConfig.getMsbIpAndPort()).andReturn(msbAddrInfo);\r
+\r
+ MSBServiceClient client = PowerMock.createMock(MSBServiceClient.class);\r
+ PowerMock.expectNew(MSBServiceClient.class, msbAddrInfo[0], Integer.parseInt(msbAddrInfo[1])).andReturn(client);\r
\r
- @Override\r
- public ServiceRegisterEntity registerServce(@QueryParam("createOrUpdate") String createOrUpdate,\r
- ServiceRegisterEntity entity) {\r
- return null;\r
+ EasyMock.expect(client.registerMicroServiceInfo(msi, false)).andReturn(null);\r
+\r
+ EasyMock.expect(client.registerMicroServiceInfo(msi, false)).andReturn(new MicroServiceFullInfo());\r
+\r
+ PowerMock.replayAll();\r
+\r
+ try {\r
+ msbRegisterUtil.register2Msb(msi);\r
+ } catch (CorrelationException e) {\r
+ // Do nothing\r
}\r
+\r
+ PowerMock.verifyAll();\r
}\r
}
\ No newline at end of file