Skip to content

Issue-381 Url field added to the report #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ public class ZeroCodeCsvReportBuilder {
private String correlationId;
private String result;
private String method;
private String url;
String requestTimeStamp;
String responseTimeStamp;
private Double responseDelayMilliSec;
private String host;

public static ZeroCodeCsvReportBuilder newInstance() {
return new ZeroCodeCsvReportBuilder();
}

public ZeroCodeCsvReport build() {
ZeroCodeCsvReport built = new ZeroCodeCsvReport(scenarioName,scenarioLoop,stepName, stepLoop,
correlationId, result, method, requestTimeStamp, responseTimeStamp, responseDelayMilliSec);
correlationId, result, method, host, url, requestTimeStamp, responseTimeStamp, responseDelayMilliSec);
return built;
}

Expand All @@ -39,6 +41,16 @@ public ZeroCodeCsvReportBuilder stepName(String stepName) {
return this;
}

public ZeroCodeCsvReportBuilder url(String url) {
this.url = url;
return this;
}

public ZeroCodeCsvReportBuilder host(String host) {
this.host = host;
return this;
}

public ZeroCodeCsvReportBuilder stepLoop(Integer stepLoop) {
this.stepLoop = stepLoop;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ public class ZeroCodeCsvReport {
private String correlationId;
private String result;
private String method;
private String host;
private String url;
String requestTimeStamp;
String responseTimeStamp;
private Double responseDelayMilliSec;

public ZeroCodeCsvReport(String scenarioName, Integer scenarioLoop, String stepName, Integer stepLoop,
String correlationId, String result, String method, String requestTimeStamp,
String correlationId, String result, String method, String host, String url, String requestTimeStamp,
String responseTimeStamp, Double responseDelayMilliSec) {
this.scenarioName = scenarioName;
this.scenarioLoop = scenarioLoop;
Expand All @@ -22,6 +24,8 @@ public ZeroCodeCsvReport(String scenarioName, Integer scenarioLoop, String stepN
this.correlationId = correlationId;
this.result = result;
this.method=method;
this.host=host;
this.url=url;
this.requestTimeStamp = requestTimeStamp;
this.responseTimeStamp = responseTimeStamp;
this.responseDelayMilliSec = responseDelayMilliSec;
Expand Down Expand Up @@ -55,6 +59,14 @@ public String getMethod() {
return method;
}

public String getHost() {
return host;
}

public String getUrl() {
return url;
}

public Double getResponseDelayMilliSec() {
return responseDelayMilliSec;
}
Expand All @@ -77,6 +89,8 @@ public String toString() {
", correlationId='" + correlationId + '\'' +
", result='" + result + '\'' +
", method='" + method + '\'' +
", host='" + host + '\'' +
", url='" + url + '\'' +
", requestTimeStamp=" + requestTimeStamp +
", responseTimeStamp=" + responseTimeStamp +
", responseDelayMilliSec=" + responseDelayMilliSec +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
Expand All @@ -49,6 +51,8 @@
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.TARGET_FULL_REPORT_DIR;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.TARGET_REPORT_DIR;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.TEST_STEP_CORRELATION_ID;
import static org.jsmart.zerocode.core.utils.ApiType.*;
import static org.jsmart.zerocode.core.utils.ApiTypeUtils.apiType;

public class ZeroCodeReportGeneratorImpl implements ZeroCodeReportGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(ZeroCodeReportGeneratorImpl.class);
Expand Down Expand Up @@ -106,16 +110,16 @@ public void generateExtentReport() {
test.getModel().setEndTime(utilDateOf(thisStep.getResponseTimeStamp()));

final Status testStatus = thisStep.getResult().equals(RESULT_PASS) ? Status.PASS : Status.FAIL;

ExtentTest step = test.createNode(thisStep.getName(), TEST_STEP_CORRELATION_ID + " " + thisStep.getCorrelationId());
if(testStatus.equals(Status.PASS)) {
step.pass(thisStep.getResult());
}else {
step.info(MarkupHelper.createCodeBlock(thisStep.getOperation() + "\t" + thisStep.getUrl()));
step.info(MarkupHelper.createCodeBlock(thisStep.getRequest(), CodeLanguage.JSON));

if (testStatus.equals(Status.PASS)) {
step.pass(thisStep.getResult());
} else {
step.info(MarkupHelper.createCodeBlock(thisStep.getOperation() + "\t" + thisStep.getUrl()));
step.info(MarkupHelper.createCodeBlock(thisStep.getRequest(), CodeLanguage.JSON));
step.info(MarkupHelper.createCodeBlock(thisStep.getResponse(), CodeLanguage.JSON));
step.fail(MarkupHelper.createCodeBlock("Reason:\n" + thisStep.getAssertions()));
step.fail(MarkupHelper.createCodeBlock("Reason:\n" + thisStep.getAssertions()));
}
extentReports.flush();
});
Expand All @@ -133,13 +137,13 @@ public void linkToSpikeChartIfEnabled() {
// (might be disabled by current runner)
// Then it's good to link it to that spike report.
// ------------------------------------------------
if(spikeChartReportEnabled || spikeChartFileName != null){
if (spikeChartReportEnabled || spikeChartFileName != null) {
final String reportName = getReportName();

String linkCodeToTargetSpikeChartHtml =
String.format("<code>&nbsp;&nbsp;<a href='%s' style=\"color: #006; background: #ff6;\"> %s </a></code>",
spikeChartFileName,
LINK_LABEL_NAME);
spikeChartFileName,
LINK_LABEL_NAME);

ExtentReportsFactory.reportName(reportName + linkCodeToTargetSpikeChartHtml);
}
Expand All @@ -148,33 +152,33 @@ public void linkToSpikeChartIfEnabled() {
protected String optionalAuthor(String scenarioName) {
String authorName = substringBetween(scenarioName, AUTHOR_MARKER, AUTHOR_MARKER);

if(authorName == null){
if (authorName == null) {
authorName = substringBetween(scenarioName, AUTHOR_MARKER, ",");
}

if(authorName == null){
if (authorName == null) {
authorName = substringBetween(scenarioName, AUTHOR_MARKER, " ");
}

if(authorName == null){
if (authorName == null) {
authorName = scenarioName.substring(scenarioName.lastIndexOf(AUTHOR_MARKER) + AUTHOR_MARKER.length());
}

if(scenarioName.lastIndexOf(AUTHOR_MARKER) == -1 || StringUtils.isEmpty(authorName)){
if (scenarioName.lastIndexOf(AUTHOR_MARKER) == -1 || StringUtils.isEmpty(authorName)) {
authorName = ANONYMOUS_AUTHOR;
}

return authorName;
}

protected String onlyScenarioName(String scenarioName) {
int index = scenarioName.indexOf(AUTHOR_MARKER);
if(index == -1) {
return scenarioName;
}else {
return scenarioName.substring(0, index -1);
}

int index = scenarioName.indexOf(AUTHOR_MARKER);
if (index == -1) {
return scenarioName;
} else {
return scenarioName.substring(0, index - 1);
}
}

@Override
Expand All @@ -198,7 +202,7 @@ public void generateHighChartReport() {
/*
* Generate: Spike Chart using HighChart
*/
if(spikeChartReportEnabled){
if (spikeChartReportEnabled) {
HighChartColumnHtml highChartColumnHtml = convertCsvRowsToHighChartData(zeroCodeCsvFlattenedRows);
generateHighChartReport(highChartColumnHtml);
}
Expand Down Expand Up @@ -255,6 +259,9 @@ public void generateCsvReport(List<ZeroCodeCsvReport> zeroCodeCsvReportRows) {
.addColumn("responseTimeStamp")
.addColumn("result")
.addColumn("method")
.addColumn("host")
//If(host enabled)
.addColumn("url")
.build();

CsvMapper csvMapper = new CsvMapper();
Expand Down Expand Up @@ -295,6 +302,29 @@ public List<ZeroCodeCsvReport> buildCsvRows() {
csvFileBuilder.correlationId(thisStep.getCorrelationId());
csvFileBuilder.result(thisStep.getResult());
csvFileBuilder.method(thisStep.getOperation());
/**
* @implNote Conditional Host and Url fields added as per API Type
**/
String host = "";
String urlPath = "";
if (apiType(thisStep.getUrl(), thisStep.getOperation()).equals(REST_CALL)) {
try {
URL u = new URL(thisStep.getUrl());
String url = u.toString();
host = url.substring(0, url.indexOf(u.getPath()));
urlPath = u.getPath();
csvFileBuilder.host(host);
csvFileBuilder.url(urlPath);
} catch (MalformedURLException e) {
LOGGER.error("####MalformedURLException: " + e.getMessage() + " In Test: " + thisResult.getScenarioName()+ ",URL: "+thisStep.getUrl());
}
} else if (apiType(thisStep.getUrl(), thisStep.getOperation()).equals(JAVA_CALL)) {
csvFileBuilder.host("NATIVE");
csvFileBuilder.url(thisStep.getUrl());
} else if (apiType(thisStep.getUrl(), thisStep.getOperation()).equals(KAFKA_CALL)) {
csvFileBuilder.host("KAFKA");
csvFileBuilder.url(thisStep.getUrl());
}
csvFileBuilder.requestTimeStamp(thisStep.getRequestTimeStamp().toString());
csvFileBuilder.responseTimeStamp(thisStep.getResponseTimeStamp().toString());
csvFileBuilder.responseDelayMilliSec(thisStep.getResponseDelay());
Expand Down Expand Up @@ -342,7 +372,7 @@ public static List<String> getAllEndPointFilesFrom(String folderName) {
return name.endsWith(".json");
});

if(files == null || files.length == 0){
if (files == null || files.length == 0) {

LOGGER.error("\n\t\t\t************\nNow files were found in folder:{}, hence could not proceed. " +
"\n(If this was intentional, then you can safely ignore this error)" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ public void testAuthorJiraStyle() throws Exception {

}



}