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 java.io.FileInputStream;
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.pap.main.PolicyPapException;
36 import org.onap.policy.pap.main.parameters.CommonTestData;
37 import org.onap.policy.pap.main.parameters.PapParameterGroup;
38 import org.onap.policy.pap.main.parameters.PapParameterHandler;
42 * Class to perform unit test of {@link PapActivator}}.
44 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
46 public class TestPapActivator {
48 private PapActivator activator;
51 * Initializes an activator.
53 * @throws Exception if an error occurs
56 public void setUp() throws Exception {
57 final String[] papConfigParameters =
58 {"-c", "parameters/PapConfigParameters.json", "-p", "parameters/topic.properties"};
59 final PapCommandLineArguments arguments = new PapCommandLineArguments(papConfigParameters);
60 final PapParameterGroup parGroup = new PapParameterHandler().getParameters(arguments);
62 Properties props = new Properties();
63 String propFile = arguments.getFullConfigurationFilePath();
64 try (FileInputStream stream = new FileInputStream(propFile)) {
68 activator = new PapActivator(parGroup, props);
72 * Method for cleanup after each test.
73 * @throws Exception if an error occurs
76 public void teardown() throws Exception {
77 if (activator != null && activator.isAlive()) {
78 activator.terminate();
83 public void testPapActivator() throws PolicyPapException {
84 assertFalse(activator.isAlive());
85 activator.initialize();
86 assertTrue(activator.isAlive());
87 assertTrue(activator.getParameterGroup().isValid());
88 assertEquals(CommonTestData.PAP_GROUP_NAME, activator.getParameterGroup().getName());
90 // repeat - should throw an exception
91 assertThatIllegalStateException().isThrownBy(() -> activator.initialize());
92 assertTrue(activator.isAlive());
93 assertTrue(activator.getParameterGroup().isValid());
97 public void testGetCurrent_testSetCurrent() {
98 assertSame(activator, PapActivator.getCurrent());
102 public void testTerminate() throws Exception {
103 activator.initialize();
104 activator.terminate();
105 assertFalse(activator.isAlive());
107 // repeat - should throw an exception
108 assertThatIllegalStateException().isThrownBy(() -> activator.terminate());
109 assertFalse(activator.isAlive());