From d9905a72a03ee7eec08386183bd39bd10b4b8b9c Mon Sep 17 00:00:00 2001 From: Yash Tiwari Date: Wed, 11 Sep 2024 14:53:51 +0530 Subject: [PATCH 1/9] Schema Validation without resolving the Json file. --- core/pom.xml | 9 ++ .../jsmart/zerocode/core/domain/Schema.java | 11 ++ .../jsmart/zerocode/core/domain/Schemas.java | 13 ++ .../ZeroCodeJsonSchemaMatcher.java | 12 ++ .../ZeroCodeJsonSchemaMatcherImpl.java | 53 ++++++++ .../ZeroCodeMultiStepsScenarioRunnerImpl.java | 3 + .../core/runner/ZeroCodeUnitRunner.java | 119 +++++++++++++++--- .../tests/helloworld/JustHelloWorldTest.java | 4 +- .../HelloWorldParameterizedValueTest.java | 1 + .../JustHelloWorldSchemaTest.java | 23 ++++ .../hello_world_status_ok_assertions.json | 20 +++ ...llo_world_status_ok_assertions_schema.json | 73 +++++++++++ kafka-testing/pom.xml | 6 + 13 files changed, 332 insertions(+), 15 deletions(-) create mode 100644 core/src/main/java/org/jsmart/zerocode/core/domain/Schema.java create mode 100644 core/src/main/java/org/jsmart/zerocode/core/domain/Schemas.java create mode 100644 core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcher.java create mode 100644 core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java create mode 100644 http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/hellowworldschema/JustHelloWorldSchemaTest.java create mode 100644 http-testing/src/test/resources/helloworldschema/hello_world_status_ok_assertions.json create mode 100644 http-testing/src/test/resources/helloworldschema/hello_world_status_ok_assertions_schema.json diff --git a/core/pom.xml b/core/pom.xml index f59e00aa5..83ddc4b9a 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -192,6 +192,15 @@ com.google.protobuf protobuf-java-util + + + + com.networknt + json-schema-validator + 1.4.0 + + + diff --git a/core/src/main/java/org/jsmart/zerocode/core/domain/Schema.java b/core/src/main/java/org/jsmart/zerocode/core/domain/Schema.java new file mode 100644 index 000000000..c08359741 --- /dev/null +++ b/core/src/main/java/org/jsmart/zerocode/core/domain/Schema.java @@ -0,0 +1,11 @@ +package org.jsmart.zerocode.core.domain; + +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +@Repeatable( value = Schemas.class ) +public @interface Schema { + String value(); +} diff --git a/core/src/main/java/org/jsmart/zerocode/core/domain/Schemas.java b/core/src/main/java/org/jsmart/zerocode/core/domain/Schemas.java new file mode 100644 index 000000000..7af9dfac0 --- /dev/null +++ b/core/src/main/java/org/jsmart/zerocode/core/domain/Schemas.java @@ -0,0 +1,13 @@ +package org.jsmart.zerocode.core.domain; + + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Schemas { + public Schema[] value() default {}; +} \ No newline at end of file diff --git a/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcher.java b/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcher.java new file mode 100644 index 000000000..e100d9d05 --- /dev/null +++ b/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcher.java @@ -0,0 +1,12 @@ +package org.jsmart.zerocode.core.engine.preprocessor; + +import com.fasterxml.jackson.databind.JsonNode; +import org.jsmart.zerocode.core.domain.Scenario; +import org.jsmart.zerocode.core.domain.ScenarioSpec; + +public interface ZeroCodeJsonSchemaMatcher { + + public boolean ismatching(JsonNode JsonFile , JsonNode JsonSchema); + + +} diff --git a/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java b/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java new file mode 100644 index 000000000..cb6db88b6 --- /dev/null +++ b/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java @@ -0,0 +1,53 @@ +package org.jsmart.zerocode.core.engine.preprocessor; + +import com.fasterxml.jackson.databind.JsonNode; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.github.tomakehurst.wiremock.common.Json; +import com.networknt.schema.JsonSchema; +import com.networknt.schema.JsonSchemaFactory; +import com.networknt.schema.SpecVersion; +import com.networknt.schema.ValidationMessage; +import org.jsmart.zerocode.core.domain.Scenario; +import org.jsmart.zerocode.core.domain.ScenarioSpec; +import org.jsmart.zerocode.core.logbuilder.ZerocodeCorrelationshipLogger; +import org.jsmart.zerocode.core.utils.SmartUtils; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Set; + +import static java.nio.charset.StandardCharsets.UTF_8; + +public class ZeroCodeJsonSchemaMatcherImpl implements ZeroCodeJsonSchemaMatcher{ + + + @Override + public boolean ismatching(JsonNode jsonFile, JsonNode schema ) { + + JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4); + JsonSchema jsonSchema = factory.getSchema(schema); + Set errors = jsonSchema.validate(jsonFile); + return errors.isEmpty(); + } +// TODO remember to remove this working of this ismatching for implementing ir inside the zerocode. + +// public static void main(String[] args) throws IOException { +// ObjectMapper mapper = new ObjectMapper(); +// SmartUtils smartUtils = new SmartUtils(); +// +// +// ZeroCodeJsonSchemaMatcherImpl zero = new ZeroCodeJsonSchemaMatcherImpl(); +// if(zero.ismatching( one , two )) +// { +// System.out.println("Matching with Schema"); +// } +// else +// { +// System.out.println("Not matching with Schema"); +// } +// } +} + diff --git a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java index ca5518366..12c4a5736 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java +++ b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java @@ -275,6 +275,9 @@ private Boolean executeRetry(RunNotifier notifier, scenarioExecutionState.addStepState(stepExecutionState); } + + // TODO I will be implementing the code for JSon Schema Validation here in case we are having the error specified. + // --------------------------------- // Handle assertion section -START // --------------------------------- diff --git a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java index 6c659e247..654468bc9 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java +++ b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java @@ -1,26 +1,18 @@ package org.jsmart.zerocode.core.runner; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.util.Modules; -import java.lang.annotation.Annotation; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; import org.jsmart.zerocode.core.di.main.ApplicationMainModule; import org.jsmart.zerocode.core.di.module.RuntimeHttpClientModule; import org.jsmart.zerocode.core.di.module.RuntimeKafkaClientModule; -import org.jsmart.zerocode.core.domain.HostProperties; -import org.jsmart.zerocode.core.domain.JsonTestCase; -import org.jsmart.zerocode.core.domain.Scenario; -import org.jsmart.zerocode.core.domain.ScenarioSpec; -import org.jsmart.zerocode.core.domain.TargetEnv; -import org.jsmart.zerocode.core.domain.UseHttpClient; -import org.jsmart.zerocode.core.domain.UseKafkaClient; +import org.jsmart.zerocode.core.domain.*; import org.jsmart.zerocode.core.domain.builders.ZeroCodeExecReportBuilder; import org.jsmart.zerocode.core.domain.builders.ZeroCodeIoWriteBuilder; import org.jsmart.zerocode.core.engine.listener.TestUtilityListener; +import org.jsmart.zerocode.core.engine.preprocessor.ZeroCodeJsonSchemaMatcherImpl; import org.jsmart.zerocode.core.httpclient.BasicHttpClient; import org.jsmart.zerocode.core.httpclient.ssl.SslTrustHttpClient; import org.jsmart.zerocode.core.kafka.client.BasicKafkaClient; @@ -41,6 +33,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.lang.annotation.Annotation; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + import static java.lang.System.getProperty; import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.CHARTS_AND_CSV; import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.ZEROCODE_JUNIT; @@ -118,13 +116,24 @@ protected void runChild(FrameworkMethod method, RunNotifier notifier) { jsonTestCaseAnno = evalScenarioToJsonTestCase(method.getMethod().getAnnotation(Scenario.class)); } + JsonTestCase jsonTestCaseSchemaAnno = method.getMethod().getAnnotation(JsonTestCase.class); + if(jsonTestCaseSchemaAnno == null){ + jsonTestCaseSchemaAnno = evalSchemaToJsonTestCase(method.getMethod().getAnnotation(Schema.class)); + } + if (isIgnored(method)) { notifier.fireTestIgnored(description); } else if (jsonTestCaseAnno != null) { - runLeafJsonTest(notifier, description, jsonTestCaseAnno); + if( jsonTestCaseSchemaAnno != null ) + runLeafJsonTest(notifier, description, jsonTestCaseAnno , jsonTestCaseSchemaAnno); + else + { + LOGGER.warn("No Json Schema was added for validation"); + runLeafJsonTest(notifier, description, jsonTestCaseAnno); + } } else { // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= @@ -205,7 +214,7 @@ protected ZeroCodeReportGenerator getInjectedReportGenerator() { return getMainModuleInjector().getInstance(ZeroCodeReportGenerator.class); } - private void runLeafJsonTest(RunNotifier notifier, Description description, JsonTestCase jsonTestCaseAnno) { + private void runLeafJsonTest(RunNotifier notifier, Description description, JsonTestCase jsonTestCaseAnno, JsonTestCase jsonTestCaseSchemaAnno) { if (jsonTestCaseAnno != null) { currentTestCase = jsonTestCaseAnno.value(); } @@ -220,6 +229,68 @@ private void runLeafJsonTest(RunNotifier notifier, Description description, Json LOGGER.debug("### Found currentTestCase : -" + child); + if( jsonTestCaseSchemaAnno == null ) + { + LOGGER.warn("### No Json Schema was added for validation"); + } + else + { + LOGGER.debug("### Found JsonSchema : -" + jsonTestCaseSchemaAnno.value()); + ObjectMapper mapper = new ObjectMapper(); + ZeroCodeJsonSchemaMatcherImpl zeroCodeJsonSchemaMatcher = new ZeroCodeJsonSchemaMatcherImpl(); + + String path1 = SmartUtils.readJsonAsString( currentTestCase ); + JsonNode jsonFile = mapper.readTree(path1); + + String path2 = SmartUtils.readJsonAsString( jsonTestCaseSchemaAnno.value() ); + + JsonNode schemaFile = mapper.readTree(path2); + + if( zeroCodeJsonSchemaMatcher.ismatching(jsonFile , schemaFile) ) + { + LOGGER.debug("### JsonSchema matches with the JsonFile."); + + } + else + { + LOGGER.error("### JsonSchema does not matches with the JsonFile."); + throw new Exception("JsonSchema does not matches with the JsonFile."); + } + } + passed = multiStepsRunner.runScenario(child, notifier, description); + + } catch (Exception ioEx) { + ioEx.printStackTrace(); + notifier.fireTestFailure(new Failure(description, ioEx)); + } + + testRunCompleted = true; + + if (passed) { + LOGGER.debug(String.format("\n**FINISHED executing all Steps for [%s] **.\nSteps were:%s", + child.getScenarioName(), + child.getSteps().stream() + .map(step -> step.getName() == null ? step.getId() : step.getName()) + .collect(Collectors.toList()))); + } + + notifier.fireTestFinished(description); + } + + private void runLeafJsonTest(RunNotifier notifier, Description description, JsonTestCase jsonTestCaseAnno) { + if (jsonTestCaseAnno != null) { + currentTestCase = jsonTestCaseAnno.value(); + } + + notifier.fireTestStarted(description); + + LOGGER.debug("### Running currentTestCase : " + currentTestCase); + + ScenarioSpec child = null; + try { + child = smartUtils.scenarioFileToJava(currentTestCase, ScenarioSpec.class); + + LOGGER.debug("### Found currentTestCase : -" + child); passed = multiStepsRunner.runScenario(child, notifier, description); } catch (Exception ioEx) { @@ -369,5 +440,25 @@ public String value() { return jsonTestCase.value() == null ? null : jsonTestCase; } + private JsonTestCase evalSchemaToJsonTestCase(Schema schema) { + // --------------------------------------------------- + // If Schema is present then convert to JsonTestCase + // --------------------------------------------------- + JsonTestCase jsonTestCase = new JsonTestCase() { + + @Override + public Class annotationType() { + return JsonTestCase.class; + } + + @Override + public String value() { + return schema != null? schema.value(): null; + } + }; + + return jsonTestCase.value() == null ? null : jsonTestCase; + } + } diff --git a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworld/JustHelloWorldTest.java b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworld/JustHelloWorldTest.java index 12046e8eb..4d0d03141 100644 --- a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworld/JustHelloWorldTest.java +++ b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworld/JustHelloWorldTest.java @@ -13,6 +13,8 @@ public class JustHelloWorldTest { @Test @Scenario("helloworld/hello_world_status_ok_assertions.json") public void testGet() throws Exception { + + } -} +} \ No newline at end of file diff --git a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldparameterizedvalue/HelloWorldParameterizedValueTest.java b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldparameterizedvalue/HelloWorldParameterizedValueTest.java index 963a632b6..313b9e911 100644 --- a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldparameterizedvalue/HelloWorldParameterizedValueTest.java +++ b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldparameterizedvalue/HelloWorldParameterizedValueTest.java @@ -1,6 +1,7 @@ package org.jsmart.zerocode.testhelp.tests.helloworldparameterizedvalue; import org.jsmart.zerocode.core.domain.Scenario; +import org.jsmart.zerocode.core.domain.Schema; import org.jsmart.zerocode.core.domain.TargetEnv; import org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner; import org.junit.Test; diff --git a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/hellowworldschema/JustHelloWorldSchemaTest.java b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/hellowworldschema/JustHelloWorldSchemaTest.java new file mode 100644 index 000000000..b202569d9 --- /dev/null +++ b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/hellowworldschema/JustHelloWorldSchemaTest.java @@ -0,0 +1,23 @@ +package org.jsmart.zerocode.testhelp.tests.hellowworldschema; + +import org.jsmart.zerocode.core.domain.Scenario; +import org.jsmart.zerocode.core.domain.Schema; +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 JustHelloWorldSchemaTest { + + @Test + @Scenario("helloworldschema/hello_world_status_ok_assertions.json") + @Schema("helloworldschema/hello_world_status_ok_assertions_schema.json") + public void testGet() throws Exception { + + + } + +} + diff --git a/http-testing/src/test/resources/helloworldschema/hello_world_status_ok_assertions.json b/http-testing/src/test/resources/helloworldschema/hello_world_status_ok_assertions.json new file mode 100644 index 000000000..0873b3a3f --- /dev/null +++ b/http-testing/src/test/resources/helloworldschema/hello_world_status_ok_assertions.json @@ -0,0 +1,20 @@ +{ + "scenarioName": "GIVEN- the GitHub REST end point, WHEN- I invoke GET, THEN- I will receive the 200 status with body", + "steps": [ + { + "name": "get_user_details", + "url": "/users/octocat", + "method": "GET", + "request": { + }, + "verify": { + "status": 200, + "body": { + "login" : "octocat", + "id" : 583231, + "type" : "User" + } + } + } + ] +} diff --git a/http-testing/src/test/resources/helloworldschema/hello_world_status_ok_assertions_schema.json b/http-testing/src/test/resources/helloworldschema/hello_world_status_ok_assertions_schema.json new file mode 100644 index 000000000..544bfd0af --- /dev/null +++ b/http-testing/src/test/resources/helloworldschema/hello_world_status_ok_assertions_schema.json @@ -0,0 +1,73 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "scenarioName": { + "type": "string" + }, + "steps": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "url": { + "type": "string" + }, + "method": { + "type": "string" + }, + "request": { + "type": "object" + }, + "verify": { + "type": "object", + "properties": { + "status": { + "type": "integer" + }, + "body": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "type": { + "type": "string" + } + }, + "required": [ + "login", + "id", + "type" + ] + } + }, + "required": [ + "status", + "body" + ] + } + }, + "required": [ + "name", + "url", + "method", + "request", + "verify" + ] + } + ] + } + }, + "required": [ + "scenarioName", + "steps" + ] +} \ No newline at end of file diff --git a/kafka-testing/pom.xml b/kafka-testing/pom.xml index 0a160f10c..1126591aa 100644 --- a/kafka-testing/pom.xml +++ b/kafka-testing/pom.xml @@ -82,6 +82,11 @@ --> + + + + + From cb84049963fa96d895da5bcc692ad3a836200737 Mon Sep 17 00:00:00 2001 From: Yash Tiwari Date: Wed, 11 Sep 2024 15:00:24 +0530 Subject: [PATCH 2/9] removed comments --- .../ZeroCodeJsonSchemaMatcherImpl.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java b/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java index cb6db88b6..3b237392b 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java +++ b/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java @@ -34,20 +34,5 @@ public boolean ismatching(JsonNode jsonFile, JsonNode schema ) { } // TODO remember to remove this working of this ismatching for implementing ir inside the zerocode. -// public static void main(String[] args) throws IOException { -// ObjectMapper mapper = new ObjectMapper(); -// SmartUtils smartUtils = new SmartUtils(); -// -// -// ZeroCodeJsonSchemaMatcherImpl zero = new ZeroCodeJsonSchemaMatcherImpl(); -// if(zero.ismatching( one , two )) -// { -// System.out.println("Matching with Schema"); -// } -// else -// { -// System.out.println("Not matching with Schema"); -// } -// } } From 1e85a2d75115851c35816791a7714dfd4832832f Mon Sep 17 00:00:00 2001 From: Yash Tiwari Date: Wed, 11 Sep 2024 16:09:31 +0530 Subject: [PATCH 3/9] Removed comments --- .../engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java b/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java index 3b237392b..8eff80ddf 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java +++ b/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java @@ -21,18 +21,17 @@ import static java.nio.charset.StandardCharsets.UTF_8; -public class ZeroCodeJsonSchemaMatcherImpl implements ZeroCodeJsonSchemaMatcher{ +public class ZeroCodeJsonSchemaMatcherImpl implements ZeroCodeJsonSchemaMatcher { @Override - public boolean ismatching(JsonNode jsonFile, JsonNode schema ) { + public boolean ismatching(JsonNode jsonFile, JsonNode schema) { JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4); JsonSchema jsonSchema = factory.getSchema(schema); Set errors = jsonSchema.validate(jsonFile); return errors.isEmpty(); } -// TODO remember to remove this working of this ismatching for implementing ir inside the zerocode. - +// TODO remember to remove the use of ismatching in main function in this CLass } From f692bb72477f5f7c1a940ed56c33b62ec63dbf30 Mon Sep 17 00:00:00 2001 From: Yash Tiwari Date: Tue, 17 Sep 2024 14:49:43 +0530 Subject: [PATCH 4/9] Json Schema validation based on response. --- .../zerocode/core/domain/ScenarioSpec.java | 3 + .../zerocode/core/domain/SchemaStep.java | 48 ++++++++++++++ .../preprocessor/StepExecutionState.java | 10 +++ .../ZeroCodeMultiStepsScenarioRunnerImpl.java | 35 +++++++++- .../core/runner/ZeroCodeUnitRunner.java | 65 ++++++++----------- ...llo_world_status_ok_assertions_schema.json | 8 +-- 6 files changed, 124 insertions(+), 45 deletions(-) create mode 100644 core/src/main/java/org/jsmart/zerocode/core/domain/SchemaStep.java diff --git a/core/src/main/java/org/jsmart/zerocode/core/domain/ScenarioSpec.java b/core/src/main/java/org/jsmart/zerocode/core/domain/ScenarioSpec.java index 9c06ffa16..6a35212f4 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/domain/ScenarioSpec.java +++ b/core/src/main/java/org/jsmart/zerocode/core/domain/ScenarioSpec.java @@ -50,6 +50,9 @@ public Parameterized getParameterized() { return parameterized; } + public void addStep(Step step) { + this.steps.add(step); + } @Override public String toString() { return "ScenarioSpec{" + diff --git a/core/src/main/java/org/jsmart/zerocode/core/domain/SchemaStep.java b/core/src/main/java/org/jsmart/zerocode/core/domain/SchemaStep.java new file mode 100644 index 000000000..1002e3598 --- /dev/null +++ b/core/src/main/java/org/jsmart/zerocode/core/domain/SchemaStep.java @@ -0,0 +1,48 @@ +package org.jsmart.zerocode.core.domain; + +import com.fasterxml.jackson.databind.JsonNode; +import com.github.tomakehurst.wiremock.common.Json; + +import java.util.List; + +public class SchemaStep extends Step{ + + private JsonNode response; + public SchemaStep(Integer loop, Retry retry, String name, String operation, String method, String url, JsonNode request, List validators, JsonNode sort, JsonNode assertions, JsonNode verify , JsonNode response , String verifyMode, boolean ignoreStep) { + super(loop, retry, name, operation, method, url, request, validators, sort, assertions, verify, verifyMode, ignoreStep); + + this.response = response; + } + + public JsonNode getResponse() + { + return response; + } + + public void setResponse(JsonNode response) { + this.response = response; + } + + @Override + public String toString() { + return "SchemaStep{" + + "loop=" + getLoop() + + ", retry='" + getRetry() + '\'' + + ", name='" + getName() + '\'' + + ", method='" + getMethod() + '\'' + + ", operation='" + getOperation() + '\'' + + ", url='" + getUrl() + '\'' + + ", request=" + getRequest() + + ", validators=" + getValidators() + + ", assertions=" + getAssertions() + + ", response=" + response + + ", verifyMode=" + getVerifyMode() + + ", verify=" + getVerify() + + ", id='" + getId() + '\'' + + ", stepFile=" + getStepFile() + + ", stepFiles=" + getStepFiles() + + ", parameterized=" + getParameterized() + + ", customLog=" + getCustomLog() + + '}'; + } +} diff --git a/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/StepExecutionState.java b/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/StepExecutionState.java index 814b7bd13..7bd108ec8 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/StepExecutionState.java +++ b/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/StepExecutionState.java @@ -31,6 +31,16 @@ public void addRequest(String requestJson) { } + public String getResponse() + { + return paramMap.get("STEP.RESPONSE"); + } + + public String getRequest() + { + return paramMap.get("STEP.REQUEST"); + } + public void addResponse(String responseJson) { paramMap.put("STEP.RESPONSE", responseJson); } diff --git a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java index 12c4a5736..bfb23d88b 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java +++ b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java @@ -1,6 +1,7 @@ package org.jsmart.zerocode.core.runner; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.NullNode; import com.google.inject.Inject; @@ -13,6 +14,7 @@ import org.jsmart.zerocode.core.domain.Parameterized; import org.jsmart.zerocode.core.domain.ScenarioSpec; +import org.jsmart.zerocode.core.domain.SchemaStep; import org.jsmart.zerocode.core.domain.Step; import org.jsmart.zerocode.core.domain.builders.ZeroCodeExecReportBuilder; @@ -21,6 +23,8 @@ import org.jsmart.zerocode.core.domain.builders.ZeroCodeIoWriteBuilder; import org.jsmart.zerocode.core.engine.assertion.FieldAssertionMatcher; import org.jsmart.zerocode.core.engine.executor.ApiServiceExecutor; + +import static org.jsmart.zerocode.core.engine.mocker.RestEndPointMocker.shouldBuildStrictUrlMatcherForAllUrls; import static org.jsmart.zerocode.core.engine.mocker.RestEndPointMocker.wireMockServer; import org.jsmart.zerocode.core.engine.preprocessor.ScenarioExecutionState; import org.jsmart.zerocode.core.engine.preprocessor.StepExecutionState; @@ -35,11 +39,14 @@ import static org.jsmart.zerocode.core.utils.ApiTypeUtils.apiType; import static org.jsmart.zerocode.core.utils.RunnerUtils.getFullyQualifiedUrl; import static org.jsmart.zerocode.core.utils.SmartUtils.prettyPrintJson; + +import org.jsmart.zerocode.core.utils.SmartUtils; import org.junit.runner.Description; import org.junit.runner.notification.RunNotifier; import org.slf4j.Logger; import static org.slf4j.LoggerFactory.getLogger; +import java.sql.SQLOutput; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -108,6 +115,11 @@ public class ZeroCodeMultiStepsScenarioRunnerImpl implements ZeroCodeMultiStepsS private Boolean stepOutcomeGreen; + private ScenarioSpec schemaScenario; + + + + @Override public synchronized boolean runScenario(ScenarioSpec scenario, RunNotifier notifier, Description description) { @@ -133,10 +145,11 @@ public synchronized boolean runScenario(ScenarioSpec scenario, RunNotifier notif ScenarioSpec parameterizedScenario = parameterizedProcessor.resolveParameterized(scenario, scnCount); + schemaScenario = new ScenarioSpec(parameterizedScenario.getLoop() , parameterizedScenario.getIgnoreStepFailures() , parameterizedScenario.getScenarioName() , new ArrayList() , parameterizedScenario.getParameterized()); + resultReportBuilder = newInstance() .loop(scnCount) .scenarioName(parameterizedScenario.getScenarioName()); - wasExecSuccessful = executeSteps(notifier, description, scenarioExecutionState, parameterizedScenario); ioWriterBuilder.result(resultReportBuilder.build()); @@ -255,6 +268,7 @@ private Boolean executeRetry(RunNotifier notifier, } executionResult = executeApi(logPrefixRelationshipId, thisStep, resolvedRequestJson, scenarioExecutionState); + // logging response final LocalDateTime responseTimeStamp = LocalDateTime.now(); correlLogger.aResponseBuilder() @@ -276,7 +290,7 @@ private Boolean executeRetry(RunNotifier notifier, } - // TODO I will be implementing the code for JSon Schema Validation here in case we are having the error specified. + // --------------------------------- // Handle assertion section -START @@ -318,6 +332,16 @@ private Boolean executeRetry(RunNotifier notifier, continue; } + + + JsonNode schemaRequest = objectMapper.readTree(stepExecutionState.getRequest()+"\n" ); + JsonNode schemaResponse = objectMapper.readTree(executionResult); + + SchemaStep schemaStep = new SchemaStep(thisStep.getLoop() , thisStep.getRetry() , thisStep.getName() , thisStep.getOperation() , thisStep.getMethod() , thisStep.getUrl() ,schemaRequest , thisStep.getValidators() , thisStep.getSort() , null , null , schemaResponse , thisStep.getVerifyMode() , thisStep.getIgnoreStep()); + + schemaScenario.addStep(schemaStep); + + boolean ignoreStepFailures = scenario.getIgnoreStepFailures() == null ? false : scenario.getIgnoreStepFailures(); if (!failureResults.isEmpty()) { stepOutcomeGreen = notificationHandler.handleAssertion( @@ -605,4 +629,11 @@ else if (ofNullable(thisStep.getVerifyMode()).orElse("LENIENT").equals("STRICT") return failureResults; } + public ScenarioSpec getSchemaScenario() { + return schemaScenario; + } + + public void setSchemaScenario(ScenarioSpec scenarioSpec) { + this.schemaScenario = scenarioSpec; + } } diff --git a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java index 654468bc9..f61a57bec 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java +++ b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java @@ -116,22 +116,22 @@ protected void runChild(FrameworkMethod method, RunNotifier notifier) { jsonTestCaseAnno = evalScenarioToJsonTestCase(method.getMethod().getAnnotation(Scenario.class)); } - JsonTestCase jsonTestCaseSchemaAnno = method.getMethod().getAnnotation(JsonTestCase.class); - if(jsonTestCaseSchemaAnno == null){ - jsonTestCaseSchemaAnno = evalSchemaToJsonTestCase(method.getMethod().getAnnotation(Schema.class)); - } + + + Schema schema = method.getMethod().getAnnotation(Schema.class); + if (isIgnored(method)) { notifier.fireTestIgnored(description); - } else if (jsonTestCaseAnno != null) { + } else if (jsonTestCaseAnno != null ) { - if( jsonTestCaseSchemaAnno != null ) - runLeafJsonTest(notifier, description, jsonTestCaseAnno , jsonTestCaseSchemaAnno); + if( schema != null ) + runLeafJsonTest(notifier, description, jsonTestCaseAnno , schema); else { - LOGGER.warn("No Json Schema was added for validation"); + LOGGER.debug("No Json Schema was added for validation"); runLeafJsonTest(notifier, description, jsonTestCaseAnno); } @@ -214,7 +214,8 @@ protected ZeroCodeReportGenerator getInjectedReportGenerator() { return getMainModuleInjector().getInstance(ZeroCodeReportGenerator.class); } - private void runLeafJsonTest(RunNotifier notifier, Description description, JsonTestCase jsonTestCaseAnno, JsonTestCase jsonTestCaseSchemaAnno) { + //This one is for schemaValidation + private void runLeafJsonTest(RunNotifier notifier, Description description, JsonTestCase jsonTestCaseAnno, Schema schemaAnno) { if (jsonTestCaseAnno != null) { currentTestCase = jsonTestCaseAnno.value(); } @@ -229,35 +230,43 @@ private void runLeafJsonTest(RunNotifier notifier, Description description, Json LOGGER.debug("### Found currentTestCase : -" + child); - if( jsonTestCaseSchemaAnno == null ) + + passed = multiStepsRunner.runScenario(child, notifier, description); + // TODO Schema validation + if( schemaAnno == null ) { LOGGER.warn("### No Json Schema was added for validation"); } else { - LOGGER.debug("### Found JsonSchema : -" + jsonTestCaseSchemaAnno.value()); + LOGGER.debug("### Found Json Schema : - \n" + smartUtils.prettyPrintJson(smartUtils.readJsonAsString(schemaAnno.value()))); + + // Schema Validation is performed here... + ObjectMapper mapper = new ObjectMapper(); + ZeroCodeJsonSchemaMatcherImpl zeroCodeJsonSchemaMatcher = new ZeroCodeJsonSchemaMatcherImpl(); - String path1 = SmartUtils.readJsonAsString( currentTestCase ); - JsonNode jsonFile = mapper.readTree(path1); + JsonNode jsonFile = mapper.valueToTree(((ZeroCodeMultiStepsScenarioRunnerImpl)multiStepsRunner).getSchemaScenario()); - String path2 = SmartUtils.readJsonAsString( jsonTestCaseSchemaAnno.value() ); + String jsonScenarioFile = SmartUtils.readJsonAsString( schemaAnno.value() ); - JsonNode schemaFile = mapper.readTree(path2); + JsonNode schemaFile = mapper.readTree(jsonScenarioFile); if( zeroCodeJsonSchemaMatcher.ismatching(jsonFile , schemaFile) ) { - LOGGER.debug("### JsonSchema matches with the JsonFile."); + LOGGER.debug("### Json Schema matches with the Json test file." ); } else { - LOGGER.error("### JsonSchema does not matches with the JsonFile."); - throw new Exception("JsonSchema does not matches with the JsonFile."); + LOGGER.error("### Json Schema does not matches with the Json test file."); + throw new Exception("Json Schema does not matches with the Json test file."); } } - passed = multiStepsRunner.runScenario(child, notifier, description); + + + } catch (Exception ioEx) { ioEx.printStackTrace(); @@ -440,25 +449,7 @@ public String value() { return jsonTestCase.value() == null ? null : jsonTestCase; } - private JsonTestCase evalSchemaToJsonTestCase(Schema schema) { - // --------------------------------------------------- - // If Schema is present then convert to JsonTestCase - // --------------------------------------------------- - JsonTestCase jsonTestCase = new JsonTestCase() { - - @Override - public Class annotationType() { - return JsonTestCase.class; - } - - @Override - public String value() { - return schema != null? schema.value(): null; - } - }; - return jsonTestCase.value() == null ? null : jsonTestCase; - } } diff --git a/http-testing/src/test/resources/helloworldschema/hello_world_status_ok_assertions_schema.json b/http-testing/src/test/resources/helloworldschema/hello_world_status_ok_assertions_schema.json index 544bfd0af..3e5bf9878 100644 --- a/http-testing/src/test/resources/helloworldschema/hello_world_status_ok_assertions_schema.json +++ b/http-testing/src/test/resources/helloworldschema/hello_world_status_ok_assertions_schema.json @@ -23,7 +23,7 @@ "request": { "type": "object" }, - "verify": { + "response": { "type": "object", "properties": { "status": { @@ -56,11 +56,7 @@ } }, "required": [ - "name", - "url", - "method", - "request", - "verify" + "response" ] } ] From 54c6ffcda188fda04788cb94a8901afcfc295f9f Mon Sep 17 00:00:00 2001 From: Yash-cor Date: Fri, 20 Sep 2024 13:27:39 +0530 Subject: [PATCH 5/9] Update pom.xml --- kafka-testing/pom.xml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kafka-testing/pom.xml b/kafka-testing/pom.xml index 1126591aa..f6c320676 100644 --- a/kafka-testing/pom.xml +++ b/kafka-testing/pom.xml @@ -84,9 +84,7 @@ --> - - - + From 41c2c4f626f0139b54b13a0cb98f9073d3d54c23 Mon Sep 17 00:00:00 2001 From: Yash Tiwari Date: Wed, 25 Sep 2024 10:50:04 +0530 Subject: [PATCH 6/9] Refactored code and made changes in imports --- core/pom.xml | 4 ---- .../ZeroCodeJsonSchemaMatcherImpl.java | 4 ---- .../ZeroCodeMultiStepsScenarioRunnerImpl.java | 12 +---------- .../core/runner/ZeroCodeUnitRunner.java | 21 +++++++------------ .../tests/helloworld/JustHelloWorldTest.java | 3 --- .../HelloWorldParameterizedValueTest.java | 1 - .../JustHelloWorldSchemaTest.java | 5 +---- kafka-testing/pom.xml | 6 ------ 8 files changed, 10 insertions(+), 46 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 83ddc4b9a..c6a437e5a 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -192,15 +192,11 @@ com.google.protobuf protobuf-java-util - - com.networknt json-schema-validator 1.4.0 - - diff --git a/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java b/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java index bb33fa449..e0898c07d 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java +++ b/core/src/main/java/org/jsmart/zerocode/core/engine/preprocessor/ZeroCodeJsonSchemaMatcherImpl.java @@ -1,13 +1,10 @@ package org.jsmart.zerocode.core.engine.preprocessor; import com.fasterxml.jackson.databind.JsonNode; - - import com.networknt.schema.JsonSchema; import com.networknt.schema.JsonSchemaFactory; import com.networknt.schema.SpecVersion; import com.networknt.schema.ValidationMessage; - import java.util.Set; @@ -22,6 +19,5 @@ public boolean ismatching(JsonNode jsonFile, JsonNode schema) { Set errors = jsonSchema.validate(jsonFile); return errors.isEmpty(); } -// TODO remember to remove the use of ismatching in main function in this CLass } diff --git a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java index bfb23d88b..9637c8cfb 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java +++ b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java @@ -23,8 +23,6 @@ import org.jsmart.zerocode.core.domain.builders.ZeroCodeIoWriteBuilder; import org.jsmart.zerocode.core.engine.assertion.FieldAssertionMatcher; import org.jsmart.zerocode.core.engine.executor.ApiServiceExecutor; - -import static org.jsmart.zerocode.core.engine.mocker.RestEndPointMocker.shouldBuildStrictUrlMatcherForAllUrls; import static org.jsmart.zerocode.core.engine.mocker.RestEndPointMocker.wireMockServer; import org.jsmart.zerocode.core.engine.preprocessor.ScenarioExecutionState; import org.jsmart.zerocode.core.engine.preprocessor.StepExecutionState; @@ -39,14 +37,11 @@ import static org.jsmart.zerocode.core.utils.ApiTypeUtils.apiType; import static org.jsmart.zerocode.core.utils.RunnerUtils.getFullyQualifiedUrl; import static org.jsmart.zerocode.core.utils.SmartUtils.prettyPrintJson; - -import org.jsmart.zerocode.core.utils.SmartUtils; import org.junit.runner.Description; import org.junit.runner.notification.RunNotifier; import org.slf4j.Logger; import static org.slf4j.LoggerFactory.getLogger; -import java.sql.SQLOutput; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -117,9 +112,6 @@ public class ZeroCodeMultiStepsScenarioRunnerImpl implements ZeroCodeMultiStepsS private ScenarioSpec schemaScenario; - - - @Override public synchronized boolean runScenario(ScenarioSpec scenario, RunNotifier notifier, Description description) { @@ -150,6 +142,7 @@ public synchronized boolean runScenario(ScenarioSpec scenario, RunNotifier notif resultReportBuilder = newInstance() .loop(scnCount) .scenarioName(parameterizedScenario.getScenarioName()); + wasExecSuccessful = executeSteps(notifier, description, scenarioExecutionState, parameterizedScenario); ioWriterBuilder.result(resultReportBuilder.build()); @@ -289,9 +282,6 @@ private Boolean executeRetry(RunNotifier notifier, scenarioExecutionState.addStepState(stepExecutionState); } - - - // --------------------------------- // Handle assertion section -START // --------------------------------- diff --git a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java index f61a57bec..823aa3ff2 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java +++ b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java @@ -8,7 +8,14 @@ import org.jsmart.zerocode.core.di.main.ApplicationMainModule; import org.jsmart.zerocode.core.di.module.RuntimeHttpClientModule; import org.jsmart.zerocode.core.di.module.RuntimeKafkaClientModule; -import org.jsmart.zerocode.core.domain.*; +import org.jsmart.zerocode.core.domain.HostProperties; +import org.jsmart.zerocode.core.domain.JsonTestCase; +import org.jsmart.zerocode.core.domain.Scenario; +import org.jsmart.zerocode.core.domain.ScenarioSpec; +import org.jsmart.zerocode.core.domain.TargetEnv; +import org.jsmart.zerocode.core.domain.UseHttpClient; +import org.jsmart.zerocode.core.domain.UseKafkaClient; +import org.jsmart.zerocode.core.domain.Schema; import org.jsmart.zerocode.core.domain.builders.ZeroCodeExecReportBuilder; import org.jsmart.zerocode.core.domain.builders.ZeroCodeIoWriteBuilder; import org.jsmart.zerocode.core.engine.listener.TestUtilityListener; @@ -116,11 +123,8 @@ protected void runChild(FrameworkMethod method, RunNotifier notifier) { jsonTestCaseAnno = evalScenarioToJsonTestCase(method.getMethod().getAnnotation(Scenario.class)); } - - Schema schema = method.getMethod().getAnnotation(Schema.class); - if (isIgnored(method)) { notifier.fireTestIgnored(description); @@ -230,7 +234,6 @@ private void runLeafJsonTest(RunNotifier notifier, Description description, Json LOGGER.debug("### Found currentTestCase : -" + child); - passed = multiStepsRunner.runScenario(child, notifier, description); // TODO Schema validation if( schemaAnno == null ) @@ -264,10 +267,6 @@ private void runLeafJsonTest(RunNotifier notifier, Description description, Json throw new Exception("Json Schema does not matches with the Json test file."); } } - - - - } catch (Exception ioEx) { ioEx.printStackTrace(); notifier.fireTestFailure(new Failure(description, ioEx)); @@ -448,8 +447,4 @@ public String value() { return jsonTestCase.value() == null ? null : jsonTestCase; } - - - - } diff --git a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworld/JustHelloWorldTest.java b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworld/JustHelloWorldTest.java index 4d0d03141..fd8edbbaf 100644 --- a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworld/JustHelloWorldTest.java +++ b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworld/JustHelloWorldTest.java @@ -13,8 +13,5 @@ public class JustHelloWorldTest { @Test @Scenario("helloworld/hello_world_status_ok_assertions.json") public void testGet() throws Exception { - - } - } \ No newline at end of file diff --git a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldparameterizedvalue/HelloWorldParameterizedValueTest.java b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldparameterizedvalue/HelloWorldParameterizedValueTest.java index 313b9e911..963a632b6 100644 --- a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldparameterizedvalue/HelloWorldParameterizedValueTest.java +++ b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldparameterizedvalue/HelloWorldParameterizedValueTest.java @@ -1,7 +1,6 @@ package org.jsmart.zerocode.testhelp.tests.helloworldparameterizedvalue; import org.jsmart.zerocode.core.domain.Scenario; -import org.jsmart.zerocode.core.domain.Schema; import org.jsmart.zerocode.core.domain.TargetEnv; import org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner; import org.junit.Test; diff --git a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/hellowworldschema/JustHelloWorldSchemaTest.java b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/hellowworldschema/JustHelloWorldSchemaTest.java index b202569d9..2a49e6975 100644 --- a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/hellowworldschema/JustHelloWorldSchemaTest.java +++ b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/hellowworldschema/JustHelloWorldSchemaTest.java @@ -15,9 +15,6 @@ public class JustHelloWorldSchemaTest { @Scenario("helloworldschema/hello_world_status_ok_assertions.json") @Schema("helloworldschema/hello_world_status_ok_assertions_schema.json") public void testGet() throws Exception { - - } -} - +} \ No newline at end of file diff --git a/kafka-testing/pom.xml b/kafka-testing/pom.xml index 1126591aa..0a160f10c 100644 --- a/kafka-testing/pom.xml +++ b/kafka-testing/pom.xml @@ -82,11 +82,6 @@ --> - - - - - From ce7f50cc3a8c194debe409f53a85a9f5d8fca39c Mon Sep 17 00:00:00 2001 From: Yash Tiwari Date: Wed, 25 Sep 2024 10:56:52 +0530 Subject: [PATCH 7/9] Refactored code in kafka pom --- kafka-testing/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/kafka-testing/pom.xml b/kafka-testing/pom.xml index e1d6b32a2..0a160f10c 100644 --- a/kafka-testing/pom.xml +++ b/kafka-testing/pom.xml @@ -107,7 +107,6 @@ - --> From f6979dcb49a7190022bc0157549a9175a489a832 Mon Sep 17 00:00:00 2001 From: Yash Tiwari Date: Mon, 7 Oct 2024 13:47:02 +0530 Subject: [PATCH 8/9] Made the updates to schema impl according to new merges to zerocode repo. --- .../ZeroCodeMultiStepsScenarioRunnerImpl.java | 2 +- .../core/runner/ZeroCodeUnitRunner.java | 48 +++---------------- 2 files changed, 8 insertions(+), 42 deletions(-) diff --git a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java index 9637c8cfb..cdd87cc99 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java +++ b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeMultiStepsScenarioRunnerImpl.java @@ -137,7 +137,7 @@ public synchronized boolean runScenario(ScenarioSpec scenario, RunNotifier notif ScenarioSpec parameterizedScenario = parameterizedProcessor.resolveParameterized(scenario, scnCount); - schemaScenario = new ScenarioSpec(parameterizedScenario.getLoop() , parameterizedScenario.getIgnoreStepFailures() , parameterizedScenario.getScenarioName() , new ArrayList() , parameterizedScenario.getParameterized()); + schemaScenario = new ScenarioSpec(parameterizedScenario.getLoop() , parameterizedScenario.getIgnoreStepFailures() , parameterizedScenario.getScenarioName() , new ArrayList() , parameterizedScenario.getParameterized() , parameterizedScenario.getMeta()); resultReportBuilder = newInstance() .loop(scnCount) diff --git a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java index 823aa3ff2..6eaff1d4b 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java +++ b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java @@ -69,7 +69,7 @@ public class ZeroCodeUnitRunner extends BlockJUnit4ClassRunner { private ZerocodeCorrelationshipLogger corrLogger; protected boolean testRunCompleted; protected boolean passed; - + protected Schema schemaAnno; private ZeroCodeMultiStepsScenarioRunner multiStepsRunner; /** @@ -123,7 +123,7 @@ protected void runChild(FrameworkMethod method, RunNotifier notifier) { jsonTestCaseAnno = evalScenarioToJsonTestCase(method.getMethod().getAnnotation(Scenario.class)); } - Schema schema = method.getMethod().getAnnotation(Schema.class); + schemaAnno = method.getMethod().getAnnotation(Schema.class); if (isIgnored(method)) { @@ -131,13 +131,11 @@ protected void runChild(FrameworkMethod method, RunNotifier notifier) { } else if (jsonTestCaseAnno != null ) { - if( schema != null ) - runLeafJsonTest(notifier, description, jsonTestCaseAnno , schema); - else + if( schemaAnno == null ) { LOGGER.debug("No Json Schema was added for validation"); - runLeafJsonTest(notifier, description, jsonTestCaseAnno); } + runLeafJsonTest(notifier, description, jsonTestCaseAnno); } else { // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= @@ -218,8 +216,8 @@ protected ZeroCodeReportGenerator getInjectedReportGenerator() { return getMainModuleInjector().getInstance(ZeroCodeReportGenerator.class); } - //This one is for schemaValidation - private void runLeafJsonTest(RunNotifier notifier, Description description, JsonTestCase jsonTestCaseAnno, Schema schemaAnno) { + + private void runLeafJsonTest(RunNotifier notifier, Description description, JsonTestCase jsonTestCaseAnno) { if (jsonTestCaseAnno != null) { currentTestCase = jsonTestCaseAnno.value(); } @@ -235,7 +233,7 @@ private void runLeafJsonTest(RunNotifier notifier, Description description, Json LOGGER.debug("### Found currentTestCase : -" + child); passed = multiStepsRunner.runScenario(child, notifier, description); - // TODO Schema validation + //Schema validation if( schemaAnno == null ) { LOGGER.warn("### No Json Schema was added for validation"); @@ -285,39 +283,7 @@ private void runLeafJsonTest(RunNotifier notifier, Description description, Json notifier.fireTestFinished(description); } - private void runLeafJsonTest(RunNotifier notifier, Description description, JsonTestCase jsonTestCaseAnno) { - if (jsonTestCaseAnno != null) { - currentTestCase = jsonTestCaseAnno.value(); - } - notifier.fireTestStarted(description); - - LOGGER.debug("### Running currentTestCase : " + currentTestCase); - - ScenarioSpec child = null; - try { - child = smartUtils.scenarioFileToJava(currentTestCase, ScenarioSpec.class); - - LOGGER.debug("### Found currentTestCase : -" + child); - passed = multiStepsRunner.runScenario(child, notifier, description); - - } catch (Exception ioEx) { - ioEx.printStackTrace(); - notifier.fireTestFailure(new Failure(description, ioEx)); - } - - testRunCompleted = true; - - if (passed) { - LOGGER.debug(String.format("\n**FINISHED executing all Steps for [%s] **.\nSteps were:%s", - child.getScenarioName(), - child.getSteps().stream() - .map(step -> step.getName() == null ? step.getId() : step.getName()) - .collect(Collectors.toList()))); - } - - notifier.fireTestFinished(description); - } private List getSmartChildrenList() { List children = getChildren(); From 37bb0d75bbef31c6ae15bb28815d68fcfdf50944 Mon Sep 17 00:00:00 2001 From: Yash Tiwari Date: Tue, 8 Oct 2024 16:02:40 +0530 Subject: [PATCH 9/9] Made changes in ZeroCodeUnitRunner --- .../org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java index 6eaff1d4b..89d4ea8b6 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java +++ b/core/src/main/java/org/jsmart/zerocode/core/runner/ZeroCodeUnitRunner.java @@ -131,10 +131,6 @@ protected void runChild(FrameworkMethod method, RunNotifier notifier) { } else if (jsonTestCaseAnno != null ) { - if( schemaAnno == null ) - { - LOGGER.debug("No Json Schema was added for validation"); - } runLeafJsonTest(notifier, description, jsonTestCaseAnno); } else {