2 * ============LICENSE_START=======================================================
3 * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
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.sim.dmaap.startstop;
23 import static org.assertj.core.api.Assertions.assertThatCode;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
32 import org.onap.policy.models.sim.dmaap.rest.CommonRestServer;
33 import org.onap.policy.models.sim.dmaap.startstop.Main;
34 import org.onap.policy.sim.dmaap.parameters.CommonTestData;
37 * Class to perform unit test of {@link Main}}.
39 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
41 public class MainTest extends CommonRestServer {
50 HttpServletServerFactoryInstance.getServerFactory().destroy();
56 * @throws Exception if an error occurs
59 public void tearDown() throws Exception {
66 public void testMain() throws Exception {
67 CommonRestServer.reconfigure();
68 final String[] NormalParameters = {"-c", CONFIG_FILE};
69 main = new Main(NormalParameters);
70 assertTrue(main.getParameters().isValid());
71 assertEquals(CommonTestData.SIM_GROUP_NAME, main.getParameters().getName());
77 public void testMain_NoArguments() {
78 final String[] NormalParameters = {};
79 main = new Main(NormalParameters);
80 assertNull(main.getParameters());
84 public void testMain_InvalidArguments() throws Exception {
85 CommonRestServer.reconfigure();
87 // note: this is missing the "-c" argument, thus the ARGUMENTS are invalid
88 final String[] NormalParameters = {CONFIG_FILE};
89 main = new Main(NormalParameters);
90 assertNull(main.getParameters());
94 public void testMain_Help() {
95 final String[] NormalParameters = {"-h"};
96 assertThatCode(() -> Main.main(NormalParameters)).doesNotThrowAnyException();
100 public void testMain_InvalidParameters() {
101 final String[] NormalParameters = {"-c", "parameters/InvalidParameters.json"};
102 main = new Main(NormalParameters);
103 assertNull(main.getParameters());