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=0fd4a335822805892e37456eb50cecd88494b0e7;hb=4db5e7d262aaa8ccf18feaa4bd93a6a925801333;hp=0027cca14cf3f3a8b76f8abc7ef7c5a737ca5663;hpb=c6ce83e505a1919db52b054f1d86add74dc8f138;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 0027cca1..0fd4a335 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java @@ -72,7 +72,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.http.HttpStatus; @@ -164,6 +166,12 @@ public class ApplicationTest { Duration checkInterval = Duration.ofMillis(1); return new ServiceSupervision(this.services, this.policies, this.getA1ClientFactory(), checkInterval); } + + @Bean + public ServletWebServerFactory servletContainer() { + return new TomcatServletWebServerFactory(); + } + } @LocalServerPort @@ -266,13 +274,23 @@ public class ApplicationTest { testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND); } - private String putPolicyUrl(String serviceName, String ricName, String policyTypeName, String policyInstanceId) { + private String putPolicyUrl(String serviceName, String ricName, String policyTypeName, String policyInstanceId, + boolean isTransient) { + String url; if (policyTypeName.isEmpty()) { - return "/policy?id=" + policyInstanceId + "&ric=" + ricName + "&service=" + serviceName; + url = "/policy?id=" + policyInstanceId + "&ric=" + ricName + "&service=" + serviceName; } else { - return "/policy?id=" + policyInstanceId + "&ric=" + ricName + "&service=" + serviceName + "&type=" + url = "/policy?id=" + policyInstanceId + "&ric=" + ricName + "&service=" + serviceName + "&type=" + policyTypeName; } + if (isTransient) { + url += "&transient=true"; + } + return url; + } + + private String putPolicyUrl(String serviceName, String ricName, String policyTypeName, String policyInstanceId) { + return putPolicyUrl(serviceName, ricName, policyTypeName, policyInstanceId, false); } @Test @@ -285,7 +303,8 @@ public class ApplicationTest { putService(serviceName); addPolicyType(policyTypeName, ricName); - String url = putPolicyUrl(serviceName, ricName, policyTypeName, policyInstanceId); + // PUT a transient policy + String url = putPolicyUrl(serviceName, ricName, policyTypeName, policyInstanceId, true); final String policyBody = jsonString(); this.rics.getRic(ricName).setState(Ric.RicState.AVAILABLE); @@ -296,11 +315,22 @@ public class ApplicationTest { assertThat(policy.id()).isEqualTo(policyInstanceId); assertThat(policy.ownerServiceName()).isEqualTo(serviceName); assertThat(policy.ric().name()).isEqualTo("ric1"); + assertThat(policy.isTransient()).isEqualTo(true); + + // Put a non transient policy + url = putPolicyUrl(serviceName, ricName, policyTypeName, policyInstanceId); + restClient().put(url, policyBody).block(); + policy = policies.getPolicy(policyInstanceId); + assertThat(policy.isTransient()).isEqualTo(false); url = "/policies"; String rsp = restClient().get(url).block(); assertThat(rsp.contains(policyInstanceId)).isTrue(); + url = "/policy?id=" + policyInstanceId; + rsp = restClient().get(url).block(); + assertThat(rsp).isEqualTo(policyBody); + // Test of error codes url = putPolicyUrl(serviceName, ricName + "XX", policyTypeName, policyInstanceId); testErrorCode(restClient().put(url, policyBody), HttpStatus.NOT_FOUND); @@ -620,12 +650,15 @@ public class ApplicationTest { private Policy addPolicy(String id, String typeName, String service, String ric) throws ServiceException { addRic(ric); - Policy p = ImmutablePolicy.builder().id(id) // + Policy p = ImmutablePolicy.builder() // + .id(id) // .json(jsonString()) // .ownerServiceName(service) // .ric(rics.getRic(ric)) // .type(addPolicyType(typeName, ric)) // - .lastModified("lastModified").build(); + .lastModified("lastModified") // + .isTransient(false) // + .build(); policies.put(p); return p; } @@ -663,7 +696,7 @@ public class ApplicationTest { } private String jsonString() { - return "{\n \"servingCellNrcgi\": \"1\"\n }"; + return "{\"servingCellNrcgi\":\"1\"}"; } @Test @@ -675,7 +708,7 @@ public class ApplicationTest { addPolicyType("type1", "ric"); addPolicyType("type2", "ric"); - for (int i = 0; i < 100; ++i) { + for (int i = 0; i < 10; ++i) { Thread t = new Thread(new ConcurrencyTestRunnable(baseUrl(), supervision, a1ClientFactory, rics, policyTypes), "TestThread_" + i);