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.configuration.Protocol;
26 import com.aventstack.extentreports.reporter.configuration.Theme;
28 import org.onap.sdc.backend.ci.tests.config.Config;
29 import org.onap.sdc.backend.ci.tests.utils.Utils;
30 import org.onap.sdc.backend.ci.tests.utils.general.FileHandling;
31 import org.onap.sdc.backend.ci.tests.utils.rest.AutomationUtils;
32 import org.testng.ITestContext;
34 public class ExtentManager {
36 private static final String VERSIONS_INFO_FILE_NAME = "versions.info";
37 private static ExtentReports extent;
38 private static ExtentHtmlReporter htmlReporter;
40 private static synchronized ExtentReports setReporter(String filePath, String htmlFile, Boolean isAppend) throws Exception {
42 extent = new ExtentReports();
43 initAndSetExtentHtmlReporter(filePath, htmlFile, isAppend);
48 private static synchronized void initAndSetExtentHtmlReporter(String filePath, String htmlFile, Boolean isAppend) throws Exception {
49 htmlReporter = new ExtentHtmlReporter(filePath + htmlFile);
50 setConfiguration(htmlReporter);
51 htmlReporter.setAppendExisting(isAppend);
52 extent.attachReporter(htmlReporter);
55 public static synchronized ExtentReports getReporter() {
59 public static void initReporter(String filepath, String htmlFile, ITestContext context) throws Exception {
61 String onboardVersion = AutomationUtils.getOnboardVersion();
62 String osVersion = AutomationUtils.getOSVersion();
63 Config config = Utils.getConfig();
64 String envData = config.getUrl();
65 String suiteName = getSuiteName(context);
67 if (suiteName.equals(suiteNameXml.TESTNG_FAILED_XML_NAME.getValue())) {
68 if (config.isUseBrowserMobProxy()) {
69 setTrafficCaptue(config);
72 setReporter(filepath, htmlFile, true);
73 String suiteNameFromVersionInfoFile = FileHandling.getKeyByValueFromPropertyFormatFile(filepath + VERSIONS_INFO_FILE_NAME, "suiteName");
74 reporterDataDefinition(onboardVersion, osVersion, envData, suiteNameFromVersionInfoFile);
76 FileHandling.deleteDirectory(ComponentBaseTest.getReportFolder());
77 FileHandling.createDirectory(filepath);
78 setReporter(filepath, htmlFile, false);
79 reporterDataDefinition(onboardVersion, osVersion, envData, suiteName);
80 AutomationUtils.createVersionsInfoFile(filepath + VERSIONS_INFO_FILE_NAME, onboardVersion, osVersion, envData, suiteName);
85 private static void reporterDataDefinition(String onboardVersion, String osVersion, String envData, String suiteNameFromVersionInfoFile)
87 extent.setSystemInfo("Onboard Version", onboardVersion);
88 extent.setSystemInfo("OS Version", osVersion);
89 extent.setSystemInfo("ExecutedOn", envData);
90 extent.setSystemInfo("SuiteName", suiteNameFromVersionInfoFile);
93 private static String getSuiteName(ITestContext context) {
94 String suitePath = context.getSuite().getXmlSuite().getFileName();
95 if (suitePath != null) {
96 File file = new File(suitePath);
97 String suiteName = file.getName();
103 private static synchronized ExtentHtmlReporter setConfiguration(ExtentHtmlReporter htmlReporter) throws Exception {
105 htmlReporter.config().setTheme(Theme.STANDARD);
106 htmlReporter.config().setEncoding("UTF-8");
107 htmlReporter.config().setProtocol(Protocol.HTTPS);
108 htmlReporter.config().setDocumentTitle("SDC Automation Report");
109 htmlReporter.config().setChartVisibilityOnOpen(true);
110 htmlReporter.config().setReportName("SDC Automation Report");
111 htmlReporter.config().setChartVisibilityOnOpen(false);
115 private static void setTrafficCaptue(Config config) {
116 boolean mobProxyStatus = config.isUseBrowserMobProxy();
117 if (mobProxyStatus) {
118 config.setCaptureTraffic(true);
124 TESTNG_FAILED_XML_NAME("testng-failed.xml");
126 private String value;
128 suiteNameXml(String value) {
132 public String getValue() {