2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019 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.assertThatIllegalStateException;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertTrue;
31 import java.util.Properties;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.policy.common.endpoints.utils.ParameterUtils;
36 import org.onap.policy.common.utils.services.Registry;
37 import org.onap.policy.models.pdp.concepts.PdpStatus;
38 import org.onap.policy.models.sim.pdp.exception.PdpSimulatorException;
39 import org.onap.policy.models.sim.pdp.parameters.CommonTestData;
40 import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterGroup;
41 import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterHandler;
44 * Class to perform unit test of {@link PdpSimulatorActivator}}.
46 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
48 public class TestPdpSimulatorActivator {
50 private PdpSimulatorActivator activator;
53 * Initializes an activator.
55 * @throws Exception if an error occurs
58 public void setUp() throws Exception {
59 Registry.newRegistry();
60 final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json" };
61 final PdpSimulatorCommandLineArguments arguments =
62 new PdpSimulatorCommandLineArguments(pdpSimulatorConfigParameters);
63 final PdpSimulatorParameterGroup parGroup = new PdpSimulatorParameterHandler().getParameters(arguments);
65 final Properties props = ParameterUtils.getTopicProperties(parGroup.getTopicParameterGroup());
66 activator = new PdpSimulatorActivator(parGroup, props);
70 * Method for cleanup after each test.
72 * @throws Exception if an error occurs
75 public void teardown() throws Exception {
76 if (activator != null && activator.isAlive()) {
77 activator.terminate();
82 public void testPdpSimulatorActivator() throws PdpSimulatorException {
83 assertFalse(activator.isAlive());
84 activator.initialize();
85 assertTrue(activator.isAlive());
86 assertTrue(activator.getParameterGroup().isValid());
87 assertEquals(CommonTestData.PDP_SIMULATOR_GROUP_NAME, activator.getParameterGroup().getName());
89 // ensure items were added to the registry
90 assertNotNull(Registry.get(PdpSimulatorConstants.REG_PDP_STATUS_OBJECT, PdpStatus.class));
92 // repeat - should throw an exception
93 assertThatIllegalStateException().isThrownBy(() -> activator.initialize());
94 assertTrue(activator.isAlive());
95 assertTrue(activator.getParameterGroup().isValid());
99 public void testTerminate() throws Exception {
100 activator.initialize();
101 activator.terminate();
102 assertFalse(activator.isAlive());
104 // ensure items have been removed from the registry
105 assertNull(Registry.getOrDefault(PdpSimulatorConstants.REG_PDP_STATUS_OBJECT, PdpStatus.class, null));
107 // repeat - should throw an exception
108 assertThatIllegalStateException().isThrownBy(() -> activator.terminate());
109 assertFalse(activator.isAlive());