aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org
diff options
context:
space:
mode:
authorChenfei Gao <cgao@research.att.com>2019-10-09 16:36:05 -0400
committerChenfei Gao <cgao@research.att.com>2019-10-09 16:36:20 -0400
commitc0feaca7b641f6c0e3214f5333a1493c9893e0cb (patch)
treec5b2d448388fb38aa74129cbc2bfb2024f3e7381 /main/src/test/java/org
parent20390c6ed94e2082cb688d76aacabe5366d908fe (diff)
Created a new simplified API for creating policies
Added a new endpoint to create multiple policies in one call Added corresponding provider method Added corresponding junit tests Issue-ID: POLICY-1991 Change-Id: I09202ededfd88cf9f1ac62ea036e98e3b5d78f98 Signed-off-by: Chenfei Gao <cgao@research.att.com>
Diffstat (limited to 'main/src/test/java/org')
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java82
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java39
2 files changed, 121 insertions, 0 deletions
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
index b065277e..6e51e369 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
@@ -151,6 +151,7 @@ public class TestApiRestServer {
+ "onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.scaleout/versions/1";
private static final String OPS_POLICIES_VFIREWALL_VERSION = "policytypes/"
+ "onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.modifyconfig/versions/1";
+ private static final String POLICIES = "policies";
private static final String KEYSTORE = System.getProperty("user.dir") + "/src/test/resources/ssl/policy-keystore";
private static final CommonTestData COMMON_TEST_DATA = new CommonTestData();
@@ -170,6 +171,11 @@ public class TestApiRestServer {
"policies/vFirewall.policy.monitoring.input.tosca.yaml"
};
+ private String[] toscaPoliciesResourceNames = {
+ "policies/vCPE.policies.optimization.input.tosca.json",
+ "policies/vCPE.policies.optimization.input.tosca.yaml"
+ };
+
private String[] toscaPolicyTypeResourceNames = {
"policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml",
"policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml",
@@ -292,6 +298,44 @@ public class TestApiRestServer {
}
@Test
+ public void testCreatePoliciesPersistent() throws Exception {
+ setupParameters(); // setup DB
+ main = startApiService(true);
+ for (String resrcName : toscaPolicyResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getToscaTopologyTemplate().getPolicies().isEmpty());
+ }
+ }
+
+ @Test
+ public void testSimpleCreatePolicies() throws Exception {
+ main = startApiService(true);
+ for (String resrcName : toscaPoliciesResourceNames) {
+ Response rawResponse = createResource(POLICIES, resrcName, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("policy type onap.policies.optimization.AffinityPolicy:0.0.0 for "
+ + "policy OSDF_CASABLANCA.Affinity_vCPE_1:1.0.0 does not exist", error.getErrorMessage());
+ }
+ }
+
+ @Test
+ public void testSimpleCreatePoliciesPersistent() throws Exception {
+ setupParameters(); // setup DB
+ main = startApiService(true);
+ for (String resrcName : toscaPoliciesResourceNames) {
+ Response rawResponse = createResource(POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getToscaTopologyTemplate().getPolicies().isEmpty());
+ }
+ }
+
+ @Test
public void testCreateGuardPolicies() {
try {
main = startApiService(true);
@@ -378,6 +422,44 @@ public class TestApiRestServer {
}
@Test
+ public void testHttpsCreatePoliciesPersistent() throws Exception {
+ setupParameters(); // setup DB
+ main = startApiService(false);
+ for (String resrcName : toscaPolicyResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, false);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getToscaTopologyTemplate().getPolicies().isEmpty());
+ }
+ }
+
+ @Test
+ public void testHttpsSimpleCreatePolicies() throws Exception {
+ main = startApiService(false);
+ for (String resrcName : toscaPoliciesResourceNames) {
+ Response rawResponse = createResource(POLICIES, resrcName, false);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("policy type onap.policies.optimization.AffinityPolicy:0.0.0 for "
+ + "policy OSDF_CASABLANCA.Affinity_vCPE_1:1.0.0 does not exist", error.getErrorMessage());
+ }
+ }
+
+ @Test
+ public void testHttpsSimpleCreatePoliciesPersistent() throws Exception {
+ setupParameters(); // setup DB
+ main = startApiService(false);
+ for (String resrcName : toscaPoliciesResourceNames) {
+ Response rawResponse = createResource(POLICIES, resrcName, false);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getToscaTopologyTemplate().getPolicies().isEmpty());
+ }
+ }
+
+ @Test
public void testHttpsCreateGuardPolicies() {
try {
main = startApiService(false);
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
index e81cbf45..2e431704 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
@@ -75,6 +75,19 @@ public class TestPolicyProvider {
private static final String POLICY_RESOURCE_WITH_BAD_POLICYTYPE_ID = "policies/vCPE.policy.bad.policytypeid.json";
private static final String POLICY_RESOURCE_WITH_BAD_POLICYTYPE_VERSION =
"policies/vCPE.policy.bad.policytypeversion.json";
+ private static final String MULTIPLE_POLICIES_RESOURCE = "policies/vCPE.policies.optimization.input.tosca.json";
+
+ // @formatter:off
+ private String[] toscaPolicyTypeResourceNames = {
+ "policytypes/onap.policies.optimization.AffinityPolicy.yaml",
+ "policytypes/onap.policies.optimization.DistancePolicy.yaml",
+ "policytypes/onap.policies.optimization.HpaPolicy.yaml",
+ "policytypes/onap.policies.optimization.QueryPolicy.yaml",
+ "policytypes/onap.policies.optimization.SubscriberPolicy.yaml",
+ "policytypes/onap.policies.optimization.Vim_fit.yaml",
+ "policytypes/onap.policies.optimization.VnfPolicy.yaml"
+ };
+ // @formatter:on
/**
* Initializes parameters.
@@ -269,6 +282,32 @@ public class TestPolicyProvider {
}
@Test
+ public void testSimpleCreatePolicy() throws Exception {
+
+ String errorMessage = "policy type onap.policies.optimization.AffinityPolicy:0.0.0 for "
+ + "policy OSDF_CASABLANCA.Affinity_vCPE_1:1.0.0 does not exist";
+ assertThatThrownBy(() -> {
+ String multiPoliciesString = ResourceUtils.getResourceAsString(MULTIPLE_POLICIES_RESOURCE);
+ ToscaServiceTemplate multiPoliciesServiceTemplate =
+ standardCoder.decode(multiPoliciesString, ToscaServiceTemplate.class);
+ policyProvider.createPolicies(multiPoliciesServiceTemplate);
+ }).hasMessage(errorMessage);
+
+ // Create required policy types
+ for (String policyTypeName : toscaPolicyTypeResourceNames) {
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(policyTypeName), ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+ }
+
+ // Create multiple policies in one call
+ String multiPoliciesString = ResourceUtils.getResourceAsString(MULTIPLE_POLICIES_RESOURCE);
+ ToscaServiceTemplate multiPoliciesServiceTemplate =
+ standardCoder.decode(multiPoliciesString, ToscaServiceTemplate.class);
+ policyProvider.createPolicies(multiPoliciesServiceTemplate);
+ }
+
+ @Test
public void testDeletePolicy() {
assertThatThrownBy(() -> {