2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019 AT&T Intellectual Property.
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.pap.main.startstop;
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 org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
35 import org.onap.policy.common.utils.services.Registry;
36 import org.onap.policy.pap.main.PapConstants;
37 import org.onap.policy.pap.main.PolicyPapException;
38 import org.onap.policy.pap.main.comm.PdpModifyRequestMap;
39 import org.onap.policy.pap.main.comm.PdpTracker;
40 import org.onap.policy.pap.main.notification.PolicyNotifier;
41 import org.onap.policy.pap.main.parameters.CommonTestData;
42 import org.onap.policy.pap.main.parameters.PapParameterGroup;
43 import org.onap.policy.pap.main.parameters.PapParameterHandler;
44 import org.onap.policy.pap.main.rest.PapStatisticsManager;
48 * Class to perform unit test of {@link PapActivator}}.
50 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
52 public class TestPapActivator {
54 private PapActivator activator;
57 * Initializes an activator.
59 * @throws Exception if an error occurs
62 public void setUp() throws Exception {
63 Registry.newRegistry();
64 HttpServletServerFactoryInstance.getServerFactory().destroy();
66 final String[] papConfigParameters = {"-c", "parameters/PapConfigParameters.json"};
67 final PapCommandLineArguments arguments = new PapCommandLineArguments(papConfigParameters);
68 final PapParameterGroup parGroup = new PapParameterHandler().getParameters(arguments);
70 activator = new PapActivator(parGroup);
74 * Method for cleanup after each test.
76 * @throws Exception if an error occurs
79 public void teardown() throws Exception {
80 if (activator != null && activator.isAlive()) {
86 public void testPapActivator() throws PolicyPapException {
87 assertFalse(activator.isAlive());
89 assertTrue(activator.isAlive());
90 assertTrue(activator.getParameterGroup().isValid());
91 assertEquals(CommonTestData.PAP_GROUP_NAME, activator.getParameterGroup().getName());
93 // ensure items were added to the registry
94 assertNotNull(Registry.get(PapConstants.REG_PDP_MODIFY_LOCK, Object.class));
95 assertNotNull(Registry.get(PapConstants.REG_STATISTICS_MANAGER, PapStatisticsManager.class));
96 assertNotNull(Registry.get(PapConstants.REG_PDP_MODIFY_MAP, PdpModifyRequestMap.class));
97 assertNotNull(Registry.get(PapConstants.REG_PDP_TRACKER, PdpTracker.class));
98 assertNotNull(Registry.get(PapConstants.REG_POLICY_NOTIFIER, PolicyNotifier.class));
100 // repeat - should throw an exception
101 assertThatIllegalStateException().isThrownBy(() -> activator.start());
102 assertTrue(activator.isAlive());
103 assertTrue(activator.getParameterGroup().isValid());
107 public void testTerminate() throws Exception {
110 assertFalse(activator.isAlive());
112 // ensure items have been removed from the registry
113 assertNull(Registry.getOrDefault(PapConstants.REG_PDP_MODIFY_LOCK, Object.class, null));
114 assertNull(Registry.getOrDefault(PapConstants.REG_STATISTICS_MANAGER, PapStatisticsManager.class, null));
115 assertNull(Registry.getOrDefault(PapConstants.REG_PDP_MODIFY_MAP, PdpModifyRequestMap.class, null));
116 assertNull(Registry.getOrDefault(PapConstants.REG_PDP_TRACKER, PdpTracker.class, null));
117 assertNull(Registry.getOrDefault(PapConstants.REG_POLICY_NOTIFIER, PolicyNotifier.class, null));
119 // repeat - should throw an exception
120 assertThatIllegalStateException().isThrownBy(() -> activator.stop());
121 assertFalse(activator.isAlive());