6d923304934973f73234dd64cabacb394bcf65f0
[sdc.git] /
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   /*
41
42   private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR =
43       "SCHEMA_GENERATOR_INITIALIZATION_ERROR";
44   private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG =
45       "Error occurred while loading questionnaire schema templates";
46   private static ApplicationConfigDao applicationConfigDao =
47       ApplicationConfigDaoFactory.getInstance().createInterface();
48   private static ApplicationConfig applicationConfig =
49       ApplicationConfigFactory.getInstance().createInterface();
50
51   @BeforeClass
52   public static void init() {
53     try {
54
55       ApplicationConfigEntity applicationConfigEntity1 =
56           new ApplicationConfigEntity("test - namespace", "vsp", "vspTemplate");
57       ApplicationConfigEntity applicationConfigEntity2 =
58           new ApplicationConfigEntity("test - namespace", "nic", "nicTemplate");
59       ApplicationConfigEntity applicationConfigEntity3 =
60           new ApplicationConfigEntity("test - namespace", "component", "componentTemplate");
61
62       applicationConfigDao.create(applicationConfigEntity1);
63       applicationConfigDao.create(applicationConfigEntity2);
64       applicationConfigDao.create(applicationConfigEntity3);
65
66     } catch (Exception e) {
67       throw new CoreException(new ErrorCode.ErrorCodeBuilder().
68           withCategory(ErrorCategory.APPLICATION).
69           withId(SCHEMA_GENERATOR_INITIALIZATION_ERROR).
70           withMessage(SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG).
71           build());
72     }
73   }
74
75   private static String loadFileToString(String path) {
76     return new String(FileUtils.toByteArray(FileUtils.loadFileToInputStream(path)));
77   }
78
79   @Test
80   public void testApplicationConfigTimestampValue() {
81     ConfigurationData configurationData = applicationConfig
82         .getConfigurationData("test - namespace", "vsp");
83
84     Assert.assertNotNull(configurationData);
85     Assert.assertNotEquals(configurationData.getTimeStamp(), 0);
86
87   }
88
89   @Test(dependsOnMethods = "testApplicationConfigTimestampValue")
90   public void testNotExistingApplicationConfigTimestampValue() {
91     try {
92       applicationConfig.getConfigurationData("test - namespace", "aaa");
93     } catch (CoreException ce) {
94       Assert.assertEquals(ce.getMessage(),
95           "Configuration for namespace test - namespace and key aaa was not found");
96     }
97
98   }
99
100   @Test(dependsOnMethods = "testApplicationConfigTimestampValue")
101   public void testInsertApplicationConfiguration() {
102     String testTemplate = loadFileToString("questionnaire/testTemplate.txt");
103     applicationConfig.insertValue("test_namespace", "test_key", testTemplate);
104
105     Assert.assertEquals(testTemplate,
106         applicationConfig.getConfigurationData("test_namespace", "test_key").getValue());
107   }
108 */
109 }