From 6f6cb574d2de3040ba114b67b9a031ed4414c1ce Mon Sep 17 00:00:00 2001 From: nchandra Date: Fri, 26 Jan 2024 21:22:33 +0000 Subject: [PATCH] issues-616 Authors and hashtags aka categories --- .../constants/ZeroCodeReportConstants.java | 1 + .../report/ZeroCodeReportGeneratorImpl.java | 90 ++++++++--------- .../ZeroCodeReportGeneratorImplTest.java | 99 ++++++++++--------- 3 files changed, 92 insertions(+), 98 deletions(-) diff --git a/core/src/main/java/org/jsmart/zerocode/core/constants/ZeroCodeReportConstants.java b/core/src/main/java/org/jsmart/zerocode/core/constants/ZeroCodeReportConstants.java index f812ff6ec..855e4a22b 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/constants/ZeroCodeReportConstants.java +++ b/core/src/main/java/org/jsmart/zerocode/core/constants/ZeroCodeReportConstants.java @@ -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"; diff --git a/core/src/main/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImpl.java b/core/src/main/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImpl.java index db5a3d4af..d356cdde4 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImpl.java +++ b/core/src/main/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImpl.java @@ -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; @@ -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); @@ -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 thisScenarioUniqueSteps = getUniqueSteps(thisScenario.getSteps()); thisScenarioUniqueSteps.forEach(thisStep -> { test.getModel().setStartTime(utilDateOf(thisStep.getRequestTimeStamp())); @@ -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 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 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 deriveNames(String scenarioName, String marker) { + List 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) { @@ -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); + } + } + } } diff --git a/core/src/test/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImplTest.java b/core/src/test/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImplTest.java index f573f38e5..60dfa5ea3 100644 --- a/core/src/test/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImplTest.java +++ b/core/src/test/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImplTest.java @@ -58,84 +58,85 @@ public void testReportFolderPresentInTargetNormalFlow() throws Exception { @Test - public void testAuthorJiraStyle() throws Exception { - String author; + public void testAuthorJiraStyle_LEGACYMARKER() throws Exception { + List 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 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 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)); }