aboutsummaryrefslogtreecommitdiffstats
path: root/sdclient/discovery-service/src/test/java/org/onap/msb/sdclient/wrapper/util/ConfigUtilTest.java
blob: b8e45f14eb4a55eb1ae9a3fdc135be8db2d0c785 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
 * Copyright 2016-2017 ZTE, Inc. and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package org.onap.msb.sdclient.wrapper.util;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.msb.sdclient.DiscoverAppConfig;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest({DiscoverAppConfig.class,ConfigUtil.class})
@PowerMockIgnore( {"javax.management.*"})
public class ConfigUtilTest {

	 private static ConfigUtil configUtil =  ConfigUtil.getInstance();
	 private static DiscoverAppConfig discoverConfig;
	 
	 @BeforeClass
	    public static void setUpBeforeClass() throws Exception {
		 discoverConfig=PowerMockito.mock(DiscoverAppConfig.class);
	     PowerMockito.when(discoverConfig.getConsulAdderss()).thenReturn("127.0.0.1:8500");
	     PowerMockito.when(discoverConfig.getConsulRegisterMode()).thenReturn("catalog");

	 }
	 
	 @Test
	    public void testinitConsulClientInfo() {
		 configUtil.initConsulClientInfo(discoverConfig);
		 Assert.assertEquals("127.0.0.1:8500",configUtil.getConsulAddress());
		 
		 PowerMockito.mockStatic(System.class);        
	     PowerMockito.when(System.getenv("CONSUL_IP")).thenReturn("10.74.151.26");
	     configUtil.initConsulClientInfo(discoverConfig);
		 Assert.assertEquals("10.74.151.26:8500",configUtil.getConsulAddress());
		 
	 }
	 
	 @Test
	    public void testinitTCP_UDP_portRange() {
		  PowerMockito.mockStatic(System.class);        
	      PowerMockito.when(System.getenv("TCP_UDP_PORT_RANGE_START")).thenReturn("8500");
	      PowerMockito.when(System.getenv("TCP_UDP_PORT_RANGE_END")).thenReturn("8600");  
	      
	      configUtil.initTCP_UDP_portRange();
	      
	      Assert.assertEquals("8500",configUtil.getTcpudpPortRangeStart());
	      Assert.assertEquals("8600",configUtil.getTcpudpPortRangeEnd());
	 }
	 
	 @Test
	    public void testinitConsulRegisterMode() {
		 
		 configUtil.initConsulRegisterMode(discoverConfig);
		 Assert.assertEquals("catalog",configUtil.getConsulRegisterMode());
		 
		  PowerMockito.mockStatic(System.class);        
	      PowerMockito.when(System.getenv("CONSUL_REGISTER_MODE")).thenReturn("agent");
	      configUtil.initConsulRegisterMode(discoverConfig);
	      Assert.assertEquals("agent",configUtil.getConsulRegisterMode());
	 }
}