2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.util;
24 import static org.junit.Assert.assertEquals;
26 import java.security.Permission;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.aai.AAISetup;
33 public class AAIConfigCommandLinePropGetterTest extends AAISetup {
35 private SecurityManager m;
36 private TestSecurityManager sm;
41 m = System.getSecurityManager();
42 sm = new TestSecurityManager();
43 System.setSecurityManager(sm);
47 public void tearDown()
49 System.setSecurityManager(m);
53 public void testMainNoArgs() {
55 AAIConfigCommandLinePropGetter.main(new String[] {});
56 } catch (SecurityException se) {
57 // assert main method ends with System.exit(0)
58 assertEquals("0", se.getMessage());
63 public void testMainReadProp() {
65 AAIConfigCommandLinePropGetter.main(new String[] {"aai.primary.filetransfer.serverlist"});
66 } catch (SecurityException se) {
67 // assert main method ends with System.exit(0)
68 assertEquals("0", se.getMessage());
73 public void testMainOneArg() {
75 AAIConfigCommandLinePropGetter.main(new String[] {"one"});
76 } catch (SecurityException se) {
77 // assert main method ends with System.exit(0)
78 assertEquals("0", se.getMessage());
83 public void testMainMoreThanOneArg() {
85 AAIConfigCommandLinePropGetter.main(new String[] {"one", "two"});
86 } catch (SecurityException se) {
87 // assert main method ends with System.exit(0)
88 assertEquals("0", se.getMessage());
93 class TestSecurityManager extends SecurityManager {
95 public void checkPermission(Permission permission) {
96 if ("exitVM".equals(permission.getName()))
98 throw new SecurityException("System.exit attempted and blocked.");
102 public void checkExit(int status) {
103 throw new SecurityException(Integer.toString(status));