Sync Integ to Master
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / utils / Utils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.utils;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
26
27 import java.io.File;
28 import java.io.FileInputStream;
29 import java.io.FileNotFoundException;
30 import java.io.InputStream;
31 import java.text.ParseException;
32 import java.text.SimpleDateFormat;
33 import java.util.ArrayList;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Map.Entry;
37 import java.util.concurrent.TimeUnit;
38
39 import org.apache.commons.lang3.StringUtils;
40 import org.apache.log4j.Logger;
41 import org.openecomp.sdc.ci.tests.config.Config;
42 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
43 import org.openecomp.sdc.common.api.ToscaNodeTypeInfo;
44 import org.openecomp.sdc.common.api.YamlConstants;
45 import org.yaml.snakeyaml.Yaml;
46
47 import com.google.gson.Gson;
48 import com.google.gson.JsonElement;
49 import com.google.gson.JsonObject;
50 import com.google.gson.JsonParser;
51
52 public final class Utils {
53
54         Gson gson = new Gson();
55
56         static Logger logger = Logger.getLogger(Utils.class.getName());
57
58         String contentTypeHeaderData = "application/json";
59         String acceptHeaderDate = "application/json";
60
61         public Utils() {
62                 /*
63                  * super();
64                  * 
65                  * StartTest.enableLogger(); logger =
66                  * Logger.getLogger(Utils.class.getName());
67                  */
68
69         }
70
71         // public String serviceTopologyPattern = "/topology/topology/%s";
72         // public String serviceTopologyTemplatePattern =
73         // "/topologytemplate/topologytemplate/%s";
74         //
75         // public String serviceTopologySearchPattern =
76         // "topology/topology/_search?q=%s";
77         // public String serviceTopologyTemplateSearchPattern =
78         // "topologytemplate/topologytemplate/_search?q=%s";
79         //
80         // public ArtifactTypeEnum getFileTypeByExtension(String fileName) {
81         //
82         // String fileExtension = null;
83         // if (fileName.matches("(.*)\\.(.*)")) {
84         // System.out.println(fileName.substring(fileName.lastIndexOf(".") + 1));
85         // fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
86         // }
87         //
88         // switch (fileExtension) {
89         // case "sh":
90         // return ArtifactTypeEnum.SHELL_SCRIPT;
91         // case "png":
92         // return ArtifactTypeEnum.ICON;
93         // case "ppp":
94         // return ArtifactTypeEnum.PUPPET;
95         // case "yang":
96         // return ArtifactTypeEnum.YANG;
97         // default:
98         // return ArtifactTypeEnum.UNKNOWN;
99         // }
100         //
101         // }
102         //
103         // public ArrayList<String> getScriptList (List<UploadArtifactInfo>
104         // artifactsList){
105         //
106         // ArrayList<String> scriptNameArray = new ArrayList<>();
107         // if (artifactsList != null){
108         // for (UploadArtifactInfo fileInArtifactsList : artifactsList){
109         // String artifactFileName = fileInArtifactsList.getArtifactName();
110         // ArtifactTypeEnum artifactFileType =
111         // fileInArtifactsList.getArtifactType();
112         // if (! artifactFileType.equals(ArtifactTypeEnum.ICON)){
113         // scriptNameArray.add(artifactFileName);
114         // }
115         // continue;
116         // }
117         // return scriptNameArray;
118         // }
119         // return null;
120         // }
121         //
122         //
123         // public String getYamlFileLocation(File testResourcesPath) {
124         // File[] files = testResourcesPath.listFiles();
125         // if (files.length == 0){
126         // return null;
127         // }else{
128         // for (int i = 0; i < files.length; i++){
129         // if (files[i].isFile()){
130         // return files[i].getAbsoluteFile().toString();
131         // }
132         // }
133         // }
134         // return null;
135         // }
136         //
137         // public String readFileContentToString (String fileName) throws
138         // IOException {
139         //
140         // Path path = Paths.get(fileName);
141         // String stringFromFile = new String(Files.readAllBytes(path));
142         // return stringFromFile;
143         //
144         //
145         // }
146         //
147         @SuppressWarnings("unchecked")
148         public ToscaNodeTypeInfo parseToscaNodeYaml(String fileContent) {
149
150                 ToscaNodeTypeInfo result = new ToscaNodeTypeInfo();
151                 Object templateVersion = null;
152                 Object templateName = null;
153
154                 if (fileContent != null) {
155                         Yaml yaml = new Yaml();
156
157                         Map<String, Object> yamlObject = (Map<String, Object>) yaml.load(fileContent);
158
159                         templateVersion = yamlObject.get(YamlConstants.TEMPLATE_VERSION);
160                         if (templateVersion != null) {
161                                 result.setTemplateVersion(templateVersion.toString());
162                         }
163                         templateName = yamlObject.get(YamlConstants.TEMPLATE_NAME);
164                         if (templateName != null) {
165                                 result.setTemplateName(templateName.toString());
166                         }
167                         Object nodeTypes = yamlObject.get(YamlConstants.NODE_TYPES);
168
169                         if (nodeTypes != null) {
170                                 Map<String, Object> nodeTypesMap = (Map<String, Object>) nodeTypes;
171                                 for (Entry<String, Object> entry : nodeTypesMap.entrySet()) {
172
173                                         String nodeName = entry.getKey();
174                                         if (nodeName != null) {
175                                                 result.setNodeName(nodeName);
176                                         }
177
178                                         break;
179
180                                 }
181                         }
182
183                 }
184
185                 return result;
186         }
187
188         //
189         //
190         // public ArtifactsMetadata getArtifactsMetadata(String response){
191         // ArtifactsMetadata artifactsMetadata = new ArtifactsMetadata();
192         //
193         // artifactsMetadata.setId(getJsonObjectValueByKey(response, "id"));
194         // artifactsMetadata.setName(getJsonObjectValueByKey(response, "name"));
195         // artifactsMetadata.setType(getJsonObjectValueByKey(response, "type"));
196         //
197         // artifactsMetadata.setCreator(getJsonObjectValueByKey(response,
198         // "creator"));
199         // artifactsMetadata.setCreationTime(getJsonObjectValueByKey(response,
200         // "creationTime"));
201         // artifactsMetadata.setLastUpdateTime(getJsonObjectValueByKey(response,
202         // "lastUpdateTime"));
203         // artifactsMetadata.setChecksum(getJsonObjectValueByKey(response,
204         // "checksum"));
205         // artifactsMetadata.setDescription(getJsonObjectValueByKey(response,
206         // "description"));
207         // artifactsMetadata.setLastUpdater(getJsonObjectValueByKey(response,
208         // "lastUpdater"));
209         //
210         // return artifactsMetadata;
211         // }
212         //
213         public static String getJsonObjectValueByKey(String metadata, String key) {
214                 JsonElement jelement = new JsonParser().parse(metadata);
215
216                 JsonObject jobject = jelement.getAsJsonObject();
217                 Object obj = jobject.get(key);
218                 if (obj == null) {
219                         return null;
220                 } else {
221                         String value;
222                         value = (String) jobject.get(key).getAsString();
223                         return value;
224                 }
225         }
226
227         public static Config getConfig() throws FileNotFoundException {
228                 Config config = Config.instance();
229                 return config;
230         }
231
232         public static Config getConfigHandleException() {
233                 Config config = null;
234                 try{
235                         config = Config.instance();
236                 }catch (Exception e){
237                         System.out.println("Configuration file not found. " + e);
238                 }
239                 return config;
240         }
241         // public void uploadNormativeTypes() throws IOException{
242         // Config config = getConfig();
243         // String[] normativeTypes = {"root", "compute", "blockStorage",
244         // "softwareComponent", "DBMS", "database", "network", "objectStorage",
245         // "webServer", "webApplication"};
246         // for( String normativeType : normativeTypes ){
247         // uploadComponent(config.getComponentsConfigDir()+File.separator+"normativeTypes"+File.separator+normativeType);
248         // }
249         //
250         // }
251         //
252         // public void uploadApacheComponent() throws IOException{
253         // Config config = getConfig();
254         // uploadComponent(config.getComponentsConfigDir()+File.separator+"apache");
255         // }
256         //
257         // public void uploadComponent(String componentDir) throws IOException{
258         //
259         // //*********************************************upload*************************************************************
260         // Config config = getConfig();
261         // ZipDirectory zipDirectory = new ZipDirectory();
262         // System.out.println(config.getEsHost());
263         //
264         // List<UploadArtifactInfo> artifactsList = new
265         // ArrayList<UploadArtifactInfo>();
266         //
267         //// read test resources and zip it as byte array
268         // byte[] zippedAsByteArray = zipDirectory.zip(componentDir, artifactsList);
269         //
270         //// encode zipped directory using base64
271         // String payload = Decoder.encode(zippedAsByteArray);
272         //
273         //// zip name build as testName with ".zip" extension
274         // String payloadZipName = getPayloadZipName(componentDir);
275         //
276         //// build json
277         // UploadResourceInfo resourceInfo = new UploadResourceInfo(payload,
278         // payloadZipName, "description", "category/mycategory", null,
279         // artifactsList);
280         // String json = new Gson().toJson(resourceInfo);
281         //
282         //// calculate md5 on the content of json
283         // String jsonMd5 =
284         // org.apache.commons.codec.digest.DigestUtils.md5Hex(json);
285         //
286         //// encode the md5 to base64, sent as header in post http request
287         // String encodedMd5 = Decoder.encode(jsonMd5.getBytes());
288         //
289         //// upload component to Elastic Search DB
290         // String url = null;
291         // HttpRequest http = new HttpRequest();
292         //
293         // url = String.format(Urls.UPLOAD_ZIP_URL, config.getCatalogFeHost(),
294         // config.getCatalogFePort());
295         //
296         //// Prepare headers to post upload component request
297         // HeaderData headerData = new HeaderData(encodedMd5, "application/json",
298         // "att", "test", "testIvanovich", "RoyalSeal", "Far_Far_Away",
299         // "getResourceArtifactListTest");
300         //
301         // MustHeaders headers = new MustHeaders(headerData);
302         // System.out.println("headers:"+headers.getMap());
303         //
304         // RestResponse response = http.httpSendPost(url, json, headers.getMap());
305         //
306         // assertEquals("upload component failed with code " +
307         // response.getErrorCode().intValue(),response.getErrorCode().intValue(),
308         // 204);
309         // }
310         //
311         // private String getPayloadZipName(String componentDir) {
312         // String payloadName;
313         // if( componentDir.contains( File.separator) ){
314         // String delimiter = null;
315         // if( File.separator.equals("\\")){
316         // delimiter ="\\\\";
317         // }
318         // else{
319         // delimiter = File.separator;
320         // }
321         // String[] split = componentDir.split(delimiter);
322         // payloadName = split[split.length-1];
323         // }
324         // else{
325         // payloadName = componentDir;
326         // }
327         // return payloadName+".zip";
328         // }
329         //
330         //
331         //
332         // public List<UploadArtifactInfo> createArtifactsList(String srcDir) {
333         //
334         // List<UploadArtifactInfo> artifactsList = new
335         // ArrayList<UploadArtifactInfo>();
336         // File srcFile = new File(srcDir);
337         // addFileToList(srcFile, artifactsList);
338         //
339         // return artifactsList;
340         // }
341         //
342         // public void addFileToList(File srcFile, List<UploadArtifactInfo>
343         // artifactsList) {
344         //
345         // File[] files = srcFile.listFiles();
346         //
347         // for (int i = 0; i < files.length; i++) {
348         // // if the file is directory, use recursion
349         // if (files[i].isDirectory()) {
350         // addFileToList(files[i], artifactsList);
351         // continue;
352         // }
353         //
354         // String fileName = files[i].getName();
355         // String artifactPath = fileName;
356         //
357         // if ( ! files[i].getName().matches("(.*)\\.y(?)ml($)")) {
358         // UploadArtifactInfo uploadArtifactInfo = new UploadArtifactInfo();
359         // uploadArtifactInfo.setArtifactName(files[i].getName());
360         // String parent = files[i].getParent();
361         //
362         // if (parent != null) {
363         // System.out.println(parent);
364         // int lastSepartor = parent.lastIndexOf(File.separator);
365         // if (lastSepartor > -1) {
366         // String actualParent = parent.substring(lastSepartor + 1);
367         // artifactPath = actualParent + "/" + artifactPath;
368         // }
369         // }
370         //
371         // uploadArtifactInfo.setArtifactPath(artifactPath);
372         // uploadArtifactInfo.setArtifactType(getFileTypeByExtension(fileName));
373         // uploadArtifactInfo.setArtifactDescription("description");
374         // artifactsList.add(uploadArtifactInfo);
375         //
376         // System.out.println("artifact list: " + artifactsList);
377         //
378         // }
379         //
380         // }
381         // }
382         //
383         //
384         // public String buildArtifactListUrl (String nodesType, String
385         // templateVersion, String artifactName) throws FileNotFoundException{
386         // //"http://172.20.43.132/sdc2/v1/catalog/resources/tosca.nodes.Root/1.0.0.wd03-SNAPSHOT/artifacts/wxs_baseline_compare.sh"
387         // Config config = getConfig();
388         // return "\"http://" + config.getCatalogBeHost() + ":" +
389         // config.getCatalogBePort() + "/sdc2/v1/catalog/resources/" +nodesType +
390         // "/" + templateVersion + "/artifacts/" + artifactName +"\"";
391         // }
392         //
393         //
394         // public void addTopologyToES(String testFolder, String
395         // serviceTopologyPattern) throws IOException{
396         // Config config = getConfig();
397         // String url = String.format(Urls.ES_URL, config.getEsHost(),
398         // config.getEsPort()) + serviceTopologyPattern;
399         // String sourceDir =
400         // config.getResourceConfigDir()+File.separator+testFolder;
401         // Path filePath = FileSystems.getDefault().getPath(sourceDir,
402         // "topology.txt");
403         // postFileContentsToUrl(url, filePath);
404         // }
405         //
406         // public void addTopologyTemplateToES(String testFolder, String
407         // serviceTopologyTemplatePattern) throws IOException{
408         // Config config = getConfig();
409         // String url = String.format(Urls.ES_URL, config.getEsHost(),
410         // config.getEsPort()) + serviceTopologyTemplatePattern;
411         // String sourceDir =
412         // config.getResourceConfigDir()+File.separator+testFolder;
413         // Path filePath = FileSystems.getDefault().getPath(sourceDir,
414         // "topologyTemplate.txt");
415         // postFileContentsToUrl(url, filePath);
416         // }
417         //
418         //
419         // public void postFileContentsToUrl(String url, Path filePath) throws
420         // IOException {
421         // HttpClientContext localContext = HttpClientContext.create();
422         // CloseableHttpResponse response = null;
423         //
424         // byte[] fileContent = Files.readAllBytes(filePath);
425         //
426         // try(CloseableHttpClient httpClient = HttpClients.createDefault()){
427         // HttpPost httpPost = new HttpPost(url);
428         // StringEntity entity = new StringEntity(new String(fileContent) ,
429         // ContentType.APPLICATION_JSON);
430         // httpPost.setEntity(entity);
431         // response = httpClient.execute(httpPost, localContext);
432         //
433         // }
434         // finally{
435         // response.close();
436         // }
437         //
438         //
439         // }
440         //
441         //
442         //// public boolean isPatternInEsDb(String patternToSearch)throws
443         // IOException{
444         //// Config config = getConfig();
445         //// String url = String.format(Urls.GET_SEARCH_DATA_FROM_ES,
446         // config.getEsHost(), config.getEsPort(),patternToSearch);
447         //// HttpRequest httpRequest = new HttpRequest();
448         //// RestResponse restResponse = httpRequest.httpSendGet(url);
449         //// if (restResponse.getErrorCode() == 200){
450         //// return true;
451         //// }
452         //// if (restResponse.getErrorCode() == 404){
453         //// return false;
454         //// }
455         ////
456         //// return false;
457         //// }
458         //
459         // public static RestResponse deleteAllDataFromEs() throws IOException{
460         // return deleteFromEsDbByPattern("_all");
461         // }
462         //
463
464         //
465         // public List<String> buildIdArrayListByTypesIndex (String index, String
466         // types) throws IOException{
467         //
468         // Config config = getConfig();
469         // HttpRequest http = new HttpRequest();
470         // RestResponse getResponce =
471         // http.httpSendGet(String.format(Urls.GET_ID_LIST_BY_INDEX_FROM_ES,
472         // config.getEsHost(), config.getEsPort(), index, types), null);
473         //
474         // List <String> idArray = new ArrayList<String>();
475         //
476         // JsonElement jelement = new JsonParser().parse(getResponce.getResponse());
477         // JsonObject jobject = jelement.getAsJsonObject();
478         // JsonObject hitsObject = (JsonObject) jobject.get("hits");
479         // JsonArray hitsArray = (JsonArray) hitsObject.get("hits");
480         // for (int i = 0; i < hitsArray.size(); i ++){
481         // JsonObject idObject = (JsonObject) hitsArray.get(i);
482         // String id = idObject.get("_id").toString();
483         // id = id.replace("\"", "");
484         // idArray.add(id);
485         // }
486         //
487         // return idArray;
488         // }
489         //
490         // public List<String> buildCategoriesTagsListFromJson(String
491         // categoriesTagsJson){
492         //
493         // ArrayList<String> categoriesTagsArray = new ArrayList<>();
494         // JsonElement jelement = new JsonParser().parse(categoriesTagsJson);
495         // JsonArray jArray = jelement.getAsJsonArray();
496         // for (int i = 0; i < jArray.size(); i ++){
497         // JsonObject categoriesTagsObject = (JsonObject) jArray.get(i);
498         // String categories = categoriesTagsObject.get("name").toString();
499         // categoriesTagsArray.add(categories);
500         // }
501         //
502         // return categoriesTagsArray;
503         // }
504         //
505         // public ArrayList <String> getCategoriesFromDb() throws Exception{
506         //
507         // ArrayList<String> categoriesFromDbArrayList = new ArrayList<>();
508         // RestResponse restResponse = new RestResponse();
509         // String contentTypeHeaderData = "application/json";
510         // String acceptHeaderDate = "application/json";
511         //
512         // Map<String, String> headersMap = new HashMap<String,String>();
513         // headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(),contentTypeHeaderData);
514         // headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
515         //
516         // HttpRequest httpRequest = new HttpRequest();
517         // String url = String.format(Urls.QUERY_NEO4J,
518         // Config.instance().getNeoHost(), Config.instance().getNeoPort());
519         // String body = "{\"statements\" : [ { \"statement\" : \"MATCH
520         // (category:category) return (category)\"} ]}";
521         // restResponse = httpRequest.httpSendPostWithAuth(url, body, headersMap,
522         // Config.instance().getNeoDBusername(),
523         // Config.instance().getNeoDBpassword());
524         //
525         // if (restResponse.getResponse()==null){
526         // return categoriesFromDbArrayList;
527         // }else{
528         // JsonElement jelement = new
529         // JsonParser().parse(restResponse.getResponse());
530         // JsonObject jobject = jelement.getAsJsonObject();
531         // JsonArray resultsArray = (JsonArray) jobject.get("results");
532         // JsonObject resObject = (JsonObject) resultsArray.get(0);
533         // JsonArray dataArray = (JsonArray) resObject.get("data");
534         // for (int i = 0; i < dataArray.size(); i ++){
535         // JsonObject rowObject = (JsonObject) dataArray.get(i);
536         // JsonArray rowArray = (JsonArray) rowObject.get("row");
537         // JsonObject nameObject = (JsonObject) rowArray.get(0);
538         // String name = nameObject.get("name").toString();
539         //// name = name.replace("\"", "");
540         // categoriesFromDbArrayList.add(name);
541         // }
542         //
543         //
544         // }
545         //
546         // return categoriesFromDbArrayList;
547         // }
548         //
549         public static void compareArrayLists(List<String> actualArraylList, List<String> expectedArrayList,
550                         String message) {
551
552                 ArrayList<String> actual = new ArrayList<String>(actualArraylList);
553                 ArrayList<String> expected = new ArrayList<String>(expectedArrayList);
554                 // assertEquals(message + " count got by rest API not match to " +
555                 // message + " expected count", expected.size(),actual.size());
556                 expected.removeAll(actual);
557                 assertEquals(message + " content got by rest API not match to " + message + " actual content", 0,
558                                 expected.size());
559         }
560
561         public static Object parseYamlConfig(String pattern) throws FileNotFoundException {
562
563                 Yaml yaml = new Yaml();
564                 Config config = getConfig();
565                 String configurationFile = config.getConfigurationFile();
566                 File file = new File(configurationFile);
567                 // File file = new
568                 // File("../catalog-be/src/main/resources/config/configuration.yaml");
569                 InputStream inputStream = new FileInputStream(file);
570                 Map<?, ?> map = (Map<?, ?>) yaml.load(inputStream);
571                 Object patternMap = (Object) map.get(pattern);
572
573                 return patternMap;
574         }
575
576         public static String getDepArtLabelFromConfig(ArtifactTypeEnum artifactTypeEnum) throws FileNotFoundException {
577
578                 @SuppressWarnings("unchecked")
579                 Map<String, Object> mapOfDepResArtTypesObjects = (Map<String, Object>) parseYamlConfig(
580                                 "deploymentResourceArtifacts");
581                 for (Map.Entry<String, Object> iter : mapOfDepResArtTypesObjects.entrySet()) {
582                         if (iter.getValue().toString().contains(artifactTypeEnum.getType())) {
583                                 return iter.getKey().toLowerCase();
584                         }
585                 }
586
587                 return "defaultLabelName";
588         }
589
590         
591         public static String multipleChar(String ch, int repeat) {
592                 return StringUtils.repeat(ch, repeat);
593         }
594         
595         public static List<String> getListOfDepResArtLabels(Boolean isLowerCase) throws FileNotFoundException {
596
597                 List<String> listOfResDepArtTypesFromConfig = new ArrayList<String>();
598                 @SuppressWarnings("unchecked")
599                 Map<String, Object> resourceDeploymentArtifacts = (Map<String, Object>) parseYamlConfig(
600                                 "deploymentResourceArtifacts");
601                 if (resourceDeploymentArtifacts != null) {
602
603                         if (isLowerCase) {
604                                 for (Map.Entry<String, Object> iter : resourceDeploymentArtifacts.entrySet()) {
605                                         listOfResDepArtTypesFromConfig.add(iter.getKey().toLowerCase());
606                                 }
607                         } else {
608
609                                 for (Map.Entry<String, Object> iter : resourceDeploymentArtifacts.entrySet()) {
610                                         listOfResDepArtTypesFromConfig.add(iter.getKey());
611                                 }
612                         }
613                 }
614                 return listOfResDepArtTypesFromConfig;
615         }
616
617         public static List<String> getListOfToscaArtLabels(Boolean isLowerCase) throws FileNotFoundException {
618
619                 List<String> listOfToscaArtTypesFromConfig = new ArrayList<String>();
620                 @SuppressWarnings("unchecked")
621                 Map<String, Object> toscaArtifacts = (Map<String, Object>) parseYamlConfig("toscaArtifacts");
622                 if (toscaArtifacts != null) {
623
624                         if (isLowerCase) {
625                                 for (Map.Entry<String, Object> iter : toscaArtifacts.entrySet()) {
626                                         listOfToscaArtTypesFromConfig.add(iter.getKey().toLowerCase());
627                                 }
628                         } else {
629                                 for (Map.Entry<String, Object> iter : toscaArtifacts.entrySet()) {
630                                         listOfToscaArtTypesFromConfig.add(iter.getKey());
631                                 }
632                         }
633                 }
634                 return listOfToscaArtTypesFromConfig;
635         }
636
637         //
638         // public static List<String> getListOfResDepArtTypes() throws
639         // FileNotFoundException {
640         //
641         // List<String> listOfResDepArtTypesFromConfig = new ArrayList<String>();
642         // @SuppressWarnings("unchecked")
643         // Map<String, Object> resourceDeploymentArtifacts = (Map<String, Object>)
644         // parseYamlConfig("resourceDeploymentArtifacts");
645         // for (Map.Entry<String, Object> iter :
646         // resourceDeploymentArtifacts.entrySet()) {
647         // listOfResDepArtTypesFromConfig.add(iter.getKey());
648         // }
649         //
650         // return listOfResDepArtTypesFromConfig;
651         // }
652         //
653         // public static List<String> getListOfDepResInstArtTypes() throws
654         // FileNotFoundException {
655         //
656         // List<String> listOfResInstDepArtTypesFromConfig = new
657         // ArrayList<String>();
658         // @SuppressWarnings("unchecked")
659         // Map<String, Object> resourceDeploymentArtifacts = (Map<String, Object>)
660         // parseYamlConfig("deploymentResourceInstanceArtifacts");
661         // for (Map.Entry<String, Object> iter :
662         // resourceDeploymentArtifacts.entrySet()) {
663         // listOfResInstDepArtTypesFromConfig.add(iter.getKey().toLowerCase());
664         // }
665         //
666         // return listOfResInstDepArtTypesFromConfig;
667         // }
668         //
669         public static List<String> getListOfResPlaceHoldersDepArtTypes() throws FileNotFoundException {
670                 List<String> listResDepArtTypesFromConfig = new ArrayList<String>();
671                 List<String> listOfResDepArtLabelsFromConfig = getListOfDepResArtLabels(false);
672                 assertNotNull("deployment artifact types list is null", listOfResDepArtLabelsFromConfig);
673                 Object parseYamlConfig = Utils.parseYamlConfig("deploymentResourceArtifacts");
674                 Map<String, Object> mapOfDepResArtTypesObjects = (Map<String, Object>) Utils
675                                 .parseYamlConfig("deploymentResourceArtifacts");
676
677                 // assertNotNull("deployment artifact types list is null",
678                 // mapOfDepResArtTypesObjects);
679                 if (listOfResDepArtLabelsFromConfig != null) {
680                         for (String resDepArtType : listOfResDepArtLabelsFromConfig) {
681                                 Object object = mapOfDepResArtTypesObjects.get(resDepArtType);
682                                 if (object instanceof Map<?, ?>) {
683                                         Map<String, Object> map = (Map<String, Object>) object;
684                                         listResDepArtTypesFromConfig.add((String) map.get("type"));
685                                 } else {
686                                         assertTrue("return object does not instance of map", false);
687                                 }
688                         }
689                 }
690                 return listResDepArtTypesFromConfig;
691         }
692
693         public static Long getEpochTimeFromUTC(String time) throws ParseException {
694             SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS zzz");
695             java.util.Date date = df.parse(time);
696             long epoch = date.getTime();
697             return epoch;
698         }
699
700         public static Long getActionDuration(Runnable func) throws Exception{
701                 long startTime = System.nanoTime();
702                 func.run();
703                 long estimateTime = System.nanoTime();
704                 long duration = TimeUnit.NANOSECONDS.toSeconds(estimateTime - startTime);
705                 return duration;
706         }
707 }