1 package org.onap.config.util;
4 import java.io.FileWriter;
5 import java.io.IOException;
6 import java.util.ArrayList;
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;
15 * Created by sheetalm on 10/13/2016.
17 public class TestUtil {
19 public final static String jsonSchemaLoc = System.getProperty("user.home")+"/TestResources/";
20 public static FileWriter fileWriter ;
22 public static void writeFile(String data) throws IOException {
23 File dir = new File(jsonSchemaLoc);
26 file = new File(jsonSchemaLoc+"/GeneratorsList.json");
28 fileWriter = new FileWriter(file);
29 fileWriter.write(data);
33 public static void cleanUp() throws Exception {
34 String data = "{name:\"SCM\"}";
35 TestUtil.writeFile(data);
36 //ConfigurationUtils.executeDdlSql("truncate dox.configuration");
38 ConfigurationUtils.executeDdlSql("truncate dox.configuration_change");
46 public static void validateConfiguraton(String nameSpace) {
47 Configuration config = ConfigurationManager.lookup();
49 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH ), "14");
51 // First value from list is picked from Merge properties
52 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_MAXSIZE ), "1048576");
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);
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);
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");
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);
80 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_JSON_SCHEMA ), "@GeneratorList.json");
82 Assert.assertEquals("@"+System.getenv("Path")+"/myschema.json",config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
84 List<String> artifactConsumer = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER );
85 Assert.assertEquals(config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER_APPC ), artifactConsumer);
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");