aboutsummaryrefslogtreecommitdiffstats
path: root/sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java
blob: 08688faab4248925f742de95de13679a980a3185 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package org.openecomp.test;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames;
import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;

public class CsarToscaTester {
	public static void main(String[] args) throws Exception {
		System.out.println("CsarToscaParser - path to CSAR's Directory is " + Arrays.toString(args));
		SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();

		File folder = new File(args[0]);
		File[] listOfFiles = folder.listFiles();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("d-MM-y-HH_mm_ss");
		String time = dateFormat.format(now);
		String csarsDir = args[1] + "/csar-reports-" + time;
		File dir = new File(csarsDir);
		dir.mkdir();


		for (File file : listOfFiles) {
			if (file.isFile()) {  
				System.out.println("File " + file.getAbsolutePath());
				String name = file.getName();
				String currentCsarDir = csarsDir+"/"+name+"-"+time;
				dir = new File(currentCsarDir);
				dir.mkdir();
				try {
					factory.getSdcCsarHelper(file.getAbsolutePath());
				} catch (SdcToscaParserException e){
					System.out.println("SdcToscaParserException caught. Code: "+e.getCode()+", message: "+ e.getMessage());
				}
				List<String> notAnalyzedReport = ThreadLocalsHolder.getCollector().getNotAnalyzedExceptionsReport();
				System.out.println("NOT ANALYZED during CSAR parsing are: " + (notAnalyzedReport != null ? notAnalyzedReport.toString() : "none"));
				List<String> warningsReport = ThreadLocalsHolder.getCollector().getWarningsReport();
				//System.out.println("WARNINGS during CSAR parsing are: " + (warningsReport != null ? warningsReport.toString() : "none"));
				List<String> criticalsReport = ThreadLocalsHolder.getCollector().getCriticalsReport();
				System.out.println("CRITICALS during CSAR parsing are: " + (criticalsReport != null ? criticalsReport.toString() : "none"));

				try {
					generateReport(time, name, currentCsarDir, criticalsReport, "critical");
					generateReport(time, name, currentCsarDir, warningsReport, "warning");
					generateReport(time, name, currentCsarDir, notAnalyzedReport, "notAnalyzed");

				} catch (IOException ex) {
					ex.printStackTrace();
				}
			}

		}		
	}

	private static void generateReport(String time, String name, String currentCsarDir, List<String> criticalsReport, String type)
			throws IOException {
		FileWriter fw;
		fw = new FileWriter(new File(currentCsarDir + "/" + criticalsReport.size() + "-"+type+"-" + name +"-"+time + ".txt"));
		for (String exception : criticalsReport) {
			fw.write(exception);
			fw.write("\r\n");
		}
		fw.close();
	}
}