2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.applicationconfig.dao;
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;
40 public class ApplicationConfigImplDaoTest {
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();
53 private final static Logger log = (Logger) LoggerFactory.getLogger
54 (ApplicationConfigImplDaoTest.class.getName());
56 private final Logger logger = (Logger) LoggerFactory.getLogger(this.getClass().getName());
59 public static void init() {
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");
69 applicationConfigDao.create(applicationConfigEntity1);
70 applicationConfigDao.create(applicationConfigEntity2);
71 applicationConfigDao.create(applicationConfigEntity3);
73 } catch (Exception 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).
83 private static String loadFileToString(String path) {
84 return new String(FileUtils.toByteArray(FileUtils.loadFileToInputStream(path)));
88 public void testApplicationConfigTimestampValue() {
89 ConfigurationData configurationData = applicationConfig
90 .getConfigurationData("test - namespace", "vsp");
92 Assert.assertNotNull(configurationData);
93 Assert.assertNotEquals(configurationData.getTimeStamp(), 0);
97 @Test(dependsOnMethods = "testApplicationConfigTimestampValue")
98 public void testNotExistingApplicationConfigTimestampValue() {
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");
109 @Test(dependsOnMethods = "testApplicationConfigTimestampValue")
110 public void testInsertApplicationConfiguration() {
111 String testTemplate = loadFileToString("questionnaire/testTemplate.txt");
112 applicationConfig.insertValue("test_namespace", "test_key", testTemplate);
114 Assert.assertEquals(testTemplate,
115 applicationConfig.getConfigurationData("test_namespace", "test_key").getValue());