cceeaf5affcb0d4dd70aab6d8c701771f6ad18cf
[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.rest.CommonRestServer;
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 extends CommonRestServer {
42     private Main main;
43
44     /**
45      * Sets 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 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());
72
73         main.shutdown();
74     }
75
76     @Test
77     public void testMain_NoArguments() {
78         final String[] NormalParameters = {};
79         main = new Main(NormalParameters);
80         assertNull(main.getParameters());
81     }
82
83     @Test
84     public void testMain_InvalidArguments() throws Exception {
85         CommonRestServer.reconfigure();
86
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());
91     }
92
93     @Test
94     public void testMain_Help() {
95         final String[] NormalParameters = {"-h"};
96         assertThatCode(() -> Main.main(NormalParameters)).doesNotThrowAnyException();
97     }
98
99     @Test
100     public void testMain_InvalidParameters() {
101         final String[] NormalParameters = {"-c", "parameters/InvalidParameters.json"};
102         main = new Main(NormalParameters);
103         assertNull(main.getParameters());
104     }
105 }