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