1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*-
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.applicationconfig.dao;
import org.openecomp.core.utilities.applicationconfig.ApplicationConfig;
import org.openecomp.core.utilities.applicationconfig.ApplicationConfigFactory;
import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDao;
import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDaoFactory;
import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class ApplicationConfigImplDaoTest {
private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR =
"SCHEMA_GENERATOR_INITIALIZATION_ERROR";
private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG =
"Error occurred while loading questionnaire schema templates";
private static ApplicationConfigDao applicationConfigDao =
ApplicationConfigDaoFactory.getInstance().createInterface();
private static ApplicationConfig applicationConfig =
ApplicationConfigFactory.getInstance().createInterface();
@BeforeClass
public static void init() {
try {
ApplicationConfigEntity applicationConfigEntity1 =
new ApplicationConfigEntity("test - namespace", "vsp", "vspTemplate");
ApplicationConfigEntity applicationConfigEntity2 =
new ApplicationConfigEntity("test - namespace", "nic", "nicTemplate");
ApplicationConfigEntity applicationConfigEntity3 =
new ApplicationConfigEntity("test - namespace", "component", "componentTemplate");
applicationConfigDao.create(applicationConfigEntity1);
applicationConfigDao.create(applicationConfigEntity2);
applicationConfigDao.create(applicationConfigEntity3);
} catch (Exception e) {
throw new CoreException(new ErrorCode.ErrorCodeBuilder().
withCategory(ErrorCategory.APPLICATION).
withId(SCHEMA_GENERATOR_INITIALIZATION_ERROR).
withMessage(SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG).
build());
}
}
private static String loadFileToString(String path) {
return new String(FileUtils.toByteArray(FileUtils.loadFileToInputStream(path)));
}
@Test
public void testApplicationConfigTimestampValue() {
ConfigurationData configurationData = applicationConfig
.getConfigurationData("test - namespace", "vsp");
Assert.assertNotNull(configurationData);
Assert.assertNotEquals(configurationData.getTimeStamp(), 0);
}
@Test(dependsOnMethods = "testApplicationConfigTimestampValue")
public void testNotExistingApplicationConfigTimestampValue() {
try {
applicationConfig.getConfigurationData("test - namespace", "aaa");
} catch (CoreException ce) {
Assert.assertEquals(ce.getMessage(),
"Configuration for namespace test - namespace and key aaa was not found");
}
}
@Test(dependsOnMethods = "testApplicationConfigTimestampValue")
public void testInsertApplicationConfiguration() {
String testTemplate = loadFileToString("questionnaire/testTemplate.txt");
applicationConfig.insertValue("test_namespace", "test_key", testTemplate);
Assert.assertEquals(testTemplate,
applicationConfig.getConfigurationData("test_namespace", "test_key").getValue());
}
}
|