From 9ce39af891ccf063d46e18ecf5a2a47eb1408930 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 8 Apr 2019 13:58:53 +0000 Subject: Add bug fixes and tests for filters Fixed bugs on filtering where lack of null checks was blocking all results. Added unit test for PDP related JPA objects. Fixed cascading and orphan control on JPA objects. Added partial testing of PdpProvider. Added partial testing of filters. Changed tag for content of operational policies from "Content" to "content". Issue-ID: POLICY-1095 Change-Id: Ieb22e06955a8434b490bae7d0f6b77d4479515e8 Signed-off-by: liamfallon --- .../models/tosca/authorative/concepts/ToscaPolicyFilter.java | 9 +++++---- .../models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java | 5 +++-- .../tosca/legacy/mapping/LegacyOperationalPolicyMapper.java | 8 ++++++-- 3 files changed, 14 insertions(+), 8 deletions(-) (limited to 'models-tosca/src/main/java/org') diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java index b4d1b3ee3..102b1fe2e 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java @@ -57,10 +57,11 @@ public class ToscaPolicyFilter implements PfObjectFilter { // @formatter:off List returnList = originalList.stream() - .filter(p -> filterOnRegexp(p.getName(), name)) - .filter(p -> version.equals(LATEST_VERSION) || filterOnRegexp(p.getVersion(), version)) - .filter(p -> filterOnRegexp(p.getType(), type)) - .filter(p -> filterOnRegexp(p.getTypeVersion(), typeVersion)) + .filter(p -> filterString(p.getName(), name)) + .filter(p -> (version != null && LATEST_VERSION.equals(version)) + || filterString(p.getVersion(), version)) + .filter(p -> filterString(p.getType(), type)) + .filter(p -> filterString(p.getTypeVersion(), typeVersion)) .collect(Collectors.toList()); // @formatter:off diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java index 041179513..7d6fbacee 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java @@ -51,8 +51,9 @@ public class ToscaPolicyTypeFilter implements PfObjectFilter { // @formatter:off List returnList = originalList.stream() - .filter(p -> filterOnRegexp(p.getName(), name)) - .filter(p -> version.equals(LATEST_VERSION) || filterOnRegexp(p.getVersion(), version)) + .filter(p -> filterString(p.getName(), name)) + .filter(p -> (version != null && LATEST_VERSION.equals(version)) + || filterString(p.getVersion(), version)) .collect(Collectors.toList()); // @formatter:off diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java index 4ddcd60cc..b6c5d3bba 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java @@ -44,6 +44,10 @@ import org.slf4j.LoggerFactory; */ public class LegacyOperationalPolicyMapper implements JpaToscaServiceTemplateMapper { + + // Property name for the operational policy content + private static final String CONTENT_PROPERTY = "content"; + private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicyMapper.class); private static final PfConceptKey LEGACY_OPERATIONAL_TYPE = @@ -64,7 +68,7 @@ public class LegacyOperationalPolicyMapper final Map propertyMap = new HashMap<>(); toscaPolicy.setProperties(propertyMap); - toscaPolicy.getProperties().put("Content", legacyOperationalPolicy.getContent()); + toscaPolicy.getProperties().put(CONTENT_PROPERTY, legacyOperationalPolicy.getContent()); final JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0"); @@ -101,7 +105,7 @@ public class LegacyOperationalPolicyMapper throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); } - final String content = toscaPolicy.getProperties().get("Content"); + final String content = toscaPolicy.getProperties().get(CONTENT_PROPERTY); if (toscaPolicy.getProperties() == null) { String errorMessage = "property \"Content\" not defined on TOSCA policy"; LOGGER.warn(errorMessage); -- cgit 1.2.3-korg