aboutsummaryrefslogtreecommitdiffstats
path: root/applications/common/src/test
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2020-02-19 16:59:01 -0500
committerPamela Dragosh <pdragosh@research.att.com>2020-02-19 19:59:33 -0500
commit3f4d4125093ca000c735adc1d6430c39e31de38c (patch)
tree5386fae347d6445bdba7599d0f42aefc85d867df /applications/common/src/test
parent56038a31a23e468f51c0b2ab349f748eafe4b6d2 (diff)
Use datatype in matchable translator
With the new changes to models/api, the full policy template will be retrieved along with inherited policy types and datatypes. Changed api caller to return tosca template instead of individual policy type so all policy types and data types are available. Changed stdmatchabletranslator to be able to flexibly go deep with list/map of datatypes of attributes. NOTE: This should be re-factored at a later date as its a bit messy. The naming application was used to test this code, but it was determined by the CCSDK team that they will not do filtering this release. Instead, switched to combined results policy type to return the full policy type. Issue-ID: POLICY-1740 Change-Id: Ieb4e46e7fb2c639a1155be3bc07f5587c4f7b09a Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'applications/common/src/test')
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java23
-rw-r--r--applications/common/src/test/resources/matchable/onap.policies.Test-1.0.0.yaml35
-rw-r--r--applications/common/src/test/resources/matchable/test.policies.input.tosca.yaml9
3 files changed, 50 insertions, 17 deletions
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java
index e9e8814c..aeb4cf88 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. 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.
@@ -70,7 +70,6 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
import org.onap.policy.models.decisions.concepts.DecisionResponse;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.onap.policy.pdp.xacml.application.common.TestUtilsCommon;
@@ -87,7 +86,7 @@ public class StdMatchableTranslatorTest {
private static final StandardYamlCoder yamlCoder = new StandardYamlCoder();
private static int port;
private static RestServerParameters clientParams;
- private static ToscaPolicyType testPolicyType;
+ private static ToscaServiceTemplate testTemplate;
@ClassRule
public static final TemporaryFolder policyFolder = new TemporaryFolder();
@@ -144,14 +143,15 @@ public class StdMatchableTranslatorTest {
//
JpaToscaServiceTemplate jtst = new JpaToscaServiceTemplate();
jtst.fromAuthorative(serviceTemplate);
- ToscaServiceTemplate completedJtst = jtst.toAuthorative();
+ testTemplate = jtst.toAuthorative();
//
- // Find the Policy Type - SHOULD only be one
+ // Make sure the Policy Types are there
//
- assertEquals(1, completedJtst.getPolicyTypes().size());
- testPolicyType = completedJtst.getPolicyTypes().get("onap.policies.Test");
- assertNotNull(testPolicyType);
- logger.info("Test Policy Type {}{}", XacmlPolicyUtils.LINE_SEPARATOR, testPolicyType);
+ assertEquals(3, testTemplate.getPolicyTypes().size());
+ assertNotNull(testTemplate.getPolicyTypes().get("onap.policies.Base"));
+ assertNotNull(testTemplate.getPolicyTypes().get("onap.policies.base.Middle"));
+ assertNotNull(testTemplate.getPolicyTypes().get("onap.policies.base.middle.Test"));
+ logger.info("Test Policy Type {}{}", XacmlPolicyUtils.LINE_SEPARATOR, testTemplate);
}
@AfterClass
@@ -191,6 +191,9 @@ public class StdMatchableTranslatorTest {
//
for (Map<String, ToscaPolicy> policies : completedJtst.getToscaTopologyTemplate().getPolicies()) {
for (ToscaPolicy policy : policies.values()) {
+ //
+ // Test that we can convert the policy
+ //
PolicyType translatedPolicy = translator.convertPolicy(policy);
assertNotNull(translatedPolicy);
assertThat(translatedPolicy.getObligationExpressions().getObligationExpression()).hasSize(1);
@@ -282,7 +285,7 @@ public class StdMatchableTranslatorTest {
public Response getSpecificVersionOfPolicyType(@PathParam("policyTypeId") String policyTypeId,
@PathParam("versionId") String versionId, @HeaderParam("X-ONAP-RequestID") UUID requestId) {
logger.info("request for policy type={} version={}", policyTypeId, versionId);
- return Response.status(Response.Status.OK).entity(testPolicyType).build();
+ return Response.status(Response.Status.OK).entity(testTemplate).build();
}
}
diff --git a/applications/common/src/test/resources/matchable/onap.policies.Test-1.0.0.yaml b/applications/common/src/test/resources/matchable/onap.policies.Test-1.0.0.yaml
index f44a3061..7179c310 100644
--- a/applications/common/src/test/resources/matchable/onap.policies.Test-1.0.0.yaml
+++ b/applications/common/src/test/resources/matchable/onap.policies.Test-1.0.0.yaml
@@ -1,9 +1,30 @@
tosca_definitions_version: tosca_simple_yaml_1_0_0
policy_types:
- onap.policies.Test:
+ onap.policies.Base:
derived_from: tosca.policies.Root
version: 1.0.0
properties:
+ baseNoMatch:
+ type: string
+ baseMatch:
+ type: string
+ metadata:
+ matchable: true
+ onap.policies.base.Middle:
+ derived_from: onap.policies.Base
+ version: 1.0.0
+ properties:
+ middleNoMatch:
+ type: string
+ middleMatch:
+ type: string
+ metadata:
+ matchable: true
+ onap.policies.base.middle.Test:
+ derived_from: onap.policies.base.Middle
+ type_version: 1.0.0
+ version: 1.0.0
+ properties:
nonmatachableString:
type: string
matchableString:
@@ -30,6 +51,10 @@ policy_types:
type: boolean
metadata:
matchable: true
+ nonmatchableListInteger:
+ type: list
+ entry_schema:
+ type: integer
matchableListString:
type: list
metadata:
@@ -39,7 +64,7 @@ policy_types:
propertyOneMap:
type: map
entry_schema:
- type: onap.datatype.level1
+ type: onap.datatype.one
data_types:
onap.datatype.one:
derived_from: tosca.datatypes.Root
@@ -49,7 +74,7 @@ data_types:
oneStringMatchable:
type: string
metadata:
- matachable: true
+ matchable: true
propertyTwoList:
type: list
entry_schema:
@@ -62,7 +87,7 @@ data_types:
twoStringMatchable:
type: string
metadata:
- matachable: true
+ matchable: true
propertyThreeMap:
type: map
entry_schema:
@@ -75,4 +100,4 @@ data_types:
threeStringMatchable:
type: string
metadata:
- matachable: true \ No newline at end of file
+ matchable: true \ No newline at end of file
diff --git a/applications/common/src/test/resources/matchable/test.policies.input.tosca.yaml b/applications/common/src/test/resources/matchable/test.policies.input.tosca.yaml
index 9a68d488..80f72b2f 100644
--- a/applications/common/src/test/resources/matchable/test.policies.input.tosca.yaml
+++ b/applications/common/src/test/resources/matchable/test.policies.input.tosca.yaml
@@ -2,13 +2,17 @@ tosca_definitions_version: tosca_simple_yaml_1_0_0
topology_template:
policies:
- Test.policy:
- type: onap.policies.Test
+ type: onap.policies.base.middle.Test
type_version: 1.0.0
version: 1.0.0
metadata:
policy-id: Test.policy
policy-version: 1
properties:
+ baseNoMatch: Do not match the base
+ baseMatch: base Match
+ middleNoMatch: Do not match the middle
+ middleMatch: middle Match
nonmatachableString: I am NON matchable
matchableString: I should be matched
nonmatachableInteger: 0
@@ -17,6 +21,7 @@ topology_template:
matchableFloat: 1.1
nonmatachableBoolean: false
matachableBoolean: true
+ nonmatchableListInteger: {0, 1, 2}
matchableListString:
- match A
- match B
@@ -25,7 +30,7 @@ topology_template:
oneStringMatchable: One should be matched
propertyTwoList:
- twoString: Two is NOT matchable
- twoStringMatachable: Two should be matched
+ twoStringMatchable: Two should be matched
propertyThreeMap:
threeString: Three is NOT matchable
threeStringMatchable: Three should be matched \ No newline at end of file