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