summaryrefslogtreecommitdiffstats
path: root/plugins/forwarding-plugins
diff options
context:
space:
mode:
authorramverma <ram.krishna.verma@est.tech>2019-08-02 08:57:40 +0000
committerramverma <ram.krishna.verma@est.tech>2019-08-02 08:57:40 +0000
commit039cd619bc102865d664bbf6b003cd33b243eaf1 (patch)
tree6880401fdb251cf7c0ddf266117dad5dc15d8099 /plugins/forwarding-plugins
parent75191319d88b94e4fc3b0151f8009419165e1c59 (diff)
Change parameters to extend ParameterGroupImpl
1. Changing all the forwarder parameter groups to extend the ParameterGroupImpl instead of implementing the ParameterGroup interface. 2. Introducing lombok in distribution. 3. Fixing all the affected test cases. 4. Creating parameter group to hold parameters needed for forwarding policies to the new lifecycle API's. Issue-ID: POLICY-1890 Change-Id: I0c8b72f355a610fa5d46daaacc9ef7f06b7cec09 Signed-off-by: ramverma <ram.krishna.verma@est.tech>
Diffstat (limited to 'plugins/forwarding-plugins')
-rw-r--r--plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterBuilder.java111
-rw-r--r--plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroup.java54
-rw-r--r--plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterBuilder.java70
-rw-r--r--plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroup.java41
-rw-r--r--plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java57
-rw-r--r--plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderParameterGroup.java55
-rw-r--r--plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarderParameterGroup.java152
-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
22 files changed, 417 insertions, 490 deletions
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterBuilder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterBuilder.java
deleted file mode 100644
index faa066fe..00000000
--- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterBuilder.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. 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.distribution.forwarding.apex.pdp;
-
-/**
- * This builder holds all the parameters needed to build an instance of {@link ApexPdpPolicyForwarderParameterGroup}
- * class.
- *
- * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
- */
-public class ApexPdpPolicyForwarderParameterBuilder {
-
- private String hostname;
- private int port;
- private boolean ignoreConflicts;
- private boolean forceUpdate;
-
- /**
- * Set host name to this {@link ApexPdpPolicyForwarderParameterBuilder} instance.
- *
- * @param hostname the host name
- */
- public ApexPdpPolicyForwarderParameterBuilder setHostname(final String hostname) {
- this.hostname = hostname;
- return this;
- }
-
- /**
- * Set port to this {@link ApexPdpPolicyForwarderParameterBuilder} instance.
- *
- * @param port the port number
- */
- public ApexPdpPolicyForwarderParameterBuilder setPort(final int port) {
- this.port = port;
- return this;
- }
-
- /**
- * Set ignore conflicts flag to this {@link ApexPdpPolicyForwarderParameterBuilder} instance.
- *
- * @param ignoreConflicts the ignore conflicts flag
- */
- public ApexPdpPolicyForwarderParameterBuilder setIgnoreConflicts(final boolean ignoreConflicts) {
- this.ignoreConflicts = ignoreConflicts;
- return this;
- }
-
- /**
- * Set force update flag to this {@link ApexPdpPolicyForwarderParameterBuilder} instance.
- *
- * @param forceUpdate the force update flag
- */
- public ApexPdpPolicyForwarderParameterBuilder setForceUpdate(final boolean forceUpdate) {
- this.forceUpdate = forceUpdate;
- return this;
- }
-
- /**
- * Returns the host name of this {@link ApexPdpPolicyForwarderParameterBuilder} instance.
- *
- * @return the host name
- */
- public String getHostname() {
- return hostname;
- }
-
- /**
- * Returns the port of this {@link ApexPdpPolicyForwarderParameterBuilder} instance.
- *
- * @return the port
- */
- public int getPort() {
- return port;
- }
-
- /**
- * Returns the ignore conflicts flag of this {@link ApexPdpPolicyForwarderParameterBuilder} instance.
- *
- * @return the ignoreConflicts
- */
- public boolean isIgnoreConflicts() {
- return ignoreConflicts;
- }
-
- /**
- * Returns the force update flag of this {@link ApexPdpPolicyForwarderParameterBuilder} instance.
- *
- * @return the forceUpdate
- */
- public boolean isForceUpdate() {
- return forceUpdate;
- }
-}
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroup.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroup.java
index bd954d8f..77c98a2d 100644
--- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroup.java
+++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroup.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. 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.
@@ -21,60 +22,29 @@
package org.onap.policy.distribution.forwarding.apex.pdp;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ValidationStatus;
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import lombok.Getter;
+
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup;
/**
* Holds the parameters for the{@link ApexPdpPolicyForwarder}.
*/
+@Getter
+@NotNull
+@NotBlank
public class ApexPdpPolicyForwarderParameterGroup extends PolicyForwarderConfigurationParameterGroup {
public static final String POLICY_FORWARDER_PLUGIN_CLASS = ApexPdpPolicyForwarder.class.getName();
private String hostname;
+ @Min(value = 1)
private int port;
private boolean ignoreConflicts;
private boolean forceUpdate;
- /**
- * Constructor for instantiating {@link ApexPdpPolicyForwarderParameterGroup} class.
- *
- * @param builder the apex forwarder parameter builder
- */
- public ApexPdpPolicyForwarderParameterGroup(final ApexPdpPolicyForwarderParameterBuilder builder) {
- this.hostname = builder.getHostname();
- this.port = builder.getPort();
- this.ignoreConflicts = builder.isIgnoreConflicts();
- this.forceUpdate = builder.isForceUpdate();
- }
-
- public String getHostname() {
- return hostname;
- }
-
- public int getPort() {
- return port;
- }
-
- public boolean isIgnoreConflicts() {
- return ignoreConflicts;
- }
-
- public boolean isForceUpdate() {
- return forceUpdate;
- }
-
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult validationResult = new GroupValidationResult(this);
- if (!ParameterValidationUtils.validateStringParameter(hostname)) {
- validationResult.setResult("hostname", ValidationStatus.INVALID,
- "must be a non-blank string containing hostname/ipaddress");
- }
- if (!ParameterValidationUtils.validateIntParameter(port)) {
- validationResult.setResult("port", ValidationStatus.INVALID, "must be a positive integer containing port");
- }
- return validationResult;
+ public ApexPdpPolicyForwarderParameterGroup() {
+ super(ApexPdpPolicyForwarderParameterGroup.class.getSimpleName());
}
}
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterBuilder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterBuilder.java
deleted file mode 100644
index f5281e6b..00000000
--- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterBuilder.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Intel Corp. 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.distribution.forwarding.file;
-
-/**
- * This builder holds all the parameters needed to build an instance of {@link FilePolicyForwarderParameterGroup}
- * class.
- */
-public class FilePolicyForwarderParameterBuilder {
-
- private String path;
- private boolean verbose = false;
-
- /**
- * Set path to this {@link FilePolicyForwarderParameterBuilder} instance.
- *
- * @param path the directory to store the policies
- */
- public FilePolicyForwarderParameterBuilder setPath(final String path) {
- this.path = path;
- return this;
- }
-
-
- /**
- * Set verbose flag to this {@link FilePolicyForwarderParameterBuilder} instance.
- *
- * @param verbose the verbose flag
- */
- public FilePolicyForwarderParameterBuilder setVerbose(final boolean verbose) {
- this.verbose = verbose;
- return this;
- }
-
- /**
- * Returns the path of this {@link FilePolicyForwarderParameterBuilder} instance.
- *
- * @return the directory
- */
- public String getPath() {
- return path;
- }
-
- /**
- * Returns the verbose flag of this {@link FilePolicyForwarderParameterBuilder} instance.
- *
- * @return the verbose
- */
- public boolean isVerbose() {
- return verbose;
- }
-}
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroup.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroup.java
index 79ab4f7f..e932d61c 100644
--- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroup.java
+++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarderParameterGroup.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.
@@ -21,45 +22,27 @@
package org.onap.policy.distribution.forwarding.file;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ValidationStatus;
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import lombok.Getter;
+import lombok.Setter;
+
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup;
/**
* Holds the parameters for the{@link FilePolicyForwarder}.
*/
+@Getter
+@Setter
+@NotNull
+@NotBlank
public class FilePolicyForwarderParameterGroup extends PolicyForwarderConfigurationParameterGroup {
public static final String POLICY_FORWARDER_PLUGIN_CLASS = FilePolicyForwarder.class.getName();
private String path;
private boolean verbose;
- /**
- * Constructor for instantiating {@link FilePolicyForwarderParameterGroup} class.
- *
- * @param builder the apex forwarder parameter builder
- */
- public FilePolicyForwarderParameterGroup(final FilePolicyForwarderParameterBuilder builder) {
- this.path = builder.getPath();
- this.verbose = builder.isVerbose();
- }
-
- public String getPath() {
- return path;
- }
-
- public boolean isVerbose() {
- return verbose;
- }
-
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult validationResult = new GroupValidationResult(this);
- if (!ParameterValidationUtils.validateStringParameter(path)) {
- validationResult.setResult("path", ValidationStatus.INVALID,
- "must be a non-blank string containing path directory");
- }
- return validationResult;
+ public FilePolicyForwarderParameterGroup() {
+ super(FilePolicyForwarderParameterGroup.class.getSimpleName());
}
}
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java
new file mode 100644
index 00000000..4b8acb10
--- /dev/null
+++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java
@@ -0,0 +1,57 @@
+/*-
+ * ============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 java.util.Collection;
+
+import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.distribution.forwarding.PolicyForwarder;
+import org.onap.policy.distribution.forwarding.PolicyForwardingException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
+
+/**
+ * This class provides an implementation of {@link PolicyForwarder} interface for forwarding the given policies & policy
+ * types to the life cycle api's of policy framework.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class LifecycleApiPolicyForwarder implements PolicyForwarder {
+
+ private LifecycleApiPolicyForwarderParameterGroup forwarderParameters;
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public void configure(final String parameterGroupName) {
+ forwarderParameters = ParameterService.get(parameterGroupName);
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public void forward(final Collection<ToscaEntity> policies) throws PolicyForwardingException {
+ // TODO: add implementation
+ }
+
+}
+
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderParameterGroup.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderParameterGroup.java
new file mode 100644
index 00000000..8ba7bdbe
--- /dev/null
+++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarderParameterGroup.java
@@ -0,0 +1,55 @@
+/*-
+ * ============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 lombok.Getter;
+
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup;
+
+/**
+ * Holds the parameters for the{@link LifecycleApiPolicyForwarder}.
+ */
+@Getter
+@NotNull
+@NotBlank
+public class LifecycleApiPolicyForwarderParameterGroup extends PolicyForwarderConfigurationParameterGroup {
+ public static final String POLICY_FORWARDER_PLUGIN_CLASS = LifecycleApiPolicyForwarder.class.getName();
+
+ private String policyApiHostName;
+ @Min(value = 1)
+ private int policyApiPort;
+ private String policyApiUserName;
+ private String policyApiPassword;
+ private String policyPapHostName;
+ @Min(value = 1)
+ private int policyPapPort;
+ private String policyPapUserName;
+ private String policyPapPassword;
+ private boolean isHttps;
+ private boolean deployPolicies = true;
+
+ public LifecycleApiPolicyForwarderParameterGroup() {
+ super(LifecycleApiPolicyForwarderParameterGroup.class.getSimpleName());
+ }
+}
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarderParameterGroup.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarderParameterGroup.java
index 5c547673..4ce35f20 100644
--- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarderParameterGroup.java
+++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarderParameterGroup.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. 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.
@@ -21,19 +22,25 @@
package org.onap.policy.distribution.forwarding.xacml.pdp;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ValidationStatus;
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import lombok.Getter;
+
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup;
/**
* Holds the parameters for the{@link XacmlPdpPolicyForwarder}.
*/
+@Getter
+@NotNull
+@NotBlank
public class XacmlPdpPolicyForwarderParameterGroup extends PolicyForwarderConfigurationParameterGroup {
public static final String POLICY_FORWARDER_PLUGIN_CLASS = XacmlPdpPolicyForwarder.class.getName();
private boolean useHttps;
private String hostname;
+ @Min(value = 1)
private int port;
private String userName;
private String password;
@@ -41,142 +48,7 @@ public class XacmlPdpPolicyForwarderParameterGroup extends PolicyForwarderConfig
private boolean isManaged;
private String pdpGroup;
- /**
- * Construct an instance.
- *
- * @param builder the builder create the instance from
- */
- private XacmlPdpPolicyForwarderParameterGroup(final XacmlPdpPolicyForwarderParameterGroupBuilder builder) {
- this.useHttps = builder.useHttps;
- this.hostname = builder.hostname;
- this.port = builder.port;
- this.userName = builder.userName;
- this.password = builder.password;
- this.clientAuth = builder.clientAuth;
- this.isManaged = builder.isManaged;
- this.pdpGroup = builder.pdpGroup;
- }
-
- public boolean isUseHttps() {
- return useHttps;
- }
-
- public String getHostname() {
- return hostname;
- }
-
- public int getPort() {
- return port;
- }
-
- public String getUserName() {
- return userName;
- }
-
- public String getPassword() {
- return password;
- }
-
- public String getClientAuth() {
- return clientAuth;
- }
-
- public boolean isManaged() {
- return isManaged;
+ public XacmlPdpPolicyForwarderParameterGroup() {
+ super(XacmlPdpPolicyForwarderParameterGroup.class.getSimpleName());
}
-
- public String getPdpGroup() {
- return pdpGroup;
- }
-
- /**
- * Builder for XacmlPdpPolicyForwarderParameterGroup.
- */
- public static class XacmlPdpPolicyForwarderParameterGroupBuilder {
- private boolean useHttps = false;
- private String hostname;
- private int port;
- private String userName;
- private String password;
- private String clientAuth;
- private boolean isManaged = true;
- private String pdpGroup;
-
- public XacmlPdpPolicyForwarderParameterGroupBuilder setUseHttps(final boolean useHttps) {
- this.useHttps = useHttps;
- return this;
- }
-
- public XacmlPdpPolicyForwarderParameterGroupBuilder setHostname(final String hostname) {
- this.hostname = hostname;
- return this;
- }
-
- public XacmlPdpPolicyForwarderParameterGroupBuilder setPort(final int port) {
- this.port = port;
- return this;
- }
-
- public XacmlPdpPolicyForwarderParameterGroupBuilder setUserName(final String userName) {
- this.userName = userName;
- return this;
- }
-
- public XacmlPdpPolicyForwarderParameterGroupBuilder setPassword(final String password) {
- this.password = password;
- return this;
- }
-
- public XacmlPdpPolicyForwarderParameterGroupBuilder setClientAuth(final String clientAuth) {
- this.clientAuth = clientAuth;
- return this;
- }
-
- public XacmlPdpPolicyForwarderParameterGroupBuilder setIsManaged(final boolean isManaged) {
- this.isManaged = isManaged;
- return this;
- }
-
- public XacmlPdpPolicyForwarderParameterGroupBuilder setPdpGroup(final String pdpGroup) {
- this.pdpGroup = pdpGroup;
- return this;
- }
-
- /**
- * Creates a new XacmlPapServletPolicyForwarderParameterGroup instance.
- */
- public XacmlPdpPolicyForwarderParameterGroup build() {
- return new XacmlPdpPolicyForwarderParameterGroup(this);
- }
- }
-
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult validationResult = new GroupValidationResult(this);
- if (!ParameterValidationUtils.validateStringParameter(hostname)) {
- validationResult.setResult("hostname", ValidationStatus.INVALID,
- "must be a non-blank string containing hostname/ipaddress");
- }
- if (!ParameterValidationUtils.validateIntParameter(port)) {
- validationResult.setResult("port", ValidationStatus.INVALID, "must be a positive integer containing port");
- }
- if (!ParameterValidationUtils.validateStringParameter(userName)) {
- validationResult.setResult("userName", ValidationStatus.INVALID,
- "must be a non-blank string containing userName");
- }
- if (!ParameterValidationUtils.validateStringParameter(password)) {
- validationResult.setResult("password", ValidationStatus.INVALID,
- "must be a non-blank string containing password");
- }
- if (!ParameterValidationUtils.validateStringParameter(clientAuth)) {
- validationResult.setResult("clientAuth", ValidationStatus.INVALID,
- "must be a non-blank string containing clientAuth");
- }
- if (!ParameterValidationUtils.validateStringParameter(pdpGroup)) {
- validationResult.setResult("pdpGroup", ValidationStatus.INVALID,
- "must be a non-blank string containing pdpGroup");
- }
- return validationResult;
- }
-
}
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