summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-application-config-manager
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-application-config-manager')
-rw-r--r--openecomp-be/backend/openecomp-sdc-application-config-manager/pom.xml55
-rw-r--r--openecomp-be/backend/openecomp-sdc-application-config-manager/src/main/java/org/openecomp/sdc/applicationconfig/ApplicationConfigManager.java35
-rw-r--r--openecomp-be/backend/openecomp-sdc-application-config-manager/src/main/java/org/openecomp/sdc/applicationconfig/impl/ApplicationConfigManagerImpl.java63
-rw-r--r--openecomp-be/backend/openecomp-sdc-application-config-manager/src/test/java/org/openecomp/sdc/applicationconfig/ApplicationConfigManagerTest.java64
4 files changed, 217 insertions, 0 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-application-config-manager/pom.xml b/openecomp-be/backend/openecomp-sdc-application-config-manager/pom.xml
new file mode 100644
index 0000000000..437114404f
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-application-config-manager/pom.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>backend</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-application-config-manager</artifactId>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.3.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>1.14</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-config-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>6.9.10</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.19.1</version>
+ <configuration>
+ <skipTests>true</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project> \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-application-config-manager/src/main/java/org/openecomp/sdc/applicationconfig/ApplicationConfigManager.java b/openecomp-be/backend/openecomp-sdc-application-config-manager/src/main/java/org/openecomp/sdc/applicationconfig/ApplicationConfigManager.java
new file mode 100644
index 0000000000..924401b9c1
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-application-config-manager/src/main/java/org/openecomp/sdc/applicationconfig/ApplicationConfigManager.java
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.applicationconfig;
+
+import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
+import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
+
+import java.util.Collection;
+
+public interface ApplicationConfigManager {
+
+ void insertIntoTable(String namespace, String key, String value);
+
+ ConfigurationData getFromTable(String namespace, String key);
+
+ Collection<ApplicationConfigEntity> getListOfConfigurationByNamespace(String namespace);
+}
diff --git a/openecomp-be/backend/openecomp-sdc-application-config-manager/src/main/java/org/openecomp/sdc/applicationconfig/impl/ApplicationConfigManagerImpl.java b/openecomp-be/backend/openecomp-sdc-application-config-manager/src/main/java/org/openecomp/sdc/applicationconfig/impl/ApplicationConfigManagerImpl.java
new file mode 100644
index 0000000000..b44c541261
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-application-config-manager/src/main/java/org/openecomp/sdc/applicationconfig/impl/ApplicationConfigManagerImpl.java
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.applicationconfig.impl;
+
+import org.openecomp.core.utilities.applicationconfig.ApplicationConfig;
+import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
+import org.openecomp.core.utilities.applicationconfig.impl.ApplicationConfigImpl;
+import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
+import org.openecomp.sdc.applicationconfig.ApplicationConfigManager;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.common.errors.ErrorCode;
+
+import java.util.Collection;
+
+public class ApplicationConfigManagerImpl implements ApplicationConfigManager {
+ private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR =
+ "SCHEMA_GENERATOR_INITIALIZATION_ERROR";
+ private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG =
+ "Error occurred while loading questionnaire schema templates";
+ private ApplicationConfig applicationConfig = new ApplicationConfigImpl();
+
+ @Override
+ public void insertIntoTable(String namespace, String key, String value) {
+ try {
+ applicationConfig.insertValue(namespace, key, value);
+ } catch (Exception exception) {
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder()
+ .withCategory(ErrorCategory.APPLICATION)
+ .withId(SCHEMA_GENERATOR_INITIALIZATION_ERROR)
+ .withMessage(SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG)
+ .build());
+ }
+ }
+
+ @Override
+ public ConfigurationData getFromTable(String namespace, String key) {
+ return applicationConfig.getConfigurationData(namespace, key);
+ }
+
+ @Override
+ public Collection<ApplicationConfigEntity> getListOfConfigurationByNamespace(String namespace) {
+ return applicationConfig.getListOfConfigurationByNamespace(namespace);
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-application-config-manager/src/test/java/org/openecomp/sdc/applicationconfig/ApplicationConfigManagerTest.java b/openecomp-be/backend/openecomp-sdc-application-config-manager/src/test/java/org/openecomp/sdc/applicationconfig/ApplicationConfigManagerTest.java
new file mode 100644
index 0000000000..291ef18e19
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-application-config-manager/src/test/java/org/openecomp/sdc/applicationconfig/ApplicationConfigManagerTest.java
@@ -0,0 +1,64 @@
+package org.openecomp.sdc.applicationconfig;
+
+import org.openecomp.sdc.applicationconfig.impl.ApplicationConfigManagerImpl;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
+import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.util.Collection;
+
+public class ApplicationConfigManagerTest {
+
+ public static final String TEST_NAMESPACE_1 = "test-app-namespace";
+ public static final String TEST_NAMESPACE_2 = "test-namespace";
+ public static final String TEST_KEY = "test-app-key";
+ public static final String TEST_VALUE = "test-app-value";
+ ApplicationConfigManager applicationConfigManager = new ApplicationConfigManagerImpl();
+
+ @Test
+ public void testInsertIntoTable() {
+ try {
+ applicationConfigManager.insertIntoTable(TEST_NAMESPACE_1, TEST_KEY, TEST_VALUE);
+ } catch (CoreException e) {
+ Assert.assertEquals(e.getMessage(),
+ "Error occurred while loading questionnaire schema templates");
+ }
+ }
+
+
+ @Test(dependsOnMethods = "testInsertIntoTable")
+ public void testGetValueFromTable() {
+ ConfigurationData value = applicationConfigManager.getFromTable(TEST_NAMESPACE_1, TEST_KEY);
+
+ Assert.assertEquals(value.getValue(), TEST_VALUE);
+ }
+
+
+ @Test(dependsOnMethods = "testInsertIntoTable")
+ public void testGetValueFromTableNegative() {
+ try {
+ ConfigurationData value =
+ applicationConfigManager.getFromTable("not-existing-namespace", "not-existing-key");
+ } catch (CoreException ce) {
+ Assert.assertEquals(ce.getMessage(),
+ "Configuration for namespace not-existing-namespace and key not-existing-key was not found");
+ }
+
+ }
+
+ @Test
+ public void testGetList() {
+ applicationConfigManager.insertIntoTable(TEST_NAMESPACE_2, "key1", "val1");
+ applicationConfigManager.insertIntoTable(TEST_NAMESPACE_2, "key2", "val2");
+ applicationConfigManager.insertIntoTable(TEST_NAMESPACE_2, "key3", "val3");
+
+ Collection<ApplicationConfigEntity> ACElist =
+ applicationConfigManager.getListOfConfigurationByNamespace(TEST_NAMESPACE_2);
+
+ Assert.assertNotNull(ACElist);
+ Assert.assertEquals(ACElist.size(), 3);
+ }
+}