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