2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
4 * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
5 * Modifications Copyright (C) 2020-2021 Bell Canada. 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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.api.main.startstop;
25 import static org.assertj.core.api.Assertions.assertThatCode;
26 import static org.assertj.core.api.Assertions.assertThatThrownBy;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertTrue;
30 import org.junit.Test;
31 import org.onap.policy.api.main.exception.PolicyApiRuntimeException;
32 import org.onap.policy.api.main.parameters.CommonTestData;
33 import org.onap.policy.common.utils.network.NetworkUtil;
34 import org.onap.policy.common.utils.resources.MessageConstants;
37 * Class to perform unit test of Main.
40 public class TestMain {
41 private static final CommonTestData COMMON_TEST_DATA = new CommonTestData();
44 public void testMain() throws Exception {
45 COMMON_TEST_DATA.makeParameters("src/test/resources/parameters/ApiConfigParameters_Https.json",
46 "src/test/resources/parameters/ApiConfigParametersXXX.json", NetworkUtil.allocPort());
47 final String[] apiConfigParameters = {"-c", "src/test/resources/parameters/ApiConfigParametersXXX.json"};
48 final Main main = new Main(apiConfigParameters);
49 assertTrue(main.getParameterGroup().isValid());
50 assertEquals(CommonTestData.API_GROUP_NAME, main.getParameterGroup().getName());
55 public void testMain_NoArguments() {
56 final String[] apiConfigParameters = {};
57 assertThatThrownBy(() -> new Main(apiConfigParameters)).isInstanceOf(PolicyApiRuntimeException.class)
58 .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_API));
62 public void testMain_InvalidArguments() {
63 final String[] apiConfigParameters = {"parameters/ApiConfigParameters.json"};
64 assertThatThrownBy(() -> new Main(apiConfigParameters)).isInstanceOf(PolicyApiRuntimeException.class)
65 .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_API));
69 public void testMain_Help() {
70 final String[] apiConfigParameters = {"-h"};
71 assertThatCode(() -> Main.main(apiConfigParameters)).doesNotThrowAnyException();
75 public void testMain_InvalidParameters() {
76 final String[] apiConfigParameters = {"-c", "parameters/ApiConfigParameters_InvalidName.json"};
77 assertThatThrownBy(() -> new Main(apiConfigParameters)).isInstanceOf(PolicyApiRuntimeException.class)
78 .hasMessage(String.format(MessageConstants.START_FAILURE_MSG, MessageConstants.POLICY_API));