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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.sim.pdp;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
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;
35 * Class to perform unit test of {@link PdpSimulatorMain}}.
37 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
39 public class TestPdpSimulatorMain {
40 private PdpSimulatorMain pdpSimulator;
47 Registry.newRegistry();
53 * @throws Exception if an error occurs
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();
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());
72 // ensure items were added to the registry
73 assertNotNull(Registry.get(PdpSimulatorConstants.REG_PDP_SIMULATOR_ACTIVATOR, PdpSimulatorActivator.class));
75 pdpSimulator.shutdown();
79 public void testPdpSimulator_NoArguments() {
80 final String[] pdpSimulatorConfigParameters = {};
81 pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
82 assertTrue(pdpSimulator.getParameters() == null);
86 public void testPdpSimulator_InvalidArguments() {
87 final String[] pdpSimulatorConfigParameters = { "src/test/resourcesPdpSimulatorConfigParameters.json" };
88 pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
89 assertTrue(pdpSimulator.getParameters() == null);
93 public void testPdpSimulator_Help() {
94 final String[] pdpSimulatorConfigParameters = { "-h" };
95 PdpSimulatorMain.main(pdpSimulatorConfigParameters);
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);