summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorJoanna Jeremicz <joanna.jeremicz@nokia.com>2021-01-29 15:43:31 +0100
committerJoanna Jeremicz <joanna.jeremicz@nokia.com>2021-02-09 07:44:39 +0100
commite36a970232174fcb4dc4aecf3d6522f7364d6425 (patch)
tree7f48a40e2d3829dca71540c285e64576b44dbba1 /src/test
parent5e694ba1575828a51704d2804471918ab5280aa1 (diff)
Add files processing config provider
- Add system variables provider - Add junit tests Issue-ID: DCAEGEN2-2600 Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com> Change-Id: Ib045270033f8f5ccbd99fc5ae30d0efa9a911a95
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/dcaegen2/services/pmmapper/config/FilesProcessingConfigTest.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/config/FilesProcessingConfigTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/config/FilesProcessingConfigTest.java
new file mode 100644
index 0000000..fd21a39
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/config/FilesProcessingConfigTest.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nokia.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.services.pmmapper.config;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+import org.onap.dcaegen2.services.pmmapper.exceptions.EnvironmentConfigException;
+
+public class FilesProcessingConfigTest {
+
+ private static final String ENV_LIMIT_RATE = "PROCESSING_LIMIT_RATE";
+
+ private EnvironmentReader mockEnvironmentReader = mock(EnvironmentReader.class);
+ private FilesProcessingConfig filesProcessingConfig;
+
+ @Test
+ public void shouldReturnCorrectValue_whenVariableIsSet() throws EnvironmentConfigException {
+ when(mockEnvironmentReader.getVariable(ENV_LIMIT_RATE)).thenReturn("128");
+ filesProcessingConfig = new FilesProcessingConfig(mockEnvironmentReader);
+ int limitRate = filesProcessingConfig.getLimitRate();
+
+ assertEquals(128, limitRate);
+ }
+
+ @Test
+ public void shouldThrowEnvironmentConfigException_whenVariableHasWrongValue() {
+ when(mockEnvironmentReader.getVariable(ENV_LIMIT_RATE)).thenReturn("not-an-int");
+ filesProcessingConfig = new FilesProcessingConfig(mockEnvironmentReader);
+ String expectedMessage = "PROCESSING_LIMIT_RATE environment variable has incorrect value.\n";
+ String causeMessage = "For input string: \"not-an-int\"";
+
+ Throwable exception = assertThrows(EnvironmentConfigException.class, () -> filesProcessingConfig.getLimitRate());
+ assertEquals(expectedMessage, exception.getMessage());
+ assertEquals(causeMessage, exception.getCause().getMessage());
+ }
+
+ @Test
+ public void shouldReturnDefaultValue_whenVariableIsNotSet() throws EnvironmentConfigException {
+ filesProcessingConfig = new FilesProcessingConfig(mockEnvironmentReader);
+ int limitRate = filesProcessingConfig.getLimitRate();
+
+ assertEquals(1, limitRate);
+ }
+}