summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java28
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyGuardPolicyProvider.java28
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyOperationalPolicyProvider.java25
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java69
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java71
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java61
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java20
-rw-r--r--main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver1.json15
-rw-r--r--main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver2.json15
-rw-r--r--pom.xml2
10 files changed, 245 insertions, 89 deletions
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java
index f6688817..cb999808 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/LegacyApiRestController.java
@@ -67,16 +67,16 @@ public class LegacyApiRestController {
private static final Logger LOGGER = LoggerFactory.getLogger(LegacyApiRestController.class);
/**
- * Retrieves all versions of a particular guard policy.
+ * Retrieves the latest version of a particular guard policy.
*
* @param policyId the ID of specified guard policy
*
* @return the Response object containing the results of the API operation
*/
@GET
- @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}")
- @ApiOperation(value = "Retrieve all versions of a particular guard policy",
- notes = "Returns a list of all versions of the specified guard policy",
+ @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{policyId}/versions/latest")
+ @ApiOperation(value = "Retrieve the latest version of a particular guard policy",
+ notes = "Returns the latest version of the specified guard policy",
response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
responseHeaders = {
@ResponseHeader(name = "X-MinorVersion",
@@ -109,7 +109,7 @@ public class LegacyApiRestController {
@ApiResponse(code = 404, message = "Resource Not Found"),
@ApiResponse(code = 500, message = "Internal Server Error")
})
- public Response getAllVersionsOfGuardPolicy(
+ public Response getLatestVersionOfGuardPolicy(
@PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
@@ -118,8 +118,8 @@ public class LegacyApiRestController {
return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(policies).build();
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}",
- policyId, pfme);
+ LOGGER.error("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/{}"
+ + "/versions/latest", policyId, pfme);
return addLoggingHeaders(addVersionControlHeaders(
Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
.entity(pfme.getErrorResponse()).build();
@@ -313,16 +313,16 @@ public class LegacyApiRestController {
}
/**
- * Retrieves all versions of a particular operational policy.
+ * Retrieves the latest version of a particular operational policy.
*
* @param policyId the ID of specified operational policy
*
* @return the Response object containing the results of the API operation
*/
@GET
- @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{policyId}")
- @ApiOperation(value = "Retrieve all versions of a particular operational policy",
- notes = "Returns a list of all versions of the specified operational policy",
+ @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{policyId}/versions/latest")
+ @ApiOperation(value = "Retrieve the latest version of a particular operational policy",
+ notes = "Returns the latest version of the specified operational policy",
response = LegacyOperationalPolicy.class,
responseHeaders = {
@ResponseHeader(name = "X-MinorVersion",
@@ -355,7 +355,7 @@ public class LegacyApiRestController {
@ApiResponse(code = 404, message = "Resource Not Found"),
@ApiResponse(code = 500, message = "Internal Server Error")
})
- public Response getAllVersionsOfOperationalPolicy(
+ public Response getLatestVersionOfOperationalPolicy(
@PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
@@ -364,8 +364,8 @@ public class LegacyApiRestController {
return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
.entity(policy).build();
} catch (PfModelException | PfModelRuntimeException pfme) {
- LOGGER.error("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{}",
- policyId, pfme);
+ LOGGER.error("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/{}"
+ + "/versions/latest", policyId, pfme);
return addLoggingHeaders(addVersionControlHeaders(
Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
.entity(pfme.getErrorResponse()).build();
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyGuardPolicyProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyGuardPolicyProvider.java
index 186ce0a3..236d26eb 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyGuardPolicyProvider.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyGuardPolicyProvider.java
@@ -68,7 +68,10 @@ public class LegacyGuardPolicyProvider implements AutoCloseable {
public Map<String, LegacyGuardPolicyOutput> fetchGuardPolicy(String policyId, String policyVersion)
throws PfModelException {
- return modelsProvider.getGuardPolicy(policyId);
+ if (policyVersion != null) {
+ validateLegacyGuardPolicyVersion(policyVersion);
+ }
+ return modelsProvider.getGuardPolicy(policyId, policyVersion);
}
/**
@@ -78,7 +81,8 @@ public class LegacyGuardPolicyProvider implements AutoCloseable {
*
* @return the map of LegacyGuardPolicyOutput objectst
*/
- public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(LegacyGuardPolicyInput body) throws PfModelException {
+ public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(LegacyGuardPolicyInput body)
+ throws PfModelException {
return modelsProvider.createGuardPolicy(body);
}
@@ -95,8 +99,9 @@ public class LegacyGuardPolicyProvider implements AutoCloseable {
throws PfModelException {
validateDeleteEligibility(policyId, policyVersion);
+ validateLegacyGuardPolicyVersion(policyVersion);
- return modelsProvider.deleteGuardPolicy(policyId);
+ return modelsProvider.deleteGuardPolicy(policyId, policyVersion);
}
/**
@@ -122,6 +127,23 @@ public class LegacyGuardPolicyProvider implements AutoCloseable {
}
/**
+ * Validates whether the legacy guard policy version is an integer.
+ *
+ * @param policyVersion the version of policy
+ *
+ * @throws PfModelException the PfModel parsing exception
+ */
+ private void validateLegacyGuardPolicyVersion(String policyVersion) throws PfModelException {
+
+ try {
+ Integer.valueOf(policyVersion);
+ } catch (NumberFormatException exc) {
+ throw new PfModelException(Response.Status.BAD_REQUEST,
+ "legacy policy version is not an integer", exc);
+ }
+ }
+
+ /**
* Constructs returned message for policy delete rule violation.
*
* @param policyId the ID of policy
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyOperationalPolicyProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyOperationalPolicyProvider.java
index ec575098..5b9fdcf8 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyOperationalPolicyProvider.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/provider/LegacyOperationalPolicyProvider.java
@@ -66,7 +66,10 @@ public class LegacyOperationalPolicyProvider implements AutoCloseable {
public LegacyOperationalPolicy fetchOperationalPolicy(String policyId, String policyVersion)
throws PfModelException {
- return modelsProvider.getOperationalPolicy(policyId);
+ if (policyVersion != null) {
+ validateLegacyOperationalPolicyVersion(policyVersion);
+ }
+ return modelsProvider.getOperationalPolicy(policyId, policyVersion);
}
/**
@@ -93,8 +96,9 @@ public class LegacyOperationalPolicyProvider implements AutoCloseable {
throws PfModelException {
validateDeleteEligibility(policyId, policyVersion);
+ validateLegacyOperationalPolicyVersion(policyVersion);
- return modelsProvider.deleteOperationalPolicy(policyId);
+ return modelsProvider.deleteOperationalPolicy(policyId, policyVersion);
}
/**
@@ -120,6 +124,23 @@ public class LegacyOperationalPolicyProvider implements AutoCloseable {
}
/**
+ * Validates whether the legacy operational policy version is an integer.
+ *
+ * @param policyVersion the version of policy
+ *
+ * @throws PfModelException the PfModel parsing exception
+ */
+ private void validateLegacyOperationalPolicyVersion(String policyVersion) throws PfModelException {
+
+ try {
+ Integer.valueOf(policyVersion);
+ } catch (NumberFormatException exc) {
+ throw new PfModelException(Response.Status.BAD_REQUEST,
+ "legacy policy version is not an integer", exc);
+ }
+ }
+
+ /**
* Constructs returned message for policy delete rule violation.
*
* @param policyId the ID of policy
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 6be91739..ec4640e3 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
@@ -107,29 +107,34 @@ public class TestApiRestServer {
private static final String GUARD_POLICIES =
"policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies";
- private static final String GUARD_POLICIES_VDNS_FL =
- "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout";
- private static final String GUARD_POLICIES_VDNS_MINMAX =
- "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.minmax.scaleout";
+ private static final String GUARD_POLICIES_VDNS_FL_LATEST =
+ "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout"
+ + "/versions/latest";
+ private static final String GUARD_POLICIES_VDNS_MINMAX_LATEST =
+ "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.minmax.scaleout"
+ + "/versions/latest";
private static final String GUARD_POLICIES_VDNS_FL_VERSION = "policytypes/"
- + "onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout/versions/1.0.0";
+ + "onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout/versions/1";
private static final String GUARD_POLICIES_VDNS_MINMAX_VERSION = "policytypes/"
- + "onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.minmax.scaleout/versions/1.0.0";
+ + "onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.minmax.scaleout/versions/1";
private static final String OPS_POLICIES =
"policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies";
- private static final String OPS_POLICIES_VCPE =
- "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.restart";
- private static final String OPS_POLICIES_VDNS =
- "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.scaleout";
- private static final String OPS_POLICIES_VFIREWALL =
- "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.modifyconfig";
+ private static final String OPS_POLICIES_VCPE_LATEST =
+ "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.restart"
+ + "/versions/latest";
+ private static final String OPS_POLICIES_VDNS_LATEST =
+ "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.scaleout"
+ + "/versions/latest";
+ private static final String OPS_POLICIES_VFIREWALL_LATEST =
+ "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.modifyconfig"
+ + "/versions/latest";
private static final String OPS_POLICIES_VCPE_VERSION = "policytypes/"
- + "onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.restart/versions/1.0.0";
+ + "onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.restart/versions/1";
private static final String OPS_POLICIES_VDNS_VERSION = "policytypes/"
- + "onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.scaleout/versions/1.0.0";
+ + "onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.scaleout/versions/1";
private static final String OPS_POLICIES_VFIREWALL_VERSION = "policytypes/"
- + "onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.modifyconfig/versions/1.0.0";
+ + "onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.modifyconfig/versions/1";
private static String KEYSTORE = System.getProperty("user.dir") + "/src/test/resources/ssl/policy-keystore";
private Main main;
@@ -469,28 +474,28 @@ public class TestApiRestServer {
assertThatCode(() -> {
main = startApiService(true);
- Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL, true);
+ Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_LATEST, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy ID: guard.frequency.scaleout",
+ assertEquals("no policy found for policy: guard.frequency.scaleout:null",
error.getErrorMessage());
rawResponse = readResource(GUARD_POLICIES_VDNS_FL_VERSION, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy ID: guard.frequency.scaleout",
+ assertEquals("no policy found for policy: guard.frequency.scaleout:1",
error.getErrorMessage());
- rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX, true);
+ rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_LATEST, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy ID: guard.minmax.scaleout",
+ assertEquals("no policy found for policy: guard.minmax.scaleout:null",
error.getErrorMessage());
rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy ID: guard.minmax.scaleout",
+ assertEquals("no policy found for policy: guard.minmax.scaleout:1",
error.getErrorMessage());
}).doesNotThrowAnyException();
}
@@ -500,40 +505,40 @@ public class TestApiRestServer {
assertThatCode(() -> {
main = startApiService(true);
- Response rawResponse = readResource(OPS_POLICIES_VCPE, true);
+ Response rawResponse = readResource(OPS_POLICIES_VCPE_LATEST, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy ID: operational.restart",
+ assertEquals("no policy found for policy: operational.restart:null",
error.getErrorMessage());
rawResponse = readResource(OPS_POLICIES_VCPE_VERSION, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy ID: operational.restart",
+ assertEquals("no policy found for policy: operational.restart:1",
error.getErrorMessage());
- rawResponse = readResource(OPS_POLICIES_VDNS, true);
+ rawResponse = readResource(OPS_POLICIES_VDNS_LATEST, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy ID: operational.scaleout",
+ assertEquals("no policy found for policy: operational.scaleout:null",
error.getErrorMessage());
rawResponse = readResource(OPS_POLICIES_VDNS_VERSION, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy ID: operational.scaleout",
+ assertEquals("no policy found for policy: operational.scaleout:1",
error.getErrorMessage());
- rawResponse = readResource(OPS_POLICIES_VFIREWALL, true);
+ rawResponse = readResource(OPS_POLICIES_VFIREWALL_LATEST, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy ID: operational.modifyconfig",
+ assertEquals("no policy found for policy: operational.modifyconfig:null",
error.getErrorMessage());
rawResponse = readResource(OPS_POLICIES_VFIREWALL_VERSION, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy ID: operational.modifyconfig",
+ assertEquals("no policy found for policy: operational.modifyconfig:1",
error.getErrorMessage());
}).doesNotThrowAnyException();
}
@@ -546,7 +551,7 @@ public class TestApiRestServer {
Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy ID: guard.frequency.scaleout",
+ assertEquals("no policy found for policy: guard.frequency.scaleout:1",
error.getErrorMessage());
}).doesNotThrowAnyException();
}
@@ -559,7 +564,7 @@ public class TestApiRestServer {
Response rawResponse = deleteResource(OPS_POLICIES_VCPE_VERSION, true);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy ID: operational.restart",
+ assertEquals("no policy found for policy: operational.restart:1",
error.getErrorMessage());
}).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 fb7c21c7..93144119 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
@@ -58,6 +58,8 @@ public class TestLegacyGuardPolicyProvider {
private static StandardCoder standardCoder;
private static final String POLICY_RESOURCE = "policies/vDNS.policy.guard.frequency.input.json";
+ private static final String POLICY_RESOURCE_VER1 = "policies/vDNS.policy.guard.frequency.input.ver1.json";
+ private static final String POLICY_RESOURCE_VER2 = "policies/vDNS.policy.guard.frequency.input.ver2.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";
@@ -103,11 +105,56 @@ public class TestLegacyGuardPolicyProvider {
assertThatThrownBy(() -> {
guardPolicyProvider.fetchGuardPolicy("dummy", null);
- }).hasMessage("no policy found for policy ID: dummy");
+ }).hasMessage("no policy found for policy: dummy:null");
assertThatThrownBy(() -> {
guardPolicyProvider.fetchGuardPolicy("dummy", "dummy");
- }).hasMessage("no policy found for policy ID: dummy");
+ }).hasMessage("legacy policy version is not an integer");
+
+ assertThatCode(() -> {
+ String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ ToscaServiceTemplate policyTypeServiceTemplate =
+ standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+
+ String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_VER1);
+ LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
+ Map<String, LegacyGuardPolicyOutput> createdPolicy = guardPolicyProvider.createGuardPolicy(policyToCreate);
+ assertNotNull(createdPolicy);
+ assertFalse(createdPolicy.isEmpty());
+
+ policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_VER2);
+ policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
+ createdPolicy = guardPolicyProvider.createGuardPolicy(policyToCreate);
+ assertNotNull(createdPolicy);
+ assertFalse(createdPolicy.isEmpty());
+
+ Map<String, LegacyGuardPolicyOutput> firstVersion =
+ guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", "1");
+ assertNotNull(firstVersion);
+ assertEquals("1",
+ firstVersion.get("guard.frequency.scaleout").getMetadata().get("policy-version").toString());
+
+ Map<String, LegacyGuardPolicyOutput> latestVersion =
+ guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", null);
+ assertNotNull(latestVersion);
+ assertEquals("2",
+ latestVersion.get("guard.frequency.scaleout").getMetadata().get("policy-version").toString());
+ }).doesNotThrowAnyException();
+
+ assertThatThrownBy(() -> {
+ guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", "1.0.0");
+ }).hasMessage("legacy policy version is not an integer");
+
+ assertThatThrownBy(() -> {
+ guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", "latest");
+ }).hasMessage("legacy policy version is not an integer");
+
+ assertThatCode(() -> {
+ guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1");
+ guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "2");
+ policyTypeProvider.deletePolicyType("onap.policies.controlloop.guard.FrequencyLimiter", "1.0.0");
+ }).doesNotThrowAnyException();
}
@Test
@@ -124,9 +171,7 @@ public class TestLegacyGuardPolicyProvider {
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);
@@ -147,42 +192,38 @@ public class TestLegacyGuardPolicyProvider {
}).hasMessage("version is marked @NonNull but is null");
assertThatThrownBy(() -> {
- guardPolicyProvider.deleteGuardPolicy("dummy", "dummy");
- }).hasMessage("no policy found for policy ID: dummy");
+ guardPolicyProvider.deleteGuardPolicy("dummy", "1.0.0");
+ }).hasMessage("legacy policy version is not an integer");
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);
assertNotNull(createdPolicy);
assertFalse(createdPolicy.isEmpty());
- }).doesNotThrowAnyException();
- assertThatCode(() -> {
Map<String, LegacyGuardPolicyOutput> deletedPolicy = guardPolicyProvider
- .deleteGuardPolicy("guard.frequency.scaleout", "1.0.0");
+ .deleteGuardPolicy("guard.frequency.scaleout", "1");
assertNotNull(deletedPolicy);
assertFalse(deletedPolicy.isEmpty());
assertTrue(deletedPolicy.containsKey("guard.frequency.scaleout"));
assertEquals("onap.policies.controlloop.guard.FrequencyLimiter",
deletedPolicy.get("guard.frequency.scaleout").getType());
- assertEquals("1.0.0", deletedPolicy.get("guard.frequency.scaleout").getVersion());
+ assertEquals("1",
+ deletedPolicy.get("guard.frequency.scaleout").getMetadata().get("policy-version").toString());
}).doesNotThrowAnyException();
assertThatThrownBy(() -> {
- guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1.0.0");
- }).hasMessage("no policy found for policy ID: guard.frequency.scaleout");
+ guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1");
+ }).hasMessage("no policy found for policy: guard.frequency.scaleout:1");
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 b5bcbbd6..5eee1e67 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
@@ -98,11 +98,54 @@ public class TestLegacyOperationalPolicyProvider {
assertThatThrownBy(() -> {
operationalPolicyProvider.fetchOperationalPolicy("dummy", null);
- }).hasMessage("no policy found for policy ID: dummy");
+ }).hasMessage("no policy found for policy: dummy:null");
assertThatThrownBy(() -> {
operationalPolicyProvider.fetchOperationalPolicy("dummy", "dummy");
- }).hasMessage("no policy found for policy ID: dummy");
+ }).hasMessage("legacy policy version is not an integer");
+
+ assertThatCode(() -> {
+ String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+ ToscaServiceTemplate policyTypeServiceTemplate =
+ standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+
+ String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
+ LegacyOperationalPolicy policyToCreate = standardCoder.decode(policyString, LegacyOperationalPolicy.class);
+ LegacyOperationalPolicy createdPolicy = operationalPolicyProvider.createOperationalPolicy(policyToCreate);
+ assertNotNull(createdPolicy);
+
+ policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
+ policyToCreate = standardCoder.decode(policyString, LegacyOperationalPolicy.class);
+ createdPolicy = operationalPolicyProvider.createOperationalPolicy(policyToCreate);
+ assertNotNull(createdPolicy);
+
+ LegacyOperationalPolicy firstVersion =
+ operationalPolicyProvider.fetchOperationalPolicy("operational.restart", "1");
+ assertNotNull(firstVersion);
+ assertEquals("1",
+ firstVersion.getPolicyVersion());
+
+ LegacyOperationalPolicy latestVersion =
+ operationalPolicyProvider.fetchOperationalPolicy("operational.restart", null);
+ assertNotNull(latestVersion);
+ assertEquals("2",
+ latestVersion.getPolicyVersion());
+ }).doesNotThrowAnyException();
+
+ assertThatThrownBy(() -> {
+ operationalPolicyProvider.fetchOperationalPolicy("operational.restart", "1.0.0");
+ }).hasMessage("legacy policy version is not an integer");
+
+ assertThatThrownBy(() -> {
+ operationalPolicyProvider.fetchOperationalPolicy("operational.restart", "latest");;
+ }).hasMessage("legacy policy version is not an integer");
+
+ assertThatCode(() -> {
+ operationalPolicyProvider.deleteOperationalPolicy("operational.restart", "1");
+ operationalPolicyProvider.deleteOperationalPolicy("operational.restart", "2");
+ policyTypeProvider.deletePolicyType("onap.policies.controlloop.Operational", "1.0.0");
+ }).doesNotThrowAnyException();
}
@Test
@@ -119,9 +162,7 @@ public class TestLegacyOperationalPolicyProvider {
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);
@@ -141,25 +182,21 @@ public class TestLegacyOperationalPolicyProvider {
assertThatThrownBy(() -> {
operationalPolicyProvider.deleteOperationalPolicy("dummy", "dummy");
- }).hasMessage("no policy found for policy ID: dummy");
+ }).hasMessage("legacy policy version is not an integer");
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);
assertNotNull(createdPolicy);
- }).doesNotThrowAnyException();
- assertThatCode(() -> {
LegacyOperationalPolicy deletedPolicy = operationalPolicyProvider
- .deleteOperationalPolicy("operational.restart", "1.0.0");
+ .deleteOperationalPolicy("operational.restart", "1");
assertNotNull(deletedPolicy);
assertEquals("operational.restart", deletedPolicy.getPolicyId());
assertTrue(deletedPolicy.getContent()
@@ -167,8 +204,8 @@ public class TestLegacyOperationalPolicyProvider {
}).doesNotThrowAnyException();
assertThatThrownBy(() -> {
- operationalPolicyProvider.deleteOperationalPolicy("operational.restart", "1.0.0");
- }).hasMessage("no policy found for policy ID: operational.restart");
+ operationalPolicyProvider.deleteOperationalPolicy("operational.restart", "1");
+ }).hasMessage("no policy found for policy: operational.restart:1");
assertThatCode(() -> {
policyTypeProvider.deletePolicyType("onap.policies.controlloop.Operational", "1.0.0");
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 8b1be3d5..947221a7 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
@@ -95,16 +95,16 @@ public class TestPolicyProvider {
public void testFetchPolicies() {
assertThatThrownBy(() -> {
- policyProvider.fetchPolicies("dummy", "dummy", null, null);
- }).hasMessage("policy with ID null:null and type dummy:dummy does not exist");
+ policyProvider.fetchPolicies("dummy", "1.0.0", null, null);
+ }).hasMessage("policy with ID null:null and type dummy:1.0.0 does not exist");
assertThatThrownBy(() -> {
- policyProvider.fetchPolicies("dummy", "dummy", "dummy", null);
- }).hasMessage("policy with ID dummy:null and type dummy:dummy does not exist");
+ policyProvider.fetchPolicies("dummy", "1.0.0", "dummy", null);
+ }).hasMessage("policy with ID dummy:null and type dummy:1.0.0 does not exist");
assertThatThrownBy(() -> {
- policyProvider.fetchPolicies("dummy", "dummy", "dummy", "dummy");
- }).hasMessage("policy with ID dummy:dummy and type dummy:dummy does not exist");
+ policyProvider.fetchPolicies("dummy", "1.0.0", "dummy", "1.0.0");
+ }).hasMessage("policy with ID dummy:1.0.0 and type dummy:1.0.0 does not exist");
}
@Test
@@ -127,8 +127,8 @@ public class TestPolicyProvider {
public void testCreatePolicy() {
assertThatThrownBy(() -> {
- policyProvider.createPolicy("dummy", "dummy", new ToscaServiceTemplate());
- }).hasMessage("policy type with ID dummy:dummy does not exist");
+ policyProvider.createPolicy("dummy", "1.0.0", new ToscaServiceTemplate());
+ }).hasMessage("policy type with ID dummy:1.0.0 does not exist");
assertThatCode(() -> {
String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
@@ -167,8 +167,8 @@ public class TestPolicyProvider {
public void testDeletePolicy() {
assertThatThrownBy(() -> {
- policyProvider.deletePolicy("dummy", "dummy", "dummy", "dummy");
- }).hasMessage("policy with ID dummy:dummy and type dummy:dummy does not exist");
+ policyProvider.deletePolicy("dummy", "1.0.0", "dummy", "1.0.0");
+ }).hasMessage("policy with ID dummy:1.0.0 and type dummy:1.0.0 does not exist");
assertThatCode(() -> {
String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
diff --git a/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver1.json b/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver1.json
new file mode 100644
index 00000000..6dc54cb8
--- /dev/null
+++ b/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver1.json
@@ -0,0 +1,15 @@
+{
+ "policy-id" : "guard.frequency.scaleout",
+ "policy-version" : "1",
+ "content" : {
+ "actor": "SO",
+ "recipe": "scaleOut",
+ "targets": ".*",
+ "clname": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
+ "limit": "1",
+ "timeWindow": "10",
+ "timeUnits": "minute",
+ "guardActiveStart": "00:00:01-05:00",
+ "guardActiveEnd": "23:59:59-05:00"
+ }
+}
diff --git a/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver2.json b/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver2.json
new file mode 100644
index 00000000..a8c325fb
--- /dev/null
+++ b/main/src/test/resources/policies/vDNS.policy.guard.frequency.input.ver2.json
@@ -0,0 +1,15 @@
+{
+ "policy-id" : "guard.frequency.scaleout",
+ "policy-version" : "2",
+ "content" : {
+ "actor": "SO",
+ "recipe": "scaleOut",
+ "targets": ".*",
+ "clname": "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3",
+ "limit": "1",
+ "timeWindow": "10",
+ "timeUnits": "minute",
+ "guardActiveStart": "00:00:01-05:00",
+ "guardActiveEnd": "23:59:59-05:00"
+ }
+}
diff --git a/pom.xml b/pom.xml
index e167eba0..cf6c1125 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,7 +47,7 @@
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<policy.common.version>1.4.0</policy.common.version>
- <policy.models.version>2.0.0</policy.models.version>
+ <policy.models.version>2.0.1-SNAPSHOT</policy.models.version>
</properties>
<modules>