summaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org
diff options
context:
space:
mode:
authorChenfei Gao <cgao@research.att.com>2019-05-07 14:46:22 -0400
committerChenfei Gao <cgao@research.att.com>2019-05-07 20:02:07 -0400
commit90555d0346c7e852e6a4dc9622ed29343353b95c (patch)
tree842bc1f51389d04481849d1e7ed5ff2d03c4f82f /main/src/test/java/org
parenta962474f4c1498a335bfd1afaa7d15859ae04be2 (diff)
Preload legacy operational policy type and guard policy types
Includes: a) Add legacy operational policy type and guard policy types into preloading list. b) Fix corresponding junit test failure. Issue-ID: POLICY-1738 Change-Id: I071e898be31e62f47d427094f1e76069fafd0148 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.java10
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java33
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java31
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java2
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java2
5 files changed, 71 insertions, 7 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 0d820548..6be91739 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
@@ -144,7 +144,7 @@ public class TestApiRestServer {
};
private String[] toscaPolicyTypeResourceNames = {
- "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.json",
+ "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.json",
"policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.json"
};
@@ -447,7 +447,7 @@ public class TestApiRestServer {
main = startApiService(true);
for (String resrcName : legacyGuardPolicyResourceNames) {
Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
}
}).doesNotThrowAnyException();
}
@@ -459,7 +459,7 @@ public class TestApiRestServer {
main = startApiService(true);
for (String resrcName : legacyOperationalPolicyResourceNames) {
Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
}
}).doesNotThrowAnyException();
}
@@ -601,7 +601,7 @@ public class TestApiRestServer {
main = startApiService(false);
for (String resrcName : legacyGuardPolicyResourceNames) {
Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, false);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
}
}).doesNotThrowAnyException();
}
@@ -613,7 +613,7 @@ public class TestApiRestServer {
main = startApiService(false);
for (String resrcName : legacyOperationalPolicyResourceNames) {
Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, false);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
}
}).doesNotThrowAnyException();
}
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java
index 76641aae..fb7c21c7 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java
@@ -40,6 +40,7 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
@@ -51,11 +52,16 @@ import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
public class TestLegacyGuardPolicyProvider {
private static LegacyGuardPolicyProvider guardPolicyProvider;
+ private static PolicyTypeProvider policyTypeProvider;
private static PolicyModelsProviderParameters providerParams;
private static ApiParameterGroup apiParamGroup;
private static StandardCoder standardCoder;
private static final String POLICY_RESOURCE = "policies/vDNS.policy.guard.frequency.input.json";
+ private static final String POLICY_TYPE_RESOURCE =
+ "policytypes/onap.policies.controlloop.guard.FrequencyLimiter.json";
+ private static final String POLICY_TYPE_ID = "onap.policies.controlloop.guard.FrequencyLimiter:1.0.0";
+ private static final String POLICY_ID = "guard.frequency.scaleout:1.0.0";
/**
* Initializes parameters.
@@ -75,6 +81,7 @@ public class TestLegacyGuardPolicyProvider {
apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams);
ParameterService.register(apiParamGroup, true);
guardPolicyProvider = new LegacyGuardPolicyProvider();
+ policyTypeProvider = new PolicyTypeProvider();
}
/**
@@ -86,6 +93,7 @@ public class TestLegacyGuardPolicyProvider {
public static void tearDown() throws PfModelException {
guardPolicyProvider.close();
+ policyTypeProvider.close();
ParameterService.deregister(apiParamGroup);
}
@@ -105,6 +113,19 @@ public class TestLegacyGuardPolicyProvider {
@Test
public void testCreateGuardPolicy() {
+ assertThatThrownBy(() -> {
+ String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
+ LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
+ guardPolicyProvider.createGuardPolicy(policyToCreate);
+ }).hasMessage("policy type " + POLICY_TYPE_ID + " for policy " + POLICY_ID + " does not exist");
+
+ assertThatCode(() -> {
+ String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ ToscaServiceTemplate policyTypeServiceTemplate =
+ standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+ }).doesNotThrowAnyException();
+
assertThatCode(() -> {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
@@ -130,6 +151,13 @@ public class TestLegacyGuardPolicyProvider {
}).hasMessage("no policy found for policy ID: dummy");
assertThatCode(() -> {
+ String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ ToscaServiceTemplate policyTypeServiceTemplate =
+ standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
Map<String, LegacyGuardPolicyOutput> createdPolicy = guardPolicyProvider.createGuardPolicy(policyToCreate);
@@ -151,5 +179,10 @@ public class TestLegacyGuardPolicyProvider {
assertThatThrownBy(() -> {
guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1.0.0");
}).hasMessage("no policy found for policy ID: guard.frequency.scaleout");
+
+ assertThatCode(() -> {
+ policyTypeProvider.deletePolicyType("onap.policies.controlloop.guard.FrequencyLimiter", "1.0.0");
+ }).doesNotThrowAnyException();
+
}
}
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java
index 8aa19793..b5bcbbd6 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java
@@ -38,6 +38,7 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
/**
@@ -48,11 +49,15 @@ import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
public class TestLegacyOperationalPolicyProvider {
private static LegacyOperationalPolicyProvider operationalPolicyProvider;
+ private static PolicyTypeProvider policyTypeProvider;
private static PolicyModelsProviderParameters providerParams;
private static ApiParameterGroup apiParamGroup;
private static StandardCoder standardCoder;
private static final String POLICY_RESOURCE = "policies/vCPE.policy.operational.input.json";
+ private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.controlloop.Operational.json";
+ private static final String POLICY_TYPE_ID = "onap.policies.controlloop.Operational:1.0.0";
+ private static final String POLICY_ID = "operational.restart:1.0.0";
/**
* Initializes parameters.
@@ -72,6 +77,7 @@ public class TestLegacyOperationalPolicyProvider {
apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams);
ParameterService.register(apiParamGroup, true);
operationalPolicyProvider = new LegacyOperationalPolicyProvider();
+ policyTypeProvider = new PolicyTypeProvider();
}
/**
@@ -83,6 +89,7 @@ public class TestLegacyOperationalPolicyProvider {
public static void tearDown() throws PfModelException {
operationalPolicyProvider.close();
+ policyTypeProvider.close();
ParameterService.deregister(apiParamGroup);
}
@@ -101,6 +108,19 @@ public class TestLegacyOperationalPolicyProvider {
@Test
public void testCreateOperationalPolicy() {
+ assertThatThrownBy(() -> {
+ String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
+ LegacyOperationalPolicy policyToCreate = standardCoder.decode(policyString, LegacyOperationalPolicy.class);
+ operationalPolicyProvider.createOperationalPolicy(policyToCreate);
+ }).hasMessage("policy type " + POLICY_TYPE_ID + " for policy " + POLICY_ID + " does not exist");
+
+ assertThatCode(() -> {
+ String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ ToscaServiceTemplate policyTypeServiceTemplate =
+ standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+ }).doesNotThrowAnyException();
+
assertThatCode(() -> {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
LegacyOperationalPolicy policyToCreate = standardCoder.decode(policyString, LegacyOperationalPolicy.class);
@@ -124,6 +144,13 @@ public class TestLegacyOperationalPolicyProvider {
}).hasMessage("no policy found for policy ID: dummy");
assertThatCode(() -> {
+ String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ ToscaServiceTemplate policyTypeServiceTemplate =
+ standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
LegacyOperationalPolicy policyToCreate = standardCoder.decode(policyString, LegacyOperationalPolicy.class);
LegacyOperationalPolicy createdPolicy = operationalPolicyProvider.createOperationalPolicy(policyToCreate);
@@ -142,5 +169,9 @@ public class TestLegacyOperationalPolicyProvider {
assertThatThrownBy(() -> {
operationalPolicyProvider.deleteOperationalPolicy("operational.restart", "1.0.0");
}).hasMessage("no policy found for policy ID: operational.restart");
+
+ assertThatCode(() -> {
+ policyTypeProvider.deletePolicyType("onap.policies.controlloop.Operational", "1.0.0");
+ }).doesNotThrowAnyException();
}
}
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 0ae718d1..8b1be3d5 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
@@ -52,7 +52,7 @@ public class TestPolicyProvider {
private static StandardCoder standardCoder;
private static final String POLICY_RESOURCE = "policies/vCPE.policy.monitoring.input.tosca.json";
- private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.json";
+ private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.json";
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";
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java
index 03d49332..7865453f 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java
@@ -52,7 +52,7 @@ public class TestPolicyTypeProvider {
private static StandardCoder standardCoder;
private static final String POLICY_RESOURCE = "policies/vCPE.policy.monitoring.input.tosca.json";
- private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.json";
+ private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.json";
/**
* Initializes parameters.