summaryrefslogtreecommitdiffstats
path: root/applications/guard/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-05-27 15:10:18 -0400
committerJim Hahn <jrh3@att.com>2021-05-27 17:09:00 -0400
commitae9007f3554ba021d76d001ca555a13d49babc8d (patch)
treeddf359c36bfd60f49e55e25f91788c04ec99726d /applications/guard/src/test
parentd1fa4ea52b243f60047a0bad5e63e947572b036b (diff)
Replace validation code with annotations
Instead of having code to validate various values, created POJOs to represent the decoded data so that bean validation annotations could be used instead. Didn't see any obvious ways to use annotations in the Optimization code, but did notice a bug (passed role instead of provisions). Extracted a common method which fixed the bug as a side-effect. Issue-ID: POLICY-2418 Change-Id: I9ef589086fc8f7f66810b66405fbf302d7570e5a Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'applications/guard/src/test')
-rw-r--r--applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java31
-rw-r--r--applications/guard/src/test/resources/test-bad-policies.yaml18
2 files changed, 21 insertions, 28 deletions
diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java
index cf8c0158..fcd5ac28 100644
--- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java
+++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java
@@ -117,27 +117,26 @@ public class GuardTranslatorTest {
// Expected message for given policy name
//
final Map<String, String> name2message = new HashMap<>();
- name2message.put("frequency-missing-properties", "Missing property limit");
- name2message.put("frequency-timewindow", "timeWindow is not an integer");
- name2message.put("frequency-badtimerange_start", "Invalid timeRange");
- name2message.put("frequency-badtimerange_end", "Invalid timeRange");
+ name2message.put("frequency-missing-properties", "item \"limit\"");
+ name2message.put("frequency-timewindow", "Cannot decode FrequencyDefinition");
+ name2message.put("frequency-badtimerange_start", "item \"startTime\"");
+ name2message.put("frequency-badtimerange_end", "item \"endTime\"");
name2message.put("frequency-badtimerange_value", "timestamp 99:99:99 could not be parsed");
- name2message.put("minmax-notarget", "Missing target field in minmax policy");
+ name2message.put("minmax-notarget", "item \"target\"");
name2message.put("minmax-nominmax", "Missing min or max field in minmax policy");
- name2message.put("blacklist-noblacklist", "Missing blacklist");
- name2message.put("filter-noalgorithm", "Missing algorithm");
+ name2message.put("blacklist-noblacklist", "item \"blacklist\"");
+ name2message.put("filter-noalgorithm", "item \"algorithm\"");
name2message.put("filter-badalgorithm",
"Unexpected value for algorithm, should be whitelist-overrides or blacklist-overrides");
- name2message.put("filter-nofilter", "Missing filters");
- name2message.put("filter-nocollection", "Filters is not a collection");
- name2message.put("filter-noarray", "Filters is not a collection");
- name2message.put("filter-missingfield", "Missing \'field\' from filter");
+ name2message.put("filter-nofilter", "item \"filters\"");
+ name2message.put("filter-nocollection", "Cannot decode FilterDefinition");
+ name2message.put("filter-noarray", "Cannot decode FilterDefinition");
+ name2message.put("filter-missingfield", "item \"field\"");
name2message.put("filter-badfield", "Unexpected value for field in filter");
- name2message.put("filter-missingfilter", "Missing \'filter\' from filter");
- name2message.put("filter-missingfunction", "Missing \'function\' from filter");
+ name2message.put("filter-missingfilter", "item \"filter\"");
+ name2message.put("filter-missingfunction", "item \"function\"");
name2message.put("filter-badfunction", "Unexpected value for function in filter");
- name2message.put("filter-missingblacklist", "Missing \'blacklist\' from filter");
- name2message.put("filter-badblacklist", "Unexpected value for blacklist in filter");
+ name2message.put("filter-missingblacklist", "item \"blacklist\"");
//
// Get the policies
//
@@ -149,7 +148,7 @@ public class GuardTranslatorTest {
assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() ->
translator.convertPolicy(policy)
- ).withMessageContaining(expectedMsg);
+ ).as(policy.getName()).withMessageContaining(expectedMsg);
}
}
}
diff --git a/applications/guard/src/test/resources/test-bad-policies.yaml b/applications/guard/src/test/resources/test-bad-policies.yaml
index bdc8ba78..d7780c1f 100644
--- a/applications/guard/src/test/resources/test-bad-policies.yaml
+++ b/applications/guard/src/test/resources/test-bad-policies.yaml
@@ -79,12 +79,13 @@ topology_template:
type_version: 1.0.0
version: 1.0.0
properties:
- badProperty: badValue
+ filters: []
- filter-badalgorithm:
type: onap.policies.controlloop.guard.common.Filter
type_version: 1.0.0
version: 1.0.0
properties:
+ filters: []
algorithm: idontknow
- filter-nofilter:
type: onap.policies.controlloop.guard.common.Filter
@@ -123,6 +124,9 @@ topology_template:
algorithm: blacklist-overrides
filters:
- field: notinaai
+ filter: vfwl*
+ function: string-contains
+ blacklist: true
- filter-missingfilter:
type: onap.policies.controlloop.guard.common.Filter
type_version: 1.0.0
@@ -150,6 +154,7 @@ topology_template:
- field: generic-vnf.vnf-name
filter: vfwl*
function: notafunction
+ blacklist: true
- filter-missingblacklist:
type: onap.policies.controlloop.guard.common.Filter
type_version: 1.0.0
@@ -160,14 +165,3 @@ topology_template:
- field: generic-vnf.vnf-name
filter: vfwl*
function: string-equal
- - filter-badblacklist:
- type: onap.policies.controlloop.guard.common.Filter
- type_version: 1.0.0
- version: 1.0.0
- properties:
- algorithm: blacklist-overrides
- filters:
- - field: generic-vnf.vnf-name
- filter: vfwl*
- function: string-equal
- blacklist: shouldbeboolean \ No newline at end of file