diff options
author | Jim Hahn <jrh3@att.com> | 2021-03-29 16:31:23 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-03-29 19:17:55 -0400 |
commit | 07f9418952d3dec141d6953099e0456f85f68807 (patch) | |
tree | 27cbedc8951f4e93d772de08b0d3c3f461d4423d /main/src/test | |
parent | 43c05f435510137c8e241c3c6d24b562f1244403 (diff) |
Validate parameters of REST calls
Added code to validate the parameters of the REST calls. As it turned
out, validation only needed to be added to one call.
Issue-ID: POLICY-2542
Change-Id: Ia9aabf75e06d6d5f996be9e3ed804218319f70c2
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/test')
6 files changed, 82 insertions, 0 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployProvider.java index a7f48ff3..575dfefc 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployProvider.java @@ -55,6 +55,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; public class TestPdpGroupDeployProvider extends ProviderSuper { + private static final String EXPECTED_EXCEPTION = "expected exception"; private static final String POLICY2_NAME = "policyB"; @@ -475,6 +476,44 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { } /** + * Tests deployPolicies() when the policies are invalid. + */ + @Test + public void testDeployPoliciesInvalidPolicies() throws Exception { + // valid list + PdpDeployPolicies policies0 = loadFile("PapPoliciesList.json", PdpDeployPolicies.class); + assertThatCode(() -> prov.deployPolicies(policies0)).doesNotThrowAnyException(); + + // null list + PdpDeployPolicies policies = new PdpDeployPolicies(); + assertThatThrownBy(() -> prov.deployPolicies(policies)).isInstanceOf(PfModelException.class) + .hasMessageContaining("policies"); + + // list containing null item + PdpDeployPolicies policies2 = loadFile("PapPoliciesNullItem.json", PdpDeployPolicies.class); + assertThatThrownBy(() -> prov.deployPolicies(policies2)).isInstanceOf(PfModelException.class) + .hasMessageContaining("policies").hasMessageContaining("null"); + + // list containing a policy with a null name + PdpDeployPolicies policies3 = loadFile("PapPoliciesNullPolicyName.json", PdpDeployPolicies.class); + assertThatThrownBy(() -> prov.deployPolicies(policies3)).isInstanceOf(PfModelException.class) + .hasMessageContaining("policies").hasMessageContaining("name").hasMessageContaining("null") + .hasMessageNotContaining("\"value\""); + + // list containing a policy with an invalid name + PdpDeployPolicies policies4 = loadFile("PapPoliciesInvalidPolicyName.json", PdpDeployPolicies.class); + assertThatThrownBy(() -> prov.deployPolicies(policies4)).isInstanceOf(PfModelException.class) + .hasMessageContaining("policies").hasMessageContaining("name").hasMessageContaining("$ abc") + .hasMessageNotContaining("version"); + + // list containing a policy with an invalid version + PdpDeployPolicies policies5 = loadFile("PapPoliciesInvalidPolicyVersion.json", PdpDeployPolicies.class); + assertThatThrownBy(() -> prov.deployPolicies(policies5)).isInstanceOf(PfModelException.class) + .hasMessageContaining("policies").hasMessageContaining("version").hasMessageContaining("abc123") + .hasMessageNotContaining("name"); + } + + /** * Tests deployPolicies() when the supported policy type uses a wild-card. * * @throws Exception if an error occurs diff --git a/main/src/test/resources/simpleDeploy/PapPoliciesInvalidPolicyName.json b/main/src/test/resources/simpleDeploy/PapPoliciesInvalidPolicyName.json new file mode 100644 index 00000000..d155c3b6 --- /dev/null +++ b/main/src/test/resources/simpleDeploy/PapPoliciesInvalidPolicyName.json @@ -0,0 +1,8 @@ +{ + "policies": [ + { + "policy-id" : "$ abc", + "policy-version": "1.2.0" + } + ] +} diff --git a/main/src/test/resources/simpleDeploy/PapPoliciesInvalidPolicyVersion.json b/main/src/test/resources/simpleDeploy/PapPoliciesInvalidPolicyVersion.json new file mode 100644 index 00000000..c4b16671 --- /dev/null +++ b/main/src/test/resources/simpleDeploy/PapPoliciesInvalidPolicyVersion.json @@ -0,0 +1,8 @@ +{ + "policies": [ + { + "policy-id" : "myPolicy", + "policy-version": "abc123" + } + ] +} diff --git a/main/src/test/resources/simpleDeploy/PapPoliciesList.json b/main/src/test/resources/simpleDeploy/PapPoliciesList.json new file mode 100644 index 00000000..a4af6d24 --- /dev/null +++ b/main/src/test/resources/simpleDeploy/PapPoliciesList.json @@ -0,0 +1,16 @@ +{ + "policies": [ + { + "policy-id" : "MyPolicy0", + "policy-version": null + }, + { + "policy-id" : "MyPolicy1", + "policy-version": "1" + }, + { + "policy-id" : "MyPolicy2", + "policy-version": "1.2.2" + } + ] +} diff --git a/main/src/test/resources/simpleDeploy/PapPoliciesNullItem.json b/main/src/test/resources/simpleDeploy/PapPoliciesNullItem.json new file mode 100644 index 00000000..2e035ec5 --- /dev/null +++ b/main/src/test/resources/simpleDeploy/PapPoliciesNullItem.json @@ -0,0 +1,3 @@ +{ + "policies": [null] +} diff --git a/main/src/test/resources/simpleDeploy/PapPoliciesNullPolicyName.json b/main/src/test/resources/simpleDeploy/PapPoliciesNullPolicyName.json new file mode 100644 index 00000000..945e3ca4 --- /dev/null +++ b/main/src/test/resources/simpleDeploy/PapPoliciesNullPolicyName.json @@ -0,0 +1,8 @@ +{ + "policies": [ + { + "policy-id" : null, + "policy-version": "1.2.0" + } + ] +} |