2 * Copyright 2016-2017 ZTE, Inc. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
14 package org.onap.msb.sdclient.wrapper.util;
16 import org.junit.Assert;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.onap.msb.sdclient.DiscoverAppConfig;
21 import org.powermock.api.mockito.PowerMockito;
22 import org.powermock.core.classloader.annotations.PowerMockIgnore;
23 import org.powermock.core.classloader.annotations.PrepareForTest;
24 import org.powermock.modules.junit4.PowerMockRunner;
26 @RunWith(PowerMockRunner.class)
27 @PrepareForTest({DiscoverAppConfig.class,ConfigUtil.class})
28 @PowerMockIgnore( {"javax.management.*"})
29 public class ConfigUtilTest {
31 private static ConfigUtil configUtil = ConfigUtil.getInstance();
32 private static DiscoverAppConfig discoverConfig;
35 public static void setUpBeforeClass() throws Exception {
36 discoverConfig=PowerMockito.mock(DiscoverAppConfig.class);
37 PowerMockito.when(discoverConfig.getConsulAdderss()).thenReturn("127.0.0.1:8500");
38 PowerMockito.when(discoverConfig.getConsulRegisterMode()).thenReturn("catalog");
43 public void testinitConsulClientInfo() {
44 configUtil.initConsulClientInfo(discoverConfig);
45 Assert.assertEquals("127.0.0.1:8500",configUtil.getConsulAddress());
47 PowerMockito.mockStatic(System.class);
48 PowerMockito.when(System.getenv("CONSUL_IP")).thenReturn("10.74.151.26");
49 configUtil.initConsulClientInfo(discoverConfig);
50 Assert.assertEquals("10.74.151.26:8500",configUtil.getConsulAddress());
55 public void testinitTCP_UDP_portRange() {
56 PowerMockito.mockStatic(System.class);
57 PowerMockito.when(System.getenv("TCP_UDP_PORT_RANGE_START")).thenReturn("8500");
58 PowerMockito.when(System.getenv("TCP_UDP_PORT_RANGE_END")).thenReturn("8600");
60 configUtil.initTCP_UDP_portRange();
62 Assert.assertEquals("8500",configUtil.getTcpudpPortRangeStart());
63 Assert.assertEquals("8600",configUtil.getTcpudpPortRangeEnd());
67 public void testinitConsulRegisterMode() {
69 configUtil.initConsulRegisterMode(discoverConfig);
70 Assert.assertEquals("catalog",configUtil.getConsulRegisterMode());
72 PowerMockito.mockStatic(System.class);
73 PowerMockito.when(System.getenv("CONSUL_REGISTER_MODE")).thenReturn("agent");
74 configUtil.initConsulRegisterMode(discoverConfig);
75 Assert.assertEquals("agent",configUtil.getConsulRegisterMode());