2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pdpx.main.startstop;
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import org.junit.After;
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.onap.policy.pdpx.main.CommonRest;
31 import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
34 * Class to perform unit test of Main.
37 public class TestMain extends CommonRest {
42 * Sets up properties and configuration.
43 * @throws Exception if an error occurs
46 public static void setUpBeforeClass() throws Exception {
47 CommonRest.setUpBeforeClass();
49 // don't want the common "main" running
50 CommonRest.stopMain();
62 public void tearDown() {
69 public void testMain() throws PolicyXacmlPdpException {
70 final String[] xacmlPdpConfigParameters = {"-c", CONFIG_FILE, "-p", "parameters/topic.properties"};
71 main = new Main(xacmlPdpConfigParameters);
77 public void testMain_NoArguments() {
78 final String[] xacmlPdpConfigParameters = {};
79 assertThatThrownBy(() -> new Main(xacmlPdpConfigParameters)).isInstanceOf(PolicyXacmlPdpException.class)
80 .hasMessage("policy xacml pdp configuration file was not specified as an argument");
84 public void testMain_InvalidArguments() {
85 final String[] xacmlPdpConfigParameters = {"parameters/XacmlPdpConfigParameters.json"};
86 assertThatThrownBy(() -> new Main(xacmlPdpConfigParameters)).isInstanceOf(PolicyXacmlPdpException.class)
87 .hasMessage("too many command line arguments specified : [parameters/XacmlPdpConfigParameters.json]");
91 public void testMain_Help() throws PolicyXacmlPdpException {
92 final String[] xacmlPdpConfigParameters = {"-h"};
93 Assert.assertTrue(new Main(xacmlPdpConfigParameters).getArgumentMessage().contains("-h,--help"));
98 public void testMain_InvalidParameters() {
99 final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters_InvalidName.json"};
100 assertThatThrownBy(() -> new Main(xacmlPdpConfigParameters)).isInstanceOf(PolicyXacmlPdpException.class)
101 .hasMessageContaining("validation error");