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.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertSame;
28 import static org.junit.Assert.assertTrue;
29 import static org.junit.Assert.fail;
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.pap.main.PolicyPapException;
35 import org.onap.policy.pap.main.parameters.CommonTestData;
36 import org.onap.policy.pap.main.parameters.PapParameterGroup;
37 import org.onap.policy.pap.main.parameters.PapParameterHandler;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
43 * Class to perform unit test of {@link PapActivator}}.
45 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
47 public class TestPapActivator {
49 private static final Logger LOGGER = LoggerFactory.getLogger(TestPapActivator.class);
50 private PapActivator activator;
53 * Initializes an activator.
54 * @throws Exception if an error occurs
57 public void setUp() throws Exception {
58 final String[] papConfigParameters = { "-c", "parameters/PapConfigParameters.json" };
59 final PapCommandLineArguments arguments = new PapCommandLineArguments(papConfigParameters);
60 final PapParameterGroup parGroup = new PapParameterHandler().getParameters(arguments);
61 activator = new PapActivator(parGroup);
65 * Method for cleanup after each test.
68 public void teardown() {
70 if (activator != null) {
71 activator.terminate();
73 } catch (final PolicyPapException exp) {
74 LOGGER.error("teardown failed", exp);
79 public void testPapActivator() throws PolicyPapException {
81 assertFalse(activator.isAlive());
82 activator.initialize();
83 assertTrue(activator.isAlive());
84 assertTrue(activator.getParameterGroup().isValid());
85 assertEquals(CommonTestData.PAP_GROUP_NAME, activator.getParameterGroup().getName());
86 } catch (final Exception exp) {
87 LOGGER.error("testPapActivator failed", exp);
88 fail("Test should not throw an exception");
92 @Test(expected = PolicyPapException.class)
93 public void testPapActivatorError() throws PolicyPapException {
94 activator.initialize();
95 assertTrue(activator.getParameterGroup().isValid());
96 activator.initialize();
100 public void testGetCurrent_testSetCurrent() {
101 assertNotNull(PapActivator.getCurrent());
103 PapActivator.setCurrent(activator);
105 assertSame(activator, PapActivator.getCurrent());