aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@est.tech>2019-07-04 14:14:39 +0000
committera.sreekumar <ajith.sreekumar@est.tech>2019-07-04 14:14:39 +0000
commitaba606406dded6ea6d9bf140ea2cbbf11fe90238 (patch)
treed4c92ddff7843439708cbcd1bf874cc0b5ae0a17 /main/src/test/java
parentdc6afa16a2b9fbd19373a1e2ca5859df2782dcb6 (diff)
Remove topic.properties and incorporate into overall config file for xacml
Change-Id: I3be6248db65041f5d9b7acfcf0fcd2f49d9d70f8 Issue-ID: POLICY-1744 Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'main/src/test/java')
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java3
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java100
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java52
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java22
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java3
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java12
6 files changed, 148 insertions, 44 deletions
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java b/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java
index 0c84419f..a32bc6fd 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -116,7 +117,7 @@ public class CommonRest {
writeJsonConfig();
- final String[] xacmlPdpConfigParameters = {"-c", CommonRest.CONFIG_FILE, "-p", "parameters/topic.properties"};
+ final String[] xacmlPdpConfigParameters = {"-c", CommonRest.CONFIG_FILE};
main = new Main(xacmlPdpConfigParameters);
if (!NetworkUtil.isTcpPortOpen("localhost", port, 20, 1000L)) {
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
index 1bf2294c..24bf48f3 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -20,6 +21,16 @@
package org.onap.policy.pdpx.main.parameters;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import org.onap.policy.common.endpoints.parameters.TopicParameters;
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+
/**
* Class to hold/create all parameters for test cases.
*
@@ -33,25 +44,90 @@ public class CommonTestData {
private static final boolean REST_SERVER_HTTPS = false;
private static final boolean REST_SERVER_AAF = false;
public static final String PDPX_GROUP_NAME = "XacmlPdpGroup";
+ public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams());
+
+ public static final Coder coder = new StandardCoder();
+
+ /**
+ * Returns topic parameters for test cases.
+ *
+ * @return topic parameters
+ */
+ public static TopicParameters getTopicParams() {
+ final TopicParameters topicParams = new TopicParameters();
+ topicParams.setTopic("POLICY-PDP-PAP");
+ topicParams.setTopicCommInfrastructure("dmaap");
+ topicParams.setServers(Arrays.asList("message-router"));
+ return topicParams;
+ }
/**
- * Returns an instance of RestServerParameters for test cases.
+ * 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 the restServerParameters object
+ * @return a property map suitable for constructing an object
*/
- public RestServerParameters getRestServerParameters(final boolean isEmpty) {
- final RestServerBuilder builder;
+ 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) {
- builder = new RestServerBuilder().setHost(REST_SERVER_HOST).setPort(REST_SERVER_PORT)
- .setUserName(REST_SERVER_USER).setPassword(REST_SERVER_PASSWORD).setHttps(REST_SERVER_HTTPS)
- .setAaf(REST_SERVER_AAF);
- } else {
- builder = new RestServerBuilder().setHost(null).setPort(0).setUserName(null).setPassword(null)
- .setHttps(REST_SERVER_HTTPS).setAaf(REST_SERVER_AAF);
+ map.put("host", REST_SERVER_HOST);
+ map.put("port", REST_SERVER_PORT);
+ map.put("userName", REST_SERVER_USER);
+ map.put("password", REST_SERVER_PASSWORD);
}
- final RestServerParameters restServerParameters = new RestServerParameters(builder);
- return restServerParameters;
+
+ return map;
+ }
+
+ /**
+ * Returns a property map for a RestServerParameters map for test cases.
+ *
+ * @param port the port for RestServer
+ * @return a property map suitable for constructing an object
+ */
+ public Map<String, Object> getRestServerParametersMap(final int port) {
+ final Map<String, Object> map = new TreeMap<>();
+ map.put("https", REST_SERVER_HTTPS);
+ map.put("aaf", REST_SERVER_AAF);
+ map.put("host", REST_SERVER_HOST);
+ map.put("port", port);
+ map.put("userName", REST_SERVER_USER);
+ map.put("password", REST_SERVER_PASSWORD);
+
+ return map;
}
+ /**
+ * Converts the contents of a map to a parameter class.
+ *
+ * @param source property map
+ * @param clazz class of object to be created from the map
+ * @return a new object represented by the map
+ */
+ public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
+ try {
+ return coder.decode(coder.encode(source), clazz);
+
+ } catch (final CoderException e) {
+ throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
+ }
+ }
+
+ /**
+ * Returns a property map for a TopicParameters 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> getTopicParametersMap(final boolean isEmpty) {
+ final Map<String, Object> map = new TreeMap<>();
+ if (!isEmpty) {
+ map.put("topicSources", TOPIC_PARAMS);
+ map.put("topicSinks", TOPIC_PARAMS);
+ }
+ return map;
+ }
}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
index 2bf6fd81..1484edfd 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -27,11 +28,12 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
-
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
+import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.parameters.GroupValidationResult;
/**
@@ -41,6 +43,7 @@ import org.onap.policy.common.parameters.GroupValidationResult;
public class TestXacmlPdpParameterGroup {
CommonTestData commonTestData = new CommonTestData();
private static File applicationPath;
+ private static CommonTestData testData = new CommonTestData();
@ClassRule
public static final TemporaryFolder applicationFolder = new TemporaryFolder();
@@ -52,11 +55,13 @@ public class TestXacmlPdpParameterGroup {
@Test
public void testXacmlPdpParameterGroup() throws IOException {
- final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
+ final RestServerParameters restServerParameters =
+ testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final TopicParameterGroup topicParameterGroup =
+ testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters =
new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME,
- restServerParameters,
- applicationPath.getAbsolutePath());
+ restServerParameters, topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(restServerParameters.getHost(), pdpxParameters.getRestServerParameters().getHost());
@@ -70,9 +75,12 @@ public class TestXacmlPdpParameterGroup {
@Test
public void testXacmlPdpParameterGroup_NullName() {
- final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
+ final RestServerParameters restServerParameters =
+ testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final TopicParameterGroup topicParameterGroup =
+ testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(null, restServerParameters,
- applicationPath.getAbsolutePath());
+ topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertFalse(validationResult.isValid());
assertEquals(null, pdpxParameters.getName());
@@ -82,10 +90,12 @@ public class TestXacmlPdpParameterGroup {
@Test
public void testXacmlPdpParameterGroup_EmptyName() {
- final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
-
+ final RestServerParameters restServerParameters =
+ testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final TopicParameterGroup topicParameterGroup =
+ testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup("", restServerParameters,
- applicationPath.getAbsolutePath());
+ topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertFalse(validationResult.isValid());
assertEquals("", pdpxParameters.getName());
@@ -95,15 +105,33 @@ public class TestXacmlPdpParameterGroup {
@Test
public void testXacmlPdpParameterGroup_EmptyRestServerParameters() {
- final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(true);
+ final RestServerParameters restServerParameters =
+ testData.toObject(testData.getRestServerParametersMap(true), RestServerParameters.class);
+ final TopicParameterGroup topicParameterGroup =
+ testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
+ final XacmlPdpParameterGroup pdpxParameters =
+ new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters,
+ topicParameterGroup, applicationPath.getAbsolutePath());
+ final GroupValidationResult validationResult = pdpxParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("\"org.onap.policy.common.endpoints.parameters.RestServerParameters\" INVALID, "
+ + "parameter group has status INVALID"));
+ }
+ @Test
+ public void testXacmlPdpParameterGroup_EmptyTopicParameterGroup() {
+ final RestServerParameters restServerParameters =
+ testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class);
+ final TopicParameterGroup topicParameterGroup =
+ testData.toObject(testData.getTopicParametersMap(true), TopicParameterGroup.class);
final XacmlPdpParameterGroup pdpxParameters =
new XacmlPdpParameterGroup(CommonTestData.PDPX_GROUP_NAME, restServerParameters,
- applicationPath.getAbsolutePath());
+ topicParameterGroup, applicationPath.getAbsolutePath());
final GroupValidationResult validationResult = pdpxParameters.validate();
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.pdpx.main.parameters.RestServerParameters\" INVALID, "
+ .contains("\"org.onap.policy.common.endpoints.parameters.TopicParameterGroup\" INVALID, "
+ "parameter group has status INVALID"));
}
}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
index 5f7eb78c..b1732048 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -25,7 +26,6 @@ import static org.junit.Assert.assertEquals;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
@@ -37,12 +37,10 @@ import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
-
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
@@ -50,14 +48,15 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
+import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
import org.onap.policy.models.decisions.concepts.DecisionResponse;
import org.onap.policy.models.errors.concepts.ErrorResponse;
import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
-import org.onap.policy.pdpx.main.parameters.RestServerBuilder;
-import org.onap.policy.pdpx.main.parameters.RestServerParameters;
+import org.onap.policy.pdpx.main.parameters.CommonTestData;
import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
import org.onap.policy.pdpx.main.startstop.Main;
import org.slf4j.Logger;
@@ -70,6 +69,7 @@ public class TestDecision {
private static int port;
private static Main main;
private static HttpClient client;
+ private static CommonTestData testData = new CommonTestData();
@ClassRule
public static final TemporaryFolder appsFolder = new TemporaryFolder();
@@ -97,9 +97,12 @@ public class TestDecision {
//
// Get the parameters file correct.
//
- RestServerParameters rest = new RestServerParameters(new RestServerBuilder()
- .setHost("0.0.0.0").setPort(port).setUserName("healthcheck").setPassword("zb!XztG34"));
- XacmlPdpParameterGroup params = new XacmlPdpParameterGroup("XacmlPdpGroup", rest, apps.getAbsolutePath());
+ RestServerParameters rest =
+ testData.toObject(testData.getRestServerParametersMap(port), RestServerParameters.class);
+ TopicParameterGroup topicParameterGroup =
+ testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
+ XacmlPdpParameterGroup params =
+ new XacmlPdpParameterGroup("XacmlPdpGroup", rest, topicParameterGroup, apps.getAbsolutePath());
final Gson gson = new GsonBuilder().create();
File fileParams = appsFolder.newFile("params.json");
String jsonParams = gson.toJson(params);
@@ -169,8 +172,7 @@ public class TestDecision {
}
private static Main startXacmlPdpService(File params) throws PolicyXacmlPdpException {
- final String[] XacmlPdpConfigParameters = {"-c", params.getAbsolutePath(), "-p",
- "parameters/topic.properties"};
+ final String[] XacmlPdpConfigParameters = {"-c", params.getAbsolutePath()};
return new Main(XacmlPdpConfigParameters);
}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java
index e8448ab2..8b6889d6 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -67,7 +68,7 @@ public class TestMain extends CommonRest {
@Test
public void testMain() throws PolicyXacmlPdpException {
- final String[] xacmlPdpConfigParameters = {"-c", CONFIG_FILE, "-p", "parameters/topic.properties"};
+ final String[] xacmlPdpConfigParameters = {"-c", CONFIG_FILE};
main = new Main(xacmlPdpConfigParameters);
main.shutdown();
main = null;
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java
index b60f4589..7e7dee22 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -25,12 +26,12 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import java.io.FileInputStream;
import java.util.Properties;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.common.endpoints.utils.ParameterUtils;
import org.onap.policy.pdpx.main.CommonRest;
import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
import org.onap.policy.pdpx.main.parameters.CommonTestData;
@@ -55,16 +56,11 @@ public class TestXacmlPdpActivator extends CommonRest {
public static void setUpBeforeClass() throws Exception {
CommonRest.setUpBeforeClass();
- final String[] xacmlPdpConfigParameters =
- {"-c", CommonRest.CONFIG_FILE, "-p", "parameters/topic.properties"};
+ final String[] xacmlPdpConfigParameters = {"-c", CommonRest.CONFIG_FILE};
final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments(xacmlPdpConfigParameters);
parGroup = new XacmlPdpParameterHandler().getParameters(arguments);
- props = new Properties();
- String propFile = arguments.getFullPropertyFilePath();
- try (FileInputStream stream = new FileInputStream(propFile)) {
- props.load(stream);
- }
+ props = ParameterUtils.getTopicProperties(parGroup.getTopicParameterGroup());
// don't want the common "main" running
CommonRest.stopMain();