Remove topic.properties and incorporate into overall config file for pdp-simulator
[policy/models.git] / models-sim / policy-models-sim-pdp / src / test / java / org / onap / policy / models / sim / pdp / TestPdpSimulatorMain.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
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.models.sim.pdp;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
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.utils.services.Registry;
31 import org.onap.policy.models.sim.pdp.exception.PdpSimulatorException;
32 import org.onap.policy.models.sim.pdp.parameters.CommonTestData;
33
34 /**
35  * Class to perform unit test of {@link PdpSimulatorMain}}.
36  *
37  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
38  */
39 public class TestPdpSimulatorMain {
40     private PdpSimulatorMain pdpSimulator;
41
42     /**
43      * Set up.
44      */
45     @Before
46     public void setUp() {
47         Registry.newRegistry();
48     }
49
50     /**
51      * Shuts "main" down.
52      *
53      * @throws Exception if an error occurs
54      */
55     @After
56     public void tearDown() throws Exception {
57         // shut down activator
58         final PdpSimulatorActivator activator = Registry.getOrDefault(PdpSimulatorConstants.REG_PDP_SIMULATOR_ACTIVATOR,
59                 PdpSimulatorActivator.class, null);
60         if (activator != null && activator.isAlive()) {
61             activator.terminate();
62         }
63     }
64
65     @Test
66     public void testPdpSimulator() throws PdpSimulatorException {
67         final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json" };
68         pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
69         assertTrue(pdpSimulator.getParameters().isValid());
70         assertEquals(CommonTestData.PDP_SIMULATOR_GROUP_NAME, pdpSimulator.getParameters().getName());
71
72         // ensure items were added to the registry
73         assertNotNull(Registry.get(PdpSimulatorConstants.REG_PDP_SIMULATOR_ACTIVATOR, PdpSimulatorActivator.class));
74
75         pdpSimulator.shutdown();
76     }
77
78     @Test
79     public void testPdpSimulator_NoArguments() {
80         final String[] pdpSimulatorConfigParameters = {};
81         pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
82         assertTrue(pdpSimulator.getParameters() == null);
83     }
84
85     @Test
86     public void testPdpSimulator_InvalidArguments() {
87         final String[] pdpSimulatorConfigParameters = { "src/test/resourcesPdpSimulatorConfigParameters.json" };
88         pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
89         assertTrue(pdpSimulator.getParameters() == null);
90     }
91
92     @Test
93     public void testPdpSimulator_Help() {
94         final String[] pdpSimulatorConfigParameters = { "-h" };
95         PdpSimulatorMain.main(pdpSimulatorConfigParameters);
96     }
97
98     @Test
99     public void testPdpSimulator_InvalidParameters() {
100         final String[] pdpSimulatorConfigParameters =
101             { "-c", "src/test/resources/PdpSimulatorConfigParameters_InvalidName.json" };
102         pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
103         assertTrue(pdpSimulator.getParameters() == null);
104     }
105 }