2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4 * Modifications Copyright (C) 2019 Nordix Foundation.
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.pdpx.main.startstop;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertSame;
27 import static org.junit.Assert.assertTrue;
29 import java.util.Properties;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.onap.policy.common.endpoints.utils.ParameterUtils;
35 import org.onap.policy.pdpx.main.CommonRest;
36 import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
37 import org.onap.policy.pdpx.main.parameters.CommonTestData;
38 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
39 import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterHandler;
43 * Class to perform unit test of XacmlPdpActivator.
46 public class TestXacmlPdpActivator extends CommonRest {
47 private static XacmlPdpParameterGroup parGroup;
48 private static Properties props;
50 private XacmlPdpActivator activator = null;
56 public static void setUpBeforeClass() throws Exception {
57 CommonRest.setUpBeforeClass();
59 final String[] xacmlPdpConfigParameters = {"-c", CommonRest.CONFIG_FILE};
60 final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments(xacmlPdpConfigParameters);
61 parGroup = new XacmlPdpParameterHandler().getParameters(arguments);
63 props = ParameterUtils.getTopicProperties(parGroup.getTopicParameterGroup());
65 // don't want the common "main" running
66 CommonRest.stopMain();
70 * Creates the activator.
74 activator = new XacmlPdpActivator(parGroup, props);
78 public void testXacmlPdpActivator() throws Exception {
79 assertFalse(activator.isAlive());
81 assertTrue(activator.isAlive());
82 assertTrue(activator.getParameterGroup().isValid());
83 assertEquals(CommonTestData.PDPX_GROUP_NAME, activator.getParameterGroup().getName());
88 public void testGetCurrent_testSetCurrent() {
89 XacmlPdpActivator.setCurrent(activator);
90 assertSame(activator, XacmlPdpActivator.getCurrent());
94 public void testTerminate() throws Exception {
97 assertFalse(activator.isAlive());
102 * @throws PolicyXacmlPdpException on termination errors
105 public void teardown() throws PolicyXacmlPdpException {
106 if (activator != null && activator.isAlive()) {