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.assertSame;
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.pap.main.PolicyPapException;
34 import org.onap.policy.pap.main.parameters.CommonTestData;
35 import org.onap.policy.pap.main.parameters.PapParameterGroup;
36 import org.onap.policy.pap.main.parameters.PapParameterHandler;
40 * Class to perform unit test of {@link PapActivator}}.
42 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
44 public class TestPapActivator {
46 private PapActivator activator;
49 * Initializes an activator.
50 * @throws Exception if an error occurs
53 public void setUp() throws Exception {
54 final String[] papConfigParameters = { "-c", "parameters/PapConfigParameters.json" };
55 final PapCommandLineArguments arguments = new PapCommandLineArguments(papConfigParameters);
56 final PapParameterGroup parGroup = new PapParameterHandler().getParameters(arguments);
57 activator = new PapActivator(parGroup);
61 * Method for cleanup after each test.
62 * @throws Exception if an error occurs
65 public void teardown() throws Exception {
66 if (activator != null && activator.isAlive()) {
67 activator.terminate();
72 public void testPapActivator() throws PolicyPapException {
73 assertFalse(activator.isAlive());
74 activator.initialize();
75 assertTrue(activator.isAlive());
76 assertTrue(activator.getParameterGroup().isValid());
77 assertEquals(CommonTestData.PAP_GROUP_NAME, activator.getParameterGroup().getName());
79 // repeat - should throw an exception
80 assertThatIllegalStateException().isThrownBy(() -> activator.initialize());
81 assertTrue(activator.isAlive());
82 assertTrue(activator.getParameterGroup().isValid());
86 public void testGetCurrent_testSetCurrent() {
87 PapActivator.setCurrent(activator);
88 assertSame(activator, PapActivator.getCurrent());
92 public void testTerminate() throws Exception {
93 activator.initialize();
94 activator.terminate();
95 assertFalse(activator.isAlive());
97 // repeat - should throw an exception
98 assertThatIllegalStateException().isThrownBy(() -> activator.terminate());
99 assertFalse(activator.isAlive());