Skip to content

Commit

Permalink
Merge pull request #674 from prayascoriolis/ISSUE-207-Meta-Data-Section
Browse files Browse the repository at this point in the history
[Issue #207] Implementing Feature : Meta Data section (Scenario JSON)
  • Loading branch information
nirmalchandra authored Oct 4, 2024
2 parents ad6c834 + d72a00d commit f52682f
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ScenarioSpec {
Expand All @@ -15,19 +16,30 @@ public class ScenarioSpec {
private final String scenarioName;
private final List<Step> steps;
private final Parameterized parameterized;
private static Map<String, List<String>> meta;

// Add getter and setter for meta
public static Map<String, List<String>> getMeta() {
return meta;
}
public void setMeta(Map<String, List<String>> meta) {
this.meta = meta;
}

@JsonCreator
public ScenarioSpec(
@JsonProperty("stepLoop") Integer loop,
@JsonProperty("ignoreStepFailures") Boolean ignoreStepFailures,
@JsonProperty("scenarioName") String scenarioName,
@JsonProperty("steps") List<Step> steps,
@JsonProperty("parameterized") Parameterized parameterized) {
@JsonProperty("parameterized") Parameterized parameterized,
@JsonProperty("meta") Map<String, List<String>> meta) {
this.loop = loop;
this.ignoreStepFailures = ignoreStepFailures;
this.scenarioName = scenarioName;
this.steps = steps;
this.parameterized = parameterized;
this.meta=meta;
}

public Integer getLoop() {
Expand Down Expand Up @@ -58,6 +70,8 @@ public String toString() {
", scenarioName='" + scenarioName + '\'' +
", steps=" + steps +
", parameterized=" + parameterized +
", meta=" + meta +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class ZeroCodeCsvReportBuilder {
String requestTimeStamp;
String responseTimeStamp;
private Double responseDelayMilliSec;
private String metaAuthors;
private String metaTickets;
private String metaCategories;
private String metaOthers;

public static ZeroCodeCsvReportBuilder newInstance() {
return new ZeroCodeCsvReportBuilder();
Expand All @@ -21,6 +25,10 @@ public static ZeroCodeCsvReportBuilder newInstance() {
public ZeroCodeCsvReport build() {
ZeroCodeCsvReport built = new ZeroCodeCsvReport(scenarioName,scenarioLoop,stepName, stepLoop,
correlationId, result, method, requestTimeStamp, responseTimeStamp, responseDelayMilliSec);
built.setMetaAuthors(metaAuthors);
built.setMetaTickets(metaTickets);
built.setMetaCategories(metaCategories);
built.setMetaOthers(metaOthers);
return built;
}

Expand Down Expand Up @@ -73,4 +81,24 @@ public ZeroCodeCsvReportBuilder responseDelayMilliSec(Double responseDelayMilliS
this.responseDelayMilliSec = responseDelayMilliSec;
return this;
}

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

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

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

public ZeroCodeCsvReportBuilder setMetaOthers(String metaOthers) {
this.metaOthers = metaOthers;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

import org.jsmart.zerocode.core.domain.reports.ZeroCodeReportStep;
import org.jsmart.zerocode.core.domain.reports.ZeroCodeExecResult;
import org.jsmart.zerocode.core.domain.ScenarioSpec;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class ZeroCodeExecReportBuilder {
private String scenarioName;
private Integer loop;
private List<ZeroCodeReportStep> steps = Collections.synchronizedList(new ArrayList());
private Map<String, List<String>> meta = ScenarioSpec.getMeta();

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

public ZeroCodeExecResult build() {
ZeroCodeExecResult built = new ZeroCodeExecResult(scenarioName, loop, steps);
ZeroCodeExecResult built = new ZeroCodeExecResult(scenarioName, loop, steps, meta);
return built;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ZeroCodeExecResult {
private String scenarioName;
private Integer loop;
private List<ZeroCodeReportStep> steps = new ArrayList<>();

private Map<String, List<String>> meta;

@JsonCreator
public ZeroCodeExecResult(
@JsonProperty("scenarioName")String scenarioName,
@JsonProperty("stepLoop")Integer loop,
@JsonProperty("steps")List<ZeroCodeReportStep> steps) {
@JsonProperty("steps")List<ZeroCodeReportStep> steps,
@JsonProperty("meta") Map<String, List<String>> meta) {
this.scenarioName = scenarioName;
this.loop = loop;
this.steps = steps;
this.meta = meta;
}

public String getScenarioName() {
Expand All @@ -47,4 +51,9 @@ public String toString() {
", steps=" + steps +
'}';
}

public Map<String, List<String>> getMeta() {
return meta;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public class ZeroCodeCsvReport {
String requestTimeStamp;
String responseTimeStamp;
private Double responseDelayMilliSec;
// defining meta data fields
private String metaAuthors;
private String metaTickets;
private String metaCategories;
private String metaOthers;

public ZeroCodeCsvReport(String scenarioName, Integer scenarioLoop, String stepName, Integer stepLoop,
String correlationId, String result, String method, String requestTimeStamp,
Expand Down Expand Up @@ -67,6 +72,40 @@ public String getResponseTimeStamp() {
return responseTimeStamp;
}

// defining meta data field setters and getters

public String getMetaAuthors() {
return metaAuthors;
}

public void setMetaAuthors(String metaAuthors) {
this.metaAuthors = metaAuthors;
}

public String getMetaTickets() {
return metaTickets;
}

public void setMetaTickets(String metaTickets) {
this.metaTickets = metaTickets;
}

public String getMetaCategories() {
return metaCategories;
}

public void setMetaCategories(String metaCategories) {
this.metaCategories = metaCategories;
}

public String getMetaOthers() {
return metaOthers;
}

public void setMetaOthers(String metaOthers) {
this.metaOthers = metaOthers;
}

@Override
public String toString() {
return "ZeroCodeCsvReport{" +
Expand All @@ -75,11 +114,15 @@ public String toString() {
", stepName='" + stepName + '\'' +
", stepLoop=" + stepLoop +
", correlationId='" + correlationId + '\'' +
", requestTimeStamp='" + requestTimeStamp + '\'' +
", responseDelayMilliSec=" + responseDelayMilliSec +
", responseTimeStamp='" + responseTimeStamp + '\'' +
", result='" + result + '\'' +
", method='" + method + '\'' +
", requestTimeStamp=" + requestTimeStamp +
", responseTimeStamp=" + responseTimeStamp +
", responseDelayMilliSec=" + responseDelayMilliSec +
", metaAuthors='" + metaAuthors + '\'' +
", metaTickets='" + metaTickets + '\'' +
", metaCategories='" + metaCategories + '\'' +
", metaOthers='" + metaOthers + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.markuputils.CodeLanguage;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
Expand Down Expand Up @@ -98,6 +99,17 @@ public void generateExtentReport() {
thisReport.getResults().forEach(thisScenario -> {
ExtentTest test = extentReports.createTest(thisScenario.getScenarioName());

/**This code checks if the scenario has meta data.
If it does, it iterates through each meta data entry and adds it to
the Extent report as an info label.**/
if (thisScenario.getMeta() != null) {
for (Map.Entry<String, List<String>> entry : thisScenario.getMeta().entrySet()) {
String key = entry.getKey();
List<String> values = entry.getValue();
test.info(MarkupHelper.createLabel(key + ": " + String.join(", ", values), ExtentColor.BLUE));
}
}

// Assign Category
test.assignCategory(DEFAULT_REGRESSION_CATEGORY); //Super set
String[] hashTagsArray = optionalCategories(thisScenario.getScenarioName()).toArray(new String[0]);
Expand Down Expand Up @@ -276,6 +288,11 @@ public void generateCsvReport(List<ZeroCodeCsvReport> zeroCodeCsvReportRows) {
.addColumn("responseTimeStamp")
.addColumn("result")
.addColumn("method")
// This adds new columns to the CSV schema for each type of meta data.
.addColumn("metaAuthors")
.addColumn("metaTickets")
.addColumn("metaCategories")
.addColumn("metaOthers")
.build();

CsvMapper csvMapper = new CsvMapper();
Expand Down Expand Up @@ -310,6 +327,18 @@ public List<ZeroCodeCsvReport> buildCsvRows() {
csvFileBuilder.scenarioLoop(thisResult.getLoop());
csvFileBuilder.scenarioName(thisResult.getScenarioName());

// Add meta information
Map<String, List<String>> meta = thisResult.getMeta();
if (meta != null) {
/**This code retrieves the meta data from the test result. If meta data exists,
* it joins the list of values for each meta data type into a comma-separated
* string and adds it to the CSV row.**/
csvFileBuilder.setMetaAuthors(String.join(", ", meta.getOrDefault("authors", Collections.emptyList())));
csvFileBuilder.setMetaTickets(String.join(", ", meta.getOrDefault("tickets", Collections.emptyList())));
csvFileBuilder.setMetaCategories(String.join(", ", meta.getOrDefault("categories", Collections.emptyList())));
csvFileBuilder.setMetaOthers(String.join(", ", meta.getOrDefault("others", Collections.emptyList())));
}

thisResult.getSteps().forEach(thisStep -> {
csvFileBuilder.stepLoop(thisStep.getLoop());
csvFileBuilder.stepName(thisStep.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.jsmart.zerocode.testhelp.tests.metadatatest;

import org.jsmart.zerocode.core.domain.JsonTestCase;
import org.jsmart.zerocode.core.domain.TargetEnv;
import org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner;
import org.junit.Test;
import org.junit.runner.RunWith;

@TargetEnv("github_host.properties")
@RunWith(ZeroCodeUnitRunner.class)
public class MetaDataTest {
@Test
@JsonTestCase("metadatatest/metadatatest.json")
public void testMetaData() throws Exception {

}
}
27 changes: 27 additions & 0 deletions http-testing/src/test/resources/metadatatest/metadatatest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"scenarioName": "Scenario - Get GitHub User Details with Metadata",
"steps": [
{
"name": "get_user_details",
"url": "/users/octocat",
"method": "GET",
"request": {
},
"assertions": {
"status": 200,
"body": {
"login": "octocat",
"id": 583231,
"type": "User"
}
}
}
],
"meta": {
"authors": ["Emma", "Sidd", "Krish"],
"tickets": ["ISSUE-519", "GT-312"],
"categories": ["api", "regression"],
"description": ["This test verifies the GitHub user API"],
"last_updated": ["2023-05-15"]
}
}

0 comments on commit f52682f

Please sign in to comment.