aboutsummaryrefslogtreecommitdiffstats
path: root/appc-core
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-03-04 09:52:33 +0000
committerTakamune Cho <takamune.cho@att.com>2019-03-04 14:46:44 +0000
commit06e71bf9229ae31f5967916bd1f01c6411bdffec (patch)
tree7c6519685add07dd075210c0fc94ef6f7667855a /appc-core
parent7316b093075f93adbe09bc50f9d54d88f677155d (diff)
Test coverage in DefaultConfiguration
Increased coverage from 79% to 89% Issue-ID: APPC-1520 Change-Id: I6a7fccb7768fe6eb996055be4d14bc366c228feb Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-core')
-rw-r--r--appc-core/appc-common-bundle/src/test/java/org/onap/appc/configuration/DefaultConfigurationTest.java28
1 files changed, 25 insertions, 3 deletions
diff --git a/appc-core/appc-common-bundle/src/test/java/org/onap/appc/configuration/DefaultConfigurationTest.java b/appc-core/appc-common-bundle/src/test/java/org/onap/appc/configuration/DefaultConfigurationTest.java
index aed414192..95429f053 100644
--- a/appc-core/appc-common-bundle/src/test/java/org/onap/appc/configuration/DefaultConfigurationTest.java
+++ b/appc-core/appc-common-bundle/src/test/java/org/onap/appc/configuration/DefaultConfigurationTest.java
@@ -7,6 +7,8 @@
* Copyright (C) 2017 Amdocs
* =============================================================================
* Modification Copyright (C) 2018 IBM.
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,14 +34,22 @@ import java.util.Properties;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mockito;
+import org.onap.appc.encryption.EncryptionTool;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.reflect.Whitebox;
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(EncryptionTool.class)
public class DefaultConfigurationTest {
private static final String propKey1 = "testKey1";
private static final String propKey2 = "testKey2";
private static final String propValue1 = "testValue1";
private static final String propValue2 = "testValue2";
+ private EncryptionTool encryptionTool;
private Properties prop = new Properties();
private DefaultConfiguration defaultConfiguration;
@@ -50,6 +60,9 @@ public class DefaultConfigurationTest {
prop.setProperty(propKey2, propValue2);
defaultConfiguration = new DefaultConfiguration();
+ PowerMockito.mockStatic(EncryptionTool.class);
+ encryptionTool = Mockito.mock(EncryptionTool.class);
+ PowerMockito.when(EncryptionTool.getInstance()).thenReturn(encryptionTool);
}
@Test
@@ -105,16 +118,25 @@ public class DefaultConfigurationTest {
defaultConfiguration.setProperty(booleanKey, "abc");
Assert.assertFalse(defaultConfiguration.getBooleanProperty(booleanKey));
}
-
+
@Test
public void testSetPropAndGetBooleanPropertyForEncryptedValue()
{
String booleanKey = "booleanKey";
+ Mockito.when(encryptionTool.decrypt("enc:true")).thenReturn("true");
defaultConfiguration.setProperty(booleanKey, "enc:true");
+ Assert.assertTrue(defaultConfiguration.getBooleanProperty(booleanKey));
+ }
+
+ @Test
+ public void testSetPropAndGetBooleanPropertyForEncryptedValueException()
+ {
+ String booleanKey = "booleanKey";
+ Mockito.when(encryptionTool.decrypt("enc:false")).thenThrow(new RuntimeException());
+ defaultConfiguration.setProperty(booleanKey, "enc:false");
Assert.assertFalse(defaultConfiguration.getBooleanProperty(booleanKey));
}
-
-
+
@Test
public void testSetPropAndGetBooleanPropertyWithDefaultValue() throws Exception {
String booleanKey = "booleanKey";