re base code
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / api / ExtentTestActions.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.api;
22
23 import com.aventstack.extentreports.ExtentTest;
24 import com.aventstack.extentreports.Status;
25 import com.aventstack.extentreports.markuputils.ExtentColor;
26 import com.aventstack.extentreports.markuputils.Markup;
27 import com.aventstack.extentreports.markuputils.MarkupHelper;
28
29 import java.io.File;
30
31
32 public class ExtentTestActions {
33         
34         public static SomeInterface testManager = new ExtentTestManager();
35         
36         public static void log(Status logStatus, Markup mark){
37                 ExtentTest test = testManager.getTest();
38                 test.log(logStatus, mark);
39         }
40
41         public static void log(Status logStatus, String message){
42                 ExtentTest test = testManager.getTest();
43                 test.log(logStatus, message);
44         }
45         
46         public static void log(Status logStatus, String message, String duration){
47                 log(logStatus, message + addDurationTag(duration));
48         }
49         
50         public static void log(Status logStatus, Throwable throwabel){
51                 ExtentTest test = testManager.getTest();
52                 test.log(logStatus, throwabel);
53         }
54         
55         public static void addTag(Status logStatus, String message){
56                 Markup m = null;
57                 switch(logStatus){
58                 case PASS:
59                         m = MarkupHelper.createLabel(message, ExtentColor.GREEN);
60                         break;
61                 case FAIL:
62                         m = MarkupHelper.createLabel(message, ExtentColor.RED);
63                         break;
64                 case SKIP:
65                         m = MarkupHelper.createLabel(message, ExtentColor.BLUE);
66                         break;
67                 case FATAL:
68                         m = MarkupHelper.createLabel(message, ExtentColor.BROWN);
69                         break;
70                 default:
71                         break;
72                 }
73                 
74                 if (m != null){
75                         log(logStatus, m);
76                 }
77         }
78         
79 //      public static String addScreenshot(Status logStatus, String screenshotName, String message) throws IOException{
80 //              String imageFilePath = null;
81 //              String uuid = UUID.randomUUID().toString();
82 //              String[] stringArray = uuid.split("-");
83 //              screenshotName = screenshotName + "-" + stringArray[stringArray.length - 1];
84 //              try {
85 //                      File imageFile = GeneralUIUtils.takeScreenshot(screenshotName, SetupCDTest.getScreenshotFolder());
86 //                      imageFilePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFile.toURI()).getPath();
87 //              } catch (IOException e) {
88 //                      e.printStackTrace();
89 //              }
90 //
91 //              ExtentTest test = ExtentTestManager.getTest();
92 //              test.log(logStatus, message, MediaEntityBuilder.createScreenCaptureFromPath(imageFilePath).build());
93 //              return imageFilePath;
94 //      }
95         
96         private static String addDurationTag(String duration){
97                 return "<td width=\"80px\">" + duration + "</td>";
98         }
99         
100         public static String addLinkTag(String fileName, String pathToFile){
101                 return String.format("<a download=\"%s\" href=\"%s\">HAR file</a>", fileName, pathToFile);
102         }
103
104         public static void addFileToReportAsLink(File harFile, String pathToFileFromReportDirectory, String message) {
105                 log(Status.INFO, message, addLinkTag(harFile.getName(), pathToFileFromReportDirectory));
106         }
107         
108         
109         
110
111
112 }