Speed up tests on policy-api
[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.assertj.core.api.Assertions.assertThatCode;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
27
28 import org.junit.Test;
29 import org.onap.policy.api.main.parameters.CommonTestData;
30 import org.onap.policy.common.utils.network.NetworkUtil;
31
32 /**
33  * Class to perform unit test of Main.
34  *
35  */
36 public class TestMain {
37     private static final CommonTestData COMMON_TEST_DATA = new CommonTestData();
38
39     @Test
40     public void testMain() throws Exception {
41         COMMON_TEST_DATA.makeParameters("src/test/resources/parameters/ApiConfigParameters_Https.json",
42                 "src/test/resources/parameters/ApiConfigParametersXXX.json", NetworkUtil.allocPort());
43         final String[] apiConfigParameters = {"-c", "src/test/resources/parameters/ApiConfigParametersXXX.json"};
44         final Main main = new Main(apiConfigParameters);
45         assertTrue(main.getParameters().isValid());
46         assertEquals(CommonTestData.API_GROUP_NAME, main.getParameters().getName());
47         main.shutdown();
48     }
49
50     @Test
51     public void testMain_NoArguments() {
52         final String[] apiConfigParameters = {};
53         final Main main = new Main(apiConfigParameters);
54         assertTrue(main.getParameters() == null);
55     }
56
57     @Test
58     public void testMain_InvalidArguments() {
59         final String[] apiConfigParameters = {"parameters/ApiConfigParameters.json"};
60         final Main main = new Main(apiConfigParameters);
61         assertTrue(main.getParameters() == null);
62     }
63
64     @Test
65     public void testMain_Help() {
66         final String[] apiConfigParameters = {"-h"};
67         assertThatCode(() -> Main.main(apiConfigParameters)).doesNotThrowAnyException();
68     }
69
70     @Test
71     public void testMain_InvalidParameters() {
72         final String[] apiConfigParameters = {"-c", "parameters/ApiConfigParameters_InvalidName.json"};
73         final Main main = new Main(apiConfigParameters);
74         assertTrue(main.getParameters() == null);
75     }
76 }