59078c2edb8025a501d91d85e965479b14a36c81
[sdc.git] / common / onap-common-configuration-management / onap-configuration-management-core / src / test / java / org / onap / config / util / TestUtil.java
1 package org.onap.config.util;
2
3 import java.io.File;
4 import java.io.FileWriter;
5 import java.io.IOException;
6 import java.util.ArrayList;
7 import java.util.List;
8
9 import org.junit.Assert;
10 import org.onap.config.ConfigurationUtils;
11 import org.onap.config.api.Configuration;
12 import org.onap.config.api.ConfigurationManager;
13
14 /**
15  * Created by sheetalm on 10/13/2016.
16  */
17 public class TestUtil {
18
19     public final static String jsonSchemaLoc = System.getProperty("user.home")+"/TestResources/";
20     public static FileWriter fileWriter ;
21
22     public static void writeFile(String data) throws IOException {
23         File dir = new File(jsonSchemaLoc);
24         File file = null;
25         dir.mkdirs();
26         file = new File(jsonSchemaLoc+"/GeneratorsList.json");
27         file.createNewFile();
28         fileWriter = new FileWriter(file);
29         fileWriter.write(data);
30         fileWriter.close();
31     }
32
33     public static void cleanUp() throws Exception {
34         String data = "{name:\"SCM\"}";
35         TestUtil.writeFile(data);
36         //ConfigurationUtils.executeDdlSql("truncate dox.configuration");
37         try{
38             ConfigurationUtils.executeDdlSql("truncate dox.configuration_change");
39         }
40         catch(Exception e){
41             e.printStackTrace();
42         }
43
44     }
45
46     public static void validateConfiguraton(String nameSpace) {
47         Configuration config = ConfigurationManager.lookup();
48
49         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH ), "14");
50
51         // First value from list is picked from Merge properties
52         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_MAXSIZE ), "1048576");
53
54         List<String> expectedExtList = new ArrayList<String>();
55         expectedExtList.add("pdf");
56         expectedExtList.add("zip");
57         expectedExtList.add("xml");
58         expectedExtList.add("pdf");
59         expectedExtList.add("tgz");
60         expectedExtList.add("xls");
61         List<String> extList = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_EXT);
62         Assert.assertEquals(expectedExtList, extList);
63
64         List<String> expectedEncList = new ArrayList<String>();
65         expectedEncList.add("Base64");
66         expectedEncList.add("MD5");
67         List<String> encList = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_ENC);
68         Assert.assertEquals(expectedEncList, encList);
69
70         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_UPPER ), "a-zA-Z_0-9");
71         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_LOWER ), "a-zA-Z");
72         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_STATUS ), "deleted");
73
74         List<String> expectedLocList = new ArrayList<String>();
75         expectedLocList.add("/opt/spool");
76         expectedLocList.add(System.getProperty("user.home")+"/asdc");
77         List<String> locList = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_LOC);
78         Assert.assertEquals(expectedLocList, locList);
79
80         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_JSON_SCHEMA ), "@GeneratorList.json");
81
82         Assert.assertEquals("@"+System.getenv("Path")+"/myschema.json",config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
83
84         List<String> artifactConsumer = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER );
85         Assert.assertEquals(config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER_APPC ), artifactConsumer);
86
87         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH ), "6");
88         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_MANDATORY_NAME ), "true");
89         Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_ENCODED ), "true");
90     }
91 }