Merge "Release 1.14.0 maven artifact"
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / util / AAIConfigCommandLinePropGetterTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.aai.util;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.security.Permission;
26
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.aai.AAISetup;
31
32 public class AAIConfigCommandLinePropGetterTest extends AAISetup {
33
34     private SecurityManager m;
35     private TestSecurityManager sm;
36
37     @Before
38     public void setUp() {
39         m = System.getSecurityManager();
40         sm = new TestSecurityManager();
41         System.setSecurityManager(sm);
42     }
43
44     @After
45     public void tearDown() {
46         System.setSecurityManager(m);
47     }
48
49     @Test
50     public void testMainNoArgs() {
51         try {
52             AAIConfigCommandLinePropGetter.main(new String[] {});
53         } catch (SecurityException se) {
54             // assert main method ends with System.exit(0)
55             assertEquals("0", se.getMessage());
56         }
57     }
58
59     @Test
60     public void testMainReadProp() {
61         try {
62             AAIConfigCommandLinePropGetter.main(new String[] {"aai.primary.filetransfer.serverlist"});
63         } catch (SecurityException se) {
64             // assert main method ends with System.exit(0)
65             assertEquals("0", se.getMessage());
66         }
67     }
68
69     @Test
70     public void testMainOneArg() {
71         try {
72             AAIConfigCommandLinePropGetter.main(new String[] {"one"});
73         } catch (SecurityException se) {
74             // assert main method ends with System.exit(0)
75             assertEquals("0", se.getMessage());
76         }
77     }
78
79     @Test
80     public void testMainMoreThanOneArg() {
81         try {
82             AAIConfigCommandLinePropGetter.main(new String[] {"one", "two"});
83         } catch (SecurityException se) {
84             // assert main method ends with System.exit(0)
85             assertEquals("0", se.getMessage());
86         }
87     }
88 }
89
90
91 class TestSecurityManager extends SecurityManager {
92     @Override
93     public void checkPermission(Permission permission) {
94         if ("exitVM".equals(permission.getName())) {
95             throw new SecurityException("System.exit attempted and blocked.");
96         }
97     }
98
99     @Override
100     public void checkExit(int status) {
101         throw new SecurityException(Integer.toString(status));
102     }
103 }