aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMagnusen, Drew (dm741q) <dm741q@att.com>2017-09-12 10:45:58 -0500
committerMagnusen, Drew (dm741q) <dm741q@att.com>2017-09-15 14:50:11 -0500
commit0ca3ecd5f8bbcac6152ee4b819d48910148c8c49 (patch)
tree9092fa30195f146c6eb0d3c8e56d57c493ab534c
parent0c625eb6e2349556f1eae87deb2fb7af7fd6132f (diff)
Added junit for feature-healthcheck
Added a junit test increase coverage of the healthcheck feature. Issue-ID: POLICY-227 Change-Id: I3f37e7fab15f2f3072b442b43b79b8241c61e306 Signed-off-by: Magnusen, Drew (dm741q) <dm741q@att.com>
-rw-r--r--feature-healthcheck/pom.xml47
-rw-r--r--feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckFeatureTest.java198
-rw-r--r--feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/RestMockHealthCheck.java41
3 files changed, 265 insertions, 21 deletions
diff --git a/feature-healthcheck/pom.xml b/feature-healthcheck/pom.xml
index 32aa4d1c..6fd81f84 100644
--- a/feature-healthcheck/pom.xml
+++ b/feature-healthcheck/pom.xml
@@ -93,28 +93,33 @@
<dependencies>
<dependency>
- <groupId>io.swagger</groupId>
- <artifactId>swagger-jersey2-jaxrs</artifactId>
- <scope>provided</scope>
+ <groupId>io.swagger</groupId>
+ <artifactId>swagger-jersey2-jaxrs</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.drools-pdp</groupId>
+ <artifactId>policy-core</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.drools-pdp</groupId>
+ <artifactId>policy-endpoints</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.drools-pdp</groupId>
+ <artifactId>policy-management</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-core</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-endpoints</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-management</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
</dependencies>
</project>
diff --git a/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckFeatureTest.java b/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckFeatureTest.java
new file mode 100644
index 00000000..a618f033
--- /dev/null
+++ b/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckFeatureTest.java
@@ -0,0 +1,198 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * feature-healthcheck
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.healthcheck;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Properties;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.onap.policy.drools.healthcheck.HealthCheck.Report;
+import org.onap.policy.drools.healthcheck.HealthCheck.Reports;
+import org.onap.policy.drools.http.client.HttpClient;
+import org.onap.policy.drools.http.server.HttpServletServer;
+import org.onap.policy.drools.persistence.SystemPersistence;
+import org.onap.policy.drools.properties.PolicyProperties;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HealthCheckFeatureTest {
+
+ /**
+ * Healthcheck Configuration File
+ */
+ private static final String HEALTH_CHECK_PROPERTIES_FILE = "feature-healthcheck.properties";
+
+ private static final Path healthCheckPropsPath = Paths.get(SystemPersistence.manager.getConfigurationPath().toString(),
+ HEALTH_CHECK_PROPERTIES_FILE);
+
+ private static final Path healthCheckPropsBackupPath = Paths.get(SystemPersistence.manager.getConfigurationPath().toString(),
+ HEALTH_CHECK_PROPERTIES_FILE + ".bak");
+
+
+ /**
+ * logger
+ */
+ private static Logger logger = LoggerFactory.getLogger(HealthCheckFeatureTest.class);
+
+ private static Properties httpProperties = new Properties();
+
+
+ @BeforeClass
+ public static void setup(){
+
+ httpProperties.setProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES, "HEALTHCHECK");
+ httpProperties.setProperty
+ (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "HEALTHCHECK" + PolicyProperties.PROPERTY_HTTP_HOST_SUFFIX,
+ "localhost");
+ httpProperties.setProperty
+ (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "HEALTHCHECK" + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX,
+ "7777");
+ httpProperties.setProperty
+ (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "HEALTHCHECK" + PolicyProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX,
+ "username");
+ httpProperties.setProperty
+ (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "HEALTHCHECK" + PolicyProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX,
+ "password");
+ httpProperties.setProperty
+ (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "HEALTHCHECK" + PolicyProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX,
+ org.onap.policy.drools.healthcheck.RestMockHealthCheck.class.getName());
+ httpProperties.setProperty
+ (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "HEALTHCHECK" + PolicyProperties.PROPERTY_MANAGED_SUFFIX,
+ "true");
+
+
+ httpProperties.setProperty(PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES, "HEALTHCHECK");
+ httpProperties.setProperty
+ (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "HEALTHCHECK" + PolicyProperties.PROPERTY_HTTP_HOST_SUFFIX,
+ "localhost");
+ httpProperties.setProperty
+ (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "HEALTHCHECK" + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX,
+ "7777");
+ httpProperties.setProperty
+ (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "HEALTHCHECK" + PolicyProperties.PROPERTY_HTTP_URL_SUFFIX,
+ "healthcheck/test");
+ httpProperties.setProperty
+ (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "HEALTHCHECK" + PolicyProperties.PROPERTY_HTTP_HTTPS_SUFFIX,
+ "false");
+ httpProperties.setProperty
+ (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "HEALTHCHECK" + PolicyProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX,
+ "username");
+ httpProperties.setProperty
+ (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "HEALTHCHECK" + PolicyProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX,
+ "password");
+ httpProperties.setProperty
+ (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "HEALTHCHECK" + PolicyProperties.PROPERTY_MANAGED_SUFFIX,
+ "true");
+
+
+ configDirSetup();
+
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ logger.info("-- tearDown() --");
+
+ configDirCleanup();
+ }
+
+ @Test
+ public void test() {
+
+ HealthCheckFeature feature = new HealthCheckFeature();
+ feature.afterStart(PolicyEngine.manager);
+
+ Reports reports = HealthCheck.monitor.healthCheck();
+
+ for (Report rpt : reports.details) {
+ if (rpt.name == "HEALTHCHECK") {
+ assertTrue(rpt.healthy);
+ assertEquals(200,rpt.code);
+ assertEquals("All Alive", rpt.message);
+ break;
+ }
+ }
+
+ feature.afterShutdown(PolicyEngine.manager);
+
+ }
+
+
+ /**
+ * setup up config directory
+ */
+ protected static void configDirSetup() {
+
+ File origPropsFile = new File(healthCheckPropsPath.toString());
+ File backupPropsFile = new File(healthCheckPropsBackupPath.toString());
+ Path configDir = Paths.get(SystemPersistence.DEFAULT_CONFIGURATION_DIR);
+
+ try {
+
+ if (Files.notExists(configDir)) {
+ Files.createDirectories(configDir);
+ }
+
+ Files.deleteIfExists(healthCheckPropsBackupPath);
+ origPropsFile.renameTo(backupPropsFile);
+
+ FileWriter writer = new FileWriter(origPropsFile);
+ httpProperties.store(writer,"Machine created healthcheck-feature Properties");
+
+ } catch (final Exception e) {
+ logger.info("Problem cleaning {}", healthCheckPropsPath, e);
+ }
+ }
+
+ /**
+ * cleanup up config directory
+ */
+ protected static void configDirCleanup() {
+
+ File origPropsFile = new File(healthCheckPropsBackupPath.toString());
+ File backupPropsFile = new File(healthCheckPropsPath.toString());
+
+ try {
+ Files.deleteIfExists(healthCheckPropsPath);
+ origPropsFile.renameTo(backupPropsFile);
+ } catch (final Exception e) {
+ logger.info("Problem cleaning {}", healthCheckPropsPath, e);
+ }
+ }
+
+}
diff --git a/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/RestMockHealthCheck.java b/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/RestMockHealthCheck.java
new file mode 100644
index 00000000..5b3b82b3
--- /dev/null
+++ b/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/RestMockHealthCheck.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * feature-healthcheck
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.healthcheck;
+
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+@Path("/")
+public class RestMockHealthCheck {
+
+ @GET
+ @Path("healthcheck/test")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response papHealthCheck() {
+ return Response.status(Status.OK).entity("All Alive").build();
+ }
+
+}