2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2021 Nokia Intellectual Property. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.sdc.frontend.ci.tests.execute.setup;
24 import com.aventstack.extentreports.ExtentReports;
25 import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
26 import com.aventstack.extentreports.reporter.configuration.Protocol;
27 import com.aventstack.extentreports.reporter.configuration.Theme;
29 import java.nio.file.Files;
30 import java.nio.file.Paths;
31 import java.text.SimpleDateFormat;
32 import java.util.Calendar;
33 import java.util.GregorianCalendar;
34 import org.onap.sdc.backend.ci.tests.config.Config;
35 import org.onap.sdc.backend.ci.tests.utils.Utils;
36 import org.onap.sdc.backend.ci.tests.utils.rest.AutomationUtils;
37 import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
38 import org.onap.sdc.frontend.ci.tests.utilities.RestCDUtils;
39 import org.testng.ITestContext;
41 public class ExtentManager {
43 private static final String VERSIONS_INFO_FILE_NAME = "versions.info";
44 private static ExtentReports extent;
45 private static ExtentHtmlReporter htmlReporter;
47 private static synchronized ExtentReports setReporter(String filePath, String htmlFile, Boolean isAppend) throws Exception {
49 extent = new ExtentReports();
50 initAndSetExtentHtmlReporter(filePath, htmlFile, isAppend);
55 private static synchronized void initAndSetExtentHtmlReporter(String filePath, String htmlFile, Boolean isAppend) throws Exception {
56 htmlReporter = new ExtentHtmlReporter(filePath + htmlFile);
57 setConfiguration(htmlReporter);
58 htmlReporter.setAppendExisting(isAppend);
59 extent.attachReporter(htmlReporter);
62 static synchronized ExtentReports getReporter() {
66 static void initReporter(String filepath, String htmlFile, ITestContext context) throws Exception {
68 String onboardVersion = AutomationUtils.getOnboardVersion();
69 String osVersion = AutomationUtils.getOSVersion();
70 Config config = Utils.getConfig();
71 String envData = config.getUrl();
72 String suiteName = getSuiteName(context);
73 String reportStartDate = null;
74 if (suiteName.equals(suiteNameXml.TESTNG_FAILED_XML_NAME.getValue())) {
75 if (config.isUseBrowserMobProxy()) {
76 setTrafficCaptue(config);
78 setReporter(filepath, htmlFile, true);
79 String suiteNameFromVersionInfoFile = FileHandling.getKeyByValueFromPropertyFormatFile(filepath + VERSIONS_INFO_FILE_NAME, "suiteName");
80 reporterDataDefinition(onboardVersion, osVersion, envData, suiteNameFromVersionInfoFile);
82 if (!Files.exists(Paths.get(filepath))) {
83 FileHandling.createDirectory(filepath);
85 setReporter(filepath, htmlFile, false);
86 Calendar calendar = new GregorianCalendar();
87 SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy hh:mm:ss a");
88 reportStartDate = formatter.format(calendar.getTime());
89 reporterDataDefinition(onboardVersion, osVersion, envData, suiteName);
91 .createVersionsInfoFile(filepath + VERSIONS_INFO_FILE_NAME, onboardVersion, osVersion, envData, suiteName, reportStartDate);
96 private static void reporterDataDefinition(String onboardVersion, String osVersion, String envData, String suiteNameFromVersionInfoFile)
98 extent.setSystemInfo("Onboard Version", onboardVersion);
99 extent.setSystemInfo("OS Version", osVersion);
100 extent.setSystemInfo("Host Name Address", RestCDUtils.getExecutionHostAddress());
101 extent.setSystemInfo("ExecutedOn", envData);
102 extent.setSystemInfo("SuiteName", suiteNameFromVersionInfoFile);
105 static String getSuiteName(ITestContext context) {
106 String suitePath = context.getSuite().getXmlSuite().getFileName();
107 if (suitePath != null) {
108 File file = new File(suitePath);
109 String suiteName = file.getName();
115 private static synchronized ExtentHtmlReporter setConfiguration(ExtentHtmlReporter htmlReporter) throws Exception {
117 htmlReporter.config().setTheme(Theme.STANDARD);
118 htmlReporter.config().setEncoding("UTF-8");
119 htmlReporter.config().setProtocol(Protocol.HTTPS);
120 htmlReporter.config().setDocumentTitle("SDC Automation Report");
121 htmlReporter.config().setChartVisibilityOnOpen(true);
122 htmlReporter.config().setReportName("SDC Automation Report");
123 htmlReporter.config().setChartVisibilityOnOpen(false);
124 htmlReporter.setStartTime(null);
128 private static void setTrafficCaptue(Config config) {
129 boolean mobProxyStatus = config.isUseBrowserMobProxy();
130 if (mobProxyStatus) {
131 config.setCaptureTraffic(true);
135 public enum suiteNameXml {
137 TESTNG_FAILED_XML_NAME("testng-failed.xml");
139 private String value;
141 suiteNameXml(String value) {
145 public String getValue() {