X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=policy-agent%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fpolicyagent%2FApplicationTest.java;h=fc4030f50b3d150e91703c8ed0497b766dcd8ef8;hb=8936c783ff4f362fbc9b96b658b5defb0701da54;hp=847cde1942b4d6019f1a61415369ab16ff42ee90;hpb=1a9139f93043e662fc7b132af2c7af2bd054d637;p=nonrtric.git diff --git a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java index 847cde19..fc4030f5 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java @@ -195,6 +195,7 @@ public class ApplicationTest { Policy policy = addPolicy("policyId", "typeName", "service", "ric"); // This should be created in the RIC supervision.checkAllRics(); // The created policy should be put in the RIC + await().untilAsserted(() -> RicState.RECOVERING.equals(rics.getRic("ric").getState())); await().untilAsserted(() -> RicState.IDLE.equals(rics.getRic("ric").getState())); Policies ricPolicies = getA1Client("ric").getPolicies(); @@ -223,22 +224,38 @@ public class ApplicationTest { public void testPutPolicy() throws Exception { reset(); putService("service1"); + this.addRic("ric1").setState(Ric.RicState.IDLE); addPolicyType("type1", "ric1"); - String url = baseUrl() + "/policy?type=type1&instance=instance1&ric=ric1&service=service1"; final String json = jsonString(); - this.rics.getRic("ric1").setState(Ric.RicState.IDLE); - + String url = baseUrl() + "/policy?type=type1&instance=instance1&ric=ric1&service=service1"; this.restTemplate.put(url, createJsonHttpEntity(json)); Policy policy = policies.getPolicy("instance1"); assertThat(policy).isNotNull(); assertThat(policy.id()).isEqualTo("instance1"); assertThat(policy.ownerServiceName()).isEqualTo("service1"); + assertThat(policy.ric().name()).isEqualTo("ric1"); url = baseUrl() + "/policies"; String rsp = this.restTemplate.getForObject(url, String.class); System.out.println(rsp); + + } + + @Test + public void testRefuseToUpdatePolicy() throws Exception { + // Test that only the json can be changed for a already created policy + // In this case service is attempted to be changed + reset(); + this.addRic("ric1").setState(Ric.RicState.IDLE); + this.addRic("ricXXX").setState(Ric.RicState.IDLE); + + this.addPolicy("instance1", "type1", "service1", "ric1"); + String urlWrongRic = baseUrl() + "/policy?type=type1&instance=instance1&ric=ricXXX&service=service1"; + this.restTemplate.put(urlWrongRic, createJsonHttpEntity(jsonString())); + Policy policy = policies.getPolicy("instance1"); + assertThat(policy.ric().name()).isEqualTo("ric1"); // Not changed } private PolicyType addPolicyType(String policyTypeName, String ricName) { @@ -348,8 +365,7 @@ public class ApplicationTest { String rsp = this.restTemplate.getForObject(url, String.class); System.out.println("*** " + rsp); assertThat(rsp).contains("type1"); - assertThat(rsp).contains("type2"); - assertThat(rsp).contains("title"); + assertThat(rsp).contains("[{\"title\":\"type2\"}"); List info = parseSchemas(rsp); assertEquals(2, info.size()); @@ -439,7 +455,7 @@ public class ApplicationTest { assertThat(info.size() == 1); ServiceStatus status = info.iterator().next(); assertThat(status.keepAliveIntervalSeconds == 1); - assertThat(status.name.equals("name")); + assertThat(status.serviceName.equals("name")); // GET (all) url = baseUrl() + "/services"; @@ -464,6 +480,18 @@ public class ApplicationTest { assertThat(entity.getStatusCode().equals(HttpStatus.NOT_FOUND)); } + @Test + public void testGetPolicyStatus() throws Exception { + reset(); + Policy policy = addPolicy("id", "typeName", "service1", "ric1"); + policy.ric().setState(Ric.RicState.IDLE); + assertThat(policies.size()).isEqualTo(1); + + String url = baseUrl() + "/policy_status?instance=id"; + String rsp = this.restTemplate.getForObject(url, String.class); + assertThat(rsp.equals("OK")); + } + private static List parseList(String jsonString, Class clazz) { List result = new ArrayList<>(); JsonArray jsonArr = JsonParser.parseString(jsonString).getAsJsonArray();