summaryrefslogtreecommitdiffstats
path: root/services/services-onappf/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'services/services-onappf/src/test/java')
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java (renamed from services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterActivator.java)13
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterConstants.java (renamed from services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterConstants.java)3
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java (renamed from services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterMain.java)9
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java (renamed from services/services-onappf/src/test/java/org/onap/policy/apex/starter/comm/TestPdpStateChangeListener.java)27
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java (renamed from services/services-onappf/src/test/java/org/onap/policy/apex/starter/comm/TestPdpUpdateListener.java)23
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/exception/TestExceptions.java (renamed from services/services-onappf/src/test/java/org/onap/policy/apex/starter/exception/TestExceptions.java)4
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java (renamed from services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/CommonTestData.java)30
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java (renamed from services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterGroup.java)26
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java (renamed from services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterHandler.java)8
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java (renamed from services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestPdpStatusParameters.java)3
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java286
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java62
12 files changed, 460 insertions, 34 deletions
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterActivator.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java
index 6da3a5eb6..238a89f66 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterActivator.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter;
+package org.onap.policy.apex.services.onappf;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
@@ -33,10 +33,13 @@ import java.util.Properties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.apex.starter.exception.ApexStarterException;
-import org.onap.policy.apex.starter.parameters.ApexStarterParameterGroup;
-import org.onap.policy.apex.starter.parameters.ApexStarterParameterHandler;
-import org.onap.policy.apex.starter.parameters.CommonTestData;
+import org.onap.policy.apex.services.onappf.ApexStarterActivator;
+import org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments;
+import org.onap.policy.apex.services.onappf.ApexStarterConstants;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
+import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
+import org.onap.policy.apex.services.onappf.parameters.CommonTestData;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpStatus;
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterConstants.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterConstants.java
index 08e56cdf8..52ca94439 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterConstants.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterConstants.java
@@ -18,9 +18,10 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter;
+package org.onap.policy.apex.services.onappf;
import org.junit.Test;
+import org.onap.policy.apex.services.onappf.ApexStarterConstants;
import org.powermock.reflect.Whitebox;
/**
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterMain.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java
index 3005e320a..c5c0fc483 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterMain.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter;
+package org.onap.policy.apex.services.onappf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -27,8 +27,11 @@ import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.apex.starter.exception.ApexStarterException;
-import org.onap.policy.apex.starter.parameters.CommonTestData;
+import org.onap.policy.apex.services.onappf.ApexStarterActivator;
+import org.onap.policy.apex.services.onappf.ApexStarterConstants;
+import org.onap.policy.apex.services.onappf.ApexStarterMain;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.parameters.CommonTestData;
import org.onap.policy.common.utils.services.Registry;
/**
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/comm/TestPdpStateChangeListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
index d0a85f9f2..c6ed44556 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/comm/TestPdpStateChangeListener.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.comm;
+package org.onap.policy.apex.services.onappf.comm;
import static org.junit.Assert.assertEquals;
@@ -37,12 +37,12 @@ import java.util.Properties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.apex.starter.ApexStarterActivator;
-import org.onap.policy.apex.starter.ApexStarterCommandLineArguments;
-import org.onap.policy.apex.starter.ApexStarterConstants;
-import org.onap.policy.apex.starter.exception.ApexStarterException;
-import org.onap.policy.apex.starter.parameters.ApexStarterParameterGroup;
-import org.onap.policy.apex.starter.parameters.ApexStarterParameterHandler;
+import org.onap.policy.apex.services.onappf.ApexStarterActivator;
+import org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments;
+import org.onap.policy.apex.services.onappf.ApexStarterConstants;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
+import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
@@ -63,6 +63,13 @@ public class TestPdpStateChangeListener {
private static final String TOPIC = "my-topic";
private ApexStarterActivator activator;
+ /**
+ * Method for setup before each test.
+ *
+ * @throws ApexStarterException if some error occurs while starting up the apex starter
+ * @throws FileNotFoundException if the file is missing
+ * @throws IOException if IO exception occurs
+ */
@Before
public void setUp() throws ApexStarterException, FileNotFoundException, IOException {
pdpUpdateMessageListener = new PdpUpdateListener();
@@ -110,8 +117,10 @@ public class TestPdpStateChangeListener {
}
/**
- * @param instance
- * @return
+ * Method to initiate a PdpUpdate.
+ *
+ * @param instance the instance id
+ * @return PdpUpdate the pdp update message
*/
private PdpUpdate performPdpUpdate(final String instance) {
final PdpUpdate pdpUpdateMsg = new PdpUpdate();
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/comm/TestPdpUpdateListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
index 2ffed2cb6..ebe0fc957 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/comm/TestPdpUpdateListener.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.comm;
+package org.onap.policy.apex.services.onappf.comm;
import static org.junit.Assert.assertEquals;
@@ -37,13 +37,13 @@ import java.util.Properties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.apex.starter.ApexStarterActivator;
-import org.onap.policy.apex.starter.ApexStarterCommandLineArguments;
-import org.onap.policy.apex.starter.ApexStarterConstants;
-import org.onap.policy.apex.starter.exception.ApexStarterException;
-import org.onap.policy.apex.starter.handler.PdpMessageHandler;
-import org.onap.policy.apex.starter.parameters.ApexStarterParameterGroup;
-import org.onap.policy.apex.starter.parameters.ApexStarterParameterHandler;
+import org.onap.policy.apex.services.onappf.ApexStarterActivator;
+import org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments;
+import org.onap.policy.apex.services.onappf.ApexStarterConstants;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.handler.PdpMessageHandler;
+import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
+import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpStatus;
@@ -61,6 +61,13 @@ public class TestPdpUpdateListener {
private static final String TOPIC = "my-topic";
private ApexStarterActivator activator;
+ /**
+ * Method for setup before each test.
+ *
+ * @throws ApexStarterException if some error occurs while starting up the apex starter
+ * @throws FileNotFoundException if the file is missing
+ * @throws IOException if IO exception occurs
+ */
@Before
public void setUp() throws ApexStarterException, FileNotFoundException, IOException {
Registry.newRegistry();
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/exception/TestExceptions.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/exception/TestExceptions.java
index 63ebeb608..3a05e72b1 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/exception/TestExceptions.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/exception/TestExceptions.java
@@ -18,9 +18,11 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.exception;
+package org.onap.policy.apex.services.onappf.exception;
import org.junit.Test;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterRunTimeException;
import org.onap.policy.common.utils.test.ExceptionsTester;
/**
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/CommonTestData.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java
index d329d1f22..7e668e9b2 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/CommonTestData.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.parameters;
+package org.onap.policy.apex.services.onappf.parameters;
import java.util.Arrays;
import java.util.List;
@@ -47,6 +47,12 @@ public class CommonTestData {
public static final String POLICY_VERSION = "0.0.1";
public static final List<ToscaPolicyTypeIdentifierParameters> SUPPORTED_POLICY_TYPES =
Arrays.asList(getSupportedPolicyTypes(POLICY_NAME, POLICY_VERSION));
+ private static final String REST_SERVER_PASSWORD = "zb!XztG34";
+ private static final String REST_SERVER_USER = "healthcheck";
+ private static final int REST_SERVER_PORT = 6969;
+ private static final String REST_SERVER_HOST = "0.0.0.0";
+ private static final boolean REST_SERVER_HTTPS = true;
+ private static final boolean REST_SERVER_AAF = false;
public static final Coder coder = new StandardCoder();
@@ -89,12 +95,34 @@ public class CommonTestData {
final Map<String, Object> map = new TreeMap<>();
map.put("name", name);
+ map.put("restServerParameters", getRestServerParametersMap(false));
map.put("pdpStatusParameters", getPdpStatusParametersMap(false));
return map;
}
/**
+ * Returns a property map for a RestServerParameters map for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return a property map suitable for constructing an object
+ */
+ public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
+ final Map<String, Object> map = new TreeMap<>();
+ map.put("https", REST_SERVER_HTTPS);
+ map.put("aaf", REST_SERVER_AAF);
+
+ if (!isEmpty) {
+ map.put("host", REST_SERVER_HOST);
+ map.put("port", REST_SERVER_PORT);
+ map.put("userName", REST_SERVER_USER);
+ map.put("password", REST_SERVER_PASSWORD);
+ }
+
+ return map;
+ }
+
+ /**
* Returns a property map for a PdpStatusParameters map for test cases.
*
* @param isEmpty boolean value to represent that object created should be empty or not
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterGroup.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java
index 8d5f1cef9..dd9e83f52 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterGroup.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.parameters;
+package org.onap.policy.apex.services.onappf.parameters;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -48,6 +48,7 @@ public class TestApexStarterParameterGroup {
final ApexStarterParameterGroup apexStarterParameters = commonTestData.toObject(
commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
ApexStarterParameterGroup.class);
+ final RestServerParameters restServerParameters = apexStarterParameters.getRestServerParameters();
final PdpStatusParameters pdpStatusParameters = apexStarterParameters.getPdpStatusParameters();
final GroupValidationResult validationResult = apexStarterParameters.validate();
assertTrue(validationResult.isValid());
@@ -56,6 +57,12 @@ public class TestApexStarterParameterGroup {
assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
assertEquals(CommonTestData.DESCRIPTION, pdpStatusParameters.getDescription());
assertEquals(CommonTestData.SUPPORTED_POLICY_TYPES, pdpStatusParameters.getSupportedPolicyTypes());
+ assertEquals(restServerParameters.getHost(), apexStarterParameters.getRestServerParameters().getHost());
+ assertEquals(restServerParameters.getPort(), apexStarterParameters.getRestServerParameters().getPort());
+ assertEquals(restServerParameters.getUserName(), apexStarterParameters.getRestServerParameters().getUserName());
+ assertEquals(restServerParameters.getPassword(), apexStarterParameters.getRestServerParameters().getPassword());
+ assertTrue(apexStarterParameters.getRestServerParameters().isHttps());
+ assertFalse(apexStarterParameters.getRestServerParameters().isAaf());
}
@Test
@@ -100,7 +107,22 @@ public class TestApexStarterParameterGroup {
final GroupValidationResult validationResult = apexStarterParameters.validate();
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.apex.starter.parameters.ApexStarterParameterGroup\" INVALID, "
+ .contains("\"org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup\" INVALID, "
+ + "parameter group has status INVALID"));
+ }
+
+ @Test
+ public void testApexStarterParameterGroupp_EmptyRestServerParameters() {
+ final Map<String, Object> map =
+ commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
+ map.put("restServerParameters", commonTestData.getRestServerParametersMap(true));
+
+ final ApexStarterParameterGroup apexStarterParameters =
+ commonTestData.toObject(map, ApexStarterParameterGroup.class);
+ final GroupValidationResult validationResult = apexStarterParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("\"org.onap.policy.apex.services.onappf.parameters.RestServerParameters\" INVALID, "
+ "parameter group has status INVALID"));
}
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterHandler.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
index baa91d23a..f91baeb45 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterHandler.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.parameters;
+package org.onap.policy.apex.services.onappf.parameters;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -27,8 +27,10 @@ import static org.junit.Assert.fail;
import java.io.FileNotFoundException;
import org.junit.Test;
-import org.onap.policy.apex.starter.ApexStarterCommandLineArguments;
-import org.onap.policy.apex.starter.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
+import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
import org.onap.policy.common.utils.coder.CoderException;
/**
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestPdpStatusParameters.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java
index 37cbbe021..e8a3f7ee0 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestPdpStatusParameters.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java
@@ -18,13 +18,14 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.starter.parameters;
+package org.onap.policy.apex.services.onappf.parameters;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
+import org.onap.policy.apex.services.onappf.parameters.PdpStatusParameters;
import org.onap.policy.common.parameters.GroupValidationResult;
/**
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java
new file mode 100644
index 000000000..72db6e091
--- /dev/null
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java
@@ -0,0 +1,286 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.apex.services.onappf.rest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.security.SecureRandom;
+import java.util.Map;
+import java.util.Properties;
+import java.util.function.Function;
+
+import javax.net.ssl.SSLContext;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.onap.policy.apex.services.onappf.ApexStarterActivator;
+import org.onap.policy.apex.services.onappf.ApexStarterConstants;
+import org.onap.policy.apex.services.onappf.ApexStarterMain;
+import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
+import org.onap.policy.apex.services.onappf.parameters.CommonTestData;
+import org.onap.policy.common.gson.GsonMessageBodyHandler;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.common.utils.services.Registry;
+import org.powermock.reflect.Whitebox;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class to perform unit test of {@link ApexStarterRestServer}.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class CommonApexStarterRestServer {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CommonApexStarterRestServer.class);
+
+ private static String KEYSTORE = System.getProperty("user.dir") + "/src/test/resources/ssl/policy-keystore";
+
+ private static Coder coder = new StandardCoder();
+
+ public static final String NOT_ALIVE = "not alive";
+ public static final String ALIVE = "alive";
+ public static final String SELF = "self";
+ public static final String NAME = "Policy PDP-A";
+ public static final String ENDPOINT_PREFIX = "policy/apex-pdp/v1/";
+
+ private static int port;
+ protected static String httpsPrefix;
+
+ private static ApexStarterMain main;
+
+ private boolean activatorWasAlive;
+
+ /**
+ * Allocates a port for the server, writes a config file, and then starts Main.
+ *
+ * @throws Exception if an error occurs
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ port = NetworkUtil.allocPort();
+
+ httpsPrefix = "https://localhost:" + port + "/";
+
+ makeConfigFile();
+
+ startMain();
+ }
+
+ /**
+ * Stops Main.
+ */
+ @AfterClass
+ public static void teardownAfterClass() {
+ try {
+ stopMain();
+
+ } catch (final ApexStarterException exp) {
+ LOGGER.error("cannot stop main", exp);
+ }
+ }
+
+ /**
+ * Set up.
+ *
+ * @throws Exception if an error occurs
+ */
+ @Before
+ public void setUp() throws Exception {
+ // restart, if not currently running
+ if (main == null) {
+ startMain();
+ }
+
+ activatorWasAlive =
+ Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class).isAlive();
+ }
+
+ /**
+ * Restores the activator's "alive" state.
+ */
+ @After
+ public void tearDown() {
+ markActivator(activatorWasAlive);
+ }
+
+ /**
+ * Verifies that an endpoint appears within the swagger response.
+ *
+ * @param endpoint the endpoint of interest
+ * @throws Exception if an error occurs
+ */
+ protected void testSwagger(final String endpoint) throws Exception {
+ final Invocation.Builder invocationBuilder = sendFqeRequest(httpsPrefix + "swagger.yaml", true);
+ final String resp = invocationBuilder.get(String.class);
+
+ assertTrue(resp.contains(ENDPOINT_PREFIX + endpoint + ":"));
+ }
+
+ /**
+ * Makes a parameter configuration file.
+ *
+ * @throws Exception if an error occurs
+ */
+ private static void makeConfigFile() throws Exception {
+ final Map<String, Object> config =
+ new CommonTestData().getApexStarterParameterGroupMap("ApexStarterParameterGroup");
+
+ @SuppressWarnings("unchecked")
+ final Map<String, Object> restParams = (Map<String, Object>) config.get("restServerParameters");
+ restParams.put("port", port);
+
+ final File file = new File("src/test/resources/TestConfigParams.json");
+ file.deleteOnExit();
+
+ coder.encode(file, config);
+ }
+
+ /**
+ * Starts the "Main".
+ *
+ * @throws Exception if an error occurs
+ */
+ private static void startMain() throws Exception {
+ Registry.newRegistry();
+
+ // make sure port is available
+ if (NetworkUtil.isTcpPortOpen("localhost", port, 1, 1L)) {
+ throw new IllegalStateException("port " + port + " is still in use");
+ }
+
+ final Properties systemProps = System.getProperties();
+ systemProps.put("javax.net.ssl.keyStore", KEYSTORE);
+ systemProps.put("javax.net.ssl.keyStorePassword", "Pol1cy_0nap");
+ System.setProperties(systemProps);
+
+ // @formatter:off
+ final String[] apexStarterConfigParameters = {
+ "-c", "src/test/resources/TestConfigParams.json",
+ "-p", "src/test/resources/topic.properties"
+ };
+ // @formatter:on
+
+ main = new ApexStarterMain(apexStarterConfigParameters);
+
+ if (!NetworkUtil.isTcpPortOpen("localhost", port, 6, 10000L)) {
+ throw new IllegalStateException("server is not listening on port " + port);
+ }
+ }
+
+ /**
+ * Stops the "Main".
+ *
+ * @throws Exception if an error occurs
+ */
+ private static void stopMain() throws ApexStarterException {
+ if (main != null) {
+ final ApexStarterMain main2 = main;
+ main = null;
+
+ main2.shutdown();
+ }
+ }
+
+ private void markActivator(final boolean wasAlive) {
+ final Object manager = Whitebox.getInternalState(
+ Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class), "manager");
+ Whitebox.setInternalState(manager, "running", wasAlive);
+ }
+
+ /**
+ * Verifies that unauthorized requests fail.
+ *
+ * @param endpoint the target end point
+ * @param sender function that sends the requests to the target
+ * @throws Exception if an error occurs
+ */
+ protected void checkUnauthRequest(final String endpoint, final Function<Invocation.Builder, Response> sender)
+ throws Exception {
+ assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(),
+ sender.apply(sendNoAuthRequest(endpoint)).getStatus());
+ }
+
+ /**
+ * Sends a request to an endpoint.
+ *
+ * @param endpoint the target endpoint
+ * @return a request builder
+ * @throws Exception if an error occurs
+ */
+ protected Invocation.Builder sendRequest(final String endpoint) throws Exception {
+ return sendFqeRequest(httpsPrefix + ENDPOINT_PREFIX + endpoint, true);
+ }
+
+ /**
+ * Sends a request to an endpoint, without any authorization header.
+ *
+ * @param endpoint the target endpoint
+ * @return a request builder
+ * @throws Exception if an error occurs
+ */
+ protected Invocation.Builder sendNoAuthRequest(final String endpoint) throws Exception {
+ return sendFqeRequest(httpsPrefix + ENDPOINT_PREFIX + endpoint, false);
+ }
+
+ /**
+ * Sends a request to a fully qualified endpoint.
+ *
+ * @param fullyQualifiedEndpoint the fully qualified target endpoint
+ * @param includeAuth if authorization header should be included
+ * @return a request builder
+ * @throws Exception if an error occurs
+ */
+ protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, final boolean includeAuth)
+ throws Exception {
+ final SSLContext sc = SSLContext.getInstance("TLSv1.2");
+ sc.init(null, NetworkUtil.getAlwaysTrustingManager(), new SecureRandom());
+ final ClientBuilder clientBuilder =
+ ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier((host, session) -> true);
+ final Client client = clientBuilder.build();
+
+ client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
+ client.register(GsonMessageBodyHandler.class);
+
+ if (includeAuth) {
+ final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34");
+ client.register(feature);
+ }
+
+ final WebTarget webTarget = client.target(fullyQualifiedEndpoint);
+
+ return webTarget.request(MediaType.APPLICATION_JSON);
+ }
+}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java
new file mode 100644
index 000000000..cd625c8dd
--- /dev/null
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.apex.services.onappf.rest;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.ws.rs.client.Invocation;
+
+import org.junit.Test;
+import org.onap.policy.common.endpoints.report.HealthCheckReport;
+
+/**
+ * Class to perform unit test of {@link ApexStarterRestServer}.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class TestHealthCheckRestControllerV1 extends CommonApexStarterRestServer {
+
+ private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
+
+ @Test
+ public void testSwagger() throws Exception {
+ super.testSwagger(HEALTHCHECK_ENDPOINT);
+ }
+
+ @Test
+ public void testHealthCheckSuccess() throws Exception {
+ final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT);
+ final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
+ validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report);
+
+ // verify it fails when no authorization info is included
+ checkUnauthRequest(HEALTHCHECK_ENDPOINT, req -> req.get());
+ }
+
+ private void validateHealthCheckReport(final String name, final String url, final boolean healthy, final int code,
+ final String message, final HealthCheckReport report) {
+ assertEquals(name, report.getName());
+ assertEquals(url, report.getUrl());
+ assertEquals(healthy, report.isHealthy());
+ assertEquals(code, report.getCode());
+ assertEquals(message, report.getMessage());
+ }
+}