diff options
author | 2023-03-31 13:20:42 +0200 | |
---|---|---|
committer | 2023-04-03 14:15:55 +0200 | |
commit | 5e7e5f2c0cdd4e5554f4d8629403b7c554b3a0aa (patch) | |
tree | 851847041e12c135a20a0d7e76b3bd0203b4ac85 /a1-policy-management/src/test | |
parent | 2d985bd69d9425ab8f747aec0550674034d7d7ac (diff) |
Changes needed to make custom adapters that accesses CCSDK
To access the CCSDK a custom adapter needs the controller configuration.
Issue-ID: CCSDK-3883
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Change-Id: I6fb3eb3bb953f3fc209229282b66c9e1aa10cdee
Diffstat (limited to 'a1-policy-management/src/test')
7 files changed, 52 insertions, 61 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 ef4ad1c8..f50d5537 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 @@ -68,10 +68,14 @@ class A1ClientFactoryTest { private A1ClientFactory factoryUnderTest; private static RicConfig ricConfig(String controllerName, String customAdapter) { + ControllerConfig controllerConfig = null; + if (!controllerName.isEmpty()) { + controllerConfig = ControllerConfig.builder().baseUrl("baseUrl").name(controllerName).build(); + } return RicConfig.builder() // .ricId(RIC_NAME) // .baseUrl("baseUrl") // - .controllerName(controllerName) // + .controllerConfig(controllerConfig) // .customAdapterClass(customAdapter) // .build(); } @@ -175,12 +179,9 @@ class A1ClientFactoryTest { @DisplayName("test create check types controllers") void create_check_types_controllers() throws ServiceException { this.ric = new Ric(ricConfig("anythingButEmpty")); - whenGetGetControllerConfigReturn(); - whenGetGetControllerConfigReturn(); assertTrue(createClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1) instanceof CcsdkA1AdapterClient); - whenGetGetControllerConfigReturn(); assertTrue(createClient(A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1) instanceof CcsdkA1AdapterClient); } @@ -194,14 +195,4 @@ class A1ClientFactoryTest { when(clientMock.getProtocolVersion()).thenReturn(Mono.just(protocol)); } - private void whenGetGetControllerConfigReturn() throws ServiceException { - ControllerConfig controllerCfg = ControllerConfig.builder() // - .name("name") // - .baseUrl("baseUrl") // - .password("pass") // - .userName("user") // - .build(); - when(applicationConfigMock.getControllerConfig(any())).thenReturn(controllerCfg); - } - } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java index b42edb8f..36b591a7 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java @@ -24,26 +24,16 @@ import java.time.Instant; import java.util.Arrays; import java.util.Vector; -import org.json.JSONObject; import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig; import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy; import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyType; import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric; -import reactor.core.publisher.Mono; public class A1ClientHelper { private A1ClientHelper() {} - protected static Mono<String> createOutputJsonResponse(String key, String value) { - JSONObject paramsJson = new JSONObject(); - paramsJson.put(key, value); - JSONObject responseJson = new JSONObject(); - responseJson.put("output", paramsJson); - return Mono.just(responseJson.toString()); - } - - protected static Ric createRic(String url) { + private static Ric createRic(String url) { RicConfig cfg = RicConfig.builder().ricId("ric") // .baseUrl(url) // .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) // @@ -51,7 +41,7 @@ public class A1ClientHelper { return new Ric(cfg); } - protected static Policy createPolicy(String nearRtRicUrl, String policyId, String json, String type) { + public static Policy createPolicy(String nearRtRicUrl, String policyId, String json, String type) { String callbackUrl = "https://test.com"; return Policy.builder() // .id(policyId) // @@ -65,14 +55,7 @@ public class A1ClientHelper { .build(); } - protected static PolicyType createPolicyType(String name) { + public static PolicyType createPolicyType(String name) { return PolicyType.builder().id(name).schema("schema").build(); } - - protected static String getCreateSchema(String policyType, String policyTypeId) { - JSONObject obj = new JSONObject(policyType); - JSONObject schemaObj = obj.getJSONObject("create_schema"); - schemaObj.put("title", policyTypeId); - return schemaObj.toString(); - } } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java index 9bd10f3a..e6c8dfe8 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java @@ -35,6 +35,7 @@ import java.net.URL; import java.nio.file.Files; import java.util.Arrays; import java.util.List; +import java.util.Vector; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -46,7 +47,9 @@ import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client.A1Protocol 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.RicConfig; import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy; +import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric; import org.springframework.http.HttpStatus; import org.springframework.web.reactive.function.client.WebClientResponseException; @@ -85,7 +88,7 @@ class CcsdkA1AdapterClientTest { void createClientWithWrongProtocol_thenErrorIsThrown() { AsyncRestClient asyncRestClient = new AsyncRestClient("", null, null, new SecurityContext("")); assertThrows(IllegalArgumentException.class, () -> { - new CcsdkA1AdapterClient(A1ProtocolType.STD_V1_1, null, null, asyncRestClient); + new CcsdkA1AdapterClient(A1ProtocolType.STD_V1_1, null, asyncRestClient); }); } @@ -93,17 +96,26 @@ class CcsdkA1AdapterClientTest { @DisplayName("test get Policy Type Identities STD V1") void getPolicyTypeIdentities_STD_V1() { clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1, // - A1ClientHelper.createRic(RIC_1_URL).getConfig(), // - controllerConfig(), asyncRestClientMock); + createRic(RIC_1_URL).getConfig(), // + asyncRestClientMock); List<String> policyTypeIds = clientUnderTest.getPolicyTypeIdentities().block(); assertEquals(1, policyTypeIds.size(), "should hardcoded to one"); assertEquals("", policyTypeIds.get(0), "should hardcoded to empty"); } + private Ric createRic(String url) { + RicConfig cfg = RicConfig.builder().ricId("ric") // + .baseUrl(url) // + .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) // + .controllerConfig(controllerConfig()) // + .build(); + return new Ric(cfg); + } + private void testGetPolicyTypeIdentities(A1ProtocolType protocolType, String expUrl) { clientUnderTest = new CcsdkA1AdapterClient(protocolType, // - A1ClientHelper.createRic(RIC_1_URL).getConfig(), // - controllerConfig(), asyncRestClientMock); + createRic(RIC_1_URL).getConfig(), // + asyncRestClientMock); String response = createOkResponseWithBody(Arrays.asList(POLICY_TYPE_1_ID)); whenAsyncPostThenReturn(Mono.just(response)); @@ -137,8 +149,8 @@ class CcsdkA1AdapterClientTest { void getTypeSchema_STD_V1() { clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1, // - A1ClientHelper.createRic(RIC_1_URL).getConfig(), // - controllerConfig(), asyncRestClientMock); + createRic(RIC_1_URL).getConfig(), // + asyncRestClientMock); String policyType = clientUnderTest.getPolicyTypeSchema("").block(); @@ -148,8 +160,8 @@ class CcsdkA1AdapterClientTest { private void testGetTypeSchema(A1ProtocolType protocolType, String expUrl, String policyTypeId, String getSchemaResponseFile) throws IOException { clientUnderTest = new CcsdkA1AdapterClient(protocolType, // - A1ClientHelper.createRic(RIC_1_URL).getConfig(), // - controllerConfig(), asyncRestClientMock); + createRic(RIC_1_URL).getConfig(), // + asyncRestClientMock); String ricResponse = loadFile(getSchemaResponseFile); JsonElement elem = gson().fromJson(ricResponse, JsonElement.class); @@ -200,8 +212,8 @@ class CcsdkA1AdapterClientTest { private void getPolicyIdentities(A1ProtocolType protocolType, String... expUrls) { clientUnderTest = new CcsdkA1AdapterClient(protocolType, // - A1ClientHelper.createRic(RIC_1_URL).getConfig(), // - controllerConfig(), asyncRestClientMock); + createRic(RIC_1_URL).getConfig(), // + asyncRestClientMock); String resp = createOkResponseWithBody(Arrays.asList("xxx")); whenAsyncPostThenReturn(Mono.just(resp)); @@ -242,8 +254,8 @@ class CcsdkA1AdapterClientTest { private void putPolicy(A1ProtocolType protocolType, String expUrl) { clientUnderTest = new CcsdkA1AdapterClient(protocolType, // - A1ClientHelper.createRic(RIC_1_URL).getConfig(), // - controllerConfig(), asyncRestClientMock); + createRic(RIC_1_URL).getConfig(), // + asyncRestClientMock); whenPostReturnOkResponse(); @@ -285,8 +297,8 @@ class CcsdkA1AdapterClientTest { @DisplayName("test post Rejected") void postRejected() { clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V1_1, // - A1ClientHelper.createRic(RIC_1_URL).getConfig(), // - controllerConfig(), asyncRestClientMock); + createRic(RIC_1_URL).getConfig(), // + asyncRestClientMock); final String policyJson = "{}"; AdapterOutput adapterOutput = new AdapterOutput(HttpStatus.BAD_REQUEST.value(), "NOK"); @@ -308,8 +320,8 @@ class CcsdkA1AdapterClientTest { private void deleteAllPolicies(A1ProtocolType protocolType, String expUrl) { clientUnderTest = new CcsdkA1AdapterClient(protocolType, // - A1ClientHelper.createRic(RIC_1_URL).getConfig(), // - controllerConfig(), asyncRestClientMock); + createRic(RIC_1_URL).getConfig(), // + asyncRestClientMock); String resp = createOkResponseWithBody(Arrays.asList("xxx")); whenAsyncPostThenReturn(Mono.just(resp)); @@ -347,8 +359,8 @@ class CcsdkA1AdapterClientTest { @DisplayName("test get Version OSC") void getVersion_OSC() { clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_OSC_V1, // Version irrelevant here - A1ClientHelper.createRic(RIC_1_URL).getConfig(), // - controllerConfig(), asyncRestClientMock); + createRic(RIC_1_URL).getConfig(), // + asyncRestClientMock); whenAsyncPostThenReturn(Mono.error(new Exception("Error"))).thenReturn(Mono.just(createOkResponseString(true))); @@ -361,8 +373,8 @@ class CcsdkA1AdapterClientTest { @DisplayName("test Get Status") void testGetStatus() { clientUnderTest = new CcsdkA1AdapterClient(A1ProtocolType.CCSDK_A1_ADAPTER_STD_V2_0_0, // - A1ClientHelper.createRic(RIC_1_URL).getConfig(), // - controllerConfig(), asyncRestClientMock); + createRic(RIC_1_URL).getConfig(), // + asyncRestClientMock); whenPostReturnOkResponse(); Policy policy = A1ClientHelper.createPolicy(RIC_1_URL, POLICY_1_ID, POLICY_JSON_VALID, POLICY_TYPE_1_ID); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1ClientTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1ClientTest.java index c376d90f..2f2cce02 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1ClientTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1ClientTest.java @@ -30,6 +30,7 @@ import java.util.Arrays; import java.util.List; import org.json.JSONException; +import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -112,8 +113,8 @@ class OscA1ClientTest { Mono<String> returnedMono = clientUnderTest.getPolicyTypeSchema(POLICY_TYPE_1_ID); verify(asyncRestClientMock).get(POLICYTYPES_URL + POLICY_TYPE_1_ID); - StepVerifier.create(returnedMono).expectNext(A1ClientHelper.getCreateSchema(policyType, POLICY_TYPE_1_ID)) - .expectComplete().verify(); + StepVerifier.create(returnedMono).expectNext(getCreateSchema(policyType, POLICY_TYPE_1_ID)).expectComplete() + .verify(); } @Test @@ -182,4 +183,11 @@ class OscA1ClientTest { verify(asyncRestClientMock).get(POLICYTYPES_URL + POLICY_TYPE_2_ID + POLICIES); verify(asyncRestClientMock).delete(POLICYTYPES_URL + POLICY_TYPE_2_ID + POLICIES + "/" + POLICY_2_ID); } + + private String getCreateSchema(String policyType, String policyTypeId) { + JSONObject obj = new JSONObject(policyType); + JSONObject schemaObj = obj.getJSONObject("create_schema"); + schemaObj.put("title", policyTypeId); + return schemaObj.toString(); + } } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/MetersTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/MetersTest.java index 9696aabc..922d139d 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/MetersTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/MetersTest.java @@ -48,8 +48,7 @@ class MetersTest { private static final PolicyType POLICY_TYPE_1 = PolicyType.builder().id(POLICY_TYPE_1_NAME).schema("").build(); private static final Ric RIC_1 = new Ric(RicConfig.builder().ricId("ric_1").baseUrl("baseUrl1") - .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))).controllerName("controllerName") - .build()); + .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))).build()); private static final String POLICY_1_ID = "policyId1"; private static final Policy POLICY_1 = Policy.builder().id(POLICY_1_ID).json("").ownerServiceId("service") diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java index 1b41ce08..77464300 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java @@ -70,7 +70,6 @@ class RicSupervisionTest { .ricId("ric_1") // .baseUrl("baseUrl1") // .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) // - .controllerName("controllerName") // .build()); private static final String POLICY_1_ID = "policyId1"; diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java index c2f419fb..1a6f1904 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java @@ -112,7 +112,6 @@ class RicSynchronizationTaskTest { ric1 = new Ric(RicConfig.builder() // .ricId(RIC_1_NAME) // .baseUrl("baseUrl1") // - .controllerName("controllerName") // .build()); policy1 = createPolicy("policyId1", false); policyTypes = new PolicyTypes(appConfig); |