summaryrefslogtreecommitdiffstats
path: root/plugins/forwarding-plugins/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/forwarding-plugins/src/test')
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroupTest.java32
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderTest.java11
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroupTest.java15
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java12
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderParameterGroupTest.java88
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderParameterGroupTest.java82
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderTest.java16
-rw-r--r--plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/CommonTestData.java53
-rw-r--r--plugins/forwarding-plugins/src/test/resources/parameters/ApexPdpPolicyForwarderParameters.json6
-rw-r--r--plugins/forwarding-plugins/src/test/resources/parameters/ApexPdpPolicyForwarderParametersInvalid.json6
-rw-r--r--plugins/forwarding-plugins/src/test/resources/parameters/EmptyParameters.json2
-rw-r--r--plugins/forwarding-plugins/src/test/resources/parameters/LifecycleApiPolicyForwarderParameters.json12
-rw-r--r--plugins/forwarding-plugins/src/test/resources/parameters/LifecycleApiPolicyForwarderParametersInvalid.json12
-rw-r--r--plugins/forwarding-plugins/src/test/resources/parameters/XacmlPdpPolicyForwarderParameters.json10
-rw-r--r--plugins/forwarding-plugins/src/test/resources/parameters/XacmlPdpPolicyForwarderParametersInvalid.json10
15 files changed, 269 insertions, 98 deletions
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroupTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroupTest.java
index 7feef452..fc0fe3db 100644
--- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroupTest.java
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroupTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. 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.
@@ -26,6 +27,7 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.CommonTestData;
/**
* Class to perform unit test of {@link ApexPdpPolicyForwarderParameterGroup}.
@@ -35,14 +37,11 @@ import org.onap.policy.common.parameters.ValidationStatus;
public class ApexPdpPolicyForwarderParameterGroupTest {
@Test
- public void testBuilderAndGetters() {
- final ApexPdpPolicyForwarderParameterBuilder builder = new ApexPdpPolicyForwarderParameterBuilder();
- builder.setHostname("10.10.10.10").setPort(1234).setIgnoreConflicts(false).setForceUpdate(true);
- final ApexPdpPolicyForwarderParameterGroup configurationParameters =
- new ApexPdpPolicyForwarderParameterGroup(builder);
- configurationParameters.setName("myConfiguration");
-
- assertEquals("myConfiguration", configurationParameters.getName());
+ public void testValidParameters() {
+ final ApexPdpPolicyForwarderParameterGroup configurationParameters = CommonTestData
+ .getPolicyForwarderParameters("src/test/resources/parameters/ApexPdpPolicyForwarderParameters.json",
+ ApexPdpPolicyForwarderParameterGroup.class);
+ assertEquals(ApexPdpPolicyForwarderParameterGroup.class.getSimpleName(), configurationParameters.getName());
assertTrue(configurationParameters.isForceUpdate());
assertEquals("10.10.10.10", configurationParameters.getHostname());
assertEquals(1234, configurationParameters.getPort());
@@ -51,23 +50,20 @@ public class ApexPdpPolicyForwarderParameterGroupTest {
}
@Test
- public void testInvalidHostName() {
- final ApexPdpPolicyForwarderParameterBuilder builder = new ApexPdpPolicyForwarderParameterBuilder();
- builder.setHostname("").setPort(1234).setIgnoreConflicts(false).setForceUpdate(true);
+ public void testInvalidParameters() {
final ApexPdpPolicyForwarderParameterGroup configurationParameters =
- new ApexPdpPolicyForwarderParameterGroup(builder);
- configurationParameters.setName("myConfiguration");
+ CommonTestData.getPolicyForwarderParameters(
+ "src/test/resources/parameters/ApexPdpPolicyForwarderParametersInvalid.json",
+ ApexPdpPolicyForwarderParameterGroup.class);
assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());
}
@Test
- public void testInvalidPort() {
- final ApexPdpPolicyForwarderParameterBuilder builder = new ApexPdpPolicyForwarderParameterBuilder();
- builder.setHostname("10.10.10.10").setPort(-1).setIgnoreConflicts(false).setForceUpdate(true);
+ public void testEmptyParameters() {
final ApexPdpPolicyForwarderParameterGroup configurationParameters =
- new ApexPdpPolicyForwarderParameterGroup(builder);
- configurationParameters.setName("myConfiguration");
+ CommonTestData.getPolicyForwarderParameters("src/test/resources/parameters/EmptyParameters.json",
+ ApexPdpPolicyForwarderParameterGroup.class);
assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());
}
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderTest.java
index cae94f18..7d6743e1 100644
--- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderTest.java
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. 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.
@@ -45,6 +46,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.common.parameters.ParameterGroup;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.distribution.forwarding.PolicyForwardingException;
+import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.CommonTestData;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -56,8 +58,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@RunWith(MockitoJUnitRunner.class)
public class ApexPdpPolicyForwarderTest {
- private static final String HOST_NAME = "10.10.10.10";
- private static final int PORT = 1234;
private static final boolean IGNORE_CONFLICTS = false;
private static final boolean FORCE_UPDATE = true;
private static final String GROUP_NAME = "apexPdpConfiguration";
@@ -70,9 +70,10 @@ public class ApexPdpPolicyForwarderTest {
*/
@BeforeClass
public static void setUp() {
- final ApexPdpPolicyForwarderParameterBuilder builder = new ApexPdpPolicyForwarderParameterBuilder();
- builder.setHostname(HOST_NAME).setPort(PORT).setIgnoreConflicts(IGNORE_CONFLICTS).setForceUpdate(FORCE_UPDATE);
- final ParameterGroup parameterGroup = new ApexPdpPolicyForwarderParameterGroup(builder);
+ final ParameterGroup parameterGroup = CommonTestData.getPolicyForwarderParameters(
+ "src/test/resources/parameters/ApexPdpPolicyForwarderParameters.json",
+ ApexPdpPolicyForwarderParameterGroup.class);
+
parameterGroup.setName(GROUP_NAME);
ParameterService.register(parameterGroup);
}
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroupTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroupTest.java
index ec677cb4..d8ebb4ec 100644
--- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroupTest.java
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroupTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Intel Corp. All rights reserved.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * 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.
@@ -34,10 +35,9 @@ public class FilePolicyForwarderParameterGroupTest {
@Test
public void testBuilderAndGetters() {
- final FilePolicyForwarderParameterBuilder builder = new FilePolicyForwarderParameterBuilder();
- builder.setPath("/tmp").setVerbose(true);
- final FilePolicyForwarderParameterGroup configurationParameters =
- new FilePolicyForwarderParameterGroup(builder);
+ final FilePolicyForwarderParameterGroup configurationParameters = new FilePolicyForwarderParameterGroup();
+ configurationParameters.setPath("/tmp");
+ configurationParameters.setVerbose(true);
configurationParameters.setName("myConfiguration");
assertEquals("myConfiguration", configurationParameters.getName());
@@ -48,10 +48,9 @@ public class FilePolicyForwarderParameterGroupTest {
@Test
public void testInvalidPath() {
- final FilePolicyForwarderParameterBuilder builder = new FilePolicyForwarderParameterBuilder();
- builder.setPath("").setVerbose(false);
- final FilePolicyForwarderParameterGroup configurationParameters =
- new FilePolicyForwarderParameterGroup(builder);
+ final FilePolicyForwarderParameterGroup configurationParameters = new FilePolicyForwarderParameterGroup();
+ configurationParameters.setPath("");
+ configurationParameters.setVerbose(false);
configurationParameters.setName("myConfiguration");
assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java
index 5c87a86c..5eae7df3 100644
--- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Intel Corp. All rights reserved.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * 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.
@@ -39,7 +40,6 @@ import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.policy.common.parameters.ParameterGroup;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -61,11 +61,11 @@ public class FilePolicyForwarderTest {
*/
@BeforeClass
public static void setUp() {
- final FilePolicyForwarderParameterBuilder builder = new FilePolicyForwarderParameterBuilder();
- builder.setPath(tempFolder.getRoot().getAbsolutePath().toString()).setVerbose(VERBOSE);
- final ParameterGroup parameterGroup = new FilePolicyForwarderParameterGroup(builder);
- parameterGroup.setName(GROUP_NAME);
- ParameterService.register(parameterGroup);
+ final FilePolicyForwarderParameterGroup configurationParameters = new FilePolicyForwarderParameterGroup();
+ configurationParameters.setPath(tempFolder.getRoot().getAbsolutePath().toString());
+ configurationParameters.setVerbose(VERBOSE);
+ configurationParameters.setName(GROUP_NAME);
+ ParameterService.register(configurationParameters);
}
/**
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderParameterGroupTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderParameterGroupTest.java
new file mode 100644
index 00000000..fe27b74f
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderParameterGroupTest.java
@@ -0,0 +1,88 @@
+/*-
+ * ============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.distribution.forwarding.lifecycle.api;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.CommonTestData;
+
+/**
+ * Class to perform unit test of {@link LifecycleApiPolicyForwarderParameterGroup}.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class LifecycleApiPolicyForwarderParameterGroupTest {
+
+ private static final String POLICY_API_HOST_NAME = "10.10.10.10";
+ private static final int POLICY_API_PORT = 1234;
+ private static final String POLICY_API_USER = "api_user";
+ private static final String POLICY_API_PASSWORD = "api_password";
+ private static final String POLICY_PAP_HOST_NAME = "20.20.20.20";
+ private static final int POLICY_PAP_PORT = 4321;
+ private static final String POLICY_PAP_USER = "pap_user";
+ private static final String POLICY_PAP_PASSWORD = "pap_password";
+
+
+ @Test
+ public void testValidParameters() {
+ final LifecycleApiPolicyForwarderParameterGroup configurationParameters =
+ CommonTestData.getPolicyForwarderParameters(
+ "src/test/resources/parameters/LifecycleApiPolicyForwarderParameters.json",
+ LifecycleApiPolicyForwarderParameterGroup.class);
+
+ assertEquals(LifecycleApiPolicyForwarderParameterGroup.class.getSimpleName(),
+ configurationParameters.getName());
+ assertTrue(configurationParameters.isHttps());
+ assertTrue(configurationParameters.isDeployPolicies());
+ assertEquals(POLICY_API_HOST_NAME, configurationParameters.getPolicyApiHostName());
+ assertEquals(POLICY_API_PORT, configurationParameters.getPolicyApiPort());
+ assertEquals(POLICY_API_USER, configurationParameters.getPolicyApiUserName());
+ assertEquals(POLICY_API_PASSWORD, configurationParameters.getPolicyApiPassword());
+ assertEquals(POLICY_PAP_HOST_NAME, configurationParameters.getPolicyPapHostName());
+ assertEquals(POLICY_PAP_PORT, configurationParameters.getPolicyPapPort());
+ assertEquals(POLICY_PAP_USER, configurationParameters.getPolicyPapUserName());
+ assertEquals(POLICY_PAP_PASSWORD, configurationParameters.getPolicyPapPassword());
+
+ assertEquals(ValidationStatus.CLEAN, configurationParameters.validate().getStatus());
+ }
+
+ @Test
+ public void testInvalidParameters() {
+ final LifecycleApiPolicyForwarderParameterGroup configurationParameters =
+ CommonTestData.getPolicyForwarderParameters(
+ "src/test/resources/parameters/LifecycleApiPolicyForwarderParametersInvalid.json",
+ LifecycleApiPolicyForwarderParameterGroup.class);
+
+ assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());
+ }
+
+ @Test
+ public void testEmptyParameters() {
+ final LifecycleApiPolicyForwarderParameterGroup configurationParameters =
+ CommonTestData.getPolicyForwarderParameters("src/test/resources/parameters/EmptyParameters.json",
+ LifecycleApiPolicyForwarderParameterGroup.class);
+
+ assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());
+ }
+}
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderParameterGroupTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderParameterGroupTest.java
index 1241b7f3..6e98b225 100644
--- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderParameterGroupTest.java
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderParameterGroupTest.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. 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.
* 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=========================================================
*/
@@ -27,72 +28,47 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarderParameterGroup;
-import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarderParameterGroup.XacmlPdpPolicyForwarderParameterGroupBuilder;
+import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.CommonTestData;
public class XacmlPdpPolicyForwarderParameterGroupTest {
+ private static final String CLIENT_AUTH = "myClientAuth";
+ private static final String PASSWORD = "myPassword";
+ private static final String USER = "myUser";
+ private static final int PORT = 1234;
+ private static final String HOST_NAME = "10.10.10.10";
+
@Test
- public void testBuilderAndGetters() {
- XacmlPdpPolicyForwarderParameterGroupBuilder builder =
- new XacmlPdpPolicyForwarderParameterGroupBuilder();
- XacmlPdpPolicyForwarderParameterGroup configurationParameters =
- builder.setUseHttps(true).setHostname("10.10.10.10").setPort(1234).setUserName("myUser")
- .setPassword("myPassword").setClientAuth("myClientAuth").setIsManaged(false).build();
+ public void testValidParameters() {
+ final XacmlPdpPolicyForwarderParameterGroup configurationParameters = CommonTestData
+ .getPolicyForwarderParameters("src/test/resources/parameters/XacmlPdpPolicyForwarderParameters.json",
+ XacmlPdpPolicyForwarderParameterGroup.class);
assertTrue(configurationParameters.isUseHttps());
- assertEquals("10.10.10.10", configurationParameters.getHostname());
- assertEquals(1234, configurationParameters.getPort());
- assertEquals("myUser", configurationParameters.getUserName());
- assertEquals("myPassword", configurationParameters.getPassword());
- assertEquals("myClientAuth", configurationParameters.getClientAuth());
+ assertEquals(HOST_NAME, configurationParameters.getHostname());
+ assertEquals(PORT, configurationParameters.getPort());
+ assertEquals(USER, configurationParameters.getUserName());
+ assertEquals(PASSWORD, configurationParameters.getPassword());
+ assertEquals(CLIENT_AUTH, configurationParameters.getClientAuth());
assertFalse(configurationParameters.isManaged());
}
@Test
- public void testInvalidHostName() {
- XacmlPdpPolicyForwarderParameterGroupBuilder builder =
- new XacmlPdpPolicyForwarderParameterGroupBuilder();
- XacmlPdpPolicyForwarderParameterGroup configurationParameters = builder.setUseHttps(true).setHostname("")
- .setPort(1234).setUserName("myUser").setPassword("myPassword").setIsManaged(false).build();
- configurationParameters.setName("myConfiguration");
-
- assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());
- }
-
- @Test
- public void testInvalidPort() {
- XacmlPdpPolicyForwarderParameterGroupBuilder builder =
- new XacmlPdpPolicyForwarderParameterGroupBuilder();
- XacmlPdpPolicyForwarderParameterGroup configurationParameters =
- builder.setUseHttps(true).setHostname("10.10.10.10").setPort(-1234).setUserName("myUser")
- .setPassword("myPassword").setIsManaged(false).build();
- configurationParameters.setName("myConfiguration");
+ public void testInvalidParameters() {
+ final XacmlPdpPolicyForwarderParameterGroup configurationParameters =
+ CommonTestData.getPolicyForwarderParameters(
+ "src/test/resources/parameters/XacmlPdpPolicyForwarderParametersInvalid.json",
+ XacmlPdpPolicyForwarderParameterGroup.class);
assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());
}
@Test
- public void testInvalidUserName() {
- XacmlPdpPolicyForwarderParameterGroupBuilder builder =
- new XacmlPdpPolicyForwarderParameterGroupBuilder();
- XacmlPdpPolicyForwarderParameterGroup configurationParameters =
- builder.setUseHttps(true).setHostname("10.10.10.10").setPort(1234).setUserName("")
- .setPassword("myPassword").setIsManaged(false).build();
- configurationParameters.setName("myConfiguration");
+ public void testEmptyParameters() {
+ final XacmlPdpPolicyForwarderParameterGroup configurationParameters =
+ CommonTestData.getPolicyForwarderParameters("src/test/resources/parameters/EmptyParameters.json",
+ XacmlPdpPolicyForwarderParameterGroup.class);
assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());
}
-
- @Test
- public void testInvalidPassword() {
- XacmlPdpPolicyForwarderParameterGroupBuilder builder =
- new XacmlPdpPolicyForwarderParameterGroupBuilder();
- XacmlPdpPolicyForwarderParameterGroup configurationParameters =
- builder.setUseHttps(true).setHostname("10.10.10.10").setPort(1234).setUserName("myUser").setPassword("")
- .setIsManaged(false).build();
- configurationParameters.setName("myConfiguration");
-
- assertEquals(ValidationStatus.INVALID, configurationParameters.validate().getStatus());
- }
-
}
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderTest.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderTest.java
index f9cd868a..03adc0e1 100644
--- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderTest.java
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpPolicyForwarderTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications 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.
@@ -50,14 +51,15 @@ import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
import org.onap.policy.common.parameters.ParameterGroup;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarder;
-import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarderParameterGroup.XacmlPdpPolicyForwarderParameterGroupBuilder;
+import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarderParameterGroup;
+import org.onap.policy.distribution.forwarding.xacml.pdp.testclasses.CommonTestData;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
public class XacmlPdpPolicyForwarderTest {
- private static final BusTopicParams BUS_TOPIC_PARAMS = BusTopicParams.builder().useHttps(false).hostname("myHost")
- .port(1234).userName("myUser").password("myPassword").managed(true).build();
+ private static final BusTopicParams BUS_TOPIC_PARAMS = BusTopicParams.builder().useHttps(true)
+ .hostname("10.10.10.10").port(1234).userName("myUser").password("myPassword").managed(false).build();
private static final String CLIENT_AUTH = "ClientAuth";
private static final String CLIENT_AUTH_VALUE = "myClientAuth";
private static final String PDP_GROUP_VALUE = "myPdpGroup";
@@ -69,11 +71,9 @@ public class XacmlPdpPolicyForwarderTest {
*/
@BeforeClass
public static void setUp() {
- final ParameterGroup parameterGroup = new XacmlPdpPolicyForwarderParameterGroupBuilder()
- .setUseHttps(BUS_TOPIC_PARAMS.isUseHttps()).setHostname(BUS_TOPIC_PARAMS.getHostname())
- .setPort(BUS_TOPIC_PARAMS.getPort()).setUserName(BUS_TOPIC_PARAMS.getUserName())
- .setPassword(BUS_TOPIC_PARAMS.getPassword()).setClientAuth(CLIENT_AUTH_VALUE)
- .setIsManaged(BUS_TOPIC_PARAMS.isManaged()).setPdpGroup(PDP_GROUP_VALUE).build();
+ final ParameterGroup parameterGroup = CommonTestData.getPolicyForwarderParameters(
+ "src/test/resources/parameters/XacmlPdpPolicyForwarderParameters.json",
+ XacmlPdpPolicyForwarderParameterGroup.class);
parameterGroup.setName("xacmlPdpConfiguration");
ParameterService.register(parameterGroup);
}
diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/CommonTestData.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/CommonTestData.java
new file mode 100644
index 00000000..386526e5
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/CommonTestData.java
@@ -0,0 +1,53 @@
+/*-
+ * ============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.distribution.forwarding.xacml.pdp.testclasses;
+
+import java.io.File;
+
+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 create parameters for test cases.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class CommonTestData {
+
+ public static final Coder coder = new StandardCoder();
+
+ /**
+ * Returns PolicyForwarderParameters for test cases.
+ *
+ * @param fileName the file name to load the parameters
+ * @param clazz the parameter class to be returned
+ * @return the specific PolicyForwarderParameters object
+ */
+ public static <T> T getPolicyForwarderParameters(final String fileName, final Class<T> clazz) {
+ final StandardCoder coder = new StandardCoder();
+ try {
+ return coder.decode(new File(fileName), clazz);
+ } catch (final CoderException exp) {
+ throw new RuntimeException("cannot read/decode " + fileName, exp);
+ }
+ }
+}
diff --git a/plugins/forwarding-plugins/src/test/resources/parameters/ApexPdpPolicyForwarderParameters.json b/plugins/forwarding-plugins/src/test/resources/parameters/ApexPdpPolicyForwarderParameters.json
new file mode 100644
index 00000000..d244e0be
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/resources/parameters/ApexPdpPolicyForwarderParameters.json
@@ -0,0 +1,6 @@
+{
+ "hostname":"10.10.10.10",
+ "port":"1234",
+ "ignoreConflicts": false,
+ "forceUpdate": true
+} \ No newline at end of file
diff --git a/plugins/forwarding-plugins/src/test/resources/parameters/ApexPdpPolicyForwarderParametersInvalid.json b/plugins/forwarding-plugins/src/test/resources/parameters/ApexPdpPolicyForwarderParametersInvalid.json
new file mode 100644
index 00000000..c87b7767
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/resources/parameters/ApexPdpPolicyForwarderParametersInvalid.json
@@ -0,0 +1,6 @@
+{
+ "hostname":"",
+ "port":"-1",
+ "ignoreConflicts": false,
+ "forceUpdate": true
+}
diff --git a/plugins/forwarding-plugins/src/test/resources/parameters/EmptyParameters.json b/plugins/forwarding-plugins/src/test/resources/parameters/EmptyParameters.json
new file mode 100644
index 00000000..7a73a41b
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/resources/parameters/EmptyParameters.json
@@ -0,0 +1,2 @@
+{
+} \ No newline at end of file
diff --git a/plugins/forwarding-plugins/src/test/resources/parameters/LifecycleApiPolicyForwarderParameters.json b/plugins/forwarding-plugins/src/test/resources/parameters/LifecycleApiPolicyForwarderParameters.json
new file mode 100644
index 00000000..0bb54279
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/resources/parameters/LifecycleApiPolicyForwarderParameters.json
@@ -0,0 +1,12 @@
+{
+ "policyApiHostName": "10.10.10.10",
+ "policyApiPort": 1234,
+ "policyApiUserName": "api_user",
+ "policyApiPassword": "api_password",
+ "policyPapHostName": "20.20.20.20",
+ "policyPapPort": "4321",
+ "policyPapUserName": "pap_user",
+ "policyPapPassword": "pap_password",
+ "isHttps": true,
+ "deployPolicies": true
+} \ No newline at end of file
diff --git a/plugins/forwarding-plugins/src/test/resources/parameters/LifecycleApiPolicyForwarderParametersInvalid.json b/plugins/forwarding-plugins/src/test/resources/parameters/LifecycleApiPolicyForwarderParametersInvalid.json
new file mode 100644
index 00000000..b10be731
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/resources/parameters/LifecycleApiPolicyForwarderParametersInvalid.json
@@ -0,0 +1,12 @@
+{
+ "policyApiHostName": "",
+ "policyApiPort": -1,
+ "policyApiUserName": "api_user",
+ "policyApiPassword": "api_password",
+ "policyPapHostName": "",
+ "policyPapPort": "-2",
+ "policyPapUserName": "pap_user",
+ "policyPapPassword": "pap_password",
+ "isHttps": true,
+ "deployPolicies": true
+} \ No newline at end of file
diff --git a/plugins/forwarding-plugins/src/test/resources/parameters/XacmlPdpPolicyForwarderParameters.json b/plugins/forwarding-plugins/src/test/resources/parameters/XacmlPdpPolicyForwarderParameters.json
new file mode 100644
index 00000000..0e115ef2
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/resources/parameters/XacmlPdpPolicyForwarderParameters.json
@@ -0,0 +1,10 @@
+{
+ "useHttps": true,
+ "hostname": "10.10.10.10",
+ "port": 1234,
+ "userName": "myUser",
+ "password": "myPassword",
+ "clientAuth": "myClientAuth",
+ "isManaged": false,
+ "pdpGroup": "myPdpGroup"
+} \ No newline at end of file
diff --git a/plugins/forwarding-plugins/src/test/resources/parameters/XacmlPdpPolicyForwarderParametersInvalid.json b/plugins/forwarding-plugins/src/test/resources/parameters/XacmlPdpPolicyForwarderParametersInvalid.json
new file mode 100644
index 00000000..03e342b6
--- /dev/null
+++ b/plugins/forwarding-plugins/src/test/resources/parameters/XacmlPdpPolicyForwarderParametersInvalid.json
@@ -0,0 +1,10 @@
+{
+ "useHttps": true,
+ "hostname": "",
+ "port": -2,
+ "userName": "",
+ "password": "",
+ "clientAuth": "myClientAuth",
+ "isManaged": false,
+ "pdpGroup": "default"
+} \ No newline at end of file