2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.sim.pdp;
24 import static org.assertj.core.api.Assertions.assertThatCode;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.policy.common.utils.services.Registry;
34 import org.onap.policy.models.sim.pdp.exception.PdpSimulatorException;
35 import org.onap.policy.models.sim.pdp.parameters.CommonTestData;
38 * Class to perform unit test of {@link PdpSimulatorMain}}.
40 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
42 public class TestPdpSimulatorMain {
43 private PdpSimulatorMain pdpSimulator;
50 Registry.newRegistry();
56 * @throws Exception if an error occurs
59 public void tearDown() throws Exception {
60 // shut down activator
61 final PdpSimulatorActivator activator = Registry.getOrDefault(PdpSimulatorConstants.REG_PDP_SIMULATOR_ACTIVATOR,
62 PdpSimulatorActivator.class, null);
63 if (activator != null && activator.isAlive()) {
64 activator.terminate();
69 public void testPdpSimulator() throws PdpSimulatorException {
70 final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json" };
71 pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
72 assertTrue(pdpSimulator.getParameters().isValid());
73 assertEquals(CommonTestData.PDP_SIMULATOR_GROUP_NAME, pdpSimulator.getParameters().getName());
75 // ensure items were added to the registry
76 assertNotNull(Registry.get(PdpSimulatorConstants.REG_PDP_SIMULATOR_ACTIVATOR, PdpSimulatorActivator.class));
78 pdpSimulator.shutdown();
82 public void testPdpSimulator_NoArguments() {
83 final String[] pdpSimulatorConfigParameters = {};
84 pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
85 assertNull(pdpSimulator.getParameters());
89 public void testPdpSimulator_InvalidArguments() {
90 final String[] pdpSimulatorConfigParameters = { "src/test/resourcesPdpSimulatorConfigParameters.json" };
91 pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
92 assertNull(pdpSimulator.getParameters());
96 public void testPdpSimulator_Help() {
97 final String[] pdpSimulatorConfigParameters = { "-h" };
98 assertThatCode(() -> PdpSimulatorMain.main(pdpSimulatorConfigParameters)).doesNotThrowAnyException();
102 public void testPdpSimulator_InvalidParameters() {
103 final String[] pdpSimulatorConfigParameters =
104 { "-c", "src/test/resources/PdpSimulatorConfigParameters_InvalidName.json" };
105 pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
106 assertNull(pdpSimulator.getParameters());