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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.api.main.startstop;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
27 import org.junit.Test;
28 import org.onap.policy.api.main.parameters.CommonTestData;
29 import org.onap.policy.common.utils.network.NetworkUtil;
32 * Class to perform unit test of Main.
35 public class TestMain {
36 private static final CommonTestData COMMON_TEST_DATA = new CommonTestData();
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());
50 public void testMain_NoArguments() {
51 final String[] apiConfigParameters = {};
52 final Main main = new Main(apiConfigParameters);
53 assertTrue(main.getParameters() == null);
57 public void testMain_InvalidArguments() {
58 final String[] apiConfigParameters = { "parameters/ApiConfigParameters.json" };
59 final Main main = new Main(apiConfigParameters);
60 assertTrue(main.getParameters() == null);
64 public void testMain_Help() {
65 final String[] apiConfigParameters = { "-h" };
66 Main.main(apiConfigParameters);
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);