aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-07-17 09:43:08 -0400
committerJim Hahn <jrh3@att.com>2019-07-18 16:04:53 -0400
commit14d66fcf742b8a15867ac0b9b82176b0958f0ae6 (patch)
tree172af7e3fc3b09593f41141f941f48fb3101c5e6 /main/src/test/java
parent120b41703b98380476ee022a98ce05da997305a6 (diff)
Modify policy/api to use RestServer from common
This also entailed removing the local copy of RestServerParameters. Change-Id: Ie5c581ab70aee60844d1660fe0a61290de6470ec Issue-ID: POLICY-1652 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/test/java')
-rw-r--r--main/src/test/java/org/onap/policy/api/main/parameters/CommonTestData.java29
-rw-r--r--main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterGroup.java3
-rw-r--r--main/src/test/java/org/onap/policy/api/main/parameters/TestRestServerParameters.java46
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java13
4 files changed, 24 insertions, 67 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
index f6266de5..32c44602 100644
--- 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
@@ -25,6 +25,12 @@ package org.onap.policy.api.main.parameters;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.TextFileUtils;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
@@ -41,12 +47,6 @@ public class CommonTestData {
*/
private static final String REST_SERVER_PORT = "6969";
- private static final String REST_SERVER_PASSWORD = "zb!XztG34";
- private static final String REST_SERVER_USER = "healthcheck";
- private static final String REST_SERVER_HOST = "0.0.0.0";
- private static final boolean REST_SERVER_HTTPS = false;
- private static final boolean REST_SERVER_AAF = false;
-
private static final String PROVIDER_GROUP_NAME = "PolicyProviderParameterGroup";
private static final String PROVIDER_IMPL = "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl";
private static final String DATABASE_DRIVER = "org.h2.Driver";
@@ -55,6 +55,8 @@ public class CommonTestData {
private static final String DATABASE_PASSWORD = "P01icY";
private static final String PERSISTENCE_UNIT = "ToscaConceptTest";
+ private Coder coder = new StandardCoder();
+
/**
* Returns an instance of RestServerParameters for test cases.
*
@@ -63,14 +65,15 @@ public class CommonTestData {
* @return the RestServerParameters object
*/
public RestServerParameters getRestServerParameters(final boolean isEmpty, int port) {
- final RestServerParameters restServerParameters;
- if (!isEmpty) {
- restServerParameters = new RestServerParameters(REST_SERVER_HOST, port, REST_SERVER_USER,
- REST_SERVER_PASSWORD, REST_SERVER_HTTPS, REST_SERVER_AAF);
- } else {
- restServerParameters = new RestServerParameters(null, 0, null, null, false, false);
+ String fileName = "src/test/resources/parameters/"
+ + (isEmpty ? "RestServerParametersEmpty" : "RestServerParameters") + ".json";
+ try {
+ String text = new String(Files.readAllBytes(new File(fileName).toPath()), StandardCharsets.UTF_8);
+ text = text.replace("6969", String.valueOf(port));
+ return coder.decode(text, RestServerParameters.class);
+ } catch (CoderException | IOException e) {
+ throw new RuntimeException("cannot read/decode " + fileName, e);
}
- 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
index b8f27e94..c12847a7 100644
--- 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
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
@@ -98,7 +99,7 @@ public class TestApiParameterGroup {
final GroupValidationResult validationResult = apiParameters.validate();
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.api.main.parameters.RestServerParameters\" INVALID, "
+ .contains("\"org.onap.policy.common.endpoints.parameters.RestServerParameters\" INVALID, "
+ "parameter group has status INVALID"));
}
diff --git a/main/src/test/java/org/onap/policy/api/main/parameters/TestRestServerParameters.java b/main/src/test/java/org/onap/policy/api/main/parameters/TestRestServerParameters.java
deleted file mode 100644
index 15323a4d..00000000
--- a/main/src/test/java/org/onap/policy/api/main/parameters/TestRestServerParameters.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy API
- * ================================================================================
- * Copyright (C) 2019 IBM.
- * ================================================================================
- * 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 org.junit.Before;
-import org.junit.Test;
-
-public class TestRestServerParameters {
-
- private RestServerParameters restServerParameters;
-
- @Before
- public void setUp() {
- restServerParameters = new RestServerParameters("host", 22, "userName", "password");
- }
-
- @Test
- public void testGetMethods() {
- assertEquals("userName", restServerParameters.getUserName());
- assertEquals("host", restServerParameters.getHost());
- assertEquals(22, restServerParameters.getPort());
- assertEquals("password", restServerParameters.getPassword());
- }
-}
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
index 6d49efd2..103eb4ca 100644
--- 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
@@ -34,7 +34,6 @@ import java.lang.reflect.Modifier;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.Properties;
-
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
@@ -45,7 +44,6 @@ 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.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
@@ -53,8 +51,9 @@ import org.junit.After;
import org.junit.Test;
import org.onap.policy.api.main.exception.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.http.server.RestServer;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -139,7 +138,7 @@ public class TestApiRestServer {
private static final String KEYSTORE = System.getProperty("user.dir") + "/src/test/resources/ssl/policy-keystore";
private static final CommonTestData COMMON_TEST_DATA = new CommonTestData();
private Main main;
- private ApiRestServer restServer;
+ private RestServer restServer;
private StandardCoder standardCoder = new StandardCoder();
private int port;
@@ -199,14 +198,14 @@ public class TestApiRestServer {
port = NetworkUtil.allocPort();
final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false, port);
restServerParams.setName(CommonTestData.API_GROUP_NAME);
- restServer = new ApiRestServer(restServerParams);
+ restServer = new RestServer(restServerParams, null, ApiRestController.class);
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("ApiRestServer [servers="));
+ assertTrue(restServer.toString().startsWith("RestServer [servers="));
} catch (final Exception exp) {
LOGGER.error("testHealthCheckFailure failed", exp);
fail("Test should not throw an exception");
@@ -252,7 +251,7 @@ public class TestApiRestServer {
port = NetworkUtil.allocPort();
final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false, port);
restServerParams.setName(CommonTestData.API_GROUP_NAME);
- restServer = new ApiRestServer(restServerParams);
+ restServer = new RestServer(restServerParams, null, ApiRestController.class);
try {
restServer.start();
final Invocation.Builder invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT);