2 * Copyright 2017 ZTE Corporation.
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
17 package org.onap.holmes.common.utils;
\r
19 import org.easymock.EasyMock;
\r
20 import org.junit.Rule;
\r
21 import org.junit.Test;
\r
22 import org.onap.holmes.common.config.MicroServiceConfig;
\r
23 import org.onap.holmes.common.exception.CorrelationException;
\r
24 import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
\r
25 import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
\r
26 import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
\r
27 import org.powermock.api.easymock.PowerMock;
\r
28 import org.powermock.core.classloader.annotations.PowerMockIgnore;
\r
29 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
30 import org.powermock.modules.junit4.rule.PowerMockRule;
\r
32 @PrepareForTest({MicroServiceConfig.class, MSBServiceClient.class, MSBRegisterUtil.class})
\r
33 @PowerMockIgnore({"javax.ws.*"})
\r
34 public class MSBRegisterUtilTest {
\r
37 public PowerMockRule powerMockRule = new PowerMockRule();
\r
38 private MSBRegisterUtil msbRegisterUtil = new MSBRegisterUtil();
\r
41 public void test_register2Msb_normal() throws Exception {
\r
42 MicroServiceInfo msi = new MicroServiceInfo();
\r
43 String[] msbAddrInfo = {"127.0.0.1", "80"};
\r
45 PowerMock.mockStatic(MicroServiceConfig.class);
\r
46 EasyMock.expect(MicroServiceConfig.getMsbIpAndPort()).andReturn(msbAddrInfo);
\r
48 MSBServiceClient client = PowerMock.createMock(MSBServiceClient.class);
\r
49 PowerMock.expectNew(MSBServiceClient.class, msbAddrInfo[0], Integer.parseInt(msbAddrInfo[1])).andReturn(client);
\r
51 EasyMock.expect(client.registerMicroServiceInfo(msi, false)).andReturn(null);
\r
53 EasyMock.expect(client.registerMicroServiceInfo(msi, false)).andReturn(new MicroServiceFullInfo());
\r
55 PowerMock.replayAll();
\r
58 msbRegisterUtil.register2Msb(msi);
\r
59 } catch (CorrelationException e) {
\r
63 PowerMock.verifyAll();
\r