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