diff options
Diffstat (limited to 'plugins/forwarding-plugins')
10 files changed, 210 insertions, 252 deletions
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java index 8b8528fb..996b887d 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java @@ -31,10 +31,8 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexException; 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.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarder; -import org.onap.policy.distribution.model.Policy; -import org.onap.policy.distribution.model.PolicyAsString; - +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,7 +44,7 @@ import org.slf4j.LoggerFactory; */ public class ApexPdpPolicyForwarder implements PolicyForwarder { - private static final Logger LOGGER = LoggerFactory.getLogger(XacmlPdpPolicyForwarder.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ApexPdpPolicyForwarder.class); private static final String POLICY_TYPE = "APEX"; private ApexPdpPolicyForwarderParameterGroup apexForwarderParameters; @@ -67,7 +65,7 @@ public class ApexPdpPolicyForwarder implements PolicyForwarder { * {@inheritDoc}. */ @Override - public void forward(final Collection<Policy> policies) throws PolicyForwardingException { + public void forward(final Collection<ToscaEntity> policies) throws PolicyForwardingException { if (policies.isEmpty()) { final String message = "No apex policy to be forwarded to an apex engine"; LOGGER.debug(message); @@ -77,12 +75,18 @@ public class ApexPdpPolicyForwarder implements PolicyForwarder { LOGGER.debug(message); throw new PolicyForwardingException(message); } else { - final Policy policy = (Policy) policies.toArray()[0]; - if (policy.getClass().isAssignableFrom(PolicyAsString.class) - && policy.getPolicyType().equalsIgnoreCase(POLICY_TYPE)) { - forwardPolicy((PolicyAsString) policy); + final ToscaEntity policy = (ToscaEntity) policies.toArray()[0]; + if (policy instanceof ToscaPolicy) { + final ToscaPolicy toscaPolicy = (ToscaPolicy) policy; + if (POLICY_TYPE.equalsIgnoreCase(toscaPolicy.getType())) { + forwardPolicy(toscaPolicy); + } else { + final String message = "Ignoring the policy as it is not an apex-pdp policy"; + LOGGER.debug(message); + throw new PolicyForwardingException(message); + } } else { - final String message = "Ignoring the policy as it is not an apex-pdp policy"; + final String message = "Ignoring the policy as it is not of type ToscaPolicy"; LOGGER.debug(message); throw new PolicyForwardingException(message); } @@ -95,11 +99,11 @@ public class ApexPdpPolicyForwarder implements PolicyForwarder { * @param apexPolicy the apex policy * @throws PolicyForwardingException if any exception occurs while forwarding policy */ - private void forwardPolicy(final PolicyAsString apexPolicy) throws PolicyForwardingException { + private void forwardPolicy(final ToscaPolicy apexPolicy) throws PolicyForwardingException { try { engineServiceFacade.init(); - final InputStream policyInputStream = IOUtils.toInputStream(apexPolicy.getPolicy(), "UTF-8"); - engineServiceFacade.deployModel(apexPolicy.getPolicyName(), policyInputStream, + final InputStream policyInputStream = IOUtils.toInputStream(apexPolicy.toString(), "UTF-8"); + engineServiceFacade.deployModel(apexPolicy.getName(), policyInputStream, apexForwarderParameters.isIgnoreConflicts(), apexForwarderParameters.isForceUpdate()); LOGGER.debug("Sucessfully forwarded the policy to apex-pdp egine at {}:{}", diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java index 51700005..55735662 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java @@ -21,8 +21,8 @@ package org.onap.policy.distribution.forwarding.file; import java.io.BufferedWriter; -import java.io.FileWriter; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.Path; @@ -32,15 +32,14 @@ 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.distribution.model.OptimizationPolicy; -import org.onap.policy.distribution.model.Policy; - +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * This class provides an implementation of {@link PolicyForwarder} interface for forwarding the given policies to - * a file directory. + * This class provides an implementation of {@link PolicyForwarder} interface for forwarding the given policies to a + * file directory. */ public class FilePolicyForwarder implements PolicyForwarder { @@ -54,7 +53,7 @@ public class FilePolicyForwarder implements PolicyForwarder { public void configure(final String parameterGroupName) { fileForwarderParameters = ParameterService.get(parameterGroupName); try { - Path path = Paths.get(fileForwarderParameters.getPath()); + final Path path = Paths.get(fileForwarderParameters.getPath()); if (!path.toFile().exists()) { Files.createDirectories(path); } @@ -67,13 +66,13 @@ public class FilePolicyForwarder implements PolicyForwarder { * {@inheritDoc}. */ @Override - public void forward(final Collection<Policy> policies) throws PolicyForwardingException { - for (Policy policy : policies) { - if (policy instanceof OptimizationPolicy) { - forwardPolicy((OptimizationPolicy) policy); + public void forward(final Collection<ToscaEntity> policies) throws PolicyForwardingException { + for (final ToscaEntity policy : policies) { + if (policy instanceof ToscaPolicy) { + forwardPolicy((ToscaPolicy) policy); } else { - final String message = "Cannot forward policy " + policy - + ". Unsupported policy type " + policy.getClass().getSimpleName(); + final String message = "Cannot forward policy " + policy + ". Unsupported policy type " + + policy.getClass().getSimpleName(); LOGGER.error(message); throw new PolicyForwardingException(message); } @@ -86,30 +85,14 @@ public class FilePolicyForwarder implements PolicyForwarder { * @param pol the policy * @throws PolicyForwardingException if any exception occurs while forwarding policy */ - private void forwardPolicy(final OptimizationPolicy pol) throws PolicyForwardingException { - final String name = pol.getPolicyName(); - Path path = Paths.get(fileForwarderParameters.getPath(), name); - try (BufferedWriter writer = new BufferedWriter(new FileWriter(path.toString()))) { + private void forwardPolicy(final ToscaPolicy pol) throws PolicyForwardingException { + final String name = pol.getName(); + final Path path = Paths.get(fileForwarderParameters.getPath(), name); + try (BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { writer.write("policyName: " + name); if (fileForwarderParameters.isVerbose()) { writer.newLine(); - writer.write("policyType: " + pol.getPolicyType()); - writer.newLine(); - writer.write("policyDescription: " + pol.getPolicyDescription()); - writer.newLine(); - writer.write("onapName: " + pol.getOnapName()); - writer.newLine(); - writer.write("configBodyType: " + pol.getConfigBodyType()); - writer.newLine(); - writer.write("configBody: " + pol.getConfigBody()); - writer.newLine(); - writer.write("timetolive: " + pol.getTimetolive().toString()); - writer.newLine(); - writer.write("guard: " + pol.getGuard()); - writer.newLine(); - writer.write("riskLevel: " + pol.getRiskLevel()); - writer.newLine(); - writer.write("riskType: " + pol.getRiskType()); + writer.write("policy: " + pol.toString()); } LOGGER.debug("Sucessfully forwarded the policy to store into file {}.", path); } catch (final InvalidPathException | IOException exp) { diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java index c50eac12..613a406f 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -22,30 +22,30 @@ package org.onap.policy.distribution.forwarding.xacml.pdp; import org.onap.policy.api.PolicyParameters; import org.onap.policy.api.PushPolicyParameters; -import org.onap.policy.distribution.model.Policy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; /** - * Adapts {@link Policy} objects to objects compatible with the XACML PDP API. + * Adapts {@link ToscaPolicy} objects to objects compatible with the XACML PDP API. */ -public interface XacmlPdpPolicyAdapter<T extends Policy> { +public interface XacmlPdpPolicyAdapter<T extends ToscaPolicy> { /** * Get the policy. - * + * * @return the policy */ T getPolicy(); /** * Get as a {@link PolicyParameters} object. - * + * * @returna {@link PolicyParameters} object */ PolicyParameters getAsPolicyParameters(); /** * Get as a {@link PushPolicyParameters} object. - * + * * @returna {@link PushPolicyParameters} object */ PushPolicyParameters getAsPushPolicyParameters(final String pdpGroups); diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarder.java index 196818b5..8eeeda7e 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarder.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarder.java @@ -24,9 +24,11 @@ package org.onap.policy.distribution.forwarding.xacml.pdp; import java.util.Collection; import java.util.Collections; + import javax.ws.rs.client.Entity; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; + import org.onap.policy.api.PolicyParameters; import org.onap.policy.api.PushPolicyParameters; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; @@ -37,8 +39,8 @@ import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.distribution.forwarding.PolicyForwarder; import org.onap.policy.distribution.forwarding.xacml.pdp.adapters.XacmlPdpOptimizationPolicyAdapter; -import org.onap.policy.distribution.model.OptimizationPolicy; -import org.onap.policy.distribution.model.Policy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -55,53 +57,53 @@ public class XacmlPdpPolicyForwarder implements PolicyForwarder { @Override - public void forward(final Collection<Policy> policies) { - for (Policy policy : policies) { + public void forward(final Collection<ToscaEntity> policies) { + for (final ToscaEntity policy : policies) { forward(policy); } } - private void forward(Policy policy) { - XacmlPdpPolicyAdapter<?> policyAdapter = getXacmlPdpPolicyAdapter(policy); + private void forward(final ToscaEntity policy) { + final XacmlPdpPolicyAdapter<?> policyAdapter = getXacmlPdpPolicyAdapter(policy); if (policyAdapter == null) { - LOGGER.error("Cannot forward policy {}. Unsupported policy type {}", - policy, policy.getClass().getSimpleName()); + LOGGER.error("Cannot forward policy {}. Unsupported policy type {}", policy, + policy.getClass().getSimpleName()); return; } - boolean policyCreated = createPolicy(policyAdapter); + final boolean policyCreated = createPolicy(policyAdapter); if (policyCreated) { pushPolicy(policyAdapter); } } - private XacmlPdpPolicyAdapter<?> getXacmlPdpPolicyAdapter(Policy policy) { - if (policy instanceof OptimizationPolicy) { - return new XacmlPdpOptimizationPolicyAdapter((OptimizationPolicy) policy); + private XacmlPdpPolicyAdapter<?> getXacmlPdpPolicyAdapter(final ToscaEntity policy) { + if (policy instanceof ToscaPolicy) { + return new XacmlPdpOptimizationPolicyAdapter((ToscaPolicy) policy); } return null; } - private boolean createPolicy(XacmlPdpPolicyAdapter<?> policyAdapter) { - PolicyParameters policyParameters = policyAdapter.getAsPolicyParameters(); - Entity<PolicyParameters> entity = Entity.entity(policyParameters, MediaType.APPLICATION_JSON); + private boolean createPolicy(final XacmlPdpPolicyAdapter<?> policyAdapter) { + final PolicyParameters policyParameters = policyAdapter.getAsPolicyParameters(); + final Entity<PolicyParameters> entity = Entity.entity(policyParameters, MediaType.APPLICATION_JSON); - return invokeHttpClient(entity, "createPolicy", policyAdapter.getPolicy().getPolicyName()); + return invokeHttpClient(entity, "createPolicy", policyAdapter.getPolicy().getName()); } - private boolean pushPolicy(XacmlPdpPolicyAdapter<?> policyAdapter) { - PushPolicyParameters pushPolicyParameters = + private boolean pushPolicy(final XacmlPdpPolicyAdapter<?> policyAdapter) { + final PushPolicyParameters pushPolicyParameters = policyAdapter.getAsPushPolicyParameters(configurationParameters.getPdpGroup()); - Entity<PushPolicyParameters> entity = Entity.entity(pushPolicyParameters, MediaType.APPLICATION_JSON); + final Entity<PushPolicyParameters> entity = Entity.entity(pushPolicyParameters, MediaType.APPLICATION_JSON); - return invokeHttpClient(entity, "pushPolicy", policyAdapter.getPolicy().getPolicyName()); + return invokeHttpClient(entity, "pushPolicy", policyAdapter.getPolicy().getName()); } private boolean invokeHttpClient(final Entity<?> entity, final String method, final String policyName) { try { - Response response = getHttpClient().put(method, entity, + final Response response = getHttpClient().put(method, entity, Collections.singletonMap("ClientAuth", configurationParameters.getClientAuth())); if (response.getStatus() != HttpStatus.OK.value()) { @@ -110,7 +112,7 @@ public class XacmlPdpPolicyForwarder implements PolicyForwarder { method, policyName, response.getStatus(), response.getStatusInfo()); return false; } - } catch (HttpClientConfigException exception) { + } catch (final HttpClientConfigException exception) { LOGGER.error("Invocation of method " + method + " failed for policy " + policyName + " due to error opening Http client", exception); return false; @@ -119,19 +121,20 @@ public class XacmlPdpPolicyForwarder implements PolicyForwarder { } private HttpClient getHttpClient() throws HttpClientConfigException { - boolean useHttps = configurationParameters.isUseHttps(); - String hostname = configurationParameters.getHostname(); - int port = configurationParameters.getPort(); - String userName = configurationParameters.getUserName(); - String password = configurationParameters.getPassword(); - boolean managed = configurationParameters.isManaged(); - BusTopicParams params = BusTopicParams.builder().clientName("SDC Dist").useHttps(useHttps).hostname(hostname) - .port(port).userName(userName).password(password).basePath(BASE_PATH).managed(managed).build(); + final boolean useHttps = configurationParameters.isUseHttps(); + final String hostname = configurationParameters.getHostname(); + final int port = configurationParameters.getPort(); + final String userName = configurationParameters.getUserName(); + final String password = configurationParameters.getPassword(); + final boolean managed = configurationParameters.isManaged(); + final BusTopicParams params = + BusTopicParams.builder().clientName("SDC Dist").useHttps(useHttps).hostname(hostname).port(port) + .userName(userName).password(password).basePath(BASE_PATH).managed(managed).build(); return getHttpClientFactory().build(params); } @Override - public void configure(String parameterGroupName) { + public void configure(final String parameterGroupName) { configurationParameters = ParameterService.get(parameterGroupName); } diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java index c1365166..f978d3a9 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -22,18 +22,18 @@ package org.onap.policy.distribution.forwarding.xacml.pdp.adapters; import org.onap.policy.api.PushPolicyParameters; import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyAdapter; -import org.onap.policy.distribution.model.Policy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; /** * Base class for {@link XacmlPdpPolicyAdapter} implementations. - * + * * @param <T> the type of policy the adapter handles */ -public abstract class AbstractXacmlPdpPolicyAdapter<T extends Policy> implements XacmlPdpPolicyAdapter<T> { +public abstract class AbstractXacmlPdpPolicyAdapter<T extends ToscaPolicy> implements XacmlPdpPolicyAdapter<T> { private T policy; - protected AbstractXacmlPdpPolicyAdapter(T policy) { + protected AbstractXacmlPdpPolicyAdapter(final T policy) { this.policy = policy; } @@ -43,10 +43,10 @@ public abstract class AbstractXacmlPdpPolicyAdapter<T extends Policy> implements } @Override - public PushPolicyParameters getAsPushPolicyParameters(String pdpGroups) { - PushPolicyParameters pushPolicyParameters = new PushPolicyParameters(); - pushPolicyParameters.setPolicyName(policy.getPolicyName()); - pushPolicyParameters.setPolicyType(policy.getPolicyType()); + public PushPolicyParameters getAsPushPolicyParameters(final String pdpGroups) { + final PushPolicyParameters pushPolicyParameters = new PushPolicyParameters(); + pushPolicyParameters.setPolicyName(policy.getName()); + pushPolicyParameters.setPolicyType(policy.getType()); pushPolicyParameters.setPdpGroup(pdpGroups); return pushPolicyParameters; } diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java index 1ec654fa..c9633b15 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java @@ -5,49 +5,42 @@ * 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.adapters; -import org.onap.policy.api.PolicyConfigType; import org.onap.policy.api.PolicyParameters; -import org.onap.policy.distribution.model.OptimizationPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; /** - * Adapts {@link OptimizationPolicy} objects to objects compatible with the XACML PDP API. + * Adapts {@link ToscaPolicy} objects to objects compatible with the XACML PDP API. */ -public class XacmlPdpOptimizationPolicyAdapter extends AbstractXacmlPdpPolicyAdapter<OptimizationPolicy> { +public class XacmlPdpOptimizationPolicyAdapter extends AbstractXacmlPdpPolicyAdapter<ToscaPolicy> { /** - * Create an instance to adapt the given {@link OptimizationPolicy}. - * - * @param optimizationPolicy the {@link OptimizationPolicy} to be adapted + * Create an instance to adapt the given {@link ToscaPolicy}. + * + * @param optimizationPolicy the {@link ToscaPolicy} to be adapted */ - public XacmlPdpOptimizationPolicyAdapter(final OptimizationPolicy optimizationPolicy) { + public XacmlPdpOptimizationPolicyAdapter(final ToscaPolicy optimizationPolicy) { super(optimizationPolicy); } @Override public PolicyParameters getAsPolicyParameters() { - PolicyParameters policyParameters = new PolicyParameters(); - policyParameters.setPolicyName(getPolicy().getPolicyName()); - policyParameters.setPolicyDescription(getPolicy().getPolicyDescription()); - policyParameters.setPolicyConfigType(PolicyConfigType.valueOf(getPolicy().getPolicyConfigType())); - policyParameters.setOnapName(getPolicy().getOnapName()); - policyParameters.setRiskLevel(getPolicy().getRiskLevel()); - policyParameters.setConfigBody(getPolicy().getConfigBody()); - policyParameters.setRiskType(getPolicy().getRiskType()); + final PolicyParameters policyParameters = new PolicyParameters(); + policyParameters.setPolicyName(getPolicy().getName()); return policyParameters; } 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 a4d1b9fd..cae94f18 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 @@ -45,8 +45,8 @@ 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.model.Policy; -import org.onap.policy.distribution.model.PolicyAsString; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; /** * Class to perform unit test of {@link ApexPdpPolicyForwarder}. @@ -89,7 +89,7 @@ public class ApexPdpPolicyForwarderTest { public void testForwardPolicy() throws ApexException, FileNotFoundException, IOException, PolicyForwardingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Collection<Policy> policies = new ArrayList<>(); + final Collection<ToscaEntity> policies = new ArrayList<>(); final ApexPdpPolicyForwarder forwarder = new ApexPdpPolicyForwarder(); forwarder.configure(GROUP_NAME); @@ -97,8 +97,7 @@ public class ApexPdpPolicyForwarderTest { forwarderField.setAccessible(true); forwarderField.set(forwarder, engineServiceFacade); - final PolicyAsString policy = new PolicyAsString("policy", "APEX", "Sample Policy of apex"); - policies.add(policy); + createPolicy(policies, "policy", "APEX", "Sample Policy of apex"); try { forwarder.forward(policies); @@ -115,7 +114,7 @@ public class ApexPdpPolicyForwarderTest { throws ApexException, FileNotFoundException, IOException, PolicyForwardingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Collection<Policy> policies = new ArrayList<>(); + final Collection<ToscaEntity> policies = new ArrayList<>(); final ApexPdpPolicyForwarder forwarder = new ApexPdpPolicyForwarder(); forwarder.configure(GROUP_NAME); @@ -126,8 +125,7 @@ public class ApexPdpPolicyForwarderTest { decodersField.setAccessible(true); decodersField.set(forwarder, engineServiceFacade); - final PolicyAsString policy1 = new PolicyAsString("policy1", "APEX", "Sample Policy of apex"); - policies.add(policy1); + createPolicy(policies, "policy1", "APEX", "Sample Policy of apex"); try { forwarder.forward(policies); @@ -143,7 +141,7 @@ public class ApexPdpPolicyForwarderTest { throws ApexException, FileNotFoundException, IOException, PolicyForwardingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Collection<Policy> policies = new ArrayList<>(); + final Collection<ToscaEntity> policies = new ArrayList<>(); final ApexPdpPolicyForwarder forwarder = new ApexPdpPolicyForwarder(); forwarder.configure(GROUP_NAME); @@ -151,11 +149,8 @@ public class ApexPdpPolicyForwarderTest { forwarderField.setAccessible(true); forwarderField.set(forwarder, engineServiceFacade); - final PolicyAsString policy1 = new PolicyAsString("policy1", "APEX", "Sample Policy of apex"); - policies.add(policy1); - - final PolicyAsString policy2 = new PolicyAsString("policy2", "APEX", "Sample Policy of apex"); - policies.add(policy2); + createPolicy(policies, "policy1", "APEX", "Sample Policy of apex"); + createPolicy(policies, "policy2", "APEX", "Sample Policy of apex"); try { forwarder.forward(policies); @@ -170,7 +165,7 @@ public class ApexPdpPolicyForwarderTest { throws ApexException, FileNotFoundException, IOException, PolicyForwardingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Collection<Policy> policies = new ArrayList<>(); + final Collection<ToscaEntity> policies = new ArrayList<>(); final ApexPdpPolicyForwarder forwarder = new ApexPdpPolicyForwarder(); forwarder.configure(GROUP_NAME); @@ -178,27 +173,31 @@ public class ApexPdpPolicyForwarderTest { forwarderField.setAccessible(true); forwarderField.set(forwarder, engineServiceFacade); - final Policy policy = new UnsupportedPolicy(); + final ToscaEntity policy = new UnsupportedPolicy(); policies.add(policy); try { forwarder.forward(policies); fail("Test must throw an exception"); } catch (final Exception exp) { - assertTrue(exp.getMessage().contains("Ignoring the policy as it is not an apex-pdp policy")); + assertTrue(exp.getMessage().contains("Ignoring the policy as it is not of type ToscaPolicy")); } } - class UnsupportedPolicy implements Policy { + class UnsupportedPolicy extends ToscaEntity { @Override - public String getPolicyName() { + public String getName() { return "unsupported"; } + } - @Override - public String getPolicyType() { - return "unsupported"; - } + private void createPolicy(final Collection<ToscaEntity> policies, final String name, final String type, + final String description) { + final ToscaPolicy policy = new ToscaPolicy(); + policy.setName(name); + policy.setType(type); + policy.setDescription(description); + policies.add(policy); } } 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 e474f693..5c87a86c 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 @@ -30,7 +30,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.ClassRule; @@ -41,8 +41,8 @@ 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.distribution.model.OptimizationPolicy; -import org.onap.policy.distribution.model.Policy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; /** * Class to perform unit test of {@link FilePolicyForwarder}. @@ -78,26 +78,15 @@ public class FilePolicyForwarderTest { @Test public void testForwardPolicy() { - final Collection<Policy> policies = new ArrayList<>(); - final OptimizationPolicy policy = new OptimizationPolicy(); - - policy.setPolicyName("test"); - policy.setPolicyDescription("test"); - policy.setOnapName(""); - policy.setConfigBody(""); - policy.setConfigBodyType(""); - policy.setTimetolive(new Date()); - policy.setGuard(""); - policy.setRiskLevel(""); - policy.setRiskType(""); - policies.add(policy); + final Collection<ToscaEntity> policies = new ArrayList<>(); + final ToscaPolicy policy = createPolicy(policies, "test", "test"); final FilePolicyForwarder forwarder = new FilePolicyForwarder(); forwarder.configure(GROUP_NAME); try { forwarder.forward(policies); - Path path = Paths.get(tempFolder.getRoot().getAbsolutePath().toString(), policy.getPolicyName()); + final Path path = Paths.get(tempFolder.getRoot().getAbsolutePath().toString(), policy.getName()); assertTrue(Files.exists(path)); } catch (final Exception exp) { fail("Test must not throw an exception"); @@ -107,20 +96,11 @@ public class FilePolicyForwarderTest { @Test @SuppressWarnings("unchecked") public void testForwardPolicyError() { - final Collection<Policy> policies = new ArrayList<>(); - OptimizationPolicy policy = new OptimizationPolicy(); - policy.setPolicyName("test"); - policy.setPolicyDescription("test"); - policy.setOnapName(""); - policy.setConfigBody(""); - policy.setConfigBodyType(""); - policy.setTimetolive(new Date()); - policy.setGuard(""); - policy.setRiskLevel(""); - policy.setRiskType(""); - - OptimizationPolicy spy = Mockito.spy(policy); - Mockito.when(spy.getRiskType()).thenThrow(IOException.class); + final Collection<ToscaEntity> policies = new ArrayList<>(); + final ToscaPolicy policy = createPolicy(policies, "test", "test"); + + final ToscaPolicy spy = Mockito.spy(policy); + Mockito.when(spy.toString()).thenThrow(IOException.class); policies.add(spy); final FilePolicyForwarder forwarder = new FilePolicyForwarder(); @@ -136,11 +116,11 @@ public class FilePolicyForwarderTest { @Test public void testForwardUnsupportedPolicy() { - final Collection<Policy> policies = new ArrayList<>(); + final Collection<ToscaEntity> policies = new ArrayList<>(); final FilePolicyForwarder forwarder = new FilePolicyForwarder(); forwarder.configure(GROUP_NAME); - final Policy policy = new UnsupportedPolicy(); + final ToscaEntity policy = new UnsupportedPolicy(); policies.add(policy); try { @@ -151,16 +131,20 @@ public class FilePolicyForwarderTest { } } - class UnsupportedPolicy implements Policy { + class UnsupportedPolicy extends ToscaEntity { @Override - public String getPolicyName() { + public String getName() { return "unsupported"; } + } - @Override - public String getPolicyType() { - return "unsupported"; - } + private ToscaPolicy createPolicy(final Collection<ToscaEntity> policies, final String name, + final String description) { + final ToscaPolicy policy = new ToscaPolicy(); + policy.setName("test"); + policy.setDescription("test"); + policies.add(policy); + return policy; } } 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 43fac718..9b495866 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 @@ -32,8 +32,10 @@ import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; + import javax.ws.rs.client.Entity; import javax.ws.rs.core.Response; + import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.BeforeClass; @@ -48,8 +50,8 @@ 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.model.OptimizationPolicy; -import org.onap.policy.distribution.model.Policy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; public class XacmlPdpPolicyForwarderTest { @@ -66,7 +68,7 @@ public class XacmlPdpPolicyForwarderTest { */ @BeforeClass public static void setUp() { - ParameterGroup parameterGroup = new XacmlPdpPolicyForwarderParameterGroupBuilder() + 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) @@ -78,29 +80,25 @@ public class XacmlPdpPolicyForwarderTest { @Test public void testForwardPolicy() throws Exception { - HttpClient httpClientMock = mock(HttpClient.class); + final HttpClient httpClientMock = mock(HttpClient.class); headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE); when(httpClientMock.put(eq("createPolicy"), anyObject(), eq(headers))).thenReturn(Response.ok().build()); when(httpClientMock.put(eq("pushPolicy"), anyObject(), eq(headers))).thenReturn(Response.ok().build()); - HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); + final HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); when(httpClientFactoryMock.build(argThat(matcher))).thenReturn(httpClientMock); - XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); + final XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); forwarder.configure("xacmlPdpConfiguration"); - Collection<Policy> policies = new ArrayList<>(); + final Collection<ToscaEntity> policies = new ArrayList<>(); - OptimizationPolicy policy1 = new OptimizationPolicy(); - policy1.setPolicyName("policy1"); - policies.add(policy1); + final ToscaPolicy policy1 = createPolicy(policies, "policy1", "optimization"); - Policy policy2 = new UnsupportedPolicy(); + final ToscaEntity policy2 = new UnsupportedPolicy(); policies.add(policy2); - OptimizationPolicy policy3 = new OptimizationPolicy(); - policy3.setPolicyName("policy3"); - policies.add(policy3); + final ToscaPolicy policy3 = createPolicy(policies, "policy3", "optimization"); forwarder.forward(policies); @@ -117,21 +115,19 @@ public class XacmlPdpPolicyForwarderTest { @Test public void testForwardPolicy_CreateFailsPushNotInvoked() throws Exception { - HttpClient httpClientMock = mock(HttpClient.class); + final HttpClient httpClientMock = mock(HttpClient.class); headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE); when(httpClientMock.put(eq("createPolicy"), anyObject(), eq(headers))).thenReturn(Response.status(400).build()); when(httpClientMock.put(eq("pushPolicy"), anyObject(), eq(headers))).thenReturn(Response.ok().build()); - HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); + final HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); when(httpClientFactoryMock.build(argThat(matcher))).thenReturn(httpClientMock); - XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); + final XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); forwarder.configure("xacmlPdpConfiguration"); - Collection<Policy> policies = new ArrayList<>(); - OptimizationPolicy policy = new OptimizationPolicy(); - policy.setPolicyName("policy"); - policies.add(policy); + final Collection<ToscaEntity> policies = new ArrayList<>(); + final ToscaPolicy policy = createPolicy(policies, "policy", "optimization"); forwarder.forward(policies); verify(httpClientMock).put(eq("createPolicy"), argThat(new PolicyParametersEntityMatcher(policy)), eq(headers)); @@ -141,21 +137,19 @@ public class XacmlPdpPolicyForwarderTest { @Test public void testForwardPolicy_PushFails() throws Exception { - HttpClient httpClientMock = mock(HttpClient.class); + final HttpClient httpClientMock = mock(HttpClient.class); headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE); when(httpClientMock.put(eq("createPolicy"), anyObject(), eq(headers))).thenReturn(Response.ok().build()); when(httpClientMock.put(eq("pushPolicy"), anyObject(), eq(headers))).thenReturn(Response.status(400).build()); - HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); + final HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); when(httpClientFactoryMock.build(argThat(matcher))).thenReturn(httpClientMock); - XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); + final XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); forwarder.configure("xacmlPdpConfiguration"); - Collection<Policy> policies = new ArrayList<>(); - OptimizationPolicy policy = new OptimizationPolicy(); - policy.setPolicyName("policy"); - policies.add(policy); + final Collection<ToscaEntity> policies = new ArrayList<>(); + final ToscaPolicy policy = createPolicy(policies, "policy", "optimization"); forwarder.forward(policies); verify(httpClientMock).put(eq("createPolicy"), argThat(new PolicyParametersEntityMatcher(policy)), eq(headers)); @@ -166,21 +160,19 @@ public class XacmlPdpPolicyForwarderTest { @Test public void testForwardPolicy_HttpClientInitFailureForPolicyCreate() throws Exception { - HttpClient httpClientMock = mock(HttpClient.class); + final HttpClient httpClientMock = mock(HttpClient.class); headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE); when(httpClientMock.put(eq("createPolicy"), anyObject(), eq(headers))).thenReturn(Response.ok().build()); when(httpClientMock.put(eq("pushPolicy"), anyObject(), eq(headers))).thenReturn(Response.status(400).build()); - HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); + final HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); when(httpClientFactoryMock.build(argThat(matcher))).thenThrow(new HttpClientConfigException()); - XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); + final XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); forwarder.configure("xacmlPdpConfiguration"); - Collection<Policy> policies = new ArrayList<>(); - OptimizationPolicy policy = new OptimizationPolicy(); - policy.setPolicyName("policy"); - policies.add(policy); + final Collection<ToscaEntity> policies = new ArrayList<>(); + final ToscaPolicy policy = createPolicy(policies, "policy", "optimization"); forwarder.forward(policies); verify(httpClientMock, times(0)).put(eq("createPolicy"), anyObject(), anyObject()); @@ -190,22 +182,20 @@ public class XacmlPdpPolicyForwarderTest { @Test public void testForwardPolicy_HttpClientInitFailureForPolicyPush() throws Exception { - HttpClient httpClientMock = mock(HttpClient.class); + final HttpClient httpClientMock = mock(HttpClient.class); headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE); when(httpClientMock.put(eq("createPolicy"), anyObject(), eq(headers))).thenReturn(Response.ok().build()); when(httpClientMock.put(eq("pushPolicy"), anyObject(), eq(headers))).thenReturn(Response.status(400).build()); - HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); + final HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class); when(httpClientFactoryMock.build(argThat(matcher))).thenReturn(httpClientMock) .thenThrow(new HttpClientConfigException()); - XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); + final XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock); forwarder.configure("xacmlPdpConfiguration"); - Collection<Policy> policies = new ArrayList<>(); - OptimizationPolicy policy = new OptimizationPolicy(); - policy.setPolicyName("policy"); - policies.add(policy); + final Collection<ToscaEntity> policies = new ArrayList<>(); + final ToscaPolicy policy = createPolicy(policies, "policy", "optimization"); forwarder.forward(policies); verify(httpClientMock).put(eq("createPolicy"), argThat(new PolicyParametersEntityMatcher(policy)), eq(headers)); @@ -221,9 +211,9 @@ public class XacmlPdpPolicyForwarderTest { } @Override - public boolean matches(Object arg0) { + public boolean matches(final Object arg0) { if (arg0 instanceof BusTopicParams) { - BusTopicParams toCompareTo = (BusTopicParams) arg0; + final BusTopicParams toCompareTo = (BusTopicParams) arg0; return toCompareTo.isUseHttps() == busTopicParams.isUseHttps() && toCompareTo.getHostname().equals(busTopicParams.getHostname()) && toCompareTo.getPort() == busTopicParams.getPort() @@ -235,65 +225,59 @@ public class XacmlPdpPolicyForwarderTest { } @Override - public void describeTo(Description arg0) {} + public void describeTo(final Description arg0) {} } class PolicyParametersEntityMatcher extends BaseMatcher<Entity<PolicyParameters>> { - private OptimizationPolicy policy; + private ToscaPolicy policy; - PolicyParametersEntityMatcher(final OptimizationPolicy policy) { + PolicyParametersEntityMatcher(final ToscaPolicy policy) { this.policy = policy; } @SuppressWarnings("unchecked") @Override - public boolean matches(Object arg0) { + public boolean matches(final Object arg0) { if (arg0 instanceof Entity) { - PolicyParameters toCompareTo = ((Entity<PolicyParameters>) arg0).getEntity(); - return toCompareTo.getPolicyName().equals(policy.getPolicyName()) - && toCompareTo.getPolicyConfigType().toString().equals(policy.getPolicyConfigType()); + final PolicyParameters toCompareTo = ((Entity<PolicyParameters>) arg0).getEntity(); + return toCompareTo.getPolicyName().equals(policy.getName()); } return false; } @Override - public void describeTo(Description arg0) {} + public void describeTo(final Description arg0) {} } class PushPolicyParametersEntityMatcher extends BaseMatcher<Entity<PushPolicyParameters>> { - private Policy policy; + private ToscaPolicy policy; - PushPolicyParametersEntityMatcher(final Policy policy) { + PushPolicyParametersEntityMatcher(final ToscaPolicy policy) { this.policy = policy; } @SuppressWarnings("unchecked") @Override - public boolean matches(Object arg0) { + public boolean matches(final Object arg0) { if (arg0 instanceof Entity) { - PushPolicyParameters toCompareTo = ((Entity<PushPolicyParameters>) arg0).getEntity(); - return toCompareTo.getPolicyName().equals(policy.getPolicyName()) - && toCompareTo.getPolicyType().equals(policy.getPolicyType()) + final PushPolicyParameters toCompareTo = ((Entity<PushPolicyParameters>) arg0).getEntity(); + return toCompareTo.getPolicyName().equals(policy.getName()) + && toCompareTo.getPolicyType().equals(policy.getType()) && toCompareTo.getPdpGroup().equals(PDP_GROUP_VALUE); } return false; } @Override - public void describeTo(Description arg0) {} + public void describeTo(final Description arg0) {} } - class UnsupportedPolicy implements Policy { - - @Override - public String getPolicyName() { - return "unsupported"; - } + class UnsupportedPolicy extends ToscaEntity { @Override - public String getPolicyType() { + public String getName() { return "unsupported"; } } @@ -301,7 +285,7 @@ public class XacmlPdpPolicyForwarderTest { private class MyXacmlPdpPolicyForwarder extends XacmlPdpPolicyForwarder { private HttpClientFactory factory; - public MyXacmlPdpPolicyForwarder(HttpClientFactory httpClientFactory) { + public MyXacmlPdpPolicyForwarder(final HttpClientFactory httpClientFactory) { this.factory = httpClientFactory; } @@ -310,4 +294,12 @@ public class XacmlPdpPolicyForwarderTest { return this.factory; } } + + private ToscaPolicy createPolicy(final Collection<ToscaEntity> policies, final String name, final String type) { + final ToscaPolicy policy1 = new ToscaPolicy(); + policy1.setName(name); + policy1.setType(type); + policies.add(policy1); + return policy1; + } } diff --git a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyDecoder.java b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyDecoder.java index c90917b8..4cd7e24c 100644 --- a/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyDecoder.java +++ b/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/testclasses/DummyDecoder.java @@ -22,27 +22,27 @@ package org.onap.policy.distribution.forwarding.xacml.pdp.testclasses; import java.util.Collection; -import org.onap.policy.distribution.model.Policy; import org.onap.policy.distribution.model.PolicyInput; import org.onap.policy.distribution.reception.decoding.PolicyDecoder; import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; /** * Class to create a dummy decoder for test cases. * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ -public class DummyDecoder implements PolicyDecoder<PolicyInput, Policy> { +public class DummyDecoder implements PolicyDecoder<PolicyInput, ToscaEntity> { private boolean canHandleValue; - private Collection<Policy> policesToReturn; + private Collection<ToscaEntity> policesToReturn; public DummyDecoder() { this.canHandleValue = false; this.policesToReturn = null; } - public DummyDecoder(final boolean canHandleValue, final Collection<Policy> policesToReturn) { + public DummyDecoder(final boolean canHandleValue, final Collection<ToscaEntity> policesToReturn) { this.canHandleValue = canHandleValue; this.policesToReturn = policesToReturn; } @@ -53,7 +53,7 @@ public class DummyDecoder implements PolicyDecoder<PolicyInput, Policy> { } @Override - public Collection<Policy> decode(final PolicyInput input) throws PolicyDecodingException { + public Collection<ToscaEntity> decode(final PolicyInput input) throws PolicyDecodingException { return policesToReturn; } |