97a8d114b7957bc708fa4aaf87043af2dcd7d91f
[vfc/nfvo/wfengine.git] / CommonLibrary / common-util / src / test / java / org / openo / baseservice / util / impl / SystemEnvVariablesDefImplTest.java
1 /*
2  * Copyright (c) 2016, Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.openo.baseservice.util.impl;
17
18 import java.io.File;
19 import java.io.IOException;
20
21 import org.junit.AfterClass;
22 import org.junit.Before;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.openo.baseservice.util.inf.SystemEnvVariables;
27
28 import junit.framework.Assert;
29 import mockit.Mocked;
30 import mockit.NonStrictExpectations;
31 import mockit.integration.junit4.JMockit;
32 import net.jcip.annotations.NotThreadSafe;
33
34 /**
35  * <br/>
36  * <p>
37  * </p>
38  * 
39  * @author
40  * @version SDNO 0.5 08-Jun-2016
41  */
42 @RunWith(JMockit.class)
43 @NotThreadSafe
44 public class SystemEnvVariablesDefImplTest {
45
46     /**
47      * <br/>
48      * 
49      * @throws java.lang.Exception
50      * @since SDNO 0.5
51      */
52     @BeforeClass
53     public static void setUpBeforeClass() throws Exception {
54     }
55
56     /**
57      * <br/>
58      * 
59      * @throws java.lang.Exception
60      * @since SDNO 0.5
61      */
62     @AfterClass
63     public static void tearDownAfterClass() throws Exception {
64     }
65
66     /**
67      * <br/>
68      * 
69      * @throws java.lang.Exception
70      * @since SDNO 0.5
71      */
72     @Before
73     public void setUp() throws Exception {
74     }
75
76     @Test
77     public void testGetAppRootException() throws Exception {
78         new NonStrictExpectations() {
79
80             @Mocked
81             File file;
82
83             {
84                 file = new File(".");
85                 file.getCanonicalPath();
86                 result = new IOException();
87             }
88
89         };
90         final SystemEnvVariables envVars =new SystemEnvVariablesDefImpl();
91         System.setProperty("catalina.base", ".");
92         final String actual = envVars.getAppRoot();
93         Assert.assertEquals(null, actual);
94     }
95
96
97     /**
98      * Test method for
99      * {@link org.openo.baseservice.util.impl.SystemEnvVariablesDefImpl#getAppRoot()}.
100      * 
101      * @throws Exception
102      */
103     @Test
104     public void testGetAppRoot() throws Exception {
105         final SystemEnvVariables envVars = new SystemEnvVariablesDefImpl();
106         final File file = new File(".");
107         final String expected = file.getCanonicalPath();
108         System.setProperty("catalina.base", ".");
109         final String actual = envVars.getAppRoot();
110         Assert.assertEquals(expected, actual);
111     }
112
113 }