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 public class ApplicationConfigImplDaoTest {
27 private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR =
28 "SCHEMA_GENERATOR_INITIALIZATION_ERROR";
29 private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG =
30 "Error occurred while loading questionnaire schema templates";
31 private static ApplicationConfigDao applicationConfigDao =
32 ApplicationConfigDaoFactory.getInstance().createInterface();
33 private static ApplicationConfig applicationConfig =
34 ApplicationConfigFactory.getInstance().createInterface();
36 private final static Logger log = (Logger) LoggerFactory.getLogger
37 (ApplicationConfigImplDaoTest.class.getName());
39 private final Logger logger = (Logger) LoggerFactory.getLogger(this.getClass().getName());
42 public static void init() {
45 ApplicationConfigEntity applicationConfigEntity1 =
46 new ApplicationConfigEntity("test - namespace", "vsp", "vspTemplate");
47 ApplicationConfigEntity applicationConfigEntity2 =
48 new ApplicationConfigEntity("test - namespace", "nic", "nicTemplate");
49 ApplicationConfigEntity applicationConfigEntity3 =
50 new ApplicationConfigEntity("test - namespace", "component", "componentTemplate");
52 applicationConfigDao.create(applicationConfigEntity1);
53 applicationConfigDao.create(applicationConfigEntity2);
54 applicationConfigDao.create(applicationConfigEntity3);
56 } catch (Exception e) {
58 throw new CoreException(new ErrorCode.ErrorCodeBuilder().
59 withCategory(ErrorCategory.APPLICATION).
60 withId(SCHEMA_GENERATOR_INITIALIZATION_ERROR).
61 withMessage(SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG).
66 private static String loadFileToString(String path) {
67 return new String(FileUtils.toByteArray(FileUtils.loadFileToInputStream(path)));
71 public void testApplicationConfigTimestampValue() {
72 ConfigurationData configurationData = applicationConfig
73 .getConfigurationData("test - namespace", "vsp");
75 Assert.assertNotNull(configurationData);
76 Assert.assertNotEquals(configurationData.getTimeStamp(), 0);
80 @Test(dependsOnMethods = "testApplicationConfigTimestampValue")
81 public void testNotExistingApplicationConfigTimestampValue() {
83 applicationConfig.getConfigurationData("test - namespace", "aaa");
84 } catch (CoreException ce) {
86 Assert.assertEquals(ce.getMessage(),
87 "Configuration for namespace test - namespace and key aaa was not found");
92 @Test(dependsOnMethods = "testApplicationConfigTimestampValue")
93 public void testInsertApplicationConfiguration() {
94 String testTemplate = loadFileToString("questionnaire/testTemplate.txt");
95 applicationConfig.insertValue("test_namespace", "test_key", testTemplate);
97 Assert.assertEquals(testTemplate,
98 applicationConfig.getConfigurationData("test_namespace", "test_key").getValue());