aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-02-19 16:56:59 +0000
committerliamfallon <liam.fallon@est.tech>2020-02-19 17:02:28 +0000
commita8765f7d8a9be082c281d46592307f5056f32fcd (patch)
treef3e8db0535d40aec786ae50dccdb363b8f644168 /main/src/test/java/org
parent19286bf7b66750aba7192af363349db2a4d5323d (diff)
Changes for cascaded get in policy models
This review adapts policy API for changes introduced for cascaded returns on filtered gets in policy-models. Issue-ID: POLICY-1402 Change-Id: I7593eb64cc497809f8485f6add40b6a64291a060 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'main/src/test/java/org')
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java58
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java6
2 files changed, 56 insertions, 8 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 d531a0ad..4af601a2 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
@@ -317,9 +317,9 @@ public class TestApiRestServer {
String firstPolicyType = response.getPolicyTypes().keySet().iterator().next();
response.getPolicyTypes().put(firstPolicyType, null);
Response rawResponse2 = createResource(POLICYTYPES, standardCoder.encode(response));
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse2.getStatus());
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse2.getStatus());
ErrorResponse errorResponse = rawResponse2.readEntity(ErrorResponse.class);
- assertEquals("no policy types specified in the service template", errorResponse.getErrorMessage());
+ assertEquals("no policy types specified on service template", errorResponse.getErrorMessage());
}
@Test
@@ -504,7 +504,14 @@ public class TestApiRestServer {
}
private void testReadPolicyTypes(String mediaType) throws Exception {
- Response rawResponse = readResource(POLICYTYPES, mediaType);
+ Response rawResponse = readResource("policytypes/onap.policies.optimization.resource.HpaPolicy", mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(namingServiceTemplate);
+ assertEquals(3, namingServiceTemplate.getPolicyTypesAsMap().size());
+ assertEquals(5, namingServiceTemplate.getDataTypesAsMap().size());
+
+ rawResponse = readResource(POLICYTYPES, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
assertFalse(response.getPolicyTypes().isEmpty());
@@ -603,6 +610,47 @@ public class TestApiRestServer {
}
@Test
+ public void testNamingPolicyGet() throws Exception {
+ Response rawResponse = createResource("policies", "policies/sdnc.policy.naming.input.tosca.yaml");
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = readResource("policytypes/"
+ + "onap.policies.Naming/versions/1.0.0/policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/1.0.0",
+ APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ ToscaServiceTemplate namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertEquals(1, namingServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
+ assertEquals(1, namingServiceTemplate.getPolicyTypesAsMap().size());
+ assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size());
+
+ rawResponse = readResource("policytypes/"
+ + "onap.policies.Naming/versions/1.0.0/policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/latest",
+ APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertEquals(1, namingServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
+ assertEquals(1, namingServiceTemplate.getPolicyTypesAsMap().size());
+ assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size());
+
+ rawResponse = readResource(
+ "policytypes/" + "onap.policies.Naming/versions/1.0.0/policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP",
+ APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertEquals(1, namingServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
+ assertEquals(1, namingServiceTemplate.getPolicyTypesAsMap().size());
+ assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size());
+
+ rawResponse = deleteResource("policytypes/"
+ + "onap.policies.Naming/versions/1.0.0/policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/1.0.0",
+ APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+
+ @Test
public void testDeletePoliciesJson() throws Exception {
testDeletePolicies(APP_JSON);
}
@@ -648,8 +696,8 @@ public class TestApiRestServer {
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
assertEquals(
- "policy with ID onap.restart.tca:1.0.0 and type "
- + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
+ "policies for filter ToscaPolicyFilter(name=onap.restart.tca, version=1.0.0, versionPrefix=null, "
+ + "type=onap.policies.monitoring.cdap.tca.hi.lo.app, typeVersion=1.0.0) do not exist",
errorResponse.getErrorMessage());
rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION2, mediaType);
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 82d25245..58576abc 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
@@ -118,11 +118,11 @@ public class TestPolicyTypeProvider {
assertThatThrownBy(() -> {
policyTypeProvider.fetchPolicyTypes("dummy", null);
- }).hasMessage("policy type with ID dummy:null does not exist");
+ }).hasMessage("policy types for filter ToscaPolicyTypeFilter(name=dummy, version=null) do not exist");
assertThatThrownBy(() -> {
policyTypeProvider.fetchPolicyTypes("dummy", "dummy");
- }).hasMessage("policy type with ID dummy:dummy does not exist");
+ }).hasMessage("policy types for filter ToscaPolicyTypeFilter(name=dummy, version=dummy) do not exist");
}
@Test
@@ -130,7 +130,7 @@ public class TestPolicyTypeProvider {
assertThatThrownBy(() -> {
policyTypeProvider.fetchLatestPolicyTypes("dummy");
- }).hasMessage("policy type with ID dummy:null does not exist");
+ }).hasMessage("policy types for filter ToscaPolicyTypeFilter(name=dummy, version=LATEST) do not exist");
}
@Test