summaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authorKrishnajinka <kris.jinka@samsung.com>2018-08-31 20:01:30 +0900
committerkrishnajinka <kris.jinka@samsung.com>2018-09-03 08:17:36 +0900
commitda9e01a78e3205ee7238196a574adcf11c041797 (patch)
treeb3e9baf1e0087b95f5b4ba54ce93ef3f1b59a471 /main/src/test
parent293600297e604c9a8d5487cd281044becdf9c405 (diff)
Add basic main structure for policy-api
Define main pom xml and update to include main. Add the main exception parameters rest startstop classes. Add test cases. Modify comments Issue-ID: POLICY-1066 Change-Id: I2e878a58eef4f021e3a9a991738194127edf4d16 Signed-off-by: krisjinka <kris.jinka@samsung.com> Signed-off-by: krishnajinka <kris.jinka@samsung.com>
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/api/main/parameters/CommonTestData.java52
-rw-r--r--main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterGroup.java92
-rw-r--r--main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java219
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java117
-rw-r--r--main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java55
-rw-r--r--main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java76
-rw-r--r--main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt7
-rw-r--r--main/src/test/resources/parameters/ApiConfigParameters.json9
-rw-r--r--main/src/test/resources/parameters/ApiConfigParameters_InvalidName.json9
-rw-r--r--main/src/test/resources/parameters/ApiConfigParameters_InvalidRestServerParameters.json9
-rw-r--r--main/src/test/resources/parameters/BadParameters.json3
-rw-r--r--main/src/test/resources/parameters/EmptyParameters.json0
-rw-r--r--main/src/test/resources/parameters/InvalidParameters.json3
-rw-r--r--main/src/test/resources/parameters/MinimumParameters.json9
-rw-r--r--main/src/test/resources/parameters/NoParameters.json8
15 files changed, 668 insertions, 0 deletions
diff --git a/main/src/test/java/org/onap/policy/api/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/api/main/parameters/CommonTestData.java
new file mode 100644
index 00000000..f86c8570
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/api/main/parameters/CommonTestData.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. 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.api.main.parameters;
+
+/**
+ * Class to hold/create all parameters for test cases.
+ *
+ */
+public class CommonTestData {
+
+ 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";
+ public static final String API_GROUP_NAME = "ApiGroup";
+
+ /**
+ * Returns an instance of ReceptionHandlerParameters for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return the restServerParameters object
+ */
+ public RestServerParameters getRestServerParameters(final boolean isEmpty) {
+ final RestServerParameters restServerParameters;
+ if (!isEmpty) {
+ restServerParameters = new RestServerParameters(REST_SERVER_HOST, REST_SERVER_PORT, REST_SERVER_USER,
+ REST_SERVER_PASSWORD);
+ } else {
+ restServerParameters = new RestServerParameters(null, 0, null, null);
+ }
+ return restServerParameters;
+ }
+
+}
diff --git a/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterGroup.java b/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterGroup.java
new file mode 100644
index 00000000..6ad8c72b
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterGroup.java
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. 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.api.main.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+/**
+ * Class to perform unit test of ApiParameterGroup.
+ *
+ */
+public class TestApiParameterGroup {
+ CommonTestData commonTestData = new CommonTestData();
+
+ @Test
+ public void testApiParameterGroup() {
+ final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
+ final ApiParameterGroup apiParameters = new ApiParameterGroup(
+ CommonTestData.API_GROUP_NAME, restServerParameters);
+ final GroupValidationResult validationResult = apiParameters.validate();
+ assertTrue(validationResult.isValid());
+ assertEquals(restServerParameters.getHost(), apiParameters.getRestServerParameters().getHost());
+ assertEquals(restServerParameters.getPort(), apiParameters.getRestServerParameters().getPort());
+ assertEquals(restServerParameters.getUserName(),
+ apiParameters.getRestServerParameters().getUserName());
+ assertEquals(restServerParameters.getPassword(),
+ apiParameters.getRestServerParameters().getPassword());
+ assertEquals(CommonTestData.API_GROUP_NAME, apiParameters.getName());
+ }
+
+ @Test
+ public void testApiParameterGroup_NullName() {
+ final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
+ final ApiParameterGroup apiParameters = new ApiParameterGroup(null,
+ restServerParameters);
+ final GroupValidationResult validationResult = apiParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertEquals(null, apiParameters.getName());
+ assertTrue(validationResult.getResult()
+ .contains("field \"name\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "must be a non-blank string"));
+ }
+
+ @Test
+ public void testApiParameterGroup_EmptyName() {
+ final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
+
+ final ApiParameterGroup apiParameters = new ApiParameterGroup("",
+ restServerParameters);
+ final GroupValidationResult validationResult = apiParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertEquals("", apiParameters.getName());
+ assertTrue(validationResult.getResult().contains("field \"name\" type \"java.lang.String\" value \"\" INVALID, "
+ + "must be a non-blank string"));
+ }
+
+ @Test
+ public void testApiParameterGroup_EmptyRestServerParameters() {
+ final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(true);
+
+ final ApiParameterGroup apiParameters = new ApiParameterGroup(
+ CommonTestData.API_GROUP_NAME, restServerParameters);
+ final GroupValidationResult validationResult = apiParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("\"org.onap.policy.api.main.parameters.RestServerParameters\" INVALID, "
+ + "parameter group has status INVALID"));
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java b/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java
new file mode 100644
index 00000000..7a065240
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterHandler.java
@@ -0,0 +1,219 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. 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.api.main.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import org.junit.Test;
+import org.onap.policy.api.main.PolicyApiException;
+import org.onap.policy.api.main.startstop.ApiCommandLineArguments;
+
+/**
+ * Class to perform unit test of ApiParameterHandler.
+ *
+ */
+public class TestApiParameterHandler {
+ @Test
+ public void testParameterHandlerNoParameterFile() throws PolicyApiException {
+ final String[] noArgumentString =
+ { "-c", "parameters/NoParameterFile.json" };
+
+ final ApiCommandLineArguments noArguments = new ApiCommandLineArguments();
+ noArguments.parse(noArgumentString);
+
+ try {
+ new ApiParameterHandler().getParameters(noArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("FileNotFoundException"));
+ }
+ }
+
+ @Test
+ public void testParameterHandlerEmptyParameters() throws PolicyApiException {
+ final String[] emptyArgumentString =
+ { "-c", "parameters/EmptyParameters.json" };
+
+ final ApiCommandLineArguments emptyArguments = new ApiCommandLineArguments();
+ emptyArguments.parse(emptyArgumentString);
+
+ try {
+ new ApiParameterHandler().getParameters(emptyArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("no parameters found in \"parameters/EmptyParameters.json\"", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerBadParameters() throws PolicyApiException {
+ final String[] badArgumentString =
+ { "-c", "parameters/BadParameters.json" };
+
+ final ApiCommandLineArguments badArguments = new ApiCommandLineArguments();
+ badArguments.parse(badArgumentString);
+
+ try {
+ new ApiParameterHandler().getParameters(badArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("error reading parameters from \"parameters/BadParameters.json\"\n"
+ + "(JsonSyntaxException):java.lang.IllegalStateException: "
+ + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerInvalidParameters() throws PolicyApiException {
+ final String[] invalidArgumentString =
+ { "-c", "parameters/InvalidParameters.json" };
+
+ final ApiCommandLineArguments invalidArguments = new ApiCommandLineArguments();
+ invalidArguments.parse(invalidArgumentString);
+
+ try {
+ new ApiParameterHandler().getParameters(invalidArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("error reading parameters from \"parameters/InvalidParameters.json\"\n"
+ + "(JsonSyntaxException):java.lang.IllegalStateException: "
+ + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerNoParameters() throws PolicyApiException {
+ final String[] noArgumentString =
+ { "-c", "parameters/NoParameters.json" };
+
+ final ApiCommandLineArguments noArguments = new ApiCommandLineArguments();
+ noArguments.parse(noArgumentString);
+
+ try {
+ new ApiParameterHandler().getParameters(noArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ String expMsg = "validation error(s) on parameters from \"parameters/NoParameters.json\"\nparameter group "
+ + "\"null\" type \"org.onap.policy.api.main.parameters.ApiParameterGroup\" INVALID, parameter "
+ + "group has status INVALID\n"
+ + " field \"name\" type \"java.lang.String\" value \"null\" INVALID, must be a non-blank string\n";
+ assertEquals(expMsg, e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerMinumumParameters() throws PolicyApiException {
+ final String[] minArgumentString =
+ { "-c", "parameters/MinimumParameters.json" };
+
+ final ApiCommandLineArguments minArguments = new ApiCommandLineArguments();
+ minArguments.parse(minArgumentString);
+
+ final ApiParameterGroup parGroup = new ApiParameterHandler().getParameters(minArguments);
+ assertEquals(CommonTestData.API_GROUP_NAME, parGroup.getName());
+ }
+
+ @Test
+ public void testApiParameterGroup() throws PolicyApiException {
+ final String[] apiConfigParameters =
+ { "-c", "parameters/ApiConfigParameters.json" };
+
+ final ApiCommandLineArguments arguments = new ApiCommandLineArguments();
+ arguments.parse(apiConfigParameters);
+
+ final ApiParameterGroup parGroup = new ApiParameterHandler().getParameters(arguments);
+ assertTrue(arguments.checkSetConfigurationFilePath());
+ assertEquals(CommonTestData.API_GROUP_NAME, parGroup.getName());
+ }
+
+ @Test
+ public void testApiParameterGroup_InvalidName() throws PolicyApiException {
+ final String[] apiConfigParameters =
+ { "-c", "parameters/ApiConfigParameters_InvalidName.json" };
+
+ final ApiCommandLineArguments arguments = new ApiCommandLineArguments();
+ arguments.parse(apiConfigParameters);
+
+ try {
+ new ApiParameterHandler().getParameters(arguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains(
+ "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string"));
+ }
+ }
+
+ @Test
+ public void testApiParameterGroup_InvalidRestServerParameters()
+ throws PolicyApiException, IOException {
+ final String[] apiConfigParameters =
+ { "-c", "parameters/ApiConfigParameters_InvalidRestServerParameters.json" };
+
+ final ApiCommandLineArguments arguments = new ApiCommandLineArguments();
+ arguments.parse(apiConfigParameters);
+
+ try {
+ new ApiParameterHandler().getParameters(arguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ final String expectedResult = new String(Files.readAllBytes(
+ Paths.get("src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt")))
+ .replaceAll("\\s+", "");
+ assertEquals(expectedResult, e.getMessage().replaceAll("\\s+", ""));
+ }
+ }
+
+ @Test
+ public void testApiVersion() throws PolicyApiException {
+ final String[] apiConfigParameters =
+ { "-v" };
+ final ApiCommandLineArguments arguments = new ApiCommandLineArguments();
+ final String version = arguments.parse(apiConfigParameters);
+ assertTrue(version.startsWith("ONAP Policy Framework Api Service"));
+ }
+
+ @Test
+ public void testApiHelp() throws PolicyApiException {
+ final String[] apiConfigParameters =
+ { "-h" };
+ final ApiCommandLineArguments arguments = new ApiCommandLineArguments();
+ final String help = arguments.parse(apiConfigParameters);
+ assertTrue(help.startsWith("usage:"));
+ }
+
+ @Test
+ public void testApiInvalidOption() throws PolicyApiException {
+ final String[] apiConfigParameters =
+ { "-d" };
+ final ApiCommandLineArguments arguments = new ApiCommandLineArguments();
+ try {
+ arguments.parse(apiConfigParameters);
+ } catch (final Exception exp) {
+ assertTrue(exp.getMessage().startsWith("invalid command line arguments specified"));
+ }
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
new file mode 100644
index 00000000..ad63d0f1
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
@@ -0,0 +1,117 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. 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.api.main.rest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+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 org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+import org.junit.Test;
+import org.onap.policy.api.main.PolicyApiException;
+import org.onap.policy.api.main.parameters.CommonTestData;
+import org.onap.policy.api.main.parameters.RestServerParameters;
+import org.onap.policy.api.main.startstop.Main;
+import org.onap.policy.common.endpoints.report.HealthCheckReport;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+
+/**
+ * Class to perform unit test of HealthCheckMonitor.
+ *
+ */
+public class TestApiRestServer {
+
+ private static final Logger LOGGER = FlexLogger.getLogger(TestApiRestServer.class);
+ private static final String NOT_ALIVE = "not alive";
+ private static final String ALIVE = "alive";
+ private static final String SELF = "self";
+ private static final String NAME = "Policy API";
+
+ @Test
+ public void testHealthCheckSuccess() throws PolicyApiException, InterruptedException {
+ final String reportString = "Report [name=Policy API, url=self, healthy=true, code=200, message=alive]";
+ final Main main = startApiService();
+ final HealthCheckReport report = performHealthCheck();
+ validateReport(NAME, SELF, true, 200, ALIVE, reportString, report);
+ stopApiService(main);
+ }
+
+ @Test
+ public void testHealthCheckFailure() throws InterruptedException {
+ final String reportString = "Report [name=Policy API, url=self, healthy=false, code=500, message=not alive]";
+ final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false);
+ restServerParams.setName(CommonTestData.API_GROUP_NAME);
+ final ApiRestServer restServer = new ApiRestServer(restServerParams);
+ restServer.start();
+ final HealthCheckReport report = performHealthCheck();
+ validateReport(NAME, SELF, false, 500, NOT_ALIVE, reportString, report);
+ assertTrue(restServer.isAlive());
+ assertTrue(restServer.toString().startsWith("ApiRestServer [servers="));
+ restServer.shutdown();
+ }
+
+ private Main startApiService() {
+ final String[] apiConfigParameters = { "-c", "parameters/ApiConfigParameters.json" };
+ return new Main(apiConfigParameters);
+ }
+
+ private void stopApiService(final Main main) throws PolicyApiException {
+ main.shutdown();
+ }
+
+ private HealthCheckReport performHealthCheck() throws InterruptedException {
+ HealthCheckReport response = null;
+ final ClientConfig clientConfig = new ClientConfig();
+
+ final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34");
+ clientConfig.register(feature);
+
+ final Client client = ClientBuilder.newClient(clientConfig);
+ final WebTarget webTarget = client.target("http://localhost:6969/healthcheck");
+
+ final Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
+ while (response == null) {
+ try {
+ response = invocationBuilder.get(HealthCheckReport.class);
+ } catch (final Exception exp) {
+ LOGGER.info("the server is not started yet. We will retry again");
+ }
+ }
+ return response;
+ }
+
+ private void validateReport(final String name, final String url, final boolean healthy, final int code,
+ final String message, final String reportString, final HealthCheckReport report) {
+ assertEquals(name, report.getName());
+ assertEquals(url, report.getUrl());
+ assertEquals(healthy, report.isHealthy());
+ assertEquals(code, report.getCode());
+ assertEquals(message, report.getMessage());
+ assertEquals(reportString, report.toString());
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java b/main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java
new file mode 100644
index 00000000..e5ab8101
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/api/main/startstop/TestApiActivator.java
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. 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.api.main.startstop;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.api.main.PolicyApiException;
+import org.onap.policy.api.main.parameters.ApiParameterGroup;
+import org.onap.policy.api.main.parameters.ApiParameterHandler;
+import org.onap.policy.api.main.parameters.CommonTestData;
+
+
+/**
+ * Class to perform unit test of ApiActivator.
+ *
+ */
+public class TestApiActivator {
+
+ @Test
+ public void testApiActivator() throws PolicyApiException {
+ final String[] apiConfigParameters =
+ { "-c", "parameters/ApiConfigParameters.json" };
+
+ final ApiCommandLineArguments arguments =
+ new ApiCommandLineArguments(apiConfigParameters);
+
+ final ApiParameterGroup parGroup = new ApiParameterHandler().getParameters(arguments);
+
+ final ApiActivator activator = new ApiActivator(parGroup);
+ activator.initialize();
+ assertTrue(activator.getParameterGroup().isValid());
+ assertEquals(CommonTestData.API_GROUP_NAME, activator.getParameterGroup().getName());
+ activator.terminate();
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java
new file mode 100644
index 00000000..47725349
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. 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.api.main.startstop;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.api.main.PolicyApiException;
+import org.onap.policy.api.main.parameters.CommonTestData;
+
+/**
+ * Class to perform unit test of Main.
+ *
+ */
+public class TestMain {
+
+ @Test
+ public void testMain() throws PolicyApiException {
+ final String[] apiConfigParameters =
+ { "-c", "parameters/ApiConfigParameters.json" };
+ final Main main = new Main(apiConfigParameters);
+ assertTrue(main.getParameters().isValid());
+ assertEquals(CommonTestData.API_GROUP_NAME, main.getParameters().getName());
+ main.shutdown();
+ }
+
+ @Test
+ public void testMain_NoArguments() {
+ final String[] apiConfigParameters =
+ {};
+ final Main main = new Main(apiConfigParameters);
+ assertTrue(main.getParameters() == null);
+ }
+
+ @Test
+ public void testMain_InvalidArguments() {
+ final String[] apiConfigParameters =
+ { "parameters/ApiConfigParameters.json" };
+ final Main main = new Main(apiConfigParameters);
+ assertTrue(main.getParameters() == null);
+ }
+
+ @Test
+ public void testMain_Help() {
+ final String[] apiConfigParameters =
+ { "-h" };
+ Main.main(apiConfigParameters);
+ }
+
+ @Test
+ public void testMain_InvalidParameters() {
+ final String[] apiConfigParameters =
+ { "-c", "parameters/ApiConfigParameters_InvalidName.json" };
+ final Main main = new Main(apiConfigParameters);
+ assertTrue(main.getParameters() == null);
+ }
+}
diff --git a/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt b/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt
new file mode 100644
index 00000000..2ab9c1b4
--- /dev/null
+++ b/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt
@@ -0,0 +1,7 @@
+validation error(s) on parameters from "parameters/ApiConfigParameters_InvalidRestServerParameters.json"
+parameter group "ApiGroup" type "org.onap.policy.api.main.parameters.ApiParameterGroup" INVALID, parameter group has status INVALID
+ parameter group "null" type "org.onap.policy.api.main.parameters.RestServerParameters" INVALID, parameter group has status INVALID
+ field "host" type "java.lang.String" value "" INVALID, must be a non-blank string containing hostname/ipaddress of the api rest server
+ field "port" type "int" value "-1" INVALID, must be a positive integer containing port of the api rest server
+ field "userName" type "java.lang.String" value "" INVALID, must be a non-blank string containing userName for api rest server credentials
+ field "password" type "java.lang.String" value "" INVALID, must be a non-blank string containing password for api rest server credentials
diff --git a/main/src/test/resources/parameters/ApiConfigParameters.json b/main/src/test/resources/parameters/ApiConfigParameters.json
new file mode 100644
index 00000000..8fae1238
--- /dev/null
+++ b/main/src/test/resources/parameters/ApiConfigParameters.json
@@ -0,0 +1,9 @@
+{
+ "name":"ApiGroup",
+ "restServerParameters":{
+ "host":"0.0.0.0",
+ "port":6969,
+ "userName":"healthcheck",
+ "password":"zb!XztG34"
+ }
+}
diff --git a/main/src/test/resources/parameters/ApiConfigParameters_InvalidName.json b/main/src/test/resources/parameters/ApiConfigParameters_InvalidName.json
new file mode 100644
index 00000000..80fb8232
--- /dev/null
+++ b/main/src/test/resources/parameters/ApiConfigParameters_InvalidName.json
@@ -0,0 +1,9 @@
+{
+ "name":" ",
+ "restServerParameters":{
+ "host":"0.0.0.0",
+ "port":6969,
+ "userName":"healthcheck",
+ "password":"zb!XztG34"
+ }
+}
diff --git a/main/src/test/resources/parameters/ApiConfigParameters_InvalidRestServerParameters.json b/main/src/test/resources/parameters/ApiConfigParameters_InvalidRestServerParameters.json
new file mode 100644
index 00000000..2d394fbc
--- /dev/null
+++ b/main/src/test/resources/parameters/ApiConfigParameters_InvalidRestServerParameters.json
@@ -0,0 +1,9 @@
+{
+ "name":"ApiGroup",
+ "restServerParameters":{
+ "host":"",
+ "port":-1,
+ "userName":"",
+ "password":""
+ }
+}
diff --git a/main/src/test/resources/parameters/BadParameters.json b/main/src/test/resources/parameters/BadParameters.json
new file mode 100644
index 00000000..de2040cc
--- /dev/null
+++ b/main/src/test/resources/parameters/BadParameters.json
@@ -0,0 +1,3 @@
+{
+ "name" : []
+} \ No newline at end of file
diff --git a/main/src/test/resources/parameters/EmptyParameters.json b/main/src/test/resources/parameters/EmptyParameters.json
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/main/src/test/resources/parameters/EmptyParameters.json
diff --git a/main/src/test/resources/parameters/InvalidParameters.json b/main/src/test/resources/parameters/InvalidParameters.json
new file mode 100644
index 00000000..de2040cc
--- /dev/null
+++ b/main/src/test/resources/parameters/InvalidParameters.json
@@ -0,0 +1,3 @@
+{
+ "name" : []
+} \ No newline at end of file
diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json
new file mode 100644
index 00000000..61c6c869
--- /dev/null
+++ b/main/src/test/resources/parameters/MinimumParameters.json
@@ -0,0 +1,9 @@
+{
+ "name":"ApiGroup",
+ "restServerParameters":{
+ "host":"0.0.0.0",
+ "port":6969,
+ "userName":"healthcheck",
+ "password":"zb!XztG34"
+ }
+}
diff --git a/main/src/test/resources/parameters/NoParameters.json b/main/src/test/resources/parameters/NoParameters.json
new file mode 100644
index 00000000..6b0805d3
--- /dev/null
+++ b/main/src/test/resources/parameters/NoParameters.json
@@ -0,0 +1,8 @@
+{
+ "restServerParameters":{
+ "host":"0.0.0.0",
+ "port":6969,
+ "userName":"healthcheck",
+ "password":"zb!XztG34"
+ }
+} \ No newline at end of file