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%2Fclients%2FSdncOscA1ClientTest.java;h=2cdfe352085761d81305e21931711a659b6d98fb;hb=73a8d2b71f8b683865d96ad78576d0f7ab654ba6;hp=2b60fe0542e011ff5dfc4629088a6a935519c073;hpb=0316038265be758ae8b1bce006b5fd017185c55d;p=nonrtric.git diff --git a/policy-agent/src/test/java/org/oransc/policyagent/clients/SdncOscA1ClientTest.java b/policy-agent/src/test/java/org/oransc/policyagent/clients/SdncOscA1ClientTest.java index 2b60fe05..2cdfe352 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/clients/SdncOscA1ClientTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/clients/SdncOscA1ClientTest.java @@ -27,7 +27,12 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.google.gson.Gson; +import com.google.gson.JsonElement; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -39,6 +44,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.OngoingStubbing; import org.oransc.policyagent.clients.A1Client.A1ProtocolType; import org.oransc.policyagent.clients.SdncOscA1Client.AdapterOutput; +import org.oransc.policyagent.clients.SdncOscA1Client.AdapterRequest; import org.oransc.policyagent.configuration.ControllerConfig; import org.oransc.policyagent.configuration.ImmutableControllerConfig; import org.oransc.policyagent.repository.Policy; @@ -111,7 +117,30 @@ public class SdncOscA1ClientTest { String expInput = SdncJsonHelper.createInputJsonString(expectedParams); verify(asyncRestClientMock).postWithAuthHeader(GET_A1_POLICY_URL, expInput, CONTROLLER_USERNAME, CONTROLLER_PASSWORD); + } + + private String loadFile(String fileName) throws IOException { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + URL url = loader.getResource(fileName); + File file = new File(url.getFile()); + return new String(Files.readAllBytes(file.toPath())); + } + + @Test + public void testGetTypeSchema_OSC() throws IOException { + clientUnderTest = new SdncOscA1Client(A1ProtocolType.SDNC_OSC_OSC_V1, // + A1ClientHelper.createRic(RIC_1_URL).getConfig(), // + controllerConfig(), asyncRestClientMock); + + String ricResponse = loadFile("test_osc_get_schema_response.json"); + JsonElement elem = gson().fromJson(ricResponse, JsonElement.class); + String responseFromController = createResponse(elem); + whenAsyncPostThenReturn(Mono.just(responseFromController)); + String response = clientUnderTest.getPolicyTypeSchema("policyTypeId").block(); + JsonElement respJson = gson().fromJson(response, JsonElement.class); + assertEquals("policyTypeId", respJson.getAsJsonObject().get("title").getAsString(), + "title should be updated to contain policyType ID"); } private String policiesUrl() { @@ -163,7 +192,7 @@ public class SdncOscA1ClientTest { .block(); assertEquals("OK", returned, ""); final String expUrl = policiesUrl() + "/" + POLICY_1_ID; - ImmutableAdapterRequest expectedInputParams = ImmutableAdapterRequest.builder() // + AdapterRequest expectedInputParams = ImmutableAdapterRequest.builder() // .nearRtRicUrl(expUrl) // .body(POLICY_JSON_VALID) // .build(); @@ -185,9 +214,13 @@ public class SdncOscA1ClientTest { Mono returnedMono = clientUnderTest .putPolicy(A1ClientHelper.createPolicy(RIC_1_URL, POLICY_1_ID, policyJson, POLICY_TYPE_1_ID)); + StepVerifier.create(returnedMono) // + .expectSubscription() // + .expectErrorMatches(t -> t instanceof WebClientResponseException) // + .verify(); final String expUrl = policiesUrl() + "/" + POLICY_1_ID; - ImmutableAdapterRequest expRequestParams = ImmutableAdapterRequest.builder() // + AdapterRequest expRequestParams = ImmutableAdapterRequest.builder() // .nearRtRicUrl(expUrl) // .body(policyJson) // .build(); @@ -207,7 +240,7 @@ public class SdncOscA1ClientTest { .block(); assertEquals("OK", returned, ""); final String expUrl = policiesUrl() + "/" + POLICY_1_ID; - ImmutableAdapterRequest expectedInputParams = ImmutableAdapterRequest.builder() // + AdapterRequest expectedInputParams = ImmutableAdapterRequest.builder() // .nearRtRicUrl(expUrl) // .build(); String expInput = SdncJsonHelper.createInputJsonString(expectedInputParams); @@ -227,7 +260,7 @@ public class SdncOscA1ClientTest { assertEquals("OK", returnedStatus, "unexpected status"); final String expUrl = policiesUrl() + "/" + POLICY_1_ID + "/status"; - ImmutableAdapterRequest expectedInputParams = ImmutableAdapterRequest.builder() // + AdapterRequest expectedInputParams = ImmutableAdapterRequest.builder() // .nearRtRicUrl(expUrl) // .build(); String expInput = SdncJsonHelper.createInputJsonString(expectedInputParams);