Merge "Add unit tests for SdnrOnapA1Client"
diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOscA1Client.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOscA1Client.java
index 993088a..67d42d7 100644
--- a/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOscA1Client.java
+++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOscA1Client.java
@@ -70,7 +70,7 @@
SdncOscAdapterInput inputParams = ImmutableSdncOscAdapterInput.builder() //
.nearRtRicUrl(ricConfig.baseUrl()) //
.build();
- String inputJsonString = createInputJsonString(gson.toJson(inputParams));
+ String inputJsonString = createInputJsonString(inputParams);
logger.debug("POST getPolicyTypeIdentities inputJsonString = {}", inputJsonString);
return restClient
@@ -85,7 +85,7 @@
SdncOscAdapterInput inputParams = ImmutableSdncOscAdapterInput.builder() //
.nearRtRicUrl(ricConfig.baseUrl()) //
.build();
- String inputJsonString = createInputJsonString(gson.toJson(inputParams));
+ String inputJsonString = createInputJsonString(inputParams);
logger.debug("POST getPolicyIdentities inputJsonString = {}", inputJsonString);
return restClient
@@ -101,7 +101,7 @@
.nearRtRicUrl(ricConfig.baseUrl()) //
.policyTypeId(policyTypeId) //
.build();
- String inputJsonString = createInputJsonString(gson.toJson(inputParams));
+ String inputJsonString = createInputJsonString(inputParams);
logger.debug("POST getPolicyType inputJsonString = {}", inputJsonString);
return restClient
@@ -119,7 +119,7 @@
.policyId(policy.id()) //
.policy(policy.json()) //
.build();
- String inputJsonString = createInputJsonString(gson.toJson(inputParams));
+ String inputJsonString = createInputJsonString(inputParams);
logger.debug("POST putPolicy inputJsonString = {}", inputJsonString);
return restClient
@@ -146,7 +146,7 @@
.nearRtRicUrl(ricConfig.baseUrl()) //
.policyId(policyId) //
.build();
- String inputJsonString = createInputJsonString(gson.toJson(inputParams));
+ String inputJsonString = createInputJsonString(inputParams);
logger.debug("POST deletePolicy inputJsonString = {}", inputJsonString);
return restClient.postWithAuthHeader("/A1-ADAPTER-API:deletePolicy", inputJsonString, a1ControllerUsername,
@@ -159,9 +159,9 @@
.flatMap(x -> Mono.just(A1ProtocolType.SDNC_OSC));
}
- private String createInputJsonString(String paramsJson) {
+ private String createInputJsonString(SdncOscAdapterInput inputParams) {
JSONObject inputJson = new JSONObject();
- inputJson.put("input", new JSONObject(paramsJson));
+ inputJson.put("input", new JSONObject(gson.toJson(inputParams)));
return inputJson.toString();
}
diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/SdnrOnapA1Client.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdnrOnapA1Client.java
index 248c218..a12b8d5 100644
--- a/policy-agent/src/main/java/org/oransc/policyagent/clients/SdnrOnapA1Client.java
+++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdnrOnapA1Client.java
@@ -20,6 +20,10 @@
package org.oransc.policyagent.clients;
+import com.google.gson.FieldNamingPolicy;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
@@ -38,27 +42,35 @@
public class SdnrOnapA1Client implements A1Client {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- private String a1ControllerBaseUrl;
- private String a1ControllerUsername;
- private String a1ControllerPassword;
+ private final String a1ControllerUsername;
+ private final String a1ControllerPassword;
private final RicConfig ricConfig;
private final AsyncRestClient restClient;
+ private static Gson gson = new GsonBuilder() //
+ .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES) //
+ .create(); //
+
public SdnrOnapA1Client(RicConfig ricConfig, String baseUrl, String username, String password) {
+ this(ricConfig, username, password, new AsyncRestClient(baseUrl + "/restconf/operations"));
+ if (logger.isDebugEnabled()) {
+ logger.debug("SdnrOnapA1Client for ric: {}, a1ControllerBaseUrl: {}", ricConfig.name(), baseUrl);
+ }
+ }
+
+ public SdnrOnapA1Client(RicConfig ricConfig, String username, String password, AsyncRestClient restClient) {
this.ricConfig = ricConfig;
- this.a1ControllerBaseUrl = baseUrl;
this.a1ControllerUsername = username;
this.a1ControllerPassword = password;
- this.restClient = new AsyncRestClient(a1ControllerBaseUrl + "/restconf/operations");
- logger.debug("SdnrOnapA1Client for ric: {}, a1ControllerBaseUrl: {}", this.ricConfig.name(),
- a1ControllerBaseUrl);
+ this.restClient = restClient;
}
@Override
public Mono<List<String>> getPolicyTypeIdentities() {
- JSONObject paramsJson = new JSONObject();
- paramsJson.put("near-rt-ric-id", ricConfig.baseUrl());
- String inputJsonString = createInputJsonString(paramsJson);
+ SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(ricConfig.baseUrl()) //
+ .build();
+ String inputJsonString = createInputJsonString(inputParams);
logger.debug("POST getPolicyTypeIdentities inputJsonString = {}", inputJsonString);
return restClient
@@ -78,10 +90,11 @@
}
public Mono<List<String>> getPolicyIdentities(String policyTypeId) {
- JSONObject paramsJson = new JSONObject();
- paramsJson.put("near-rt-ric-id", ricConfig.baseUrl());
- paramsJson.put("policy-type-id", policyTypeId);
- String inputJsonString = createInputJsonString(paramsJson);
+ SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(ricConfig.baseUrl()) //
+ .policyTypeId(policyTypeId) //
+ .build();
+ String inputJsonString = createInputJsonString(inputParams);
logger.debug("POST getPolicyIdentities inputJsonString = {}", inputJsonString);
return restClient
@@ -93,10 +106,11 @@
@Override
public Mono<String> getPolicyTypeSchema(String policyTypeId) {
- JSONObject paramsJson = new JSONObject();
- paramsJson.put("near-rt-ric-id", ricConfig.baseUrl());
- paramsJson.put("policy-type-id", policyTypeId);
- String inputJsonString = createInputJsonString(paramsJson);
+ SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(ricConfig.baseUrl()) //
+ .policyTypeId(policyTypeId) //
+ .build();
+ String inputJsonString = createInputJsonString(inputParams);
logger.debug("POST getPolicyType inputJsonString = {}", inputJsonString);
return restClient
@@ -108,13 +122,14 @@
@Override
public Mono<String> putPolicy(Policy policy) {
- JSONObject paramsJson = new JSONObject();
- paramsJson.put("near-rt-ric-id", ricConfig.baseUrl());
- paramsJson.put("policy-instance-id", policy.id());
- paramsJson.put("policy-type-id", policy.type().name());
- paramsJson.put("policy-instance", policy.json());
- paramsJson.put("properties", new JSONArray());
- String inputJsonString = createInputJsonString(paramsJson);
+ SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(ricConfig.baseUrl()) //
+ .policyTypeId(policy.type().name()) //
+ .policyInstanceId(policy.id()) //
+ .policyInstance(policy.json()) //
+ .properties(new ArrayList<String>()) //
+ .build();
+ String inputJsonString = createInputJsonString(inputParams);
logger.debug("POST putPolicy inputJsonString = {}", inputJsonString);
return restClient.postWithAuthHeader("/A1-ADAPTER-API:createPolicyInstance", inputJsonString,
@@ -122,11 +137,12 @@
}
public Mono<String> deletePolicy(String policyTypeId, String policyId) {
- JSONObject paramsJson = new JSONObject();
- paramsJson.put("near-rt-ric-id", ricConfig.baseUrl());
- paramsJson.put("policy-instance-id", policyId);
- paramsJson.put("policy-type-id", policyTypeId);
- String inputJsonString = createInputJsonString(paramsJson);
+ SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(ricConfig.baseUrl()) //
+ .policyTypeId(policyTypeId) //
+ .policyInstanceId(policyId) //
+ .build();
+ String inputJsonString = createInputJsonString(inputParams);
logger.debug("POST deletePolicy inputJsonString = {}", inputJsonString);
return restClient.postWithAuthHeader("/A1-ADAPTER-API:deletePolicyInstance", inputJsonString,
@@ -157,9 +173,9 @@
.flatMap(x -> Mono.just(A1ProtocolType.SDNR_ONAP));
}
- private String createInputJsonString(JSONObject paramsJson) {
+ private String createInputJsonString(SdnrOnapAdapterInput inputParams) {
JSONObject inputJson = new JSONObject();
- inputJson.put("input", paramsJson);
+ inputJson.put("input", new JSONObject(gson.toJson(inputParams)));
return inputJson.toString();
}
diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/SdnrOnapAdapterInput.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdnrOnapAdapterInput.java
new file mode 100644
index 0000000..ac12173
--- /dev/null
+++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdnrOnapAdapterInput.java
@@ -0,0 +1,41 @@
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
+ * 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.oransc.policyagent.clients;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
+
+@Value.Immutable
+@Gson.TypeAdapters
+public interface SdnrOnapAdapterInput {
+ public String nearRtRicId();
+
+ public Optional<String> policyTypeId();
+
+ public Optional<String> policyInstanceId();
+
+ public Optional<String> policyInstance();
+
+ public Optional<List<String>> properties();
+}
diff --git a/policy-agent/src/test/java/org/oransc/policyagent/clients/A1ClientHelper.java b/policy-agent/src/test/java/org/oransc/policyagent/clients/A1ClientHelper.java
index 7906446..4fd8405 100644
--- a/policy-agent/src/test/java/org/oransc/policyagent/clients/A1ClientHelper.java
+++ b/policy-agent/src/test/java/org/oransc/policyagent/clients/A1ClientHelper.java
@@ -45,7 +45,7 @@
private A1ClientHelper() {
}
- protected static String createInputJsonString(SdncOscAdapterInput inputParams) {
+ protected static <T> String createInputJsonString(T inputParams) {
JSONObject inputJson = new JSONObject();
inputJson.put("input", new JSONObject(gson.toJson(inputParams)));
return inputJson.toString();
diff --git a/policy-agent/src/test/java/org/oransc/policyagent/clients/SdnrOnapA1ClientTest.java b/policy-agent/src/test/java/org/oransc/policyagent/clients/SdnrOnapA1ClientTest.java
new file mode 100644
index 0000000..6974bff
--- /dev/null
+++ b/policy-agent/src/test/java/org/oransc/policyagent/clients/SdnrOnapA1ClientTest.java
@@ -0,0 +1,262 @@
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
+ * 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.oransc.policyagent.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 reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.test.StepVerifier;
+
+@ExtendWith(MockitoExtension.class)
+public class SdnrOnapA1ClientTest {
+ 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\"}}";
+
+ SdnrOnapA1Client clientUnderTest;
+
+ AsyncRestClient asyncRestClientMock;
+
+ @BeforeEach
+ public void init() {
+ asyncRestClientMock = mock(AsyncRestClient.class);
+ clientUnderTest = new SdnrOnapA1Client(A1ClientHelper.createRic(RIC_1_URL).getConfig(), CONTROLLER_USERNAME,
+ CONTROLLER_PASSWORD, asyncRestClientMock);
+ }
+
+ @Test
+ public void testGetPolicyTypeIdentities() {
+ SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(RIC_1_URL) //
+ .build();
+ String inputJsonString = A1ClientHelper.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
+ public void testGetPolicyIdentities() {
+ SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(RIC_1_URL) //
+ .build();
+ String inputJsonStringGetTypeIds = A1ClientHelper.createInputJsonString(inputParams);
+ inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(RIC_1_URL) //
+ .policyTypeId(POLICY_TYPE_1_ID) //
+ .build();
+ String inputJsonStringGetPolicyIdsType1 = A1ClientHelper.createInputJsonString(inputParams);
+ inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(RIC_1_URL) //
+ .policyTypeId(POLICY_TYPE_2_ID) //
+ .build();
+ String inputJsonStringGetPolicyIdsType2 = A1ClientHelper.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
+ public void testGetValidPolicyType() {
+ SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(RIC_1_URL) //
+ .policyTypeId(POLICY_TYPE_1_ID) //
+ .build();
+ String inputJsonString = A1ClientHelper.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
+ public void testGetInvalidPolicyType() {
+ SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(RIC_1_URL) //
+ .policyTypeId(POLICY_TYPE_1_ID) //
+ .build();
+ String inputJsonString = A1ClientHelper.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
+ public void testPutPolicy() {
+ SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.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 = A1ClientHelper.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
+ public void testDeletePolicy() {
+ SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(RIC_1_URL) //
+ .policyTypeId(POLICY_TYPE_1_ID) //
+ .policyInstanceId(POLICY_1_ID) //
+ .build();
+ String inputJsonString = A1ClientHelper.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
+ public void testDeleteAllPolicies() {
+ SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(RIC_1_URL) //
+ .build();
+ String inputJsonStringGetTypeIds = A1ClientHelper.createInputJsonString(inputParams);
+ inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(RIC_1_URL) //
+ .policyTypeId(POLICY_TYPE_1_ID) //
+ .build();
+ String inputJsonStringGetPolicyIdsType1 = A1ClientHelper.createInputJsonString(inputParams);
+ inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(RIC_1_URL) //
+ .policyTypeId(POLICY_TYPE_2_ID) //
+ .build();
+ String inputJsonStringGetPolicyIdsType2 = A1ClientHelper.createInputJsonString(inputParams);
+ inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(RIC_1_URL) //
+ .policyTypeId(POLICY_TYPE_1_ID) //
+ .policyInstanceId(POLICY_1_ID) //
+ .build();
+ String inputJsonStringDeletePolicy1 = A1ClientHelper.createInputJsonString(inputParams);
+ inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ .nearRtRicId(RIC_1_URL) //
+ .policyTypeId(POLICY_TYPE_2_ID) //
+ .policyInstanceId(POLICY_2_ID) //
+ .build();
+ String inputJsonStringDeletePolicy2 = A1ClientHelper.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);
+ }
+}