Fix some sonars in policy-models
[policy/models.git] / models-sim / models-sim-dmaap / src / test / java / org / onap / policy / sim / dmaap / startstop / MainTest.java
1 /*
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.sim.dmaap.startstop;
22
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;
27
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.DmaapSimException;
33 import org.onap.policy.models.sim.dmaap.startstop.Main;
34 import org.onap.policy.sim.dmaap.parameters.CommonTestData;
35
36 /**
37  * Class to perform unit test of {@link Main}}.
38  *
39  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
40  */
41 public class MainTest {
42     private Main main;
43
44     /**
45      * Set up.
46      */
47     @Before
48     public void setUp() {
49         main = null;
50         HttpServletServerFactoryInstance.getServerFactory().destroy();
51     }
52
53     /**
54      * Shuts "main" down.
55      *
56      * @throws Exception if an error occurs
57      */
58     @After
59     public void tearDown() throws Exception {
60         if (main != null) {
61             main.shutdown();
62         }
63     }
64
65     @Test
66     public void testMain() throws DmaapSimException {
67         final String[] NormalParameters = {"-c", "parameters/NormalParameters.json"};
68         main = new Main(NormalParameters);
69         assertTrue(main.getParameters().isValid());
70         assertEquals(CommonTestData.SIM_GROUP_NAME, main.getParameters().getName());
71
72         main.shutdown();
73     }
74
75     @Test
76     public void testMain_NoArguments() {
77         final String[] NormalParameters = {};
78         main = new Main(NormalParameters);
79         assertNull(main.getParameters());
80     }
81
82     @Test
83     public void testMain_InvalidArguments() {
84         // note: this is missing the "-c" argument, thus the ARGUMENTS are invalid
85         final String[] NormalParameters = {"parameters/NormalParameters.json"};
86         main = new Main(NormalParameters);
87         assertNull(main.getParameters());
88     }
89
90     @Test
91     public void testMain_Help() {
92         final String[] NormalParameters = {"-h"};
93         assertThatCode(() -> Main.main(NormalParameters)).doesNotThrowAnyException();
94     }
95
96     @Test
97     public void testMain_InvalidParameters() {
98         final String[] NormalParameters = {"-c", "parameters/InvalidParameters.json"};
99         main = new Main(NormalParameters);
100         assertNull(main.getParameters());
101     }
102 }