[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / lib / openecomp-core-lib / openecomp-config-lib / src / test / java / org / openecomp / sdc / applicationconfig / dao / ApplicationConfigImplDaoTest.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.dao;
22
23 import org.openecomp.core.utilities.applicationconfig.ApplicationConfig;
24 import org.openecomp.core.utilities.applicationconfig.ApplicationConfigFactory;
25 import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDao;
26 import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDaoFactory;
27 import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
28 import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
29 import org.openecomp.core.utilities.file.FileUtils;
30 import org.openecomp.sdc.common.errors.CoreException;
31 import org.openecomp.sdc.common.errors.ErrorCategory;
32 import org.openecomp.sdc.common.errors.ErrorCode;
33 import org.testng.Assert;
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.Test;
36
37
38 public class ApplicationConfigImplDaoTest {
39
40   private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR =
41       "SCHEMA_GENERATOR_INITIALIZATION_ERROR";
42   private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG =
43       "Error occurred while loading questionnaire schema templates";
44   private static ApplicationConfigDao applicationConfigDao =
45       ApplicationConfigDaoFactory.getInstance().createInterface();
46   private static ApplicationConfig applicationConfig =
47       ApplicationConfigFactory.getInstance().createInterface();
48
49   @BeforeClass
50   public static void init() {
51     try {
52
53       ApplicationConfigEntity applicationConfigEntity1 =
54           new ApplicationConfigEntity("test - namespace", "vsp", "vspTemplate");
55       ApplicationConfigEntity applicationConfigEntity2 =
56           new ApplicationConfigEntity("test - namespace", "nic", "nicTemplate");
57       ApplicationConfigEntity applicationConfigEntity3 =
58           new ApplicationConfigEntity("test - namespace", "component", "componentTemplate");
59
60       applicationConfigDao.create(applicationConfigEntity1);
61       applicationConfigDao.create(applicationConfigEntity2);
62       applicationConfigDao.create(applicationConfigEntity3);
63
64     } catch (Exception e) {
65       throw new CoreException(new ErrorCode.ErrorCodeBuilder().
66           withCategory(ErrorCategory.APPLICATION).
67           withId(SCHEMA_GENERATOR_INITIALIZATION_ERROR).
68           withMessage(SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG).
69           build());
70     }
71   }
72
73   private static String loadFileToString(String path) {
74     return new String(FileUtils.toByteArray(FileUtils.loadFileToInputStream(path)));
75   }
76
77   @Test
78   public void testApplicationConfigTimestampValue() {
79     ConfigurationData configurationData = applicationConfig
80         .getConfigurationData("test - namespace", "vsp");
81
82     Assert.assertNotNull(configurationData);
83     Assert.assertNotEquals(configurationData.getTimeStamp(), 0);
84
85   }
86
87   @Test(dependsOnMethods = "testApplicationConfigTimestampValue")
88   public void testNotExistingApplicationConfigTimestampValue() {
89     try {
90       applicationConfig.getConfigurationData("test - namespace", "aaa");
91     } catch (CoreException ce) {
92       Assert.assertEquals(ce.getMessage(),
93           "Configuration for namespace test - namespace and key aaa was not found");
94     }
95
96   }
97
98   @Test(dependsOnMethods = "testApplicationConfigTimestampValue")
99   public void testInsertApplicationConfiguration() {
100     String testTemplate = loadFileToString("questionnaire/testTemplate.txt");
101     applicationConfig.insertValue("test_namespace", "test_key", testTemplate);
102
103     Assert.assertEquals(testTemplate,
104         applicationConfig.getConfigurationData("test_namespace", "test_key").getValue());
105   }
106
107 }