summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java2
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PapStatisticsManager.java116
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/StatisticsProvider.java22
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/startstop/Main.java2
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java38
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPapRestServer.java54
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPapStatisticsManager.java89
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java36
8 files changed, 247 insertions, 112 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java
index 6f4c1cc0..58dccc86 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckProvider.java
@@ -46,7 +46,7 @@ public class HealthCheckProvider {
report.setName(NAME);
report.setUrl(URL);
- boolean alive = PapActivator.isAlive();
+ boolean alive = PapActivator.getCurrent().isAlive();
report.setHealthy(alive);
report.setCode(alive ? 200 : 500);
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PapStatisticsManager.java b/main/src/main/java/org/onap/policy/pap/main/rest/PapStatisticsManager.java
index 98148117..32893668 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PapStatisticsManager.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PapStatisticsManager.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +21,7 @@
package org.onap.policy.pap.main.rest;
+import java.util.concurrent.atomic.AtomicLong;
import lombok.Getter;
/**
@@ -30,24 +32,22 @@ import lombok.Getter;
public class PapStatisticsManager {
@Getter
- private static long totalPdpCount;
- @Getter
- private static long totalPdpGroupCount;
- @Getter
- private static long totalPolicyDeployCount;
- @Getter
- private static long policyDeploySuccessCount;
- @Getter
- private static long policyDeployFailureCount;
- @Getter
- private static long totalPolicyDownloadCount;
- @Getter
- private static long policyDownloadSuccessCount;
- @Getter
- private static long policyDownloadFailureCount;
+ private static final PapStatisticsManager instance = new PapStatisticsManager();
- private PapStatisticsManager() {
- throw new IllegalStateException("Instantiation of the class is not allowed");
+ private final AtomicLong totalPdpCount = new AtomicLong(0);
+ private final AtomicLong totalPdpGroupCount = new AtomicLong(0);
+ private final AtomicLong totalPolicyDeployCount = new AtomicLong(0);
+ private final AtomicLong policyDeploySuccessCount = new AtomicLong(0);
+ private final AtomicLong policyDeployFailureCount = new AtomicLong(0);
+ private final AtomicLong totalPolicyDownloadCount = new AtomicLong(0);
+ private final AtomicLong policyDownloadSuccessCount = new AtomicLong(0);
+ private final AtomicLong policyDownloadFailureCount = new AtomicLong(0);
+
+ /**
+ * Constructs the object.
+ */
+ protected PapStatisticsManager() {
+ super();
}
/**
@@ -55,8 +55,8 @@ public class PapStatisticsManager {
*
* @return the updated value of totalPdpCount
*/
- public static long updateTotalPdpCount() {
- return ++totalPdpCount;
+ public long updateTotalPdpCount() {
+ return totalPdpCount.incrementAndGet();
}
/**
@@ -64,8 +64,8 @@ public class PapStatisticsManager {
*
* @return the updated value of totalPdpGroupCount
*/
- public static long updateTotalPdpGroupCount() {
- return ++totalPdpGroupCount;
+ public long updateTotalPdpGroupCount() {
+ return totalPdpGroupCount.incrementAndGet();
}
/**
@@ -73,8 +73,8 @@ public class PapStatisticsManager {
*
* @return the updated value of totalPolicyDeployCount
*/
- public static long updateTotalPolicyDeployCount() {
- return ++totalPolicyDeployCount;
+ public long updateTotalPolicyDeployCount() {
+ return totalPolicyDeployCount.incrementAndGet();
}
/**
@@ -82,8 +82,8 @@ public class PapStatisticsManager {
*
* @return the updated value of policyDeploySuccessCount
*/
- public static long updatePolicyDeploySuccessCount() {
- return ++policyDeploySuccessCount;
+ public long updatePolicyDeploySuccessCount() {
+ return policyDeploySuccessCount.incrementAndGet();
}
/**
@@ -91,8 +91,8 @@ public class PapStatisticsManager {
*
* @return the updated value of policyDeployFailureCount
*/
- public static long updatePolicyDeployFailureCount() {
- return ++policyDeployFailureCount;
+ public long updatePolicyDeployFailureCount() {
+ return policyDeployFailureCount.incrementAndGet();
}
/**
@@ -100,8 +100,8 @@ public class PapStatisticsManager {
*
* @return the updated value of totalPolicyDownloadCount
*/
- public static long updateTotalPolicyDownloadCount() {
- return ++totalPolicyDownloadCount;
+ public long updateTotalPolicyDownloadCount() {
+ return totalPolicyDownloadCount.incrementAndGet();
}
/**
@@ -109,8 +109,8 @@ public class PapStatisticsManager {
*
* @return the updated value of policyDownloadSuccessCount
*/
- public static long updatePolicyDownloadSuccessCount() {
- return ++policyDownloadSuccessCount;
+ public long updatePolicyDownloadSuccessCount() {
+ return policyDownloadSuccessCount.incrementAndGet();
}
/**
@@ -118,21 +118,53 @@ public class PapStatisticsManager {
*
* @return the updated value of policyDownloadFailureCount
*/
- public static long updatePolicyDownloadFailureCount() {
- return ++policyDownloadFailureCount;
+ public long updatePolicyDownloadFailureCount() {
+ return policyDownloadFailureCount.incrementAndGet();
}
/**
* Reset all the statistics counts to 0.
*/
- public static void resetAllStatistics() {
- totalPdpCount = 0L;
- totalPdpGroupCount = 0L;
- totalPolicyDeployCount = 0L;
- policyDeploySuccessCount = 0L;
- policyDeployFailureCount = 0L;
- totalPolicyDownloadCount = 0L;
- policyDownloadSuccessCount = 0L;
- policyDownloadFailureCount = 0L;
+ public void resetAllStatistics() {
+ totalPdpCount.set(0L);
+ totalPdpGroupCount.set(0L);
+ totalPolicyDeployCount.set(0L);
+ policyDeploySuccessCount.set(0L);
+ policyDeployFailureCount.set(0L);
+ totalPolicyDownloadCount.set(0L);
+ policyDownloadSuccessCount.set(0L);
+ policyDownloadFailureCount.set(0L);
+ }
+
+ public long getTotalPdpCount() {
+ return totalPdpCount.get();
+ }
+
+ public long getTotalPdpGroupCount() {
+ return totalPdpGroupCount.get();
+ }
+
+ public long getTotalPolicyDeployCount() {
+ return totalPolicyDeployCount.get();
+ }
+
+ public long getPolicyDeploySuccessCount() {
+ return policyDeploySuccessCount.get();
+ }
+
+ public long getPolicyDeployFailureCount() {
+ return policyDeployFailureCount.get();
+ }
+
+ public long getTotalPolicyDownloadCount() {
+ return totalPolicyDownloadCount.get();
+ }
+
+ public long getPolicyDownloadSuccessCount() {
+ return policyDownloadSuccessCount.get();
+ }
+
+ public long getPolicyDownloadFailureCount() {
+ return policyDownloadFailureCount.get();
}
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsProvider.java
index 38ae5034..026ccf49 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsProvider.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,15 +37,18 @@ public class StatisticsProvider {
*/
public StatisticsReport fetchCurrentStatistics() {
final StatisticsReport report = new StatisticsReport();
- report.setCode(PapActivator.isAlive() ? 200 : 500);
- report.setTotalPdpCount(PapStatisticsManager.getTotalPdpCount());
- report.setTotalPdpGroupCount(PapStatisticsManager.getTotalPdpGroupCount());
- report.setTotalPolicyDownloadCount(PapStatisticsManager.getTotalPolicyDownloadCount());
- report.setPolicyDownloadSuccessCount(PapStatisticsManager.getPolicyDownloadSuccessCount());
- report.setPolicyDownloadFailureCount(PapStatisticsManager.getPolicyDownloadFailureCount());
- report.setTotalPolicyDeployCount(PapStatisticsManager.getTotalPolicyDeployCount());
- report.setPolicyDeploySuccessCount(PapStatisticsManager.getPolicyDeploySuccessCount());
- report.setPolicyDeployFailureCount(PapStatisticsManager.getPolicyDeployFailureCount());
+ report.setCode(PapActivator.getCurrent().isAlive() ? 200 : 500);
+
+ PapStatisticsManager mgr = PapStatisticsManager.getInstance();
+ report.setTotalPdpCount(mgr.getTotalPdpCount());
+ report.setTotalPdpGroupCount(mgr.getTotalPdpGroupCount());
+ report.setTotalPolicyDownloadCount(mgr.getTotalPolicyDownloadCount());
+ report.setPolicyDownloadSuccessCount(mgr.getPolicyDownloadSuccessCount());
+ report.setPolicyDownloadFailureCount(mgr.getPolicyDownloadFailureCount());
+ report.setTotalPolicyDeployCount(mgr.getTotalPolicyDeployCount());
+ report.setPolicyDeploySuccessCount(mgr.getPolicyDeploySuccessCount());
+ report.setPolicyDeployFailureCount(mgr.getPolicyDeployFailureCount());
+
return report;
}
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/Main.java b/main/src/main/java/org/onap/policy/pap/main/startstop/Main.java
index 602e04df..cbe4dcc9 100644
--- a/main/src/main/java/org/onap/policy/pap/main/startstop/Main.java
+++ b/main/src/main/java/org/onap/policy/pap/main/startstop/Main.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -75,6 +76,7 @@ public class Main {
// Now, create the activator for the policy pap service
activator = new PapActivator(parameterGroup);
+ PapActivator.setCurrent(activator);
// Start the activator
try {
diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
index 9fb3535b..18b87641 100644
--- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
+++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
@@ -21,6 +21,8 @@
package org.onap.policy.pap.main.startstop;
+import lombok.Getter;
+import lombok.Setter;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.pap.main.PolicyPapException;
import org.onap.policy.pap.main.parameters.PapParameterGroup;
@@ -39,7 +41,19 @@ public class PapActivator {
private static final Logger LOGGER = LoggerFactory.getLogger(PapActivator.class);
private final PapParameterGroup papParameterGroup;
- private static volatile boolean alive = false;
+
+ /**
+ * The current activator. This is initialized to a dummy instance used until the real
+ * one has been configured.
+ */
+ @Getter
+ @Setter
+ private static volatile PapActivator current = new PapActivator(null);
+
+ @Getter
+ @Setter(lombok.AccessLevel.PRIVATE)
+ private volatile boolean alive = false;
+
private PapRestServer restServer;
/**
@@ -61,7 +75,7 @@ public class PapActivator {
LOGGER.debug("Policy pap starting as a service . . .");
startPapRestServer();
registerToParameterService(papParameterGroup);
- PapActivator.setAlive(true);
+ setAlive(true);
LOGGER.debug("Policy pap started as a service");
} catch (final Exception exp) {
LOGGER.error("Policy pap service startup failed", exp);
@@ -77,7 +91,7 @@ public class PapActivator {
public void terminate() throws PolicyPapException {
try {
deregisterToParameterService(papParameterGroup);
- PapActivator.setAlive(false);
+ setAlive(false);
// Stop the pap rest server
restServer.stop();
@@ -115,24 +129,6 @@ public class PapActivator {
}
/**
- * Returns the alive status of pap service.
- *
- * @return the alive
- */
- public static boolean isAlive() {
- return alive;
- }
-
- /**
- * Change the alive status of pap service.
- *
- * @param status the status
- */
- private static void setAlive(final boolean status) {
- alive = status;
- }
-
- /**
* Starts the pap rest server using configuration parameters.
*
* @throws PolicyPapException if server start fails
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPapRestServer.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPapRestServer.java
index a8451992..77ac8f1e 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPapRestServer.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPapRestServer.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,6 +77,8 @@ public class TestPapRestServer {
*/
@After
public void teardown() {
+ PapStatisticsManager.getInstance().resetAllStatistics();
+
try {
if (NetworkUtil.isTcpPortOpen("localhost", 6969, 1, 1000L)) {
if (main != null) {
@@ -103,21 +106,16 @@ public class TestPapRestServer {
}
@Test
- public void testHealthCheckFailure() throws InterruptedException, IOException {
+ public void testHealthCheckFailure() throws Exception {
final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false);
restServerParams.setName(CommonTestData.PAP_GROUP_NAME);
restServer = new PapRestServer(restServerParams);
- try {
- restServer.start();
- final Invocation.Builder invocationBuilder = sendHttpRequest(HEALTHCHECK_ENDPOINT);
- final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
- validateHealthCheckReport(NAME, SELF, false, 500, NOT_ALIVE, report);
- assertTrue(restServer.isAlive());
- assertTrue(restServer.toString().startsWith("PapRestServer [servers="));
- } catch (final Exception exp) {
- LOGGER.error("testHealthCheckFailure failed", exp);
- fail("Test should not throw an exception");
- }
+ restServer.start();
+ final Invocation.Builder invocationBuilder = sendHttpRequest(HEALTHCHECK_ENDPOINT);
+ final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
+ validateHealthCheckReport(NAME, SELF, false, 500, NOT_ALIVE, report);
+ assertTrue(restServer.isAlive());
+ assertTrue(restServer.toString().startsWith("PapRestServer [servers="));
}
@Test
@@ -144,7 +142,6 @@ public class TestPapRestServer {
invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT);
report = invocationBuilder.get(StatisticsReport.class);
validateStatisticsReport(report, 1, 200);
- PapStatisticsManager.resetAllStatistics();
} catch (final Exception exp) {
LOGGER.error("testPapStatistics_200 failed", exp);
fail("Test should not throw an exception");
@@ -161,7 +158,6 @@ public class TestPapRestServer {
final Invocation.Builder invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT);
final StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
validateStatisticsReport(report, 0, 500);
- PapStatisticsManager.resetAllStatistics();
} catch (final Exception exp) {
LOGGER.error("testPapStatistics_500 failed", exp);
fail("Test should not throw an exception");
@@ -182,15 +178,9 @@ public class TestPapRestServer {
}
@Test
- public void testPapStatisticsConstructorIsPrivate() {
- try {
- final Constructor<PapStatisticsManager> constructor = PapStatisticsManager.class.getDeclaredConstructor();
- assertTrue(Modifier.isPrivate(constructor.getModifiers()));
- constructor.setAccessible(true);
- constructor.newInstance();
- } catch (final Exception exp) {
- assertTrue(exp.getCause().toString().contains("Instantiation of the class is not allowed"));
- }
+ public void testPapStatisticsConstructorIsProtected() throws Exception {
+ final Constructor<PapStatisticsManager> constructor = PapStatisticsManager.class.getDeclaredConstructor();
+ assertTrue(Modifier.isProtected(constructor.getModifiers()));
}
private Main startPapService(final boolean http) {
@@ -265,14 +255,16 @@ public class TestPapRestServer {
}
private void updateDistributionStatistics() {
- PapStatisticsManager.updateTotalPdpCount();
- PapStatisticsManager.updateTotalPdpGroupCount();
- PapStatisticsManager.updateTotalPolicyDeployCount();
- PapStatisticsManager.updatePolicyDeploySuccessCount();
- PapStatisticsManager.updatePolicyDeployFailureCount();
- PapStatisticsManager.updateTotalPolicyDownloadCount();
- PapStatisticsManager.updatePolicyDownloadSuccessCount();
- PapStatisticsManager.updatePolicyDownloadFailureCount();
+ PapStatisticsManager mgr = PapStatisticsManager.getInstance();
+
+ mgr.updateTotalPdpCount();
+ mgr.updateTotalPdpGroupCount();
+ mgr.updateTotalPolicyDeployCount();
+ mgr.updatePolicyDeploySuccessCount();
+ mgr.updatePolicyDeployFailureCount();
+ mgr.updateTotalPolicyDownloadCount();
+ mgr.updatePolicyDownloadSuccessCount();
+ mgr.updatePolicyDownloadFailureCount();
}
private void validateStatisticsReport(final StatisticsReport report, final int count, final int code) {
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPapStatisticsManager.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPapStatisticsManager.java
new file mode 100644
index 00000000..d4e4f81a
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPapStatisticsManager.java
@@ -0,0 +1,89 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.rest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
+import org.junit.Test;
+
+public class TestPapStatisticsManager {
+
+ @Test
+ public void test() {
+ PapStatisticsManager mgr = PapStatisticsManager.getInstance();
+ assertNotNull(mgr);
+
+ // should return the same manager
+ assertSame(mgr, PapStatisticsManager.getInstance());
+
+ // work with a new object so we don't have to worry about initial counts
+ mgr = new PapStatisticsManager();
+
+ // try each update
+
+ assertEquals(0, mgr.getTotalPdpCount());
+ assertEquals(1, mgr.updateTotalPdpCount());
+ assertEquals(1, mgr.getTotalPdpCount());
+
+ assertEquals(0, mgr.getTotalPdpGroupCount());
+ assertEquals(1, mgr.updateTotalPdpGroupCount());
+ assertEquals(1, mgr.getTotalPdpGroupCount());
+
+ assertEquals(0, mgr.getTotalPolicyDeployCount());
+ assertEquals(1, mgr.updateTotalPolicyDeployCount());
+ assertEquals(1, mgr.getTotalPolicyDeployCount());
+
+ assertEquals(0, mgr.getPolicyDeploySuccessCount());
+ assertEquals(1, mgr.updatePolicyDeploySuccessCount());
+ assertEquals(1, mgr.getPolicyDeploySuccessCount());
+
+ assertEquals(0, mgr.getPolicyDeployFailureCount());
+ assertEquals(1, mgr.updatePolicyDeployFailureCount());
+ assertEquals(1, mgr.getPolicyDeployFailureCount());
+
+ assertEquals(0, mgr.getTotalPolicyDownloadCount());
+ assertEquals(1, mgr.updateTotalPolicyDownloadCount());
+ assertEquals(1, mgr.getTotalPolicyDownloadCount());
+
+ assertEquals(0, mgr.getPolicyDownloadSuccessCount());
+ assertEquals(1, mgr.updatePolicyDownloadSuccessCount());
+ assertEquals(1, mgr.getPolicyDownloadSuccessCount());
+
+ assertEquals(0, mgr.getPolicyDownloadFailureCount());
+ assertEquals(1, mgr.updatePolicyDownloadFailureCount());
+ assertEquals(1, mgr.getPolicyDownloadFailureCount());
+
+ // now check reset
+ mgr.resetAllStatistics();
+
+ assertEquals(0, mgr.getPolicyDeployFailureCount());
+ assertEquals(0, mgr.getTotalPdpCount());
+ assertEquals(0, mgr.getTotalPdpGroupCount());
+ assertEquals(0, mgr.getTotalPolicyDeployCount());
+ assertEquals(0, mgr.getPolicyDeploySuccessCount());
+ assertEquals(0, mgr.getPolicyDeployFailureCount());
+ assertEquals(0, mgr.getTotalPolicyDownloadCount());
+ assertEquals(0, mgr.getPolicyDownloadSuccessCount());
+ assertEquals(0, mgr.getPolicyDownloadFailureCount());
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java b/main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java
index 3781be47..8e8e6c09 100644
--- a/main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java
+++ b/main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,10 +22,14 @@
package org.onap.policy.pap.main.startstop;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.onap.policy.pap.main.PolicyPapException;
import org.onap.policy.pap.main.parameters.CommonTestData;
@@ -45,6 +50,18 @@ public class TestPapActivator {
private PapActivator activator;
/**
+ * Initializes an activator.
+ * @throws Exception if an error occurs
+ */
+ @Before
+ public void setUp() throws Exception {
+ final String[] papConfigParameters = { "-c", "parameters/PapConfigParameters.json" };
+ final PapCommandLineArguments arguments = new PapCommandLineArguments(papConfigParameters);
+ final PapParameterGroup parGroup = new PapParameterHandler().getParameters(arguments);
+ activator = new PapActivator(parGroup);
+ }
+
+ /**
* Method for cleanup after each test.
*/
@After
@@ -60,12 +77,10 @@ public class TestPapActivator {
@Test
public void testPapActivator() throws PolicyPapException {
- final String[] papConfigParameters = { "-c", "parameters/PapConfigParameters.json" };
- final PapCommandLineArguments arguments = new PapCommandLineArguments(papConfigParameters);
- final PapParameterGroup parGroup = new PapParameterHandler().getParameters(arguments);
- activator = new PapActivator(parGroup);
try {
+ assertFalse(activator.isAlive());
activator.initialize();
+ assertTrue(activator.isAlive());
assertTrue(activator.getParameterGroup().isValid());
assertEquals(CommonTestData.PAP_GROUP_NAME, activator.getParameterGroup().getName());
} catch (final Exception exp) {
@@ -76,12 +91,17 @@ public class TestPapActivator {
@Test(expected = PolicyPapException.class)
public void testPapActivatorError() throws PolicyPapException {
- final String[] papConfigParameters = { "-c", "parameters/PapConfigParameters.json" };
- final PapCommandLineArguments arguments = new PapCommandLineArguments(papConfigParameters);
- final PapParameterGroup parGroup = new PapParameterHandler().getParameters(arguments);
- activator = new PapActivator(parGroup);
activator.initialize();
assertTrue(activator.getParameterGroup().isValid());
activator.initialize();
}
+
+ @Test
+ public void testGetCurrent_testSetCurrent() {
+ assertNotNull(PapActivator.getCurrent());
+
+ PapActivator.setCurrent(activator);
+
+ assertSame(activator, PapActivator.getCurrent());
+ }
}