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=71bd9a5eed4ba42240d830449492a4ec53b6247c;hb=96805287db06a91e569c184cc34ba4e69e4d22b2;hp=2308fcf1f522b17c93b0f75c4d2fbdba76f4cab4;hpb=a2ad32a98e7a3f32214d3ecd7ca9730e3602d11f;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 2308fcf1..71bd9a5e 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java @@ -22,6 +22,7 @@ package org.oransc.policyagent; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; @@ -86,6 +87,7 @@ import org.springframework.web.reactive.function.client.WebClientResponseExcepti import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import reactor.util.annotation.Nullable; @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @@ -496,10 +498,37 @@ public class ApplicationTest { testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND); } + @Test + public void testGetPolicyIdsFilter() throws Exception { + addPolicy("id1", "type1", "service1", "ric1"); + addPolicy("id2", "type1", "service2", "ric1"); + addPolicy("id3", "type2", "service1", "ric1"); + + String url = "/policy_ids?type=type1"; + String rsp = restClient().get(url).block(); + logger.info(rsp); + assertThat(rsp).contains("id1"); + assertThat(rsp).contains("id2"); + assertThat(rsp.contains("id3")).isFalse(); + + url = "/policy_ids?type=type1&service=service1&ric=ric1"; + rsp = restClient().get(url).block(); + assertThat(rsp).isEqualTo("[\"id1\"]"); + + // Test get policy ids for non existing type + url = "/policy_ids?type=type1XXX"; + testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND); + + // Test get policy ids for non existing RIC + url = "/policy_ids?ric=XXX"; + testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND); + } + @Test public void testPutAndGetService() throws Exception { // PUT - putService("name", 0); + putService("name", 0, HttpStatus.CREATED); + putService("name", 0, HttpStatus.OK); // GET one service String url = "/services?name=name"; @@ -540,7 +569,7 @@ public class ApplicationTest { @Test public void testServiceSupervision() throws Exception { - putService("service1", 1); + putService("service1", 1, HttpStatus.CREATED); addPolicyType("type1", "ric1"); String url = putPolicyUrl("service1", "ric1", "type1", "instance1"); @@ -593,13 +622,16 @@ public class ApplicationTest { } private void putService(String name) { - putService(name, 0); + putService(name, 0, null); } - private void putService(String name, long keepAliveIntervalSeconds) { + private void putService(String name, long keepAliveIntervalSeconds, @Nullable HttpStatus expectedStatus) { String url = "/service"; String body = createServiceJson(name, keepAliveIntervalSeconds); - restClient().put(url, body).block(); + ResponseEntity resp = restClient().putForEntity(url, body).block(); + if (expectedStatus != null) { + assertEquals(expectedStatus, resp.getStatusCode(), ""); + } } private String baseUrl() {