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 final static String jsonSchemaLoc = System.getProperty("user.home")+"/TestResources/";
34 public static FileWriter fileWriter ;
36 public static void writeFile(String data) throws IOException {
37 File dir = new File(jsonSchemaLoc);
39 File file = new File(jsonSchemaLoc+"/GeneratorsList.json");
41 fileWriter = new FileWriter(file);
42 fileWriter.write(data);
46 public static void cleanUp() throws Exception {
47 String data = "{name:\"SCM\"}";
48 TestUtil.writeFile(data);
51 public static void validateConfiguraton(String nameSpace) {
52 Configuration config = ConfigurationManager.lookup();
54 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH ), "14");
56 // First value from list is picked from Merge properties
57 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_MAXSIZE ), "1048576");
59 List<String> expectedExtList = new ArrayList<String>();
60 expectedExtList.add("pdf");
61 expectedExtList.add("zip");
62 expectedExtList.add("xml");
63 expectedExtList.add("pdf");
64 expectedExtList.add("tgz");
65 expectedExtList.add("xls");
66 List<String> extList = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_EXT);
67 Assert.assertEquals(expectedExtList, extList);
69 List<String> expectedEncList = new ArrayList<String>();
70 expectedEncList.add("Base64");
71 expectedEncList.add("MD5");
72 List<String> encList = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_ENC);
73 Assert.assertEquals(expectedEncList, encList);
75 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_UPPER ), "a-zA-Z_0-9");
76 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_LOWER ), "a-zA-Z");
77 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_STATUS ), "deleted");
79 List<String> expectedLocList = new ArrayList<String>();
80 expectedLocList.add("/opt/spool");
81 expectedLocList.add(System.getProperty("user.home")+"/asdc");
82 List<String> locList = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_LOC);
83 Assert.assertEquals(expectedLocList, locList);
85 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_JSON_SCHEMA ), "@GeneratorList.json");
87 Assert.assertEquals("@"+System.getenv("Path")+"/myschema.json",config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
89 List<String> artifactConsumer = config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER );
90 Assert.assertEquals(config.getAsStringValues(nameSpace, ConfigTestConstant.ARTIFACT_CONSUMER_APPC ), artifactConsumer);
92 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH ), "6");
93 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_MANDATORY_NAME ), "true");
94 Assert.assertEquals(config.getAsString(nameSpace, ConfigTestConstant.ARTIFACT_ENCODED ), "true");