diff options
author | 2022-11-18 15:34:05 +0100 | |
---|---|---|
committer | 2022-11-18 14:43:35 +0000 | |
commit | 9ac52d8433cefa67cd56a05e28ec4acc85c99132 (patch) | |
tree | 244a5770e2d4de311e830e2afd2c7bd18252d45f /rest-services/cbs-client | |
parent | 892730e092b799f56b24cedeab371d2881d698b0 (diff) |
[CBS-CLIENT] Increase code coverage
- Add tests for CbsClientConfigMap
Issue-ID: DCAEGEN2-3165
Signed-off-by: Piotr Marcinkiewicz <piotr.marcinkiewicz@nokia.com>
Change-Id: I0e2f649cd27ad23608cb74aa4035854642236a61
Diffstat (limited to 'rest-services/cbs-client')
-rw-r--r-- | rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientConfigMapTest.java | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientConfigMapTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientConfigMapTest.java index aa5655fc..ef5f158e 100644 --- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientConfigMapTest.java +++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientConfigMapTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START==================================== * DCAEGEN2-SERVICES-SDK * ========================================================= - * Copyright (C) 2021 Nokia. All rights reserved. + * Copyright (C) 2021-2022 Nokia. All rights reserved. * Copyright (C) 2021 Wipro Limited. * ========================================================= * Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,6 +33,7 @@ import java.io.FileReader; import org.junit.Rule; import org.junit.contrib.java.lang.system.EnvironmentVariables; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsRequests; @@ -43,18 +44,22 @@ public class CbsClientConfigMapTest { private static final String SAMPLE_EXPECTED_CONFIG = "src/test/resources/sample_expected_service_config.json"; private static final String SAMPLE_EXPECTED_POLICY_CONFIG = "src/test/resources/sample_expected_policy_config.json"; private static final String SAMPLE_EXPECTED_ALL_CONFIG = "src/test/resources/sample_expected_all_config.json"; + private static final String CONFIG_MAP_FILE_PATH = "src/test/resources/application_config.yaml"; @Rule public final EnvironmentVariables envs = new EnvironmentVariables(); + @BeforeEach + void setUp() { + envs.set("AAF_USER", "admin"); + envs.set("AAF_PASSWORD", "admin_secret"); + } + @Test void shouldFetchUsingProperConfigMapFile() throws FileNotFoundException { // given - envs.set("AAF_USER", "admin"); - envs.set("AAF_PASSWORD", "admin_secret"); - String configMapFilePath = "src/test/resources/application_config.yaml"; String policySyncFilePath = "src/test/resources/policies.json"; String requestPath = "/service_component/app-name"; - final CbsClient cut = new CbsClientConfigMap(configMapFilePath, policySyncFilePath, requestPath); + final CbsClient cut = new CbsClientConfigMap(CONFIG_MAP_FILE_PATH, policySyncFilePath, requestPath); RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); @@ -69,12 +74,9 @@ public class CbsClientConfigMapTest { @Test void shouldFetchUsingConfigMapFileAndPolicySyncFile() throws FileNotFoundException { // given - envs.set("AAF_USER", "admin"); - envs.set("AAF_PASSWORD", "admin_secret"); - String configMapFilePath = "src/test/resources/application_config.yaml"; String policySyncFilePath = "src/test/resources/policies.json"; String requestPath = "/service_component_all/app-name"; - final CbsClient cut = new CbsClientConfigMap(configMapFilePath, policySyncFilePath, requestPath); + final CbsClient cut = new CbsClientConfigMap(CONFIG_MAP_FILE_PATH, policySyncFilePath, requestPath); RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); @@ -89,12 +91,9 @@ public class CbsClientConfigMapTest { @Test void shouldFetchUsingConfigMapFileWhenPolicySyncFileAbsent() throws FileNotFoundException { // given - envs.set("AAF_USER", "admin"); - envs.set("AAF_PASSWORD", "admin_secret"); - String configMapFilePath = "src/test/resources/application_config.yaml"; String policySyncFilePath = ""; String requestPath = "/service_component_all/app-name"; - final CbsClient cut = new CbsClientConfigMap(configMapFilePath, policySyncFilePath, requestPath); + final CbsClient cut = new CbsClientConfigMap(CONFIG_MAP_FILE_PATH, policySyncFilePath, requestPath); RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); @@ -106,6 +105,34 @@ public class CbsClientConfigMapTest { assertThat(result).isEqualTo(convertToJson(new JsonReader(new FileReader(SAMPLE_EXPECTED_ALL_CONFIG)))); } + @Test + void shouldVerifyConfigMapFileWhenFileIsCorrect() { + // given + String policySyncFilePath = "src/test/resources/policies.json"; + String requestPath = "/service_component/app-name"; + final CbsClientConfigMap cut = new CbsClientConfigMap(CONFIG_MAP_FILE_PATH, policySyncFilePath, requestPath); + + //when + boolean isCorrect = cut.verifyConfigMapFile(); + + // then + assertThat(isCorrect).isTrue(); + } + + @Test + void shouldVerifyConfigMapFileWhenFileDoesNotExist() { + // given + String notExistingFilePath = ""; + String requestPath = "/service_component/app-name"; + final CbsClientConfigMap cut = new CbsClientConfigMap(notExistingFilePath, notExistingFilePath, requestPath); + + //when + boolean isCorrect = cut.verifyConfigMapFile(); + + // then + assertThat(isCorrect).isFalse(); + } + private JsonObject convertToJson(JsonReader jsonReader) { Gson gson = new GsonBuilder().create(); return gson.fromJson(jsonReader, JsonObject.class); |