1 package org.openecomp.config.util;
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;
9 import java.io.FileWriter;
10 import java.io.IOException;
11 import java.util.ArrayList;
12 import java.util.List;
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;
19 * Created by sheetalm on 10/13/2016.
21 public class TestUtil {
23 public final static String jsonSchemaLoc = System.getProperty("user.home")+"/TestResources/";
24 public static FileWriter fileWriter ;
26 public static void writeFile(String data) throws IOException {
27 File dir = new File(jsonSchemaLoc);
30 file = new File(jsonSchemaLoc+"/GeneratorsList.json");
32 fileWriter = new FileWriter(file);
33 fileWriter.write(data);
37 public static void cleanUp() throws Exception {
38 String data = "{name:\"SCM\"}";
39 TestUtil.writeFile(data);
40 //ConfigurationUtils.executeDdlSql("truncate dox.configuration");
42 ConfigurationUtils.executeDdlSql("truncate dox.configuration_change");
50 public static void validateConfiguraton(String nameSpace) {
51 Configuration config = ConfigurationManager.lookup();
53 Assert.assertEquals(config.getAsString(nameSpace, ARTIFACT_NAME_MAXLENGTH ), "14");
55 // First value from list is picked from Merge properties
56 Assert.assertEquals(config.getAsString(nameSpace, ARTIFACT_MAXSIZE ), "1048576");
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);
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);
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");
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);
84 Assert.assertEquals(config.getAsString(nameSpace, ARTIFACT_JSON_SCHEMA ), "@GeneratorList.json");
86 Assert.assertEquals("@"+System.getenv("Path")+"/myschema.json",config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
88 List<String> artifactConsumer = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER );
89 Assert.assertEquals(config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER_APPC ), artifactConsumer);
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");