d770b56c552545cda449a63ee9f2930d6ea59f25
[policy/api.git] / main / src / test / java / org / onap / policy / api / main / startstop / TestMain.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
4  *  Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.api.main.startstop;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26
27 import org.junit.Test;
28 import org.onap.policy.api.main.parameters.CommonTestData;
29 import org.onap.policy.common.utils.network.NetworkUtil;
30
31 /**
32  * Class to perform unit test of Main.
33  *
34  */
35 public class TestMain {
36     private static final CommonTestData COMMON_TEST_DATA = new CommonTestData();
37
38     @Test
39     public void testMain() throws Exception {
40         COMMON_TEST_DATA.makeParameters("src/test/resources/parameters/ApiConfigParameters.json",
41                         "src/test/resources/parameters/ApiConfigParametersXXX.json", NetworkUtil.allocPort());
42         final String[] apiConfigParameters = { "-c", "src/test/resources/parameters/ApiConfigParametersXXX.json" };
43         final Main main = new Main(apiConfigParameters);
44         assertTrue(main.getParameters().isValid());
45         assertEquals(CommonTestData.API_GROUP_NAME, main.getParameters().getName());
46         main.shutdown();
47     }
48
49     @Test
50     public void testMain_NoArguments() {
51         final String[] apiConfigParameters = {};
52         final Main main = new Main(apiConfigParameters);
53         assertTrue(main.getParameters() == null);
54     }
55
56     @Test
57     public void testMain_InvalidArguments() {
58         final String[] apiConfigParameters = { "parameters/ApiConfigParameters.json" };
59         final Main main = new Main(apiConfigParameters);
60         assertTrue(main.getParameters() == null);
61     }
62
63     @Test
64     public void testMain_Help() {
65         final String[] apiConfigParameters = { "-h" };
66         Main.main(apiConfigParameters);
67     }
68
69     @Test
70     public void testMain_InvalidParameters() {
71         final String[] apiConfigParameters = { "-c", "parameters/ApiConfigParameters_InvalidName.json" };
72         final Main main = new Main(apiConfigParameters);
73         assertTrue(main.getParameters() == null);
74     }
75 }