summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/test/java
diff options
context:
space:
mode:
authorecaiyanlinux <martin.c.yan@est.tech>2020-10-27 20:40:57 +0100
committerecaiyanlinux <martin.c.yan@est.tech>2020-10-28 12:32:16 +0100
commit988f2af648a069ae86a4d9fc9499b80716ca8443 (patch)
treedc956a54fc74969362b3b76e8c411a55b91d932d /a1-policy-management/src/test/java
parentc655306c67fd9ed6b95d6b111f7bedab79c02f44 (diff)
Remove code for sdnc onap controller
sdnc onap controller is dismissed rename SdncOscA1Client to CcsdkA1AdapterClient rename SdncJsonHelper to A1AdapterJsonHelper update comments accordingly Signed-off-by: ecaiyanlinux <martin.c.yan@est.tech> Issue-ID: CCSDK-2502 Change-Id: If525dab599f9fd28203e85dcd57c010c67e20a8b
Diffstat (limited to 'a1-policy-management/src/test/java')
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java5
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java (renamed from a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOscA1ClientTest.java)80
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOnapA1ClientTest.java271
3 files changed, 42 insertions, 314 deletions
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java
index 89adf68a..3ca35430 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java
@@ -135,13 +135,12 @@ class A1ClientFactoryTest {
void create_check_types_controllers() throws ServiceException {
this.ric = new Ric(ricConfig("anythingButEmpty"));
whenGetGetControllerConfigReturn();
- assertTrue(createClient(A1ProtocolType.SDNC_ONAP) instanceof SdncOnapA1Client);
whenGetGetControllerConfigReturn();
- assertTrue(createClient(A1ProtocolType.SDNC_OSC_STD_V1_1) instanceof SdncOscA1Client);
+ assertTrue(createClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1) instanceof CcsdkA1AdapterClient);
whenGetGetControllerConfigReturn();
- assertTrue(createClient(A1ProtocolType.SDNC_OSC_OSC_V1) instanceof SdncOscA1Client);
+ assertTrue(createClient(A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1) instanceof CcsdkA1AdapterClient);
}
private void whenGetProtocolVersionThrowException(A1Client... clientMocks) {
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOscA1ClientTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java
index 4eca44d4..87615f68 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOscA1ClientTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java
@@ -44,8 +44,8 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.stubbing.OngoingStubbing;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client.A1ProtocolType;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.ImmutableAdapterOutput.Builder;
-import org.onap.ccsdk.oran.a1policymanagementservice.clients.SdncOscA1Client.AdapterOutput;
-import org.onap.ccsdk.oran.a1policymanagementservice.clients.SdncOscA1Client.AdapterRequest;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.CcsdkA1AdapterClient.AdapterOutput;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.CcsdkA1AdapterClient.AdapterRequest;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ControllerConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableControllerConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
@@ -56,7 +56,7 @@ import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@ExtendWith(MockitoExtension.class)
-class SdncOscA1ClientTest {
+class CcsdkA1AdapterClientTest {
private static final String CONTROLLER_USERNAME = "username";
private static final String CONTROLLER_PASSWORD = "password";
private static final String RIC_1_URL = "RicUrl";
@@ -68,7 +68,7 @@ class SdncOscA1ClientTest {
private static final String POLICY_1_ID = "policy1";
private static final String POLICY_JSON_VALID = "{\"scope\":{\"ueId\":\"ue1\"}}";
- SdncOscA1Client clientUnderTest;
+ CcsdkA1AdapterClient clientUnderTest;
@Mock
AsyncRestClient asyncRestClientMock;
@@ -85,13 +85,13 @@ class SdncOscA1ClientTest {
@Test
void createClientWithWrongProtocol_thenErrorIsThrown() {
assertThrows(IllegalArgumentException.class, () -> {
- new SdncOscA1Client(A1ProtocolType.STD_V1_1, null, null, new AsyncRestClient("", null));
+ new CcsdkA1AdapterClient(A1ProtocolType.STD_V1_1, null, null, new AsyncRestClient("", null));
});
}
@Test
void getPolicyTypeIdentities_STD_V1() {
- clientUnderTest = new SdncOscA1Client(A1ProtocolType.SDNC_OSC_STD_V1_1, //
+ clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1, //
A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
controllerConfig(), asyncRestClientMock);
List<String> policyTypeIds = clientUnderTest.getPolicyTypeIdentities().block();
@@ -100,7 +100,7 @@ class SdncOscA1ClientTest {
}
private void testGetPolicyTypeIdentities(A1ProtocolType protocolType, String expUrl) {
- clientUnderTest = new SdncOscA1Client(protocolType, //
+ clientUnderTest = new CcsdkA1AdapterClient(protocolType, //
A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
controllerConfig(), asyncRestClientMock);
@@ -115,25 +115,25 @@ class SdncOscA1ClientTest {
ImmutableAdapterRequest expectedParams = ImmutableAdapterRequest.builder() //
.nearRtRicUrl(expUrl) //
.build();
- String expInput = SdncJsonHelper.createInputJsonString(expectedParams);
+ String expInput = A1AdapterJsonHelper.createInputJsonString(expectedParams);
verify(asyncRestClientMock).postWithAuthHeader(GET_A1_POLICY_URL, expInput, CONTROLLER_USERNAME,
CONTROLLER_PASSWORD);
}
@Test
void getPolicyTypeIdentities_OSC() {
- testGetPolicyTypeIdentities(A1ProtocolType.SDNC_OSC_OSC_V1, RIC_1_URL + "/a1-p/policytypes");
+ testGetPolicyTypeIdentities(A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1, RIC_1_URL + "/a1-p/policytypes");
}
@Test
void getPolicyTypeIdentities_STD_V2() {
- testGetPolicyTypeIdentities(A1ProtocolType.SDNC_OSC_STD_V2_0_0, RIC_1_URL + "/A1-P/v2/policytypes");
+ testGetPolicyTypeIdentities(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V2_0_0, RIC_1_URL + "/A1-P/v2/policytypes");
}
@Test
void getTypeSchema_STD_V1() {
- clientUnderTest = new SdncOscA1Client(A1ProtocolType.SDNC_OSC_STD_V1_1, //
+ clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1, //
A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
controllerConfig(), asyncRestClientMock);
@@ -144,7 +144,7 @@ class SdncOscA1ClientTest {
private void testGetTypeSchema(A1ProtocolType protocolType, String expUrl, String policyTypeId,
String getSchemaResponseFile) throws IOException {
- clientUnderTest = new SdncOscA1Client(protocolType, //
+ clientUnderTest = new CcsdkA1AdapterClient(protocolType, //
A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
controllerConfig(), asyncRestClientMock);
@@ -162,7 +162,7 @@ class SdncOscA1ClientTest {
ImmutableAdapterRequest expectedParams = ImmutableAdapterRequest.builder() //
.nearRtRicUrl(expUrl) //
.build();
- String expInput = SdncJsonHelper.createInputJsonString(expectedParams);
+ String expInput = A1AdapterJsonHelper.createInputJsonString(expectedParams);
verify(asyncRestClientMock).postWithAuthHeader(GET_A1_POLICY_URL, expInput, CONTROLLER_USERNAME,
CONTROLLER_PASSWORD);
@@ -171,13 +171,13 @@ class SdncOscA1ClientTest {
@Test
void getTypeSchema_OSC() throws IOException {
String expUrl = RIC_1_URL + "/a1-p/policytypes/policyTypeId";
- testGetTypeSchema(A1ProtocolType.SDNC_OSC_OSC_V1, expUrl, "policyTypeId", "test_osc_get_schema_response.json");
+ testGetTypeSchema(A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1, expUrl, "policyTypeId", "test_osc_get_schema_response.json");
}
@Test
void getTypeSchema_STD_V2() throws IOException {
String expUrl = RIC_1_URL + "/A1-P/v2/policytypes/policyTypeId";
- testGetTypeSchema(A1ProtocolType.SDNC_OSC_STD_V2_0_0, expUrl, "policyTypeId",
+ testGetTypeSchema(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V2_0_0, expUrl, "policyTypeId",
"test_oran_get_schema_response.json");
}
@@ -186,14 +186,14 @@ class SdncOscA1ClientTest {
// One integer and one string
String inputString = "[1, \"1\" ]";
- List<String> result = SdncJsonHelper.parseJsonArrayOfString(inputString).collectList().block();
+ List<String> result = A1AdapterJsonHelper.parseJsonArrayOfString(inputString).collectList().block();
assertEquals(2, result.size());
assertEquals("1", result.get(0));
assertEquals("1", result.get(1));
}
private void getPolicyIdentities(A1ProtocolType protocolType, String... expUrls) {
- clientUnderTest = new SdncOscA1Client(protocolType, //
+ clientUnderTest = new CcsdkA1AdapterClient(protocolType, //
A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
controllerConfig(), asyncRestClientMock);
String resp = createOkResponseWithBody(Arrays.asList("xxx"));
@@ -206,7 +206,7 @@ class SdncOscA1ClientTest {
ImmutableAdapterRequest expectedParams = ImmutableAdapterRequest.builder() //
.nearRtRicUrl(expUrl) //
.build();
- String expInput = SdncJsonHelper.createInputJsonString(expectedParams);
+ String expInput = A1AdapterJsonHelper.createInputJsonString(expectedParams);
verify(asyncRestClientMock).postWithAuthHeader(GET_A1_POLICY_URL, expInput, CONTROLLER_USERNAME,
CONTROLLER_PASSWORD);
}
@@ -215,25 +215,25 @@ class SdncOscA1ClientTest {
@Test
void getPolicyIdentities_STD_V1() {
String expUrl = RIC_1_URL + "/A1-P/v1/policies";
- getPolicyIdentities(A1ProtocolType.SDNC_OSC_STD_V1_1, expUrl);
+ getPolicyIdentities(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1, expUrl);
}
@Test
void getPolicyIdentities_STD_V2() {
String expUrlPolicies = RIC_1_URL + "/A1-P/v2/policytypes";
String expUrlInstances = RIC_1_URL + "/A1-P/v2/policytypes/xxx/policies";
- getPolicyIdentities(A1ProtocolType.SDNC_OSC_STD_V2_0_0, expUrlPolicies, expUrlInstances);
+ getPolicyIdentities(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V2_0_0, expUrlPolicies, expUrlInstances);
}
@Test
void getPolicyIdentities_OSC() {
String expUrlTypes = RIC_1_URL + "/a1-p/policytypes";
String expUrlInstances = RIC_1_URL + "/a1-p/policytypes/xxx/policies";
- getPolicyIdentities(A1ProtocolType.SDNC_OSC_OSC_V1, expUrlTypes, expUrlInstances);
+ getPolicyIdentities(A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1, expUrlTypes, expUrlInstances);
}
private void putPolicy(A1ProtocolType protocolType, String expUrl) {
- clientUnderTest = new SdncOscA1Client(protocolType, //
+ clientUnderTest = new CcsdkA1AdapterClient(protocolType, //
A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
controllerConfig(), asyncRestClientMock);
@@ -248,7 +248,7 @@ class SdncOscA1ClientTest {
.nearRtRicUrl(expUrl) //
.body(POLICY_JSON_VALID) //
.build();
- String expInput = SdncJsonHelper.createInputJsonString(expectedInputParams);
+ String expInput = A1AdapterJsonHelper.createInputJsonString(expectedInputParams);
verify(asyncRestClientMock).postWithAuthHeader(PUT_A1_URL, expInput, CONTROLLER_USERNAME, CONTROLLER_PASSWORD);
@@ -257,25 +257,25 @@ class SdncOscA1ClientTest {
@Test
void putPolicy_OSC() {
String expUrl = RIC_1_URL + "/a1-p/policytypes/type1/policies/policy1";
- putPolicy(A1ProtocolType.SDNC_OSC_OSC_V1, expUrl);
+ putPolicy(A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1, expUrl);
}
@Test
void putPolicy_STD_V1() {
String expUrl = RIC_1_URL + "/A1-P/v1/policies/policy1";
- putPolicy(A1ProtocolType.SDNC_OSC_STD_V1_1, expUrl);
+ putPolicy(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1, expUrl);
}
@Test
void putPolicy_STD_V2() {
String expUrl =
RIC_1_URL + "/A1-P/v2/policytypes/type1/policies/policy1?notificationDestination=https://test.com";
- putPolicy(A1ProtocolType.SDNC_OSC_STD_V2_0_0, expUrl);
+ putPolicy(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V2_0_0, expUrl);
}
@Test
void postRejected() {
- clientUnderTest = new SdncOscA1Client(A1ProtocolType.SDNC_OSC_STD_V1_1, //
+ clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1, //
A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
controllerConfig(), asyncRestClientMock);
@@ -285,7 +285,7 @@ class SdncOscA1ClientTest {
.httpStatus(HttpStatus.BAD_REQUEST.value()) // ERROR
.build();
- String resp = SdncJsonHelper.createOutputJsonString(adapterOutput);
+ String resp = A1AdapterJsonHelper.createOutputJsonString(adapterOutput);
whenAsyncPostThenReturn(Mono.just(resp));
Mono<String> returnedMono = clientUnderTest
@@ -301,7 +301,7 @@ class SdncOscA1ClientTest {
}
private void deleteAllPolicies(A1ProtocolType protocolType, String expUrl) {
- clientUnderTest = new SdncOscA1Client(protocolType, //
+ clientUnderTest = new CcsdkA1AdapterClient(protocolType, //
A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
controllerConfig(), asyncRestClientMock);
String resp = createOkResponseWithBody(Arrays.asList("xxx"));
@@ -312,7 +312,7 @@ class SdncOscA1ClientTest {
ImmutableAdapterRequest expectedParams = ImmutableAdapterRequest.builder() //
.nearRtRicUrl(expUrl) //
.build();
- String expInput = SdncJsonHelper.createInputJsonString(expectedParams);
+ String expInput = A1AdapterJsonHelper.createInputJsonString(expectedParams);
verify(asyncRestClientMock).postWithAuthHeader(DELETE_A1_URL, expInput, CONTROLLER_USERNAME,
CONTROLLER_PASSWORD);
}
@@ -320,24 +320,24 @@ class SdncOscA1ClientTest {
@Test
void deleteAllPolicies_STD_V2() {
String expUrl1 = RIC_1_URL + "/A1-P/v2/policytypes/xxx/policies/xxx";
- deleteAllPolicies(A1ProtocolType.SDNC_OSC_STD_V2_0_0, expUrl1);
+ deleteAllPolicies(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V2_0_0, expUrl1);
}
@Test
void deleteAllPolicies_STD_V1() {
String expUrl1 = RIC_1_URL + "/A1-P/v1/policies/xxx";
- deleteAllPolicies(A1ProtocolType.SDNC_OSC_STD_V1_1, expUrl1);
+ deleteAllPolicies(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1, expUrl1);
}
@Test
void deleteAllPolicies_OSC() {
String expUrl1 = RIC_1_URL + "/a1-p/policytypes/xxx/policies/xxx";
- deleteAllPolicies(A1ProtocolType.SDNC_OSC_OSC_V1, expUrl1);
+ deleteAllPolicies(A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1, expUrl1);
}
@Test
void getVersion_OSC() {
- clientUnderTest = new SdncOscA1Client(A1ProtocolType.SDNC_OSC_OSC_V1, // Version irrelevant here
+ clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1, // Version irrelevant here
A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
controllerConfig(), asyncRestClientMock);
@@ -345,12 +345,12 @@ class SdncOscA1ClientTest {
A1ProtocolType returnedVersion = clientUnderTest.getProtocolVersion().block();
- assertEquals(A1ProtocolType.SDNC_OSC_STD_V1_1, returnedVersion);
+ assertEquals(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1, returnedVersion);
}
@Test
void testGetStatus() {
- clientUnderTest = new SdncOscA1Client(A1ProtocolType.SDNC_OSC_STD_V2_0_0, //
+ clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V2_0_0, //
A1ClientHelper.createRic(RIC_1_URL).getConfig(), //
controllerConfig(), asyncRestClientMock);
whenPostReturnOkResponse();
@@ -364,14 +364,14 @@ class SdncOscA1ClientTest {
ImmutableAdapterRequest expectedParams = ImmutableAdapterRequest.builder() //
.nearRtRicUrl(expUrl) //
.build();
- String expInput = SdncJsonHelper.createInputJsonString(expectedParams);
+ String expInput = A1AdapterJsonHelper.createInputJsonString(expectedParams);
verify(asyncRestClientMock).postWithAuthHeader(GET_A1_POLICY_STATUS_URL, expInput, CONTROLLER_USERNAME,
CONTROLLER_PASSWORD);
}
private Gson gson() {
- return SdncOscA1Client.gson;
+ return CcsdkA1AdapterClient.gson;
}
private String loadFile(String fileName) throws IOException {
@@ -394,7 +394,7 @@ class SdncOscA1ClientTest {
.body(gson().toJson(body)) //
.httpStatus(HttpStatus.OK.value()) //
.build();
- return SdncJsonHelper.createOutputJsonString(output);
+ return A1AdapterJsonHelper.createOutputJsonString(output);
}
private String createOkResponseString(boolean withBody) {
@@ -404,7 +404,7 @@ class SdncOscA1ClientTest {
} else {
responseBuilder.body(Optional.empty());
}
- return SdncJsonHelper.createOutputJsonString(responseBuilder.build());
+ return A1AdapterJsonHelper.createOutputJsonString(responseBuilder.build());
}
private OngoingStubbing<Mono<String>> whenAsyncPostThenReturn(Mono<String> response) {
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOnapA1ClientTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOnapA1ClientTest.java
deleted file mode 100644
index c2118c12..00000000
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOnapA1ClientTest.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/*-
- * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ========================LICENSE_END===================================
- */
-
-package org.onap.ccsdk.oran.a1policymanagementservice.clients;
-
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.json.JSONException;
-import org.junit.jupiter.api.BeforeEach;
-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.onap.ccsdk.oran.a1policymanagementservice.configuration.ControllerConfig;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableControllerConfig;
-
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-import reactor.test.StepVerifier;
-
-@ExtendWith(MockitoExtension.class)
-class SdncOnapA1ClientTest {
- private static final String CONTROLLER_USERNAME = "username";
- private static final String CONTROLLER_PASSWORD = "password";
- private static final String RIC_1_URL = "RicUrl";
- private static final String POLICYTYPES_IDENTITIES_URL = "/A1-ADAPTER-API:getPolicyTypes";
- private static final String POLICIES_IDENTITIES_URL = "/A1-ADAPTER-API:getPolicyInstances";
- private static final String POLICYTYPES_URL = "/A1-ADAPTER-API:getPolicyType";
- private static final String PUT_POLICY_URL = "/A1-ADAPTER-API:createPolicyInstance";
- private static final String DELETE_POLICY_URL = "/A1-ADAPTER-API:deletePolicyInstance";
-
- private static final String POLICY_TYPE_1_ID = "type1";
- private static final String POLICY_TYPE_2_ID = "type2";
- private static final String POLICY_TYPE_SCHEMA_VALID = "{\"type\":\"type1\"}";
- private static final String POLICY_TYPE_SCHEMA_INVALID = "\"type\":\"type1\"}";
- private static final String POLICY_1_ID = "policy1";
- private static final String POLICY_2_ID = "policy2";
- private static final String POLICY_JSON_VALID = "{\"scope\":{\"ueId\":\"ue1\"}}";
-
- SdncOnapA1Client clientUnderTest;
-
- AsyncRestClient asyncRestClientMock;
-
- @BeforeEach
- void init() {
- asyncRestClientMock = mock(AsyncRestClient.class);
- ControllerConfig controllerCfg = ImmutableControllerConfig.builder() //
- .name("name") //
- .baseUrl("baseUrl") //
- .password(CONTROLLER_PASSWORD) //
- .userName(CONTROLLER_USERNAME) //
- .build();
-
- clientUnderTest = new SdncOnapA1Client(A1ClientHelper.createRic(RIC_1_URL).getConfig(), controllerCfg,
- asyncRestClientMock);
- }
-
- @Test
- void testGetPolicyTypeIdentities() {
- SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
- .nearRtRicId(RIC_1_URL) //
- .build();
- String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams);
-
- List<String> policyTypeIds = Arrays.asList(POLICY_TYPE_1_ID, POLICY_TYPE_2_ID);
- Mono<String> policyTypeIdsResp =
- A1ClientHelper.createOutputJsonResponse("policy-type-id-list", policyTypeIds.toString());
- whenAsyncPostThenReturn(policyTypeIdsResp);
-
- Mono<List<String>> returnedMono = clientUnderTest.getPolicyTypeIdentities();
- verify(asyncRestClientMock).postWithAuthHeader(POLICYTYPES_IDENTITIES_URL, inputJsonString, CONTROLLER_USERNAME,
- CONTROLLER_PASSWORD);
- StepVerifier.create(returnedMono).expectNext(policyTypeIds).expectComplete().verify();
- }
-
- @Test
- void testGetPolicyIdentities() {
- SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
- .nearRtRicId(RIC_1_URL) //
- .build();
- String inputJsonStringGetTypeIds = SdncJsonHelper.createInputJsonString(inputParams);
- inputParams = ImmutableSdncOnapAdapterInput.builder() //
- .nearRtRicId(RIC_1_URL) //
- .policyTypeId(POLICY_TYPE_1_ID) //
- .build();
- String inputJsonStringGetPolicyIdsType1 = SdncJsonHelper.createInputJsonString(inputParams);
- inputParams = ImmutableSdncOnapAdapterInput.builder() //
- .nearRtRicId(RIC_1_URL) //
- .policyTypeId(POLICY_TYPE_2_ID) //
- .build();
- String inputJsonStringGetPolicyIdsType2 = SdncJsonHelper.createInputJsonString(inputParams);
-
- List<String> policyTypeIds = Arrays.asList(POLICY_TYPE_1_ID, POLICY_TYPE_2_ID);
- Mono<String> policyTypeIdsResp =
- A1ClientHelper.createOutputJsonResponse("policy-type-id-list", policyTypeIds.toString());
- List<String> policyIdsType1 = Arrays.asList(POLICY_1_ID);
- Mono<String> policyIdsType1Resp =
- A1ClientHelper.createOutputJsonResponse("policy-instance-id-list", policyIdsType1.toString());
- List<String> policyIdsType2 = Arrays.asList(POLICY_2_ID);
- Mono<String> policyIdsType2Resp =
- A1ClientHelper.createOutputJsonResponse("policy-instance-id-list", policyIdsType2.toString());
- whenAsyncPostThenReturn(policyTypeIdsResp).thenReturn(policyIdsType1Resp).thenReturn(policyIdsType2Resp);
-
- Mono<List<String>> returnedMono = clientUnderTest.getPolicyIdentities();
- StepVerifier.create(returnedMono).expectNext(Arrays.asList(POLICY_1_ID, POLICY_2_ID)).expectComplete().verify();
- verify(asyncRestClientMock).postWithAuthHeader(POLICYTYPES_IDENTITIES_URL, inputJsonStringGetTypeIds,
- CONTROLLER_USERNAME, CONTROLLER_PASSWORD);
- verify(asyncRestClientMock).postWithAuthHeader(POLICIES_IDENTITIES_URL, inputJsonStringGetPolicyIdsType1,
- CONTROLLER_USERNAME, CONTROLLER_PASSWORD);
- verify(asyncRestClientMock).postWithAuthHeader(POLICIES_IDENTITIES_URL, inputJsonStringGetPolicyIdsType2,
- CONTROLLER_USERNAME, CONTROLLER_PASSWORD);
- }
-
- @Test
- void testGetValidPolicyType() {
- SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
- .nearRtRicId(RIC_1_URL) //
- .policyTypeId(POLICY_TYPE_1_ID) //
- .build();
- String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams);
-
- String policyType = "{\"policySchema\": " + POLICY_TYPE_SCHEMA_VALID + ", \"statusSchema\": {} }";
- Mono<String> policyTypeResp = A1ClientHelper.createOutputJsonResponse("policy-type", policyType);
- whenAsyncPostThenReturn(policyTypeResp);
-
- Mono<String> returnedMono = clientUnderTest.getPolicyTypeSchema(POLICY_TYPE_1_ID);
- verify(asyncRestClientMock).postWithAuthHeader(POLICYTYPES_URL, inputJsonString, CONTROLLER_USERNAME,
- CONTROLLER_PASSWORD);
- StepVerifier.create(returnedMono).expectNext(POLICY_TYPE_SCHEMA_VALID).expectComplete().verify();
- }
-
- @Test
- void testGetInvalidPolicyType() {
- SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
- .nearRtRicId(RIC_1_URL) //
- .policyTypeId(POLICY_TYPE_1_ID) //
- .build();
- String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams);
-
- String policyType = "{\"policySchema\": " + POLICY_TYPE_SCHEMA_INVALID + ", \"statusSchema\": {} }";
- Mono<String> policyTypeResp = A1ClientHelper.createOutputJsonResponse("policy-type", policyType);
- whenAsyncPostThenReturn(policyTypeResp);
-
- Mono<String> returnedMono = clientUnderTest.getPolicyTypeSchema(POLICY_TYPE_1_ID);
- verify(asyncRestClientMock).postWithAuthHeader(POLICYTYPES_URL, inputJsonString, CONTROLLER_USERNAME,
- CONTROLLER_PASSWORD);
- StepVerifier.create(returnedMono).expectErrorMatches(throwable -> throwable instanceof JSONException).verify();
- }
-
- @Test
- void testPutPolicy() {
- SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
- .nearRtRicId(RIC_1_URL) //
- .policyTypeId(POLICY_TYPE_1_ID) //
- .policyInstanceId(POLICY_1_ID) //
- .policyInstance(POLICY_JSON_VALID) //
- .properties(new ArrayList<String>()) //
- .build();
- String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams);
-
- whenAsyncPostThenReturn(Mono.empty());
-
- Mono<String> returnedMono = clientUnderTest
- .putPolicy(A1ClientHelper.createPolicy(RIC_1_URL, POLICY_1_ID, POLICY_JSON_VALID, POLICY_TYPE_1_ID));
- verify(asyncRestClientMock).postWithAuthHeader(PUT_POLICY_URL, inputJsonString, CONTROLLER_USERNAME,
- CONTROLLER_PASSWORD);
- StepVerifier.create(returnedMono).expectComplete().verify();
- }
-
- @Test
- void testDeletePolicy() {
- SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
- .nearRtRicId(RIC_1_URL) //
- .policyTypeId(POLICY_TYPE_1_ID) //
- .policyInstanceId(POLICY_1_ID) //
- .build();
- String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams);
-
- whenAsyncPostThenReturn(Mono.empty());
-
- Mono<String> returnedMono = clientUnderTest
- .deletePolicy(A1ClientHelper.createPolicy(RIC_1_URL, POLICY_1_ID, POLICY_JSON_VALID, POLICY_TYPE_1_ID));
- verify(asyncRestClientMock).postWithAuthHeader(DELETE_POLICY_URL, inputJsonString, CONTROLLER_USERNAME,
- CONTROLLER_PASSWORD);
- StepVerifier.create(returnedMono).expectComplete().verify();
- }
-
- @Test
- void testDeleteAllPolicies() {
- SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
- .nearRtRicId(RIC_1_URL) //
- .build();
- String inputJsonStringGetTypeIds = SdncJsonHelper.createInputJsonString(inputParams);
- inputParams = ImmutableSdncOnapAdapterInput.builder() //
- .nearRtRicId(RIC_1_URL) //
- .policyTypeId(POLICY_TYPE_1_ID) //
- .build();
- String inputJsonStringGetPolicyIdsType1 = SdncJsonHelper.createInputJsonString(inputParams);
- inputParams = ImmutableSdncOnapAdapterInput.builder() //
- .nearRtRicId(RIC_1_URL) //
- .policyTypeId(POLICY_TYPE_2_ID) //
- .build();
- String inputJsonStringGetPolicyIdsType2 = SdncJsonHelper.createInputJsonString(inputParams);
- inputParams = ImmutableSdncOnapAdapterInput.builder() //
- .nearRtRicId(RIC_1_URL) //
- .policyTypeId(POLICY_TYPE_1_ID) //
- .policyInstanceId(POLICY_1_ID) //
- .build();
- String inputJsonStringDeletePolicy1 = SdncJsonHelper.createInputJsonString(inputParams);
- inputParams = ImmutableSdncOnapAdapterInput.builder() //
- .nearRtRicId(RIC_1_URL) //
- .policyTypeId(POLICY_TYPE_2_ID) //
- .policyInstanceId(POLICY_2_ID) //
- .build();
- String inputJsonStringDeletePolicy2 = SdncJsonHelper.createInputJsonString(inputParams);
-
- List<String> policyTypeIds = Arrays.asList(POLICY_TYPE_1_ID, POLICY_TYPE_2_ID);
- Mono<String> policyTypeIdsResp =
- A1ClientHelper.createOutputJsonResponse("policy-type-id-list", policyTypeIds.toString());
- List<String> policyIdsType1 = Arrays.asList(POLICY_1_ID);
- Mono<String> policyIdsType1Resp =
- A1ClientHelper.createOutputJsonResponse("policy-instance-id-list", policyIdsType1.toString());
- List<String> policyIdsType2 = Arrays.asList(POLICY_2_ID);
- Mono<String> policyIdsType2Resp =
- A1ClientHelper.createOutputJsonResponse("policy-instance-id-list", policyIdsType2.toString());
- whenAsyncPostThenReturn(policyTypeIdsResp).thenReturn(policyIdsType1Resp).thenReturn(Mono.empty())
- .thenReturn(policyIdsType2Resp).thenReturn(Mono.empty());
-
- Flux<String> returnedFlux = clientUnderTest.deleteAllPolicies();
- StepVerifier.create(returnedFlux).expectComplete().verify();
- verify(asyncRestClientMock).postWithAuthHeader(POLICYTYPES_IDENTITIES_URL, inputJsonStringGetTypeIds,
- CONTROLLER_USERNAME, CONTROLLER_PASSWORD);
- verify(asyncRestClientMock).postWithAuthHeader(POLICIES_IDENTITIES_URL, inputJsonStringGetPolicyIdsType1,
- CONTROLLER_USERNAME, CONTROLLER_PASSWORD);
- verify(asyncRestClientMock).postWithAuthHeader(DELETE_POLICY_URL, inputJsonStringDeletePolicy1,
- CONTROLLER_USERNAME, CONTROLLER_PASSWORD);
- verify(asyncRestClientMock).postWithAuthHeader(POLICIES_IDENTITIES_URL, inputJsonStringGetPolicyIdsType2,
- CONTROLLER_USERNAME, CONTROLLER_PASSWORD);
- verify(asyncRestClientMock).postWithAuthHeader(DELETE_POLICY_URL, inputJsonStringDeletePolicy2,
- CONTROLLER_USERNAME, CONTROLLER_PASSWORD);
- }
-
- private OngoingStubbing<Mono<String>> whenAsyncPostThenReturn(Mono<String> response) {
- return when(asyncRestClientMock.postWithAuthHeader(anyString(), anyString(), anyString(), anyString()))
- .thenReturn(response);
- }
-}