2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.sdc.backend.ci.tests.api;
23 import com.aventstack.extentreports.ExtentReports;
24 import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
25 import com.aventstack.extentreports.reporter.ExtentXReporter;
26 import com.aventstack.extentreports.reporter.configuration.Protocol;
27 import com.aventstack.extentreports.reporter.configuration.Theme;
29 import org.onap.sdc.backend.ci.tests.config.Config;
30 import org.onap.sdc.backend.ci.tests.utils.Utils;
31 import org.onap.sdc.backend.ci.tests.utils.general.FileHandling;
32 import org.onap.sdc.backend.ci.tests.utils.rest.AutomationUtils;
33 import org.testng.ITestContext;
35 public class ExtentManager {
37 private static final String VERSIONS_INFO_FILE_NAME = "versions.info";
38 private static ExtentReports extent;
39 private static ExtentHtmlReporter htmlReporter;
40 private static ExtentXReporter extentxReporter;
42 public enum suiteNameXml {
44 TESTNG_FAILED_XML_NAME("testng-failed.xml");
46 suiteNameXml(String value) {
52 public String getValue() {
58 public synchronized static ExtentReports setReporter(String filePath, String htmlFile, Boolean isAppend) throws Exception {
59 String dbIp = Utils.getConfig().getReportDBhost();
60 int dbPort = Utils.getConfig().getReportDBport();
63 extentxReporter = new ExtentXReporter(dbIp, dbPort);
64 extent = new ExtentReports();
65 initAndSetExtentHtmlReporter(filePath, htmlFile, isAppend);
67 if (extentxReporter.config().getReportObjectId() != null) {
68 setExtentXReporter(isAppend);
70 extentxReporter.stop();
76 public synchronized static void setExtentXReporter(Boolean isAppend) {
77 extentxReporter.setAppendExisting(isAppend);
78 extent.attachReporter(extentxReporter);
81 public synchronized static void initAndSetExtentHtmlReporter(String filePath, String htmlFile, Boolean isAppend) throws Exception {
82 htmlReporter = new ExtentHtmlReporter(filePath + htmlFile);
83 setConfiguration(htmlReporter);
84 htmlReporter.setAppendExisting(isAppend);
85 extent.attachReporter(htmlReporter);
88 public synchronized static ExtentReports getReporter() {
92 public static void initReporter(String filepath, String htmlFile, ITestContext context) throws Exception {
94 String onboardVersion = AutomationUtils.getOnboardVersion();
95 String osVersion = AutomationUtils.getOSVersion();
96 Config config = Utils.getConfig();
97 String envData = config.getUrl();
98 String suiteName = getSuiteName(context);
100 if (suiteName.equals(suiteNameXml.TESTNG_FAILED_XML_NAME.getValue())) {
101 if (config.isUseBrowserMobProxy()) {
102 setTrafficCaptue(config);
105 setReporter(filepath, htmlFile, true);
106 String suiteNameFromVersionInfoFile = FileHandling.getKeyByValueFromPropertyFormatFile(filepath + VERSIONS_INFO_FILE_NAME, "suiteName");
107 reporterDataDefinition(onboardVersion, osVersion, envData, suiteNameFromVersionInfoFile);
109 FileHandling.deleteDirectory(ComponentBaseTest.getReportFolder());
110 FileHandling.createDirectory(filepath);
111 setReporter(filepath, htmlFile, false);
112 reporterDataDefinition(onboardVersion, osVersion, envData, suiteName);
113 AutomationUtils.createVersionsInfoFile(filepath + VERSIONS_INFO_FILE_NAME, onboardVersion, osVersion, envData, suiteName);
118 public static void reporterDataDefinition(String onboardVersion, String osVersion, String envData, String suiteNameFromVersionInfoFile)
120 extent.setSystemInfo("Onboard Version", onboardVersion);
121 extent.setSystemInfo("OS Version", osVersion);
122 // extent.setSystemInfo("Host Name Address", RestCDUtils.getExecutionHostAddress());
123 extent.setSystemInfo("ExecutedOn", envData);
124 extent.setSystemInfo("SuiteName", suiteNameFromVersionInfoFile);
127 public static String getSuiteName(ITestContext context) {
128 String suitePath = context.getSuite().getXmlSuite().getFileName();
129 if (suitePath != null) {
130 File file = new File(suitePath);
131 String suiteName = file.getName();
137 public synchronized static ExtentHtmlReporter setConfiguration(ExtentHtmlReporter htmlReporter) throws Exception {
139 htmlReporter.config().setTheme(Theme.STANDARD);
140 htmlReporter.config().setEncoding("UTF-8");
141 htmlReporter.config().setProtocol(Protocol.HTTPS);
142 htmlReporter.config().setDocumentTitle("SDC Automation Report");
143 htmlReporter.config().setChartVisibilityOnOpen(true);
144 // htmlReporter.config().setReportName(AutomationUtils.getATTVersion());
145 htmlReporter.config().setReportName("SDC Automation Report");
146 htmlReporter.config().setChartVisibilityOnOpen(false);
147 // htmlReporter.config().setJS(icon);
151 public static void closeReporter() {
155 public static void setTrafficCaptue(Config config) {
156 boolean mobProxyStatus = config.isUseBrowserMobProxy();
157 if (mobProxyStatus) {
158 config.setCaptureTraffic(true);