From b3828de54af94f66e3a6e22bcaeb3372d14eab34 Mon Sep 17 00:00:00 2001 From: Michael Mokry Date: Tue, 14 Nov 2017 15:01:13 -0600 Subject: Refactor to provide Common Policy Validation Provides a common class to perform policy validation during create/udpate of policies by the GUI and API for consistency. Change-Id: Ied459e73d48517bb50064cd10d6a1c871b8311e5 Issue-ID: POLICY-449 Signed-off-by: Michael Mokry --- .../rest/api/test/PolicyEngineServicesTest.java | 42 +++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'ONAP-PDP-REST/src/test/java/org') diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java index ac8b269eb..8fea627c9 100644 --- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java +++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java @@ -453,9 +453,9 @@ public class PolicyEngineServicesTest { pep.setAttributes(attributes); pep.setRiskLevel("5"); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); // Checks for BRMS Raw Policy pep.setPolicyConfigType(PolicyConfigType.BRMS_RAW); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) @@ -469,9 +469,9 @@ public class PolicyEngineServicesTest { .headers(headers)).andExpect(status().isBadRequest()); pep.setRiskLevel("5"); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); } @Test @@ -505,11 +505,11 @@ public class PolicyEngineServicesTest { .headers(headers)).andExpect(status().isBadRequest()); pep.setConfigName("configName"); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); pep.setConfigBody("{'test':'test}"); pep.setConfigBodyType(PolicyType.JSON); mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); Map> attributes = new HashMap<>(); Map matching = new HashMap<>(); matching.put("key", "value"); @@ -517,7 +517,7 @@ public class PolicyEngineServicesTest { pep.setAttributes(attributes); pep.setConfigBody("testBody"); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); } @Test @@ -546,15 +546,15 @@ public class PolicyEngineServicesTest { .headers(headers)).andExpect(status().isBadRequest()); pep.setConfigBody("{\"onapname\":\"test\"}"); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); pep.setRiskLevel("test"); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) .headers(headers)).andExpect(status().isBadRequest()); pep.setRiskLevel("4"); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); } @Test @@ -588,15 +588,15 @@ public class PolicyEngineServicesTest { .headers(headers)).andExpect(status().isBadRequest()); pep.setConfigBody("{\"onapname\":\"test\", \"serviceTypePolicyName\":\"value\"}"); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); pep.setRiskLevel("test"); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) .headers(headers)).andExpect(status().isBadRequest()); pep.setRiskLevel("4"); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); } @Test @@ -626,9 +626,9 @@ public class PolicyEngineServicesTest { .headers(headers)).andExpect(status().isBadRequest()); pep.setConfigBody("{\"configName\":\"test\"}"); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); } @Test @@ -659,10 +659,10 @@ public class PolicyEngineServicesTest { .headers(headers)).andExpect(status().isBadRequest()); pep.setRiskLevel("4"); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); pep.setConfigBody("{\"service\":\"test\",\"uuid\":\"test\",\"location\":\"test\",\"configName\":\"test\",\"description\":\"test\",\"priority\":\"test\",\"version\":\"test\"}"); mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); } @Test @@ -708,18 +708,18 @@ public class PolicyEngineServicesTest { .headers(headers)).andExpect(status().isBadRequest()); pep.setOnapName("xyz"); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); attributes.remove(AttributeType.MATCHING); attributes.put(AttributeType.SETTINGS, matching); pep.setAttributes(attributes); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); attributes.put(AttributeType.MATCHING, matching); pep.setAttributes(attributes); mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON) - .headers(headers)).andExpect(status().isInternalServerError()); + .headers(headers)).andExpect(status().isBadRequest()); } @Test -- cgit 1.2.3-korg