Skip to content

Commit

Permalink
Merge branch 'master' into 409-csvsource-from-file
Browse files Browse the repository at this point in the history
  • Loading branch information
authorjapps authored Jan 26, 2024
2 parents 082dc1a + eaf1487 commit dcad5cc
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface ZeroCodeReportConstants {
String REPORT_TITLE_DEFAULT = "Zerocode Test Report";
String REPORT_DISPLAY_NAME_DEFAULT = "Zerocode Interactive Report";
String DEFAULT_REGRESSION_CATEGORY = "Regression";
String DEFAULT_REGRESSION_AUTHOR = "All";
String LINK_LABEL_NAME = "Spike Chart(Click here)";
String ZEROCODE_JUNIT = "zerocode.junit";
String CHARTS_AND_CSV = "gen-smart-charts-csv-reports";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import org.apache.commons.lang.StringUtils;
import org.jsmart.zerocode.core.domain.builders.ExtentReportsFactory;
import org.jsmart.zerocode.core.domain.builders.HighChartColumnHtmlBuilder;
import org.jsmart.zerocode.core.domain.builders.ZeroCodeChartKeyValueArrayBuilder;
import org.jsmart.zerocode.core.domain.builders.ZeroCodeChartKeyValueBuilder;
import org.jsmart.zerocode.core.domain.builders.ZeroCodeCsvReportBuilder;
import org.jsmart.zerocode.core.domain.builders.*;
import org.jsmart.zerocode.core.domain.reports.ZeroCodeExecResult;
import org.jsmart.zerocode.core.domain.reports.ZeroCodeReport;
import org.jsmart.zerocode.core.domain.reports.ZeroCodeReportStep;
Expand All @@ -35,21 +30,8 @@

import static java.util.Collections.emptyList;
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang.StringUtils.substringBetween;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.AUTHOR_MARKER_NEW;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.CATEGORY_MARKER;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.*;
import static org.jsmart.zerocode.core.domain.builders.ExtentReportsFactory.getReportName;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.ANONYMOUS_CAT;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.AUTHOR_MARKER_OLD;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.DEFAULT_REGRESSION_CATEGORY;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.HIGH_CHART_HTML_FILE_NAME;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.LINK_LABEL_NAME;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.RESULT_PASS;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.TARGET_FILE_NAME;
import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.TARGET_FULL_REPORT_CSV_FILE_NAME;
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;

public class ZeroCodeReportGeneratorImpl implements ZeroCodeReportGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(ZeroCodeReportGeneratorImpl.class);
Expand Down Expand Up @@ -115,10 +97,21 @@ public void generateExtentReport() {

thisReport.getResults().forEach(thisScenario -> {
ExtentTest test = extentReports.createTest(thisScenario.getScenarioName());

// Assign Category
test.assignCategory(DEFAULT_REGRESSION_CATEGORY); //Super set
test.assignCategory(optionalCategory(thisScenario.getScenarioName())); //Sub sets
String[] hashTagsArray = optionalCategories(thisScenario.getScenarioName()).toArray(new String[0]);
if(hashTagsArray.length > 0) {
test.assignCategory(hashTagsArray); //Sub categories
}

// Assign Authors
test.assignAuthor(DEFAULT_REGRESSION_AUTHOR); //Super set
String[] authorsArray = optionalAuthors(thisScenario.getScenarioName()).toArray(new String[0]);
if(authorsArray.length > 0) {
test.assignAuthor(authorsArray); //Sub authors
}

test.assignAuthor(optionalAuthor(thisScenario.getScenarioName()));
List<ZeroCodeReportStep> thisScenarioUniqueSteps = getUniqueSteps(thisScenario.getSteps());
thisScenarioUniqueSteps.forEach(thisStep -> {
test.getModel().setStartTime(utilDateOf(thisStep.getRequestTimeStamp()));
Expand Down Expand Up @@ -166,42 +159,33 @@ public void linkToSpikeChartIfEnabled() {

/**
* @param scenarioName String containing a name of an author
* @return author of the test scenario
* @return authors of the test scenario
*/
protected String optionalAuthor(String scenarioName) {
String authorName = deriveName(scenarioName, AUTHOR_MARKER_OLD);
authorName = ANONYMOUS_CAT.equals(authorName) ? deriveName(scenarioName, AUTHOR_MARKER_NEW) : authorName;
return authorName;
protected List<String> optionalAuthors(String scenarioName) {
return deriveNames(scenarioName, AUTHOR_MARKER_NEW);
}

/**
* @param scenarioName String containing hash tags of a category
* @return category of the test scenario
* @param scenarioName String containing hashtags of a category
* @return hashtags aka categories of the test scenario
*/
protected String optionalCategory(String scenarioName) {
return deriveName(scenarioName, CATEGORY_MARKER);
protected List<String> optionalCategories(String scenarioName) {
return deriveNames(scenarioName, CATEGORY_MARKER);
}

private String deriveName(String scenarioName, String marker) {
String authorName = substringBetween(scenarioName, marker, marker);

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

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

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

if (scenarioName.lastIndexOf(marker) == -1 || StringUtils.isEmpty(authorName)) {
authorName = ANONYMOUS_CAT;
private List<String> deriveNames(String scenarioName, String marker) {
List<String> nameList = new ArrayList<>();
for(String thisName : scenarioName.trim().split(" ")){
if(thisName.startsWith(marker) && !thisName.startsWith(AUTHOR_MARKER_OLD)){
nameList.add(thisName);
}
// Depreciated, but still supports. Remove this via a new ticket
if(thisName.startsWith(AUTHOR_MARKER_OLD)){
nameList.add(thisName);
}
}
return nameList;

return authorName;
}

protected String onlyScenarioName(String scenarioName) {
Expand Down Expand Up @@ -430,4 +414,12 @@ private String createTimeStampedFileName() {
".html";
}

public static void main(String[] args) {
String sss = "A quick brown fox jumps over a lazy dog @ODS-X @Licenc_Y Z";
for(String st : sss.trim().split(" ")){
if(st.startsWith("@")){
System.out.println(st);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,84 +58,85 @@ public void testReportFolderPresentInTargetNormalFlow() throws Exception {


@Test
public void testAuthorJiraStyle() throws Exception {
String author;
public void testAuthorJiraStyle_LEGACYMARKER() throws Exception {
List<String> authors;

// OLD - Deprecated
author = zeroCodeReportGenerator.optionalAuthor("PayPal One touch payment @@Peter@@");
assertThat(author, is("Peter"));
authors = zeroCodeReportGenerator.optionalAuthors("PayPal One touch payment @@Peter");
assertThat(authors.get(0), is("@@Peter"));

author = zeroCodeReportGenerator.optionalAuthor("PayPal One touch @@payment @@Peter@@");
assertThat(author, is("payment "));
authors = zeroCodeReportGenerator.optionalAuthors("PayPal One touch payment");
assertThat(authors.size(), is(0));

author = zeroCodeReportGenerator.optionalAuthor("PayPal One touch payment @@Peter Gibson@@");
assertThat(author, is("Peter Gibson"));
authors = zeroCodeReportGenerator.optionalAuthors("PayPal One touch @@payment @@Peter");
assertThat(authors.get(0), is("@@payment"));
assertThat(authors.get(1), is("@@Peter"));
assertThat(authors.size(), is(2));

author = zeroCodeReportGenerator.optionalAuthor("PayPal One touch payment @@Peter Gibson");
assertThat(author, is("Peter"));
authors = zeroCodeReportGenerator.optionalAuthors("PayPal One touch payment @@Peter-Gibson");
assertThat(authors.get(0), is("@@Peter-Gibson"));

author = zeroCodeReportGenerator.optionalAuthor("PayPal One touch payment @@Peter");
assertThat(author, is("Peter"));

author = zeroCodeReportGenerator.optionalAuthor("@@Peter, PayPal One touch payment ");
assertThat(author, is("Peter"));

author = zeroCodeReportGenerator.optionalAuthor("PayPal One touch payment");
assertThat(author, is("Anonymous"));
authors = zeroCodeReportGenerator.optionalAuthors("PayPal One touch payment @@Peter Gibson");
assertThat(authors.get(0), is("@@Peter"));

authors = zeroCodeReportGenerator.optionalAuthors("@@Peter- PayPal One touch payment ");
assertThat(authors.get(0), is("@@Peter-"));
}

@Test
public void testAuthorJiraStyle_new() throws Exception {
String author;
List<String> authors;

author = zeroCodeReportGenerator.optionalAuthor("PayPal One touch payment @Peter@");
assertThat(author, is("Peter"));

author = zeroCodeReportGenerator.optionalAuthor("PayPal One touch @payment @Peter@");
assertThat(author, is("payment "));
// OLD - Deprecated
authors = zeroCodeReportGenerator.optionalAuthors("PayPal One touch payment @Peter");
assertThat(authors.get(0), is("@Peter"));

author = zeroCodeReportGenerator.optionalAuthor("PayPal One touch payment @Peter Gibson@");
assertThat(author, is("Peter Gibson"));
authors = zeroCodeReportGenerator.optionalAuthors("PayPal One touch payment");
assertThat(authors.size(), is(0));

author = zeroCodeReportGenerator.optionalAuthor("PayPal One touch payment @Peter Gibson");
assertThat(author, is("Peter"));
authors = zeroCodeReportGenerator.optionalAuthors("PayPal One touch @payment @Peter");
assertThat(authors.get(0), is("@payment"));
assertThat(authors.get(1), is("@Peter"));
assertThat(authors.size(), is(2));

author = zeroCodeReportGenerator.optionalAuthor("PayPal One touch payment @Peter");
assertThat(author, is("Peter"));
authors = zeroCodeReportGenerator.optionalAuthors("PayPal One touch payment @Peter-Gibson");
assertThat(authors.get(0), is("@Peter-Gibson"));

author = zeroCodeReportGenerator.optionalAuthor("@Peter, PayPal One touch payment ");
assertThat(author, is("Peter"));
authors = zeroCodeReportGenerator.optionalAuthors("PayPal One touch payment @Peter Gibson");
assertThat(authors.get(0), is("@Peter"));

author = zeroCodeReportGenerator.optionalAuthor("PayPal One touch payment");
assertThat(author, is("Anonymous"));
authors = zeroCodeReportGenerator.optionalAuthors("@Peter- PayPal One touch payment ");
assertThat(authors.get(0), is("@Peter-"));

}

@Test
public void testCategoryHashTag() throws Exception {
String author;
List<String> categories;

author = zeroCodeReportGenerator.optionalCategory("PayPal One touch payment #Smoke#");
assertThat(author, is("Smoke"));
categories = zeroCodeReportGenerator.optionalCategories("PayPal One touch payment #Smoke");
assertThat(categories.get(0), is("#Smoke"));
assertThat(categories.size(), is(1));

author = zeroCodeReportGenerator.optionalCategory("PayPal One touch #Smoke #PDC#");
assertThat(author, is("Smoke "));
categories = zeroCodeReportGenerator.optionalCategories("PayPal One touch #Smoke #PDC");
assertThat(categories.get(0), is("#Smoke"));
assertThat(categories.get(1), is("#PDC"));
assertThat(categories.size(), is(2));

author = zeroCodeReportGenerator.optionalCategory("PayPal One touch payment #SIT Smoke#");
assertThat(author, is("SIT Smoke"));
categories = zeroCodeReportGenerator.optionalCategories("PayPal One touch payment #SIT_Smoke");
assertThat(categories.get(0), is("#SIT_Smoke"));

author = zeroCodeReportGenerator.optionalCategory("PayPal One touch payment #PDC Gibson");
assertThat(author, is("PDC"));
categories = zeroCodeReportGenerator.optionalCategories("PayPal One touch payment #PDC-Gibson");
assertThat(categories.get(0), is("#PDC-Gibson"));

author = zeroCodeReportGenerator.optionalCategory("PayPal One touch payment #PDC");
assertThat(author, is("PDC"));
categories = zeroCodeReportGenerator.optionalCategories("PayPal One touch payment #PDC");
assertThat(categories.get(0), is("#PDC"));

author = zeroCodeReportGenerator.optionalCategory("#PDC, PayPal One touch payment ");
assertThat(author, is("PDC"));
categories = zeroCodeReportGenerator.optionalCategories("#PDC, PayPal One touch payment ");
assertThat(categories.get(0), is("#PDC,"));

author = zeroCodeReportGenerator.optionalCategory("PayPal One touch payment");
assertThat(author, is("Anonymous"));
categories = zeroCodeReportGenerator.optionalCategories("PayPal One touch payment");
assertThat(categories.size(), is(0));

}

Expand Down

0 comments on commit dcad5cc

Please sign in to comment.