diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/test/java')
2 files changed, 65 insertions, 96 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/test/java/org/openecomp/core/nosqldb/util/CassandraConfigurationManagerTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/test/java/org/openecomp/core/nosqldb/util/CassandraConfigurationManagerTest.java new file mode 100644 index 0000000000..021f1c715b --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/test/java/org/openecomp/core/nosqldb/util/CassandraConfigurationManagerTest.java @@ -0,0 +1,65 @@ +/* + * Copyright © 2016-2018 European Support Limited + * ================================================================================ + * Modifications Copyright (C) 2021 AT&T. + * ================================================================================ + * 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. + */ + +package org.openecomp.core.nosqldb.util; + +import java.io.FileNotFoundException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * @author EVITALIY + * @since 22 Oct 17 + */ +public class CassandraConfigurationManagerTest { + + private static final String NON_EXISTENT = "unexistentfile"; + + @AfterEach + public void resetSystemVar() { + System.clearProperty(CassandraConfigurationManager.JVM_PARAM_CONFIGURATION_FILE); + } + + @Test + public void testGetInstanceSystemProperty() throws Throwable { + System.setProperty(CassandraConfigurationManager.JVM_PARAM_CONFIGURATION_FILE, NON_EXISTENT); + RuntimeException e = Assertions.assertThrows(RuntimeException.class,()-> { + CassandraConfigurationManager.getInstance(); + }); + Assertions.assertTrue(e.getCause() instanceof FileNotFoundException); + Assertions.assertEquals("Failed to read configuration unexistentfile",e.getMessage()); + } + + @Test() + public void testGetInstanceDefault() { + // Do not set the JVM param for config file, by default code will get it from Resource + CassandraConfigurationManager manager = CassandraConfigurationManager.getInstance(); + Assertions.assertArrayEquals(new String[] {"127.0.0.1"}, manager.getAddresses()); + Assertions.assertEquals(9042, manager.getCassandraPort()); + Assertions.assertEquals("dox", manager.getKeySpace()); + Assertions.assertEquals("LOCAL_QUORUM", manager.getConsistencyLevel()); + Assertions.assertEquals(null, manager.getLocalDataCenter()); + Assertions.assertEquals("Aa1234%^!", manager.getPassword()); + Assertions.assertEquals(30000L, manager.getReconnectTimeout().longValue()); + Assertions.assertEquals("/path/path", manager.getTruststorePath()); + Assertions.assertEquals("Aa123456", manager.getTruststorePassword()); + Assertions.assertFalse(manager.isSsl()); + Assertions.assertFalse(manager.isAuthenticate()); + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/test/java/org/openecomp/core/nosqldb/util/ConfigurationManagerTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/test/java/org/openecomp/core/nosqldb/util/ConfigurationManagerTest.java deleted file mode 100644 index d6e7245450..0000000000 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/test/java/org/openecomp/core/nosqldb/util/ConfigurationManagerTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright © 2016-2018 European Support Limited - * - * 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. - */ - -package org.openecomp.core.nosqldb.util; - -import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertNotNull; - -import java.io.Closeable; -import java.io.IOException; -import java.lang.reflect.Field; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -/** - * @author EVITALIY - * @since 22 Oct 17 - */ -public class ConfigurationManagerTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private static final String NON_EXISTENT = "unexistentfile"; - - @Before - public void resetInstance() throws NoSuchFieldException, IllegalAccessException { - Field field = ConfigurationManager.class.getDeclaredField("instance"); - field.setAccessible(true); - field.set(null, null); - } - - @Test - public void testGetInstanceSystemProperty() throws Throwable { - - expectedException.expect(IOException.class); - expectedException.expectMessage(containsString(NON_EXISTENT)); - - try (ConfigurationSystemPropertyUpdater updater = new ConfigurationSystemPropertyUpdater(NON_EXISTENT)) { - ConfigurationManager.getInstance(); - } catch (RuntimeException e) { - Throwable cause = e.getCause(); - throw cause == null ? e : cause; - } - } - - @Test() - public void testGetInstanceDefault() { - - try (ConfigurationSystemPropertyUpdater property = new ConfigurationSystemPropertyUpdater()) { - ConfigurationManager manager = ConfigurationManager.getInstance(); - assertNotNull(manager.getUsername()); - } - } - - - private static class ConfigurationSystemPropertyUpdater implements Closeable { - - private final String oldValue; - - private ConfigurationSystemPropertyUpdater(String value) { - this.oldValue = System.getProperty(ConfigurationManager.CONFIGURATION_YAML_FILE); - System.setProperty(ConfigurationManager.CONFIGURATION_YAML_FILE, value); - } - - private ConfigurationSystemPropertyUpdater() { - this.oldValue = System.getProperty(ConfigurationManager.CONFIGURATION_YAML_FILE); - System.clearProperty(ConfigurationManager.CONFIGURATION_YAML_FILE); - } - - @Override - public void close() { - - if (oldValue == null) { - System.clearProperty(ConfigurationManager.CONFIGURATION_YAML_FILE); - } else { - System.setProperty(ConfigurationManager.CONFIGURATION_YAML_FILE, oldValue); - } - } - } -} |