[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / backend / openecomp-sdc-application-config-manager / src / test / java / org / openecomp / sdc / applicationconfig / ApplicationConfigManagerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.applicationconfig;
22
23 import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
24 import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
25 import org.openecomp.sdc.applicationconfig.impl.ApplicationConfigManagerImpl;
26 import org.openecomp.sdc.common.errors.CoreException;
27 import org.testng.Assert;
28 import org.testng.annotations.Test;
29
30 import java.util.Collection;
31
32 /**
33  * Created by Talio on 8/9/2016.
34  */
35 public class ApplicationConfigManagerTest {
36
37   public static final String TEST_NAMESPACE_1 = "test-app-namespace";
38   public static final String TEST_NAMESPACE_2 = "test-namespace";
39   public static final String TEST_KEY = "test-app-key";
40   public static final String TEST_VALUE = "test-app-value";
41   ApplicationConfigManager applicationConfigManager = new ApplicationConfigManagerImpl();
42
43   @Test
44   public void testInsertIntoTable() {
45     try {
46       applicationConfigManager.insertIntoTable(TEST_NAMESPACE_1, TEST_KEY, TEST_VALUE);
47     } catch (CoreException exception) {
48       Assert.assertEquals(exception.getMessage(),
49           "Error occurred while loading questionnaire schema templates");
50     }
51   }
52
53
54   @Test(dependsOnMethods = "testInsertIntoTable")
55   public void testGetValueFromTable() {
56     ConfigurationData value = applicationConfigManager.getFromTable(TEST_NAMESPACE_1, TEST_KEY);
57
58     Assert.assertEquals(value.getValue(), TEST_VALUE);
59   }
60
61
62   @Test(dependsOnMethods = "testInsertIntoTable")
63   public void testGetValueFromTableNegative() {
64     try {
65       ConfigurationData value =
66           applicationConfigManager.getFromTable("not-existing-namespace", "not-existing-key");
67     } catch (CoreException ce) {
68       Assert.assertEquals(ce.getMessage(),
69           "Configuration for namespace not-existing-namespace and key not-existing-key was not found");
70     }
71
72   }
73
74   @Test
75   public void testGetList() {
76     applicationConfigManager.insertIntoTable(TEST_NAMESPACE_2, "key1", "val1");
77     applicationConfigManager.insertIntoTable(TEST_NAMESPACE_2, "key2", "val2");
78     applicationConfigManager.insertIntoTable(TEST_NAMESPACE_2, "key3", "val3");
79
80     Collection<ApplicationConfigEntity> ACElist =
81         applicationConfigManager.getListOfConfigurationByNamespace(TEST_NAMESPACE_2);
82
83     Assert.assertNotNull(ACElist);
84     Assert.assertEquals(ACElist.size(), 3);
85   }
86 }