Add Unit Tests
[holmes/common.git] / holmes-actions / src / test / java / org / onap / holmes / common / utils / MSBRegisterUtilTest.java
1 /**\r
2  * Copyright 2017 ZTE Corporation.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package org.onap.holmes.common.utils;\r
18 \r
19 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\r
20 import javax.ws.rs.QueryParam;\r
21 \r
22 import org.easymock.EasyMock;\r
23 import org.junit.Rule;\r
24 import org.junit.Test;\r
25 import org.junit.runner.RunWith;\r
26 import org.onap.holmes.common.exception.CorrelationException;\r
27 import org.onap.holmes.common.msb.MicroserviceBusRest;\r
28 import org.onap.holmes.common.api.entity.ServiceRegisterEntity;\r
29 import org.onap.holmes.common.config.MicroServiceConfig;\r
30 import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;\r
31 import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;\r
32 import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;\r
33 import org.powermock.api.easymock.PowerMock;\r
34 import org.powermock.core.classloader.annotations.PowerMockIgnore;\r
35 import org.powermock.core.classloader.annotations.PrepareForTest;\r
36 import org.powermock.modules.junit4.PowerMockRunner;\r
37 import org.powermock.modules.junit4.rule.PowerMockRule;\r
38 \r
39 @PrepareForTest({MicroServiceConfig.class, MSBServiceClient.class, MSBRegisterUtil.class})\r
40 @PowerMockIgnore({"javax.ws.*"})\r
41 public class MSBRegisterUtilTest {\r
42 \r
43     @Rule\r
44     public PowerMockRule powerMockRule = new PowerMockRule();\r
45     private MSBRegisterUtil msbRegisterUtil = new MSBRegisterUtil();\r
46 \r
47     @Test\r
48     public void test_register2Msb_normal() throws Exception {\r
49         MicroServiceInfo msi = new MicroServiceInfo();\r
50         String[] msbAddrInfo = {"127.0.0.1", "80"};\r
51 \r
52         PowerMock.mockStatic(MicroServiceConfig.class);\r
53         EasyMock.expect(MicroServiceConfig.getMsbIpAndPort()).andReturn(msbAddrInfo);\r
54 \r
55         MSBServiceClient client = PowerMock.createMock(MSBServiceClient.class);\r
56         PowerMock.expectNew(MSBServiceClient.class, msbAddrInfo[0], Integer.parseInt(msbAddrInfo[1])).andReturn(client);\r
57 \r
58         EasyMock.expect(client.registerMicroServiceInfo(msi, false)).andReturn(null);\r
59 \r
60         EasyMock.expect(client.registerMicroServiceInfo(msi, false)).andReturn(new MicroServiceFullInfo());\r
61 \r
62         PowerMock.replayAll();\r
63 \r
64         try {\r
65             msbRegisterUtil.register2Msb(msi);\r
66         } catch (CorrelationException e) {\r
67             // Do nothing\r
68         }\r
69 \r
70         PowerMock.verifyAll();\r
71     }\r
72 }