public interface A1Client {
- public static enum A1ProtocolType {
- UNKNOWN, STD_V1, OSC_V1, SDNC_OSC, SDNR_ONAP
+ public enum A1ProtocolType {
+ UNKNOWN, //
+ STD_V1, //
+ OSC_V1, //
+ SDNC_OSC, //
+ SDNC_ONAP
}
public Mono<A1ProtocolType> getProtocolVersion();
}
protected A1Client createSdnrOnapA1Client(Ric ric) {
- return new SdnrOnapA1Client(ric.getConfig(), appConfig.getA1ControllerBaseUrl(),
+ return new SdncOnapA1Client(ric.getConfig(), appConfig.getA1ControllerBaseUrl(),
appConfig.getA1ControllerUsername(), appConfig.getA1ControllerPassword());
}
* limitations under the License.
* ========================LICENSE_END===================================
*/
+
package org.oransc.policyagent.clients;
import java.lang.invoke.MethodHandles;
import org.oransc.policyagent.repository.Policy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
+import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public class OscA1Client implements A1Client {
+ private static final String URL_PREFIX = "/a1-p";
+
+ private static final String POLICYTYPES = "/policytypes";
+ private static final String CREATE_SCHEMA = "create_schema";
+ private static final String TITLE = "title";
+
+ private static final String HEALTHCHECK = "/healthcheck";
+
+ private static final UriComponentsBuilder POLICY_TYPE_SCHEMA_URI =
+ UriComponentsBuilder.fromPath("/policytypes/{policy-type-name}");
+
+ private static final UriComponentsBuilder POLICY_URI =
+ UriComponentsBuilder.fromPath("/policytypes/{policy-type-name}/policies/{policy-id}");
+
+ private static final UriComponentsBuilder POLICY_IDS_URI =
+ UriComponentsBuilder.fromPath("/policytypes/{policy-type-name}/policies");
+
+ private static final UriComponentsBuilder POLICY_STATUS_URI =
+ UriComponentsBuilder.fromPath("/policytypes/{policy-type-name}/policies/{policy-id}/status");
+
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final AsyncRestClient restClient;
public OscA1Client(RicConfig ricConfig) {
- String baseUrl = ricConfig.baseUrl() + "/a1-p";
+ String baseUrl = ricConfig.baseUrl() + URL_PREFIX;
this.restClient = new AsyncRestClient(baseUrl);
- logger.debug("OscA1Client for ric: {}", ricConfig.name());
+ if (logger.isDebugEnabled()) {
+ logger.debug("OscA1Client for ric: {}", ricConfig.name());
+ }
}
public OscA1Client(AsyncRestClient restClient) {
@Override
public Mono<List<String>> getPolicyTypeIdentities() {
- return restClient.get("/policytypes") //
+ return restClient.get(POLICYTYPES) //
.flatMap(this::parseJsonArrayOfString);
}
public Mono<List<String>> getPolicyIdentities() {
return getPolicyTypeIdentities() //
.flatMapMany(types -> Flux.fromIterable(types)) //
- .flatMap(type -> getPolicyIdentities(type)) //
+ .flatMap(type -> getPolicyIdentitiesById(type)) //
.flatMap(policyIds -> Flux.fromIterable(policyIds)) //
.collectList();
}
- private Mono<List<String>> getPolicyIdentities(String typeId) {
- return restClient.get("/policytypes/" + typeId + "/policies") //
- .flatMap(this::parseJsonArrayOfString);
- }
-
@Override
public Mono<String> getPolicyTypeSchema(String policyTypeId) {
- return restClient.get("/policytypes/" + policyTypeId) //
+ String uri = POLICY_TYPE_SCHEMA_URI.buildAndExpand(policyTypeId).toUriString();
+ return restClient.get(uri) //
.flatMap(response -> getCreateSchema(response, policyTypeId));
}
- private Mono<String> getCreateSchema(String policyTypeResponse, String policyTypeId) {
- try {
- JSONObject obj = new JSONObject(policyTypeResponse);
- JSONObject schemaObj = obj.getJSONObject("create_schema");
- schemaObj.put("title", policyTypeId);
- return Mono.just(schemaObj.toString());
- } catch (Exception e) {
- logger.error("Unexcpected response for policy type: {}", policyTypeResponse, e);
- return Mono.error(e);
- }
- }
-
@Override
public Mono<String> putPolicy(Policy policy) {
- return restClient.put("/policytypes/" + policy.type().name() + "/policies/" + policy.id(), policy.json());
+ String uri = POLICY_URI.buildAndExpand(policy.type().name(), policy.id()).toUriString();
+ return restClient.put(uri, policy.json());
}
@Override
public Mono<String> deletePolicy(Policy policy) {
- return deletePolicy(policy.type().name(), policy.id());
- }
-
- private Mono<String> deletePolicy(String typeId, String policyId) {
- return restClient.delete("/policytypes/" + typeId + "/policies/" + policyId);
+ return deletePolicyById(policy.type().name(), policy.id());
}
@Override
public Mono<A1ProtocolType> getProtocolVersion() {
- return restClient.get("/healthcheck") //
+ return restClient.get(HEALTHCHECK) //
.flatMap(resp -> Mono.just(A1ProtocolType.OSC_V1));
}
.flatMap(typeId -> deletePoliciesForType(typeId)); //
}
+ @Override
+ public Mono<String> getPolicyStatus(Policy policy) {
+ String uri = POLICY_STATUS_URI.buildAndExpand(policy.type().name(), policy.id()).toUriString();
+ return restClient.get(uri);
+
+ }
+
+ private Mono<List<String>> getPolicyIdentitiesById(String typeId) {
+ String uri = POLICY_IDS_URI.buildAndExpand(typeId).toUriString();
+ return restClient.get(uri) //
+ .flatMap(this::parseJsonArrayOfString);
+ }
+
+ private Mono<String> getCreateSchema(String policyTypeResponse, String policyTypeId) {
+ try {
+ JSONObject obj = new JSONObject(policyTypeResponse);
+ JSONObject schemaObj = obj.getJSONObject(CREATE_SCHEMA);
+ schemaObj.put(TITLE, policyTypeId);
+ return Mono.just(schemaObj.toString());
+ } catch (Exception e) {
+ logger.error("Unexcpected response for policy type: {}", policyTypeResponse, e);
+ return Mono.error(e);
+ }
+ }
+
+ private Mono<String> deletePolicyById(String typeId, String policyId) {
+ String uri = POLICY_URI.buildAndExpand(typeId, policyId).toUriString();
+ return restClient.delete(uri);
+ }
+
private Flux<String> deletePoliciesForType(String typeId) {
- return getPolicyIdentities(typeId) //
+ return getPolicyIdentitiesById(typeId) //
.flatMapMany(policyIds -> Flux.fromIterable(policyIds)) //
- .flatMap(policyId -> deletePolicy(typeId, policyId)); //
+ .flatMap(policyId -> deletePolicyById(typeId, policyId)); //
}
private Mono<List<String>> parseJsonArrayOfString(String inputString) {
return Mono.error(ex);
}
}
-
- @Override
- public Mono<String> getPolicyStatus(Policy policy) {
- // /a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}/status
- return restClient.get("/policytypes/" + policy.type().name() + "/policies/" + policy.id() + "/status");
-
- }
}
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
-public class SdnrOnapA1Client implements A1Client {
+public class SdncOnapA1Client implements A1Client {
+ private static final String URL_PREFIX = "/A1-ADAPTER-API:";
+
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final String a1ControllerUsername;
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES) //
.create(); //
- public SdnrOnapA1Client(RicConfig ricConfig, String baseUrl, String username, String password) {
+ public SdncOnapA1Client(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) {
+ public SdncOnapA1Client(RicConfig ricConfig, String username, String password, AsyncRestClient restClient) {
this.ricConfig = ricConfig;
this.a1ControllerUsername = username;
this.a1ControllerPassword = password;
@Override
public Mono<List<String>> getPolicyTypeIdentities() {
- SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(ricConfig.baseUrl()) //
.build();
String inputJsonString = createInputJsonString(inputParams);
logger.debug("POST getPolicyTypeIdentities inputJsonString = {}", inputJsonString);
return restClient
- .postWithAuthHeader("/A1-ADAPTER-API:getPolicyTypes", inputJsonString, a1ControllerUsername,
+ .postWithAuthHeader(URL_PREFIX + "getPolicyTypes", inputJsonString, a1ControllerUsername,
a1ControllerPassword) //
.flatMap(response -> getValueFromResponse(response, "policy-type-id-list")) //
.flatMap(this::parseJsonArrayOfString);
}
public Mono<List<String>> getPolicyIdentities(String policyTypeId) {
- SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(ricConfig.baseUrl()) //
.policyTypeId(policyTypeId) //
.build();
logger.debug("POST getPolicyIdentities inputJsonString = {}", inputJsonString);
return restClient
- .postWithAuthHeader("/A1-ADAPTER-API:getPolicyInstances", inputJsonString, a1ControllerUsername,
+ .postWithAuthHeader(URL_PREFIX + "getPolicyInstances", inputJsonString, a1ControllerUsername,
a1ControllerPassword) //
.flatMap(response -> getValueFromResponse(response, "policy-instance-id-list")) //
.flatMap(this::parseJsonArrayOfString);
@Override
public Mono<String> getPolicyTypeSchema(String policyTypeId) {
- SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(ricConfig.baseUrl()) //
.policyTypeId(policyTypeId) //
.build();
logger.debug("POST getPolicyType inputJsonString = {}", inputJsonString);
return restClient
- .postWithAuthHeader("/A1-ADAPTER-API:getPolicyType", inputJsonString, a1ControllerUsername,
+ .postWithAuthHeader(URL_PREFIX + "getPolicyType", inputJsonString, a1ControllerUsername,
a1ControllerPassword) //
.flatMap(response -> getValueFromResponse(response, "policy-type")) //
.flatMap(this::extractPolicySchema);
@Override
public Mono<String> putPolicy(Policy policy) {
- SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(ricConfig.baseUrl()) //
.policyTypeId(policy.type().name()) //
.policyInstanceId(policy.id()) //
String inputJsonString = createInputJsonString(inputParams);
logger.debug("POST putPolicy inputJsonString = {}", inputJsonString);
- return restClient.postWithAuthHeader("/A1-ADAPTER-API:createPolicyInstance", inputJsonString,
+ return restClient.postWithAuthHeader(URL_PREFIX + "createPolicyInstance", inputJsonString,
a1ControllerUsername, a1ControllerPassword);
}
- public Mono<String> deletePolicy(String policyTypeId, String policyId) {
- SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ public Mono<String> deletePolicyByIds(String policyTypeId, String policyId) {
+ SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(ricConfig.baseUrl()) //
.policyTypeId(policyTypeId) //
.policyInstanceId(policyId) //
String inputJsonString = createInputJsonString(inputParams);
logger.debug("POST deletePolicy inputJsonString = {}", inputJsonString);
- return restClient.postWithAuthHeader("/A1-ADAPTER-API:deletePolicyInstance", inputJsonString,
+ return restClient.postWithAuthHeader(URL_PREFIX + "deletePolicyInstance", inputJsonString,
a1ControllerUsername, a1ControllerPassword);
}
@Override
public Mono<String> deletePolicy(Policy policy) {
- return deletePolicy(policy.type().name(), policy.id());
+ return deletePolicyByIds(policy.type().name(), policy.id());
}
@Override
.flatMap(typeId -> deletePoliciesForType(typeId)); //
}
- private Flux<String> deletePoliciesForType(String typeId) {
- return getPolicyIdentities(typeId) //
- .flatMapMany(policyIds -> Flux.fromIterable(policyIds)) //
- .flatMap(policyId -> deletePolicy(typeId, policyId)); //
- }
-
@Override
public Mono<A1ProtocolType> getProtocolVersion() {
return getPolicyTypeIdentities() //
- .flatMap(x -> Mono.just(A1ProtocolType.SDNR_ONAP));
+ .flatMap(x -> Mono.just(A1ProtocolType.SDNC_ONAP));
}
- private String createInputJsonString(SdnrOnapAdapterInput inputParams) {
- JSONObject inputJson = new JSONObject();
- inputJson.put("input", new JSONObject(gson.toJson(inputParams)));
- return inputJson.toString();
+ @Override
+ public Mono<String> getPolicyStatus(Policy policy) {
+ return Mono.error(new Exception("Status not implemented in the controller"));
}
private Mono<String> getValueFromResponse(String response, String key) {
}
}
- @Override
- public Mono<String> getPolicyStatus(Policy policy) {
- return Mono.error(new Exception("Status not implemented in the controller"));
+ private Flux<String> deletePoliciesForType(String typeId) {
+ return getPolicyIdentities(typeId) //
+ .flatMapMany(policyIds -> Flux.fromIterable(policyIds)) //
+ .flatMap(policyId -> deletePolicyByIds(typeId, policyId)); //
+ }
+
+ private String createInputJsonString(SdncOnapAdapterInput inputParams) {
+ JSONObject inputJson = new JSONObject();
+ inputJson.put("input", new JSONObject(gson.toJson(inputParams)));
+ return inputJson.toString();
}
}
@Value.Immutable
@Gson.TypeAdapters
-public interface SdnrOnapAdapterInput {
+public interface SdncOnapAdapterInput {
public String nearRtRicId();
public Optional<String> policyTypeId();
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;
import reactor.core.publisher.Mono;
public class SdncOscA1Client implements A1Client {
+ private static final String URL_PREFIX = "/A1-ADAPTER-API:";
+
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final String a1ControllerUsername;
logger.debug("POST getPolicyTypeIdentities inputJsonString = {}", inputJsonString);
return restClient
- .postWithAuthHeader("/A1-ADAPTER-API:getPolicyTypeIdentities", inputJsonString, a1ControllerUsername,
+ .postWithAuthHeader(URL_PREFIX + "getPolicyTypeIdentities", inputJsonString, a1ControllerUsername,
a1ControllerPassword) //
.flatMap(response -> getValueFromResponse(response, "policy-type-id-list")) //
.flatMap(this::parseJsonArrayOfString);
logger.debug("POST getPolicyIdentities inputJsonString = {}", inputJsonString);
return restClient
- .postWithAuthHeader("/A1-ADAPTER-API:getPolicyIdentities", inputJsonString, a1ControllerUsername,
+ .postWithAuthHeader(URL_PREFIX + "getPolicyIdentities", inputJsonString, a1ControllerUsername,
a1ControllerPassword) //
.flatMap(response -> getValueFromResponse(response, "policy-id-list")) //
.flatMap(this::parseJsonArrayOfString);
logger.debug("POST getPolicyType inputJsonString = {}", inputJsonString);
return restClient
- .postWithAuthHeader("/A1-ADAPTER-API:getPolicyType", inputJsonString, a1ControllerUsername,
+ .postWithAuthHeader(URL_PREFIX + "getPolicyType", inputJsonString, a1ControllerUsername,
a1ControllerPassword) //
.flatMap(response -> getValueFromResponse(response, "policy-type")) //
.flatMap(this::extractPolicySchema);
logger.debug("POST putPolicy inputJsonString = {}", inputJsonString);
return restClient
- .postWithAuthHeader("/A1-ADAPTER-API:putPolicy", inputJsonString, a1ControllerUsername,
- a1ControllerPassword) //
+ .postWithAuthHeader(URL_PREFIX + "putPolicy", inputJsonString, a1ControllerUsername, a1ControllerPassword)
.flatMap(response -> getValueFromResponse(response, "returned-policy")) //
.flatMap(this::validateJson);
}
@Override
public Mono<String> deletePolicy(Policy policy) {
- return deletePolicy(policy.id());
+ return deletePolicyById(policy.id());
}
@Override
public Flux<String> deleteAllPolicies() {
return getPolicyIdentities() //
.flatMapMany(policyIds -> Flux.fromIterable(policyIds)) // )
- .flatMap(policyId -> deletePolicy(policyId)); //
- }
-
- public Mono<String> deletePolicy(String policyId) {
- SdncOscAdapterInput inputParams = ImmutableSdncOscAdapterInput.builder() //
- .nearRtRicUrl(ricConfig.baseUrl()) //
- .policyId(policyId) //
- .build();
- String inputJsonString = createInputJsonString(inputParams);
- logger.debug("POST deletePolicy inputJsonString = {}", inputJsonString);
-
- return restClient.postWithAuthHeader("/A1-ADAPTER-API:deletePolicy", inputJsonString, a1ControllerUsername,
- a1ControllerPassword);
+ .flatMap(policyId -> deletePolicyById(policyId)); //
}
@Override
.flatMap(x -> Mono.just(A1ProtocolType.SDNC_OSC));
}
- private String createInputJsonString(SdncOscAdapterInput inputParams) {
- JSONObject inputJson = new JSONObject();
- inputJson.put("input", new JSONObject(gson.toJson(inputParams)));
- return inputJson.toString();
+ @Override
+ public Mono<String> getPolicyStatus(Policy policy) {
+ return Mono.error(new Exception("Status not implemented in the SDNC controller"));
}
private Mono<String> getValueFromResponse(String response, String key) {
}
}
- @Override
- public Mono<String> getPolicyStatus(Policy policy) {
- return Mono.error(new Exception("Status not implemented in the SDNC controller"));
+ private Mono<String> deletePolicyById(String policyId) {
+ SdncOscAdapterInput inputParams = ImmutableSdncOscAdapterInput.builder() //
+ .nearRtRicUrl(ricConfig.baseUrl()) //
+ .policyId(policyId) //
+ .build();
+
+ String inputJsonString = createInputJsonString(inputParams);
+ logger.debug("POST deletePolicy inputJsonString = {}", inputJsonString);
+
+ return restClient.postWithAuthHeader(URL_PREFIX + "deletePolicy", inputJsonString, a1ControllerUsername,
+ a1ControllerPassword);
+ }
+
+ private String createInputJsonString(SdncOscAdapterInput params) {
+ JSONObject inputJson = new JSONObject();
+ inputJson.put("input", new JSONObject(gson.toJson(params)));
+ return inputJson.toString();
}
}
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
-
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.oransc.policyagent.repository.Policy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
+import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public class StdA1Client implements A1Client {
+ private static final String URL_PREFIX = "/A1-P/v1";
+
+ private static final String POLICYTYPES_URI = "/policytypes";
+ private static final String POLICY_TYPE_ID = "policyTypeId";
+
+ private static final String POLICIES_URI = "/policies";
+ private static final String POLICY_SCHEMA = "policySchema";
+
+ private static final UriComponentsBuilder POLICY_TYPE_SCHEMA_URI =
+ UriComponentsBuilder.fromPath("/policytypes/{policy-type-name}");
+
+ private static final UriComponentsBuilder POLICY_URI =
+ UriComponentsBuilder.fromPath("/policies/{policy-id}").queryParam(POLICY_TYPE_ID, "{policy-type-name}");
+
+ private static final UriComponentsBuilder POLICY_DELETE_URI =
+ UriComponentsBuilder.fromPath("/policies/{policy-id}");
+
+ private static final UriComponentsBuilder POLICY_STATUS_URI =
+ UriComponentsBuilder.fromPath("/policies/{policy-id}/status");
+
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final AsyncRestClient restClient;
public StdA1Client(RicConfig ricConfig) {
- String baseUrl = ricConfig.baseUrl() + "/A1-P/v1";
+ String baseUrl = ricConfig.baseUrl() + URL_PREFIX;
this.restClient = new AsyncRestClient(baseUrl);
}
- public StdA1Client(RicConfig ricConfig, AsyncRestClient restClient) {
+ public StdA1Client(AsyncRestClient restClient) {
this.restClient = restClient;
}
@Override
public Mono<List<String>> getPolicyIdentities() {
- return restClient.get("/policies") //
+ return restClient.get(POLICIES_URI) //
.flatMap(this::parseJsonArrayOfString);
}
@Override
public Mono<String> putPolicy(Policy policy) {
- String url = "/policies/" + policy.id() + "?policyTypeId=" + policy.type().name();
- return restClient.put(url, policy.json()) //
+ String uri = POLICY_URI.buildAndExpand(policy.id(), policy.type().name()).toUriString();
+ return restClient.put(uri, policy.json()) //
.flatMap(this::validateJson);
}
@Override
public Mono<List<String>> getPolicyTypeIdentities() {
- return restClient.get("/policytypes") //
+ return restClient.get(POLICYTYPES_URI) //
.flatMap(this::parseJsonArrayOfString);
}
@Override
public Mono<String> getPolicyTypeSchema(String policyTypeId) {
- return restClient.get("/policytypes/" + policyTypeId) //
+ String uri = POLICY_TYPE_SCHEMA_URI.buildAndExpand(policyTypeId).toUriString();
+ return restClient.get(uri) //
.flatMap(this::extractPolicySchema);
}
@Override
public Mono<String> deletePolicy(Policy policy) {
- return deletePolicy(policy.id());
+ return deletePolicyById(policy.id());
}
@Override
public Flux<String> deleteAllPolicies() {
return getPolicyIdentities() //
.flatMapMany(policyIds -> Flux.fromIterable(policyIds)) // )
- .flatMap(policyId -> deletePolicy(policyId)); //
+ .flatMap(policyId -> deletePolicyById(policyId)); //
}
@Override
.flatMap(x -> Mono.just(A1ProtocolType.STD_V1));
}
- private Mono<String> deletePolicy(String policyId) {
- return restClient.delete("/policies/" + policyId);
+ @Override
+ public Mono<String> getPolicyStatus(Policy policy) {
+ String uri = POLICY_STATUS_URI.buildAndExpand(policy.id()).toUriString();
+ return restClient.get(uri);
+ }
+
+ private Mono<String> deletePolicyById(String policyId) {
+ String uri = POLICY_DELETE_URI.buildAndExpand(policyId).toUriString();
+ return restClient.delete(uri);
}
private Mono<List<String>> parseJsonArrayOfString(String inputString) {
private Mono<String> extractPolicySchema(String inputString) {
try {
JSONObject jsonObject = new JSONObject(inputString);
- JSONObject schemaObject = jsonObject.getJSONObject("policySchema");
+ JSONObject schemaObject = jsonObject.getJSONObject(POLICY_SCHEMA);
String schemaString = schemaObject.toString();
return Mono.just(schemaString);
} catch (JSONException ex) { // invalid json
}
}
- @Override
- public Mono<String> getPolicyStatus(Policy policy) {
- return restClient.get("/policies/" + policy.id() + "/status");
- }
-
}
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
-
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.oransc.policyagent.configuration.ApplicationConfig;
.expectNext(sdnrOnapA1ClientMock) //
.verifyComplete();
- assertEquals(A1ProtocolType.SDNR_ONAP, ric.getProtocolVersion(), "Not correct protocol");
+ assertEquals(A1ProtocolType.SDNC_ONAP, ric.getProtocolVersion(), "Not correct protocol");
}
@Test
private void whenGetProtocolVersionSdnrOnapA1ClientReturnCorrectProtocol() {
doReturn(sdnrOnapA1ClientMock).when(factoryUnderTest).createSdnrOnapA1Client(any(Ric.class));
- when(sdnrOnapA1ClientMock.getProtocolVersion()).thenReturn(Mono.just(A1ProtocolType.SDNR_ONAP));
+ when(sdnrOnapA1ClientMock.getProtocolVersion()).thenReturn(Mono.just(A1ProtocolType.SDNC_ONAP));
}
private void whenGetProtocolVersionSdncOscA1ClientThrowException() {
import reactor.test.StepVerifier;
@ExtendWith(MockitoExtension.class)
-public class SdnrOnapA1ClientTest {
+public 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 POLICY_2_ID = "policy2";
private static final String POLICY_JSON_VALID = "{\"scope\":{\"ueId\":\"ue1\"}}";
- SdnrOnapA1Client clientUnderTest;
+ SdncOnapA1Client clientUnderTest;
AsyncRestClient asyncRestClientMock;
@BeforeEach
public void init() {
asyncRestClientMock = mock(AsyncRestClient.class);
- clientUnderTest = new SdnrOnapA1Client(A1ClientHelper.createRic(RIC_1_URL).getConfig(), CONTROLLER_USERNAME,
+ clientUnderTest = new SdncOnapA1Client(A1ClientHelper.createRic(RIC_1_URL).getConfig(), CONTROLLER_USERNAME,
CONTROLLER_PASSWORD, asyncRestClientMock);
}
@Test
public void testGetPolicyTypeIdentities() {
- SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.build();
String inputJsonString = A1ClientHelper.createInputJsonString(inputParams);
@Test
public void testGetPolicyIdentities() {
- SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.build();
String inputJsonStringGetTypeIds = A1ClientHelper.createInputJsonString(inputParams);
- inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.policyTypeId(POLICY_TYPE_1_ID) //
.build();
String inputJsonStringGetPolicyIdsType1 = A1ClientHelper.createInputJsonString(inputParams);
- inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.policyTypeId(POLICY_TYPE_2_ID) //
.build();
@Test
public void testGetValidPolicyType() {
- SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.policyTypeId(POLICY_TYPE_1_ID) //
.build();
@Test
public void testGetInvalidPolicyType() {
- SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.policyTypeId(POLICY_TYPE_1_ID) //
.build();
@Test
public void testPutPolicy() {
- SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.policyTypeId(POLICY_TYPE_1_ID) //
.policyInstanceId(POLICY_1_ID) //
@Test
public void testDeletePolicy() {
- SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.policyTypeId(POLICY_TYPE_1_ID) //
.policyInstanceId(POLICY_1_ID) //
@Test
public void testDeleteAllPolicies() {
- SdnrOnapAdapterInput inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.build();
String inputJsonStringGetTypeIds = A1ClientHelper.createInputJsonString(inputParams);
- inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.policyTypeId(POLICY_TYPE_1_ID) //
.build();
String inputJsonStringGetPolicyIdsType1 = A1ClientHelper.createInputJsonString(inputParams);
- inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.policyTypeId(POLICY_TYPE_2_ID) //
.build();
String inputJsonStringGetPolicyIdsType2 = A1ClientHelper.createInputJsonString(inputParams);
- inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.policyTypeId(POLICY_TYPE_1_ID) //
.policyInstanceId(POLICY_1_ID) //
.build();
String inputJsonStringDeletePolicy1 = A1ClientHelper.createInputJsonString(inputParams);
- inputParams = ImmutableSdnrOnapAdapterInput.builder() //
+ inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.policyTypeId(POLICY_TYPE_2_ID) //
.policyInstanceId(POLICY_2_ID) //
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();
whenAsyncPostThenReturn(policyIdsResp);
Mono<List<String>> returnedMono = clientUnderTest.getPolicyIdentities();
+
verify(asyncRestClientMock).postWithAuthHeader(POLICIES_IDENTITIES_URL, inputJsonString, CONTROLLER_USERNAME,
CONTROLLER_PASSWORD);
StepVerifier.create(returnedMono).expectNext(policyIds).expectComplete().verify();
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();
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();
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).expectNext(POLICY_JSON_VALID).expectComplete().verify();
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).expectErrorMatches(throwable -> throwable instanceof JSONException).verify();
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();
whenAsyncPostThenReturn(policyIdsResp).thenReturn(Mono.empty());
Flux<String> returnedFlux = clientUnderTest.deleteAllPolicies();
+
StepVerifier.create(returnedFlux).expectComplete().verify();
verify(asyncRestClientMock).postWithAuthHeader(POLICIES_IDENTITIES_URL, inputJsonStringGetIds,
CONTROLLER_USERNAME, CONTROLLER_PASSWORD);
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.oransc.policyagent.repository.Policy;
-
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
StdA1Client clientUnderTest;
+ @Mock
AsyncRestClient asyncRestClientMock;
@BeforeEach
public void init() {
- asyncRestClientMock = mock(AsyncRestClient.class);
- clientUnderTest = new StdA1Client(A1ClientHelper.createRic(RIC_URL).getConfig(), asyncRestClientMock);
+ clientUnderTest = new StdA1Client(asyncRestClientMock);
}
@Test