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