2 * ============LICENSE_START=======================================================
3 * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
4 * Modifications Copyright (C) 2021 Nordix Foundation.
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.sim.dmaap.startstop;
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.assertj.core.api.Assertions.assertThatCode;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
34 import org.onap.policy.models.sim.dmaap.rest.CommonRestServer;
35 import org.onap.policy.models.sim.dmaap.startstop.DmaapSimCommandLineArguments;
36 import org.onap.policy.models.sim.dmaap.startstop.Main;
37 import org.onap.policy.sim.dmaap.parameters.CommonTestData;
40 * Class to perform unit test of {@link Main}}.
42 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
44 public class MainTest extends CommonRestServer {
53 HttpServletServerFactoryInstance.getServerFactory().destroy();
59 * @throws Exception if an error occurs
62 public void tearDown() throws Exception {
69 public void testMain() throws Exception {
70 CommonRestServer.reconfigure();
71 final String[] NormalParameters = {"-c", CONFIG_FILE};
72 main = new Main(NormalParameters);
73 assertTrue(main.getParameters().isValid());
74 assertEquals(CommonTestData.SIM_GROUP_NAME, main.getParameters().getName());
80 public void testMain_NoArguments() {
81 final String[] NormalParameters = {};
82 main = new Main(NormalParameters);
83 assertNull(main.getParameters());
87 public void testMain_InvalidArguments() throws Exception {
88 CommonRestServer.reconfigure();
90 // note: this is missing the "-c" argument, thus the ARGUMENTS are invalid
91 final String[] NormalParameters = {CONFIG_FILE};
92 main = new Main(NormalParameters);
93 assertNull(main.getParameters());
97 public void testMain_Help() {
98 final String[] NormalParameters = {"-h"};
99 assertThatCode(() -> Main.main(NormalParameters)).doesNotThrowAnyException();
103 public void testMain_InvalidParameters() {
104 final String[] NormalParameters = {"-c", "parameters/InvalidParameters.json"};
105 main = new Main(NormalParameters);
106 assertNull(main.getParameters());
110 public void testDmaapSimVersion() {
111 String[] testArgs = {"-v"};
112 DmaapSimCommandLineArguments sutArgs = new DmaapSimCommandLineArguments(testArgs);
113 assertThat(sutArgs.version()).startsWith("ONAP DMaaP simulator Service");