Repository: authorjapps/zerocode
Pull request #617 (2024-01-26 21:23:54)

issues-616 Authors and hashtags aka categories
ISSUE #616 

# <Feature Title>

PR Branch
**_#ADD LINK TO THE PR BRANCH_**

## Motivation and Context

## Checklist:

* [x] Unit tests added

* [ ] Integration tests added

* [x] Test names are meaningful

* [x] Feature manually tested

* [ ] Branch build passed

* [ ] No 'package.*' in the imports

* [ ] Relevant Wiki page updated with clear instruction for the end user
  * [ ] Not applicable. This was only a refactor change, no functional or behaviour changes were introduced

* [ ] Http test added to `http-testing` module(if applicable) ?
  * [ ] Not applicable. The changes did not affect HTTP automation flow

* [ ] Kafka test added to `kafka-testing` module(if applicable) ?
  * [ ] Not applicable. The changes did not affect Kafka automation flow



Patch:
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 f812ff6e..855e4a22 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 db5a3d4a..d356cdde 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.CsvParser;
 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 java.util.stream.Collectors;
 
 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 class ZeroCodeReportGeneratorImpl implements ZeroCodeReportGenerator {
 
             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()));
@@ -166,42 +159,33 @@ public class ZeroCodeReportGeneratorImpl implements ZeroCodeReportGenerator {
 
     /**
      * @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) {
@@ -430,4 +414,12 @@ public class ZeroCodeReportGeneratorImpl implements ZeroCodeReportGenerator {
                 ".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);
+            }
+        }
+    }
 }


Test patch:
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 f573f38e..60dfa5ea 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 class ZeroCodeReportGeneratorImplTest {
 
 
     @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));
 
     }