From 4b4404a2ab0b239a1cc17510196195ec599d66ae Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Fri, 21 Aug 2020 11:35:17 +0200 Subject: Some improvements if NBI V2.0 Improved generated swagger API. Furter alignments to https://opensource.zalando.com/restful-api-guidelines/#118 Improved unitttest for faulty JSON in configuration. Changed names: "NonRT-RIC" to "Non-RT RIC" and "NearRT-RIC" to "Near-RT RIC" Change-Id: I4ca0d45605a770b5c33e34019671e088e3fe979d Issue-ID: CCSDK-2498 Signed-off-by: PatrikBuhr --- .../ApplicationTestV2.java | 2 +- .../tasks/RefreshConfigTaskTest.java | 35 +++++++--------------- 2 files changed, 11 insertions(+), 26 deletions(-) (limited to 'a1-policy-management/src/test') diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/ApplicationTestV2.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/ApplicationTestV2.java index 3a7068d6..591b29c9 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/ApplicationTestV2.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/ApplicationTestV2.java @@ -255,7 +255,7 @@ class ApplicationTestV2 { Policy policy2 = addPolicy("policyId2", "typeName", "service", ric1Name); Ric ric2 = addRic("ric2"); - getA1Client(ric1Name).putPolicy(policy2); // put it in the RIC (NearRT-RIC) + getA1Client(ric1Name).putPolicy(policy2); // put it in the RIC (Near-RT RIC) policies.remove(policy2); // Remove it from the repo -> should be deleted in the RIC String policyId = "policyId"; diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java index 72b20600..572ba0b5 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java @@ -143,21 +143,6 @@ class RefreshConfigTaskTest { assertThat(logAppender.list.get(0).getFormattedMessage()).isEqualTo("Configuration refresh terminated"); } - @Test - void startWithStubbedRefreshReturnError_thenErrorAndTerminationLogged() { - refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_DOES_NOT_EXIST, null, null, false); - String errorMessage = "Error"; - doReturn(Flux.error(new Exception(errorMessage))).when(refreshTaskUnderTest).createRefreshTask(); - - final ListAppender logAppender = LoggingUtils.getLogListAppender(RefreshConfigTask.class, ERROR); - - refreshTaskUnderTest.start(); - - ILoggingEvent event = logAppender.list.get(0); - assertThat(event.getFormattedMessage()) - .isEqualTo("Configuration refresh terminated due to exception java.lang.Exception: " + errorMessage); - } - @Test void stop_thenTaskIsDisposed() throws Exception { refreshTaskUnderTest = this.createTestObject(CONFIG_FILE_DOES_NOT_EXIST, null, null, false); @@ -202,7 +187,8 @@ class RefreshConfigTaskTest { refreshTaskUnderTest.systemEnvironment = new Properties(); // When - doReturn(getIncorrectJson()).when(refreshTaskUnderTest).createInputStream(any()); + final String JUNK_JSON = "{\"junk }"; + doReturn(getJsonSteam(JUNK_JSON)).when(refreshTaskUnderTest).createInputStream(any()); doReturn("fileName").when(appConfig).getLocalConfigurationFilePath(); final ListAppender logAppender = LoggingUtils.getLogListAppender(RefreshConfigTask.class, ERROR); @@ -269,7 +255,7 @@ class RefreshConfigTaskTest { doReturn(Mono.just(props)).when(refreshTaskUnderTest).getEnvironment(any()); doReturn(Mono.just(cbsClient)).when(refreshTaskUnderTest).createCbsClient(props); - JsonObject configAsJson = getJsonRootObject(true); + JsonObject configAsJson = getJsonRootObject(getCorrectJson()); String newBaseUrl = "newBaseUrl"; modifyTheRicConfiguration(configAsJson, newBaseUrl); when(cbsClient.get(any())).thenReturn(Mono.just(configAsJson)); @@ -309,8 +295,8 @@ class RefreshConfigTaskTest { doReturn(Mono.just(props)).when(refreshTaskUnderTest).getEnvironment(any()); doReturn(Mono.just(cbsClient)).when(refreshTaskUnderTest).createCbsClient(props); - JsonObject configAsJson = getJsonRootObject(false); - when(cbsClient.get(any())).thenReturn(Mono.just(configAsJson)); + JsonObject emptyJsonObject = new JsonObject(); + when(cbsClient.get(any())).thenReturn(Mono.just(emptyJsonObject)); final ListAppender logAppender = LoggingUtils.getLogListAppender(RefreshConfigTask.class, ERROR); @@ -368,9 +354,9 @@ class RefreshConfigTaskTest { .addProperty("baseUrl", newBaseUrl); } - private JsonObject getJsonRootObject(boolean valid) throws JsonIOException, JsonSyntaxException, IOException { - JsonObject rootObject = JsonParser - .parseReader(new InputStreamReader(valid ? getCorrectJson() : getIncorrectJson())).getAsJsonObject(); + private JsonObject getJsonRootObject(InputStream inStream) + throws JsonIOException, JsonSyntaxException, IOException { + JsonObject rootObject = JsonParser.parseReader(new InputStreamReader(inStream)).getAsJsonObject(); return rootObject; } @@ -380,8 +366,7 @@ class RefreshConfigTaskTest { return new ByteArrayInputStream((string.getBytes(StandardCharsets.UTF_8))); } - private static InputStream getIncorrectJson() { - String string = "{}"; // - return new ByteArrayInputStream((string.getBytes(StandardCharsets.UTF_8))); + private static InputStream getJsonSteam(String json) { + return new ByteArrayInputStream((json.getBytes(StandardCharsets.UTF_8))); } } -- cgit 1.2.3-korg