Removed code that stored configuration in DB
[sdc.git] / common / onap-common-configuration-management / onap-configuration-management-core / src / test / java / org / onap / config / util / TestUtil.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.config.util;
18
19 import java.io.File;
20 import java.io.FileWriter;
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.List;
24 import org.junit.Assert;
25 import org.onap.config.api.Configuration;
26 import org.onap.config.api.ConfigurationManager;
27
28 /**
29  * Created by sheetalm on 10/13/2016.
30  */
31 public class TestUtil {
32
33     public final static String jsonSchemaLoc = System.getProperty("user.home")+"/TestResources/";
34     public static FileWriter fileWriter ;
35
36     public static void writeFile(String data) throws IOException {
37         File dir = new File(jsonSchemaLoc);
38         dir.mkdirs();
39         File file = new File(jsonSchemaLoc+"/GeneratorsList.json");
40         file.createNewFile();
41         fileWriter = new FileWriter(file);
42         fileWriter.write(data);
43         fileWriter.close();
44     }
45
46     public static void cleanUp() throws Exception {
47         String data = "{name:\"SCM\"}";
48         TestUtil.writeFile(data);
49     }
50
51     public static void validateConfiguraton(String nameSpace) {
52         Configuration config = ConfigurationManager.lookup();
53
54         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH ), "14");
55
56         // First value from list is picked from Merge properties
57         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_MAXSIZE ), "1048576");
58
59         List<String> expectedExtList = new ArrayList<String>();
60         expectedExtList.add("pdf");
61         expectedExtList.add("zip");
62         expectedExtList.add("xml");
63         expectedExtList.add("pdf");
64         expectedExtList.add("tgz");
65         expectedExtList.add("xls");
66         List<String> extList = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_EXT);
67         Assert.assertEquals(expectedExtList, extList);
68
69         List<String> expectedEncList = new ArrayList<String>();
70         expectedEncList.add("Base64");
71         expectedEncList.add("MD5");
72         List<String> encList = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_ENC);
73         Assert.assertEquals(expectedEncList, encList);
74
75         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_UPPER ), "a-zA-Z_0-9");
76         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_LOWER ), "a-zA-Z");
77         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_STATUS ), "deleted");
78
79         List<String> expectedLocList = new ArrayList<String>();
80         expectedLocList.add("/opt/spool");
81         expectedLocList.add(System.getProperty("user.home")+"/asdc");
82         List<String> locList = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_LOC);
83         Assert.assertEquals(expectedLocList, locList);
84
85         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_JSON_SCHEMA ), "@GeneratorList.json");
86
87         Assert.assertEquals("@"+System.getenv("Path")+"/myschema.json",config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
88
89         List<String> artifactConsumer = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER );
90         Assert.assertEquals(config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER_APPC ), artifactConsumer);
91
92         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH ), "6");
93         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_MANDATORY_NAME ), "true");
94         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_ENCODED ), "true");
95     }
96 }