2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.config.util;
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;
29 * Created by sheetalm on 10/13/2016.
31 public class TestUtil {
33 public static final String jsonSchemaLoc = System.getProperty("user.home") + "/TestResources/";
35 public static void cleanUp() throws Exception {
36 String data = "{name:\"SCM\"}";
37 TestUtil.writeFile(data);
40 public static void writeFile(String data) throws IOException {
41 File dir = new File(jsonSchemaLoc);
43 File file = new File(jsonSchemaLoc + "/GeneratorsList.json");
45 FileWriter fileWriter = new FileWriter(file);
46 fileWriter.write(data);
50 public static void validateConfiguration(String nameSpace) {
51 Configuration config = ConfigurationManager.lookup();
53 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH), "14");
55 // First value from list is picked from Merge properties
56 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_MAXSIZE), "1048576");
58 List<String> expectedExtList = new ArrayList<>();
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<>();
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, ConfigTestConstant.ARTIFACT_NAME_UPPER), "a-zA-Z_0-9");
75 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_LOWER), "a-zA-Z");
76 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_STATUS), "deleted");
78 List<String> expectedLocList = new ArrayList<>();
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, ConfigTestConstant.ARTIFACT_JSON_SCHEMA),
85 "@GeneratorList.json");
87 Assert.assertEquals("@" + getenv(ConfigTestConstant.PATH) + "/myschema.json",
88 config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
90 List<String> artifactConsumer = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER);
91 Assert.assertEquals(config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER_APPC),
94 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH), "6");
95 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_MANDATORY_NAME), "true");
96 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_ENCODED), "true");
100 * This to make the behavior of tests consistent with "env:X" in configuration files
101 * when environment variable X is not defined.
103 public static String getenv(String name) {
104 String value = System.getenv(name);
105 return value == null ? "" : value;