X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fclients%2FSdncOscA1ClientTest.java;h=18ef0979c09dd2a3da2f15d9587a7fb27f5e1c18;hb=67cb2d0bd5b6294cd021f4c8931bcb9d5c2a5dc5;hp=68c61ee6c3721d1a4bba00cdfcc6ad72916b17a2;hpb=96d753b3b44f6b3014d625456dcc21e8282e6c11;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 68c61ee6..18ef0979 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 @@ -36,9 +36,13 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.OngoingStubbing; +import org.oransc.policyagent.clients.A1Client.A1ProtocolType; import org.oransc.policyagent.clients.SdncOscA1Client.AdapterRequest; import org.oransc.policyagent.clients.SdncOscA1Client.AdapterResponse; +import org.oransc.policyagent.configuration.ControllerConfig; +import org.oransc.policyagent.configuration.ImmutableControllerConfig; import org.oransc.policyagent.repository.Policy; +import org.oransc.policyagent.repository.Ric; import org.springframework.web.reactive.function.client.WebClientResponseException; import reactor.core.publisher.Mono; @@ -62,20 +66,54 @@ public class SdncOscA1ClientTest { AsyncRestClient asyncRestClientMock; + private ControllerConfig controllerConfig() { + return ImmutableControllerConfig.builder() // + .name("name") // + .baseUrl("baseUrl") // + .password(CONTROLLER_PASSWORD) // + .userName(CONTROLLER_USERNAME) // + .build(); + } + @BeforeEach public void init() { asyncRestClientMock = mock(AsyncRestClient.class); - clientUnderTest = new SdncOscA1Client(A1ClientHelper.createRic(RIC_1_URL).getConfig(), CONTROLLER_USERNAME, - CONTROLLER_PASSWORD, asyncRestClientMock); + Ric ric = A1ClientHelper.createRic(RIC_1_URL); + + clientUnderTest = new SdncOscA1Client(A1ProtocolType.SDNC_OSC_STD_V1_1, ric.getConfig(), controllerConfig(), + asyncRestClientMock); } @Test - public void testGetPolicyTypeIdentities() { + public void testGetPolicyTypeIdentities_STD() { List policyTypeIds = clientUnderTest.getPolicyTypeIdentities().block(); assertEquals(1, policyTypeIds.size(), "should hardcoded to one"); assertEquals("", policyTypeIds.get(0), "should hardcoded to empty"); } + @Test + public void testGetPolicyTypeIdentities_OSC() { + clientUnderTest = new SdncOscA1Client(A1ProtocolType.SDNC_OSC_OSC_V1, // + A1ClientHelper.createRic(RIC_1_URL).getConfig(), // + controllerConfig(), asyncRestClientMock); + + String response = createResponse(Arrays.asList(POLICY_TYPE_1_ID)); + whenAsyncPostThenReturn(Mono.just(response)); + + List policyTypeIds = clientUnderTest.getPolicyTypeIdentities().block(); + assertEquals(1, policyTypeIds.size(), ""); + assertEquals(POLICY_TYPE_1_ID, policyTypeIds.get(0), ""); + + String expUrl = RIC_1_URL + "/a1-p/policytypes"; + AdapterRequest expectedParams = ImmutableAdapterRequest.builder() // + .nearRtRicUrl(expUrl) // + .build(); + String expInput = SdncJsonHelper.createInputJsonString(expectedParams); + verify(asyncRestClientMock).postWithAuthHeader(GET_A1_POLICY_URL, expInput, CONTROLLER_USERNAME, + CONTROLLER_PASSWORD); + + } + private String policiesUrl() { return RIC_1_URL + "/A1-P/v1/policies"; } @@ -84,16 +122,19 @@ public class SdncOscA1ClientTest { return SdncOscA1Client.gson; } - @Test - public void testGetPolicyIdentities() { - - List policyIds = Arrays.asList(POLICY_1_ID, POLICY_2_ID); + private String createResponse(Object obj) { AdapterResponse output = ImmutableAdapterResponse.builder() // - .body(gson().toJson(policyIds)) // + .body(gson().toJson(obj)) // .httpStatus(200) // .build(); - String policyIdsResp = gson().toJson(output); + return gson().toJson(output); + } + + @Test + public void testGetPolicyIdentities() { + + String policyIdsResp = createResponse(Arrays.asList(POLICY_1_ID, POLICY_2_ID)); whenAsyncPostThenReturn(Mono.just(policyIdsResp)); List returned = clientUnderTest.getPolicyIdentities().block(); @@ -102,7 +143,7 @@ public class SdncOscA1ClientTest { AdapterRequest expectedParams = ImmutableAdapterRequest.builder() // .nearRtRicUrl(policiesUrl()) // .build(); - String expInput = A1ClientHelper.createInputJsonString(expectedParams); + String expInput = SdncJsonHelper.createInputJsonString(expectedParams); verify(asyncRestClientMock).postWithAuthHeader(GET_A1_POLICY_URL, expInput, CONTROLLER_USERNAME, CONTROLLER_PASSWORD); @@ -127,7 +168,7 @@ public class SdncOscA1ClientTest { .nearRtRicUrl(expUrl) // .body(POLICY_JSON_VALID) // .build(); - String expInput = A1ClientHelper.createInputJsonString(expectedInputParams); + String expInput = SdncJsonHelper.createInputJsonString(expectedInputParams); verify(asyncRestClientMock).postWithAuthHeader(PUT_A1_URL, expInput, CONTROLLER_USERNAME, CONTROLLER_PASSWORD); } @@ -151,7 +192,7 @@ public class SdncOscA1ClientTest { .nearRtRicUrl(expUrl) // .body(policyJson) // .build(); - String expRequest = A1ClientHelper.createInputJsonString(expRequestParams); + String expRequest = SdncJsonHelper.createInputJsonString(expRequestParams); verify(asyncRestClientMock).postWithAuthHeader(PUT_A1_URL, expRequest, CONTROLLER_USERNAME, CONTROLLER_PASSWORD); StepVerifier.create(returnedMono) @@ -170,7 +211,7 @@ public class SdncOscA1ClientTest { AdapterRequest expectedInputParams = ImmutableAdapterRequest.builder() // .nearRtRicUrl(expUrl) // .build(); - String expInput = A1ClientHelper.createInputJsonString(expectedInputParams); + String expInput = SdncJsonHelper.createInputJsonString(expectedInputParams); verify(asyncRestClientMock).postWithAuthHeader(DELETE_A1_URL, expInput, CONTROLLER_USERNAME, CONTROLLER_PASSWORD); @@ -184,18 +225,25 @@ public class SdncOscA1ClientTest { String returnedStatus = clientUnderTest.getPolicyStatus(policy).block(); - assertEquals("OK", returnedStatus, "unexpeted status"); + assertEquals("OK", returnedStatus, "unexpected status"); final String expUrl = policiesUrl() + "/" + POLICY_1_ID + "/status"; AdapterRequest expectedInputParams = ImmutableAdapterRequest.builder() // .nearRtRicUrl(expUrl) // .build(); - String expInput = A1ClientHelper.createInputJsonString(expectedInputParams); + String expInput = SdncJsonHelper.createInputJsonString(expectedInputParams); verify(asyncRestClientMock).postWithAuthHeader(GET_A1_POLICY_STATUS_URL, expInput, CONTROLLER_USERNAME, CONTROLLER_PASSWORD); } + @Test + public void testGetVersion() { + whenPostReturnOkResponse(); + A1ProtocolType returnedVersion = clientUnderTest.getProtocolVersion().block(); + assertEquals(A1ProtocolType.SDNC_OSC_STD_V1_1, returnedVersion, ""); + } + private void whenPostReturnOkResponse() { AdapterResponse adapterResponse = ImmutableAdapterResponse.builder() // .body("OK") //