From 67cb2d0bd5b6294cd021f4c8931bcb9d5c2a5dc5 Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Thu, 9 Apr 2020 07:48:26 +0200 Subject: [PATCH] Bugfix controller adaption The input to the controllers is Json, so the follwing has changed (illustrated by an example): From: {"input":"{\"near-rt-ric-url\":\"XXXX/A1-P/v1/policies\"}"} To: {"input":{"near-rt-ric-url":"XXXX/A1-P/v1/policies"}} Change-Id: I668eda2072fff9ce71bdbfed32fcb1a40b0799c8 Issue-ID: NONRTRIC-164 Signed-off-by: PatrikBuhr --- .../oransc/policyagent/clients/SdncJsonHelper.java | 9 +++++--- .../oransc/policyagent/clients/A1ClientHelper.java | 12 ---------- .../policyagent/clients/SdncOnapA1ClientTest.java | 26 +++++++++++----------- .../policyagent/clients/SdncOscA1ClientTest.java | 21 +++++++++++------ 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncJsonHelper.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncJsonHelper.java index 7c669612..0245a153 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncJsonHelper.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncJsonHelper.java @@ -23,6 +23,8 @@ package org.oransc.policyagent.clients; import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import java.util.ArrayList; import java.util.List; @@ -61,9 +63,10 @@ class SdncJsonHelper { } public static String createInputJsonString(T params) { - JSONObject inputJson = new JSONObject(); - inputJson.put("input", gson.toJson(params)); - return inputJson.toString(); + JsonElement paramsJson = gson.toJsonTree(params); + JsonObject jsonObj = new JsonObject(); + jsonObj.add("input", paramsJson); + return gson.toJson(jsonObj); } public static Mono getValueFromResponse(String response, String key) { 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 1855949d..21808567 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 @@ -20,9 +20,6 @@ package org.oransc.policyagent.clients; -import com.google.gson.FieldNamingPolicy; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import java.util.Arrays; import java.util.Vector; @@ -38,19 +35,10 @@ import org.oransc.policyagent.repository.Ric; import reactor.core.publisher.Mono; public class A1ClientHelper { - private static Gson gson = new GsonBuilder() // - .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES) // - .create(); private A1ClientHelper() { } - protected static String createInputJsonString(T inputParams) { - JSONObject inputJson = new JSONObject(); - inputJson.put("input", gson.toJson(inputParams)); - return inputJson.toString(); - } - protected static Mono createOutputJsonResponse(String key, String value) { JSONObject paramsJson = new JSONObject(); paramsJson.put(key, value); diff --git a/policy-agent/src/test/java/org/oransc/policyagent/clients/SdncOnapA1ClientTest.java b/policy-agent/src/test/java/org/oransc/policyagent/clients/SdncOnapA1ClientTest.java index 20bbf48f..c7f90737 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/clients/SdncOnapA1ClientTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/clients/SdncOnapA1ClientTest.java @@ -84,7 +84,7 @@ public class SdncOnapA1ClientTest { SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() // .nearRtRicId(RIC_1_URL) // .build(); - String inputJsonString = A1ClientHelper.createInputJsonString(inputParams); + String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams); List policyTypeIds = Arrays.asList(POLICY_TYPE_1_ID, POLICY_TYPE_2_ID); Mono policyTypeIdsResp = @@ -102,17 +102,17 @@ public class SdncOnapA1ClientTest { SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() // .nearRtRicId(RIC_1_URL) // .build(); - String inputJsonStringGetTypeIds = A1ClientHelper.createInputJsonString(inputParams); + String inputJsonStringGetTypeIds = SdncJsonHelper.createInputJsonString(inputParams); inputParams = ImmutableSdncOnapAdapterInput.builder() // .nearRtRicId(RIC_1_URL) // .policyTypeId(POLICY_TYPE_1_ID) // .build(); - String inputJsonStringGetPolicyIdsType1 = A1ClientHelper.createInputJsonString(inputParams); + String inputJsonStringGetPolicyIdsType1 = SdncJsonHelper.createInputJsonString(inputParams); inputParams = ImmutableSdncOnapAdapterInput.builder() // .nearRtRicId(RIC_1_URL) // .policyTypeId(POLICY_TYPE_2_ID) // .build(); - String inputJsonStringGetPolicyIdsType2 = A1ClientHelper.createInputJsonString(inputParams); + String inputJsonStringGetPolicyIdsType2 = SdncJsonHelper.createInputJsonString(inputParams); List policyTypeIds = Arrays.asList(POLICY_TYPE_1_ID, POLICY_TYPE_2_ID); Mono policyTypeIdsResp = @@ -141,7 +141,7 @@ public class SdncOnapA1ClientTest { .nearRtRicId(RIC_1_URL) // .policyTypeId(POLICY_TYPE_1_ID) // .build(); - String inputJsonString = A1ClientHelper.createInputJsonString(inputParams); + String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams); String policyType = "{\"policySchema\": " + POLICY_TYPE_SCHEMA_VALID + ", \"statusSchema\": {} }"; Mono policyTypeResp = A1ClientHelper.createOutputJsonResponse("policy-type", policyType); @@ -159,7 +159,7 @@ public class SdncOnapA1ClientTest { .nearRtRicId(RIC_1_URL) // .policyTypeId(POLICY_TYPE_1_ID) // .build(); - String inputJsonString = A1ClientHelper.createInputJsonString(inputParams); + String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams); String policyType = "{\"policySchema\": " + POLICY_TYPE_SCHEMA_INVALID + ", \"statusSchema\": {} }"; Mono policyTypeResp = A1ClientHelper.createOutputJsonResponse("policy-type", policyType); @@ -180,7 +180,7 @@ public class SdncOnapA1ClientTest { .policyInstance(POLICY_JSON_VALID) // .properties(new ArrayList()) // .build(); - String inputJsonString = A1ClientHelper.createInputJsonString(inputParams); + String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams); whenAsyncPostThenReturn(Mono.empty()); @@ -198,7 +198,7 @@ public class SdncOnapA1ClientTest { .policyTypeId(POLICY_TYPE_1_ID) // .policyInstanceId(POLICY_1_ID) // .build(); - String inputJsonString = A1ClientHelper.createInputJsonString(inputParams); + String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams); whenAsyncPostThenReturn(Mono.empty()); @@ -214,29 +214,29 @@ public class SdncOnapA1ClientTest { SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() // .nearRtRicId(RIC_1_URL) // .build(); - String inputJsonStringGetTypeIds = A1ClientHelper.createInputJsonString(inputParams); + String inputJsonStringGetTypeIds = SdncJsonHelper.createInputJsonString(inputParams); inputParams = ImmutableSdncOnapAdapterInput.builder() // .nearRtRicId(RIC_1_URL) // .policyTypeId(POLICY_TYPE_1_ID) // .build(); - String inputJsonStringGetPolicyIdsType1 = A1ClientHelper.createInputJsonString(inputParams); + String inputJsonStringGetPolicyIdsType1 = SdncJsonHelper.createInputJsonString(inputParams); inputParams = ImmutableSdncOnapAdapterInput.builder() // .nearRtRicId(RIC_1_URL) // .policyTypeId(POLICY_TYPE_2_ID) // .build(); - String inputJsonStringGetPolicyIdsType2 = A1ClientHelper.createInputJsonString(inputParams); + String inputJsonStringGetPolicyIdsType2 = SdncJsonHelper.createInputJsonString(inputParams); inputParams = ImmutableSdncOnapAdapterInput.builder() // .nearRtRicId(RIC_1_URL) // .policyTypeId(POLICY_TYPE_1_ID) // .policyInstanceId(POLICY_1_ID) // .build(); - String inputJsonStringDeletePolicy1 = A1ClientHelper.createInputJsonString(inputParams); + String inputJsonStringDeletePolicy1 = SdncJsonHelper.createInputJsonString(inputParams); inputParams = ImmutableSdncOnapAdapterInput.builder() // .nearRtRicId(RIC_1_URL) // .policyTypeId(POLICY_TYPE_2_ID) // .policyInstanceId(POLICY_2_ID) // .build(); - String inputJsonStringDeletePolicy2 = A1ClientHelper.createInputJsonString(inputParams); + String inputJsonStringDeletePolicy2 = SdncJsonHelper.createInputJsonString(inputParams); List policyTypeIds = Arrays.asList(POLICY_TYPE_1_ID, POLICY_TYPE_2_ID); Mono policyTypeIdsResp = 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 cba60e79..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 @@ -108,7 +108,7 @@ public class SdncOscA1ClientTest { AdapterRequest expectedParams = ImmutableAdapterRequest.builder() // .nearRtRicUrl(expUrl) // .build(); - String expInput = A1ClientHelper.createInputJsonString(expectedParams); + String expInput = SdncJsonHelper.createInputJsonString(expectedParams); verify(asyncRestClientMock).postWithAuthHeader(GET_A1_POLICY_URL, expInput, CONTROLLER_USERNAME, CONTROLLER_PASSWORD); @@ -143,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); @@ -168,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); } @@ -192,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) @@ -211,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); @@ -225,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") // -- 2.16.6