diff --git a/modules/cucumblan-api/pom.xml b/modules/cucumblan-api/pom.xml index 41e79547..b451acde 100644 --- a/modules/cucumblan-api/pom.xml +++ b/modules/cucumblan-api/pom.xml @@ -4,7 +4,7 @@ cucumblan-api jar cucumblan-api - 1.1.7-SNAPSHOT + 1.1.9-SNAPSHOT 1.1.4 6.7.0 diff --git a/modules/cucumblan-api/src/main/java/io/virtualan/cucumblan/core/BaseStepDefinition.java b/modules/cucumblan-api/src/main/java/io/virtualan/cucumblan/core/BaseStepDefinition.java index 2248618e..0d982cf8 100644 --- a/modules/cucumblan-api/src/main/java/io/virtualan/cucumblan/core/BaseStepDefinition.java +++ b/modules/cucumblan-api/src/main/java/io/virtualan/cucumblan/core/BaseStepDefinition.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue; import io.cucumber.datatable.DataTable; +import io.cucumber.java.After; import io.cucumber.java.Before; import io.cucumber.java.Scenario; import io.cucumber.java.en.And; @@ -98,6 +99,8 @@ public class BaseStepDefinition { private Scenario scenario; private int sequence; private String acceptContentType; + private boolean skipScenario = false; + /** * Load action processors. */ @@ -128,7 +131,9 @@ public static void loadStandardProcessors() { */ @Given("^(.*) with an path param (.*) of (.*)") public void readRequestByPathParam(String dummy, String identifier, String value) { - request = given().pathParam(identifier, StepDefinitionHelper.getActualValue(value)); + if(!this.skipScenario){ + request = given().pathParam(identifier, StepDefinitionHelper.getActualValue(value)); + } } @@ -140,7 +145,9 @@ public void readRequestByPathParam(String dummy, String identifier, String value */ @Given("^enable cert for (.*) of (.*)") public void cert(String identifier, String value) { - RestAssured.authentication = RestAssured.certificate(identifier, value); + if(!this.skipScenario) { + RestAssured.authentication = RestAssured.certificate(identifier, value); + } } /** @@ -151,10 +158,12 @@ public void cert(String identifier, String value) { */ @Given("^basic authentication with (.*) and (.*)") public void auth(String username, String password) { - byte[] authBasic = Base64.encode(String - .format("%s:%s", StepDefinitionHelper.getActualValue(username), - StepDefinitionHelper.getActualValue(password)).getBytes()); - request.header("Authorization", String.format("Basic %s", new String(authBasic))); + if (!this.skipScenario) { + byte[] authBasic = Base64.encode(String + .format("%s:%s", StepDefinitionHelper.getActualValue(username), + StepDefinitionHelper.getActualValue(password)).getBytes()); + request.header("Authorization", String.format("Basic %s", new String(authBasic))); + } } /** @@ -165,8 +174,10 @@ public void auth(String username, String password) { */ @Given("^(.*) auth with (.*) token$") public void bearer(String auth, String token) { - request.header("Authorization", String - .format("%s %s", auth, Helper.getActualValueForAll(token, ScenarioContext.getContext()))); + if (!this.skipScenario) { + request.header("Authorization", String + .format("%s %s", auth, Helper.getActualValueForAll(token, ScenarioContext.getContext()))); + } } /** @@ -176,7 +187,9 @@ public void bearer(String auth, String token) { */ @Given("^(.*) perform a api action") public void readRequestByPathParam(String dummy) { - request = given(); + if (!this.skipScenario) { + request = given(); + } } /** @@ -188,10 +201,12 @@ public void readRequestByPathParam(String dummy) { */ @Given("^(.*) with an header param (.*) of (.*)") public void readRequestByHeaderParam(String dummy, String identifier, String value) { - if("Accept".equalsIgnoreCase(identifier)){ - acceptContentType = value; + if (!this.skipScenario) { + if ("Accept".equalsIgnoreCase(identifier)) { + acceptContentType = value; + } + request = request.header(identifier, StepDefinitionHelper.getActualValue(value)); } - request = request.header(identifier, StepDefinitionHelper.getActualValue(value)); } @@ -203,15 +218,16 @@ public void readRequestByHeaderParam(String dummy, String identifier, String val */ @Given("add (.*) with given header params$") public void readAllHeaderParams(String nameIgnore, Map parameterMap) { - for (Map.Entry params : parameterMap.entrySet()) { - if("Accept".equalsIgnoreCase(params.getKey())){ - acceptContentType = StepDefinitionHelper.getActualValue(params.getValue()).toString(); + if (!this.skipScenario) { + for (Map.Entry params : parameterMap.entrySet()) { + if ("Accept".equalsIgnoreCase(params.getKey())) { + acceptContentType = StepDefinitionHelper.getActualValue(params.getValue()).toString(); + } + request = request + .header(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); } - request = request - .header(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); } } - /** * Read request. * @@ -220,10 +236,12 @@ public void readAllHeaderParams(String nameIgnore, Map parameter */ @Given("add (.*) with given cookie params$") public void readAllCookieParams(String nameIgnore, Map parameterMap) { - for (Map.Entry params : parameterMap.entrySet()) { - request = request.cookie(new - Cookie.Builder(params.getKey(), - StepDefinitionHelper.getActualValue(params.getValue()).toString()).build()); + if (!this.skipScenario) { + for (Map.Entry params : parameterMap.entrySet()) { + request = request.cookie(new + Cookie.Builder(params.getKey(), + StepDefinitionHelper.getActualValue(params.getValue()).toString()).build()); + } } } @@ -236,7 +254,9 @@ public void readAllCookieParams(String nameIgnore, Map parameter */ @Given("^(.*) with an query param (.*) of (.*)") public void readRequestByQueryParam(String dummy, String identifier, String value) { - request = given().queryParam(identifier, StepDefinitionHelper.getActualValue(value)); + if (!this.skipScenario) { + request = given().queryParam(identifier, StepDefinitionHelper.getActualValue(value)); + } } /** @@ -247,8 +267,11 @@ public void readRequestByQueryParam(String dummy, String identifier, String valu */ @Given("^Provided all the feature level parameters$") public void loadGlobalParam(Map globalParams) throws IOException { - ScenarioContext.setContext(globalParams); - scenario.attach(new JSONObject(ScenarioContext.getPrintableContextObject()).toString(), "application/json", "requestData : " + scenario.getName()+" : " + (sequence++)); + if (!this.skipScenario) { + ScenarioContext.setContext(globalParams); + scenario.attach(new JSONObject(ScenarioContext.getPrintableContextObject()).toString(), + "application/json", "requestData : " + scenario.getName() + " : " + (sequence++)); + } } /** @@ -258,15 +281,17 @@ public void loadGlobalParam(Map globalParams) throws IOException */ @Given("^Provided all the feature level parameters from file$") public void loadGlobalParamFromFile() throws IOException { - Properties properties = new Properties(); - InputStream stream = ApplicationConfiguration.class.getClassLoader() - .getResourceAsStream("cucumblan-env.properties"); - if (stream != null) { - properties.load(stream); - ScenarioContext.setContext((Map) properties); - } else { - LOGGER.warning( - "cucumblan-env.properties is not configured. Need to add if default data loaded"); + if(!this.skipScenario) { + Properties properties = new Properties(); + InputStream stream = ApplicationConfiguration.class.getClassLoader() + .getResourceAsStream("cucumblan-env.properties"); + if (stream != null) { + properties.load(stream); + ScenarioContext.setContext((Map) properties); + } else { + LOGGER.warning( + "cucumblan-env.properties is not configured. Need to add if default data loaded"); + } } } @@ -275,10 +300,11 @@ public void loadGlobalParamFromFile() throws IOException { */ @Then("^Verify all the feature level parameters exists") public void validateGlobalParam() { - assertTrue("Valid Global Parameters are present ", ScenarioContext.hasContextValues()); + if (!this.skipScenario) { + assertTrue("Valid Global Parameters are present ", ScenarioContext.hasContextValues()); + } } - /** * Add variable. * @@ -287,8 +313,15 @@ public void validateGlobalParam() { */ @Given("^Add the (.*) value of the key as (.*)") public void addVariable(String responseValue, String key) { - ScenarioContext.setContext(key, - Helper.getActualValueForAll(responseValue, ScenarioContext.getContext()).toString()); + if (!this.skipScenario) { + if (responseValue.startsWith("[") && responseValue.endsWith("]")) { + ScenarioContext.setContext(key, + Helper.getActualValueForAll(responseValue, ScenarioContext.getContext()).toString()); + } else { + ScenarioContext.setContext(key, responseValue); + + } + } } /** @@ -300,8 +333,10 @@ public void addVariable(String responseValue, String key) { */ @Given("^evaluate the (.*) decimal value of the key as (.*)") public void modifyDecimalVariable(String responseValue, String key) throws IOException { - ScenarioContext.setContext(key, ExcelAndMathHelper.evaluateWithVariables(Double.class, - responseValue, ScenarioContext.getContext()).toString()); + if (!this.skipScenario) { + ScenarioContext.setContext(key, ExcelAndMathHelper.evaluateWithVariables(Double.class, + responseValue, ScenarioContext.getContext()).toString()); + } } @@ -314,10 +349,25 @@ public void modifyDecimalVariable(String responseValue, String key) throws IOExc */ @Given("^evaluate the (.*) integer value of the key as (.*)") public void modifyIntVariable(String responseValue, String key) throws IOException { - ScenarioContext.setContext(key, ExcelAndMathHelper.evaluateWithVariables(Integer.class, - responseValue, ScenarioContext.getContext()).toString()); + if (!this.skipScenario) { + ScenarioContext.setContext(key, ExcelAndMathHelper.evaluateWithVariables(Integer.class, + responseValue, ScenarioContext.getContext()).toString()); + } } + /** + * perform the skip scenario + * + * @param condition the response value excel based + * @throws IOException the io exception + */ + @Given("^perform the (.*) condition to skip scenario") + public void modifyBooleanVariable(String condition) throws IOException { + skipScenario = (Boolean) ExcelAndMathHelper.evaluateWithVariables(Boolean.class, condition,ScenarioContext.getContext()); + scenario.log("condition :" + condition + " : is Skipped : " + skipScenario ); + } + + /** * Modify variable. * @@ -327,8 +377,10 @@ public void modifyIntVariable(String responseValue, String key) throws IOExcepti */ @Given("^evaluate the (.*) boolean value of the key as (.*)") public void modifyBooleanVariable(String responseValue, String key) throws IOException { - ScenarioContext.setContext(key, ExcelAndMathHelper.evaluateWithVariables(Boolean.class, - responseValue, ScenarioContext.getContext()).toString()); + if (!this.skipScenario) { + ScenarioContext.setContext(key, ExcelAndMathHelper.evaluateWithVariables(Boolean.class, + responseValue, ScenarioContext.getContext()).toString()); + } } @@ -341,10 +393,11 @@ public void modifyBooleanVariable(String responseValue, String key) throws IOExc */ @Given("^Modify the (.*) value of the key as (.*)") public void modifyStringVariable(String responseValue, String key) throws IOException { - ScenarioContext.setContext(key, - Helper.getActualValueForAll(responseValue, ScenarioContext.getContext()).toString()); + if (!this.skipScenario) { + ScenarioContext.setContext(key, + Helper.getActualValueForAll(responseValue, ScenarioContext.getContext()).toString()); + } } - /** * Load as global param. * @@ -353,22 +406,24 @@ public void modifyStringVariable(String responseValue, String key) throws IOExce */ @Given("^Store the (.*) value of the key as (.*)") public void loadAsGlobalParam(String responseKey, String key) { - String value = validatableResponse.extract().body().jsonPath().getString(responseKey); - if (value != null) { - ScenarioContext - .setContext(key, validatableResponse.extract().body().jsonPath().getString(responseKey)); - } else if (response.getCookie(responseKey) != null) { - ScenarioContext - .setContext(key, response.getCookie(responseKey)); - } else if (response.getHeader(responseKey) != null) { - ScenarioContext - .setContext(key, response.getCookie(responseKey)); - } else { - LOGGER.warning(responseKey +" : for " + key + " not found"); - scenario.log(responseKey +" : for " + key + " not found"); + if (!this.skipScenario) { + String value = validatableResponse.extract().body().jsonPath().getString(responseKey); + if (value != null) { + ScenarioContext + .setContext(key, + validatableResponse.extract().body().jsonPath().getString(responseKey)); + } else if (response.getCookie(responseKey) != null) { + ScenarioContext + .setContext(key, response.getCookie(responseKey)); + } else if (response.getHeader(responseKey) != null) { + ScenarioContext + .setContext(key, response.getCookie(responseKey)); + } else { + LOGGER.warning(responseKey + " : for " + key + " not found"); + scenario.log(responseKey + " : for " + key + " not found"); + } } } - /** * Read request. * @@ -377,10 +432,12 @@ public void loadAsGlobalParam(String responseKey, String key) { */ @Given("^add (.*) with given path params$") public void readParamsRequest(String nameIgnore, Map parameterMap) { - request = request.contentType("application/json"); - for (Map.Entry params : parameterMap.entrySet()) { - request = request - .pathParam(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); + if (!this.skipScenario) { + request = request.contentType("application/json"); + for (Map.Entry params : parameterMap.entrySet()) { + request = request + .pathParam(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); + } } } @@ -392,16 +449,17 @@ public void readParamsRequest(String nameIgnore, Map parameterMa */ @Given("^add (.*) with (.*) given form params$") public void readMultiParamsRequest(String nameIgnore, String contentType, Map parameterMap) { - request = request.config(RestAssured.config() - .encoderConfig(EncoderConfig.encoderConfig() - .encodeContentTypeAs(contentType, - ContentType.fromContentType(contentType)))); - for (Map.Entry params : parameterMap.entrySet()) { - request = request - .param(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); + if (!this.skipScenario) { + request = request.config(RestAssured.config() + .encoderConfig(EncoderConfig.encoderConfig() + .encodeContentTypeAs(contentType, + ContentType.fromContentType(contentType)))); + for (Map.Entry params : parameterMap.entrySet()) { + request = request + .param(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); + } } } - /** * Read request. * @@ -410,31 +468,35 @@ public void readMultiParamsRequest(String nameIgnore, String contentType, Map parameterMap) { - request = request.config(RestAssured.config() - .encoderConfig(EncoderConfig.encoderConfig() - .encodeContentTypeAs(contentType, - ContentType.fromContentType(contentType)))); - for (Map.Entry params : parameterMap.entrySet()) { - if (params.getKey().contains("MULTI-PART")) { - if(params.getValue() != null) { - String fileAndType = StepDefinitionHelper.getActualValue(params.getValue()).toString(); - if(params.getKey().split("=").length == 2 && fileAndType.split("=").length ==2) { - request = request - .multiPart(params.getKey().split("=")[1], - new File(BaseStepDefinition.class.getClassLoader().getResource(fileAndType.split("=")[0]).getFile()), - fileAndType.split("=")[1]); - } else { - scenario.log("MULTI-PART was not set up correctly. should be like key => MULTI-PART => MULTI-PART=uploadtext.txt value => filename.txt=plain/txt"); - LOGGER.warning("MULTI-PART was not set up correctly. should be like key => MULTI-PART => MULTI-PART=uploadtext.txt value => filename.txt=plain/txt"); + if (!this.skipScenario) { + request = request.config(RestAssured.config() + .encoderConfig(EncoderConfig.encoderConfig() + .encodeContentTypeAs(contentType, + ContentType.fromContentType(contentType)))); + for (Map.Entry params : parameterMap.entrySet()) { + if (params.getKey().contains("MULTI-PART")) { + if (params.getValue() != null) { + String fileAndType = StepDefinitionHelper.getActualValue(params.getValue()).toString(); + if (params.getKey().split("=").length == 2 && fileAndType.split("=").length == 2) { + request = request + .multiPart(params.getKey().split("=")[1], + new File(BaseStepDefinition.class.getClassLoader() + .getResource(fileAndType.split("=")[0]).getFile()), + fileAndType.split("=")[1]); + } else { + scenario.log( + "MULTI-PART was not set up correctly. should be like key => MULTI-PART => MULTI-PART=uploadtext.txt value => filename.txt=plain/txt"); + LOGGER.warning( + "MULTI-PART was not set up correctly. should be like key => MULTI-PART => MULTI-PART=uploadtext.txt value => filename.txt=plain/txt"); + } } + } else { + request = request + .param(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); } - } else { - request = request - .param(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); } } } - /** * Read request. * @@ -443,13 +505,14 @@ public void readPathParamsRequest(String nameIgnore, String contentType, Map parameterMap) { - request = request.contentType("application/json"); - for (Map.Entry params : parameterMap.entrySet()) { - request = request - .queryParam(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); + if (!this.skipScenario) { + request = request.contentType("application/json"); + for (Map.Entry params : parameterMap.entrySet()) { + request = request + .queryParam(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); + } } } - /** * Read request. * @@ -459,10 +522,12 @@ public void readRequest(String nameIgnore, Map parameterMap) { */ @Given("add (.*) with contentType (.*) given query params$") public void readRequest(String nameIgnore, String contentType, Map parameterMap) { - request = request.contentType(contentType); - for (Map.Entry params : parameterMap.entrySet()) { - request = request - .queryParam(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); + if (!this.skipScenario) { + request = request.contentType(contentType); + for (Map.Entry params : parameterMap.entrySet()) { + request = request + .queryParam(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); + } } } @@ -475,13 +540,14 @@ public void readRequest(String nameIgnore, String contentType, Map parameterMap) { - request = request.contentType(contentType); - for (Map.Entry params : parameterMap.entrySet()) { - request = request - .queryParam(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); + if (!this.skipScenario) { + request = request.contentType(contentType); + for (Map.Entry params : parameterMap.entrySet()) { + request = request + .queryParam(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); + } } } - /** * Load request. * @@ -490,10 +556,12 @@ public void loadRequest(String nameIgnore, String contentType, Map parameterMap) { - request = request.contentType("application/json"); - for (Map.Entry params : parameterMap.entrySet()) { - request = request - .queryParam(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); + if (!this.skipScenario) { + request = request.contentType("application/json"); + for (Map.Entry params : parameterMap.entrySet()) { + request = request + .queryParam(params.getKey(), StepDefinitionHelper.getActualValue(params.getValue())); + } } } @@ -505,7 +573,9 @@ public void loadRequest(String nameIgnore, Map parameterMap) { */ @Given("^add (.*) data with (.*) given input$") public void createRequest(String body, String contentType) { - request = request.contentType(contentType).body(body); + if (!this.skipScenario) { + request = request.contentType(contentType).body(body); + } } @@ -518,16 +588,17 @@ public void createRequest(String body, String contentType) { */ @Given("add (.*) data file with (.*) given input$") public void createFileRequest(String fileBody, String contentType) throws IOException { - String body = HelperUtil.readFileAsString(fileBody); - if (body != null) { - Map mapHeader = new HashMap(); - mapHeader.put("content-type", contentType); - request = request.headers(mapHeader).contentType(contentType).body(body); - } else { - Assert.assertTrue(fileBody + " input file is missing ", false); + if (!this.skipScenario) { + String body = HelperUtil.readFileAsString(fileBody); + if (body != null) { + Map mapHeader = new HashMap(); + mapHeader.put("content-type", contentType); + request = request.headers(mapHeader).contentType(contentType).body(body); + } else { + Assert.assertTrue(fileBody + " input file is missing ", false); + } } } - /** * Create request. * @@ -539,18 +610,19 @@ public void createFileRequest(String fileBody, String contentType) throws IOExce @Given("add (.*) data inline with (.*) given input$") public void createInlineRequest(String fileBody, String contentType, List input) throws IOException { - if (input != null && !input.isEmpty()) { - Map mapHeader = new HashMap(); - mapHeader.put("content-type", contentType); - String listString = input.stream().map(Object::toString) - .collect(Collectors.joining()); - request = request.headers(mapHeader).contentType(contentType).body(listString); - } else { - Assert.assertTrue(fileBody + " input inline is missing ", false); + if (!this.skipScenario) { + if (input != null && !input.isEmpty()) { + Map mapHeader = new HashMap(); + mapHeader.put("content-type", contentType); + String listString = input.stream().map(Object::toString) + .collect(Collectors.joining()); + request = request.headers(mapHeader).contentType(contentType).body(listString); + } else { + Assert.assertTrue(fileBody + " input inline is missing ", false); + } } } - /** * Create request. * @@ -562,11 +634,12 @@ public void createInlineRequest(String fileBody, String contentType, List parameterMap) throws Exception { - jsonBody = Mapson.buildMAPsonAsJson(parameterMap, ScenarioContext.getContext()); + if(!this.skipScenario){ + jsonBody = Mapson.buildMAPsonAsJson(parameterMap, ScenarioContext.getContext()); scenario.attach(jsonBody , contentType, "requestData : " + scenario.getName()+" : " + (sequence++)); request = request.contentType(contentType).body(jsonBody); - + } } @@ -579,10 +652,12 @@ public void createRequest(String nameIgnore, String contentType, Map parameterMap) throws Exception { - jsonBody = Mapson.buildMAPsonAsJson(parameterMap, ScenarioContext.getContext()); - scenario.attach(jsonBody - , "application/json", "requestData : " + scenario.getName()+" : " + (sequence++)); - request = request.contentType("application/json").body(jsonBody); + if (!this.skipScenario) { + jsonBody = Mapson.buildMAPsonAsJson(parameterMap, ScenarioContext.getContext()); + scenario.attach(jsonBody + , "application/json", "requestData : " + scenario.getName() + " : " + (sequence++)); + request = request.contentType("application/json").body(jsonBody); + } } /** @@ -594,10 +669,12 @@ public void createRequest(String nameIgnore, Map parameterMap) t */ @Given("^Update (.*) with given input$") public void updateRequest(String nameIgnore, Map parameterMap) throws Exception { - jsonBody = Mapson.buildMAPsonAsJson(parameterMap, ScenarioContext.getContext()); - scenario.attach(jsonBody - , "application/json", "requestData : " + scenario.getName()+" : " + (sequence++)); - request = request.contentType("application/json").body(jsonBody); + if (!this.skipScenario) { + jsonBody = Mapson.buildMAPsonAsJson(parameterMap, ScenarioContext.getContext()); + scenario.attach(jsonBody + , "application/json", "requestData : " + scenario.getName() + " : " + (sequence++)); + request = request.contentType("application/json").body(jsonBody); + } } /** @@ -611,10 +688,12 @@ public void updateRequest(String nameIgnore, Map parameterMap) t @Given("^Update (.*) with contentType (.*) given input$") public void updateRequest(String nameIgnore, String contentType, Map parameterMap) throws Exception { - jsonBody = Mapson.buildMAPsonAsJson(parameterMap, ScenarioContext.getContext()); - scenario.attach(jsonBody - , "application/json", "requestData : " + scenario.getName()+" : " + (sequence++)); - request = request.contentType(contentType).body(jsonBody); + if (!this.skipScenario) { + jsonBody = Mapson.buildMAPsonAsJson(parameterMap, ScenarioContext.getContext()); + scenario.attach(jsonBody + , "application/json", "requestData : " + scenario.getName() + " : " + (sequence++)); + request = request.contentType(contentType).body(jsonBody); + } } @@ -629,24 +708,26 @@ public void updateRequest(String nameIgnore, String contentType, Map readData) throws Throwable { - attachResponse(validatableResponse); - StandardProcessing processing = stdProcessorMap.get(type); - if (processing != null) { - if (validatableResponse != null - && validatableResponse.extract().body().asString() != null) { - String readXML = readData.stream().map(Object::toString) - .collect(Collectors.joining()); - String jsonRequestActual = processing - .postResponseProcessing(validatableResponse.extract().body().asString()); - String jsonRequestExpected = processing.postResponseProcessing(readXML); - - if (jsonRequestExpected != null && jsonRequestActual != null) { - Map mapson = Mapson.buildMAPsonFromJson(jsonRequestExpected); - Map mapsonExpected = Mapson.buildMAPsonFromJson(jsonRequestActual); - mapsonExpected.forEach((k, v) -> { - if (!ExcludeConfiguration.shouldSkip(resource, (String) k)) { - if (v == null) { - if (mapson.get(k) == null) { - assertNull(mapson.get(k)); + if (!this.skipScenario) { + attachResponse(validatableResponse); + StandardProcessing processing = stdProcessorMap.get(type); + if (processing != null) { + if (validatableResponse != null + && validatableResponse.extract().body().asString() != null) { + String readXML = readData.stream().map(Object::toString) + .collect(Collectors.joining()); + String jsonRequestActual = processing + .postResponseProcessing(validatableResponse.extract().body().asString()); + String jsonRequestExpected = processing.postResponseProcessing(readXML); + + if (jsonRequestExpected != null && jsonRequestActual != null) { + Map mapson = Mapson.buildMAPsonFromJson(jsonRequestExpected); + Map mapsonExpected = Mapson.buildMAPsonFromJson(jsonRequestActual); + mapsonExpected.forEach((k, v) -> { + if (!ExcludeConfiguration.shouldSkip(resource, (String) k)) { + if (v == null) { + if (mapson.get(k) == null) { + assertNull(mapson.get(k)); + } else { + assertEquals(" ", mapson.get(k)); + } } else { - assertEquals(" ", mapson.get(k)); + LOGGER.info("Key: " + k + " Expected : " + v + " ==> Actual " + mapson.get(k)); + assertEquals("Key: " + k + " Expected : " + v + " ==> Actual " + mapson.get(k), + v, mapson.get(k)); } - } else { - LOGGER.info("Key: " + k + " Expected : " + v + " ==> Actual " + mapson.get(k)); - assertEquals("Key: " + k + " Expected : " + v + " ==> Actual " + mapson.get(k), - v, mapson.get(k)); } - } - }); + }); + } else { + assertTrue("Standard " + type + " has no response validation ", false); + } } else { - assertTrue("Standard " + type + " has no response validation ", false); + assertTrue("Api Response was not received ", false); } } else { - assertTrue("Api Response was not received ", false); + assertTrue("Standard " + type + " is not implemented for response ", false); } - } else { - assertTrue("Standard " + type + " is not implemented for response ", false); } } @@ -849,45 +946,46 @@ public void verifyFormatedMapson(String type, String resource, List read @Given("^Verify-standard (.*) all (.*) file (.*) api includes following in the response$") public void verifyFormatedMapson(String type, String file, String resource) throws Throwable { - attachResponse(validatableResponse); - StandardProcessing processing = stdProcessorMap.get(type); - if (processing != null) { - if (validatableResponse != null - && validatableResponse.extract().body().asString() != null) { - String body = HelperUtil.readFileAsString(file); - String jsonRequestActual = processing - .postResponseProcessing(validatableResponse.extract().body().asString()); - String jsonRequestExpected = processing.postResponseProcessing(body); - if (jsonRequestExpected != null && jsonRequestActual != null) { - Map mapson = Mapson.buildMAPsonFromJson(jsonRequestExpected); - Map mapsonExpected = Mapson.buildMAPsonFromJson(jsonRequestActual); - mapsonExpected.forEach((k, v) -> { - if (!ExcludeConfiguration.shouldSkip(resource, (String) k)) { - if (v == null) { - if (mapson.get(k) == null) { - assertNull(mapson.get(k)); + if (!this.skipScenario) { + attachResponse(validatableResponse); + StandardProcessing processing = stdProcessorMap.get(type); + if (processing != null) { + if (validatableResponse != null + && validatableResponse.extract().body().asString() != null) { + String body = HelperUtil.readFileAsString(file); + String jsonRequestActual = processing + .postResponseProcessing(validatableResponse.extract().body().asString()); + String jsonRequestExpected = processing.postResponseProcessing(body); + if (jsonRequestExpected != null && jsonRequestActual != null) { + Map mapson = Mapson.buildMAPsonFromJson(jsonRequestExpected); + Map mapsonExpected = Mapson.buildMAPsonFromJson(jsonRequestActual); + mapsonExpected.forEach((k, v) -> { + if (!ExcludeConfiguration.shouldSkip(resource, (String) k)) { + if (v == null) { + if (mapson.get(k) == null) { + assertNull(mapson.get(k)); + } else { + assertEquals(" ", mapson.get(k)); + } } else { - assertEquals(" ", mapson.get(k)); + LOGGER.info("Key: " + k + " Expected : " + v + " ==> Actual " + mapson.get(k)); + assertEquals("Key: " + k + " Expected : " + v + " ==> Actual " + mapson.get(k), + v, mapson.get(k)); } - } else { - LOGGER.info("Key: " + k + " Expected : " + v + " ==> Actual " + mapson.get(k)); - assertEquals("Key: " + k + " Expected : " + v + " ==> Actual " + mapson.get(k), - v, mapson.get(k)); } - } - }); + }); + } else { + assertTrue("Standard " + type + " has no response validation ", false); + } } else { - assertTrue("Standard " + type + " has no response validation ", false); + assertTrue("Api Response was not received ", false); } } else { - assertTrue("Api Response was not received ", false); + assertTrue("Standard " + type + " is not implemented for response ", false); } - } else { - assertTrue("Standard " + type + " is not implemented for response ", false); } } - /** * Verify response. * @@ -897,25 +995,26 @@ public void verifyFormatedMapson(String type, String file, String resource) */ @And("^Verify-all (.*) api includes following in the response$") public void verifyResponseMapson(String resource, DataTable data) throws Throwable { - attachResponse(validatableResponse); - data.asMap(String.class, String.class).forEach((k, v) -> { - if (!ExcludeConfiguration.shouldSkip(resource, (String) k)) { - Map mapson = Mapson.buildMAPsonFromJson( - validatableResponse.extract().body().asString()); - if (v == null) { - if (mapson.get(k) == null) { - assertNull(mapson.get(k)); + if (!this.skipScenario) { + attachResponse(validatableResponse); + data.asMap(String.class, String.class).forEach((k, v) -> { + if (!ExcludeConfiguration.shouldSkip(resource, (String) k)) { + Map mapson = Mapson.buildMAPsonFromJson( + validatableResponse.extract().body().asString()); + if (v == null) { + if (mapson.get(k) == null) { + assertNull(mapson.get(k)); + } else { + assertEquals(" ", mapson.get(k)); + } } else { - assertEquals(" ", mapson.get(k)); + LOGGER.info("Key: " + k + " Expected : " + v + " ==> Actual " + mapson.get(k)); + assertEquals(v, mapson.get(k)); } - } else { - LOGGER.info("Key: " + k + " Expected : " + v + " ==> Actual " + mapson.get(k)); - assertEquals(v, mapson.get(k)); } - } - }); + }); + } } - /** * Mock single response. * @@ -925,10 +1024,12 @@ public void verifyResponseMapson(String resource, DataTable data) throws Throwab */ @And("^Verify (.*) response inline includes in the response$") public void verifyFileResponse(String resource, List xmlString) throws Throwable { - attachResponse(validatableResponse); - String listString = xmlString.stream().map(Object::toString) - .collect(Collectors.joining()); - HelperUtil.assertXMLEquals(listString, response.asString()); + if (!this.skipScenario) { + attachResponse(validatableResponse); + String listString = xmlString.stream().map(Object::toString) + .collect(Collectors.joining()); + HelperUtil.assertXMLEquals(listString, response.asString()); + } } /** @@ -941,12 +1042,14 @@ public void verifyFileResponse(String resource, List xmlString) throws T @And("^Verify (.*) response XML File (.*) includes in the response$") public void verifyXMLResponse(String resource, String fileBody) throws Throwable { - attachResponse(validatableResponse); - String body = HelperUtil.readFileAsString(fileBody); - if (body != null) { - HelperUtil.assertXMLEquals(body, response.asString()); - } else { - Assert.assertTrue(fileBody + " file is missing :", false); + if (!this.skipScenario) { + attachResponse(validatableResponse); + String body = HelperUtil.readFileAsString(fileBody); + if (body != null) { + HelperUtil.assertXMLEquals(body, response.asString()); + } else { + Assert.assertTrue(fileBody + " file is missing :", false); + } } } @@ -960,20 +1063,21 @@ public void verifyXMLResponse(String resource, String fileBody) @And("^Verify (.*) response (.*) include byPath (.*) includes in the response$") public void verifyXMLByPathResponse(String resource, String contentType, String fileBody, List xpaths) throws Exception { - String body = HelperUtil.readFileAsString(fileBody); - attachActualResponse(body); - attachResponse(validatableResponse); - if (body != null) { - if(contentType.contains("xml")) { - HelperUtil.assertXpathsEqual(xpaths, body, response.asString()); + if (!this.skipScenario) { + String body = HelperUtil.readFileAsString(fileBody); + attachActualResponse(body); + attachResponse(validatableResponse); + if (body != null) { + if (contentType.contains("xml")) { + HelperUtil.assertXpathsEqual(xpaths, body, response.asString()); + } else { + HelperUtil.assertJsonpathEqual(xpaths, body, response.asString()); + } } else { - HelperUtil.assertJsonpathEqual(xpaths, body, response.asString()); + Assert.assertTrue(fileBody + " file is missing :", false); } - } else { - Assert.assertTrue(fileBody + " file is missing :", false); } } - /** * Mock single response. * @@ -981,9 +1085,11 @@ public void verifyXMLByPathResponse(String resource, String contentType, * @param context the context */ @And("^Verify (.*) response with (.*) includes in the response$") - public void verifySingleResponse(String resource, String context) { - attachResponse(validatableResponse); - assertEquals(context, validatableResponse.extract().body().asString()); + public void verifySingleResponse(String resource, String context) { + if (!this.skipScenario) { + attachResponse(validatableResponse); + assertEquals(context, validatableResponse.extract().body().asString()); + } } @@ -996,12 +1102,16 @@ public void verifySingleResponse(String resource, String context) { */ @And("^Verify (.*) includes following in the response$") public void verifyResponse(String dummyString, DataTable data) throws Throwable { - attachResponse(validatableResponse); - data.asMap(String.class, String.class).forEach((k, v) -> { - LOGGER - .info(v + " : " + validatableResponse.extract().body().jsonPath().getString((String) k)); - assertEquals(StepDefinitionHelper.getActualValue((String) v), - validatableResponse.extract().body().jsonPath().getString((String) k)); - }); + if (!this.skipScenario) { + attachResponse(validatableResponse); + data.asMap(String.class, String.class).forEach((k, v) -> { + LOGGER + .info( + v + " : " + validatableResponse.extract().body().jsonPath().getString((String) k)); + assertEquals(StepDefinitionHelper.getActualValue((String) v), + validatableResponse.extract().body().jsonPath().getString((String) k)); + }); + } } } + diff --git a/modules/cucumblan-db/pom.xml b/modules/cucumblan-db/pom.xml index 9b2b4f7e..0af6f61a 100644 --- a/modules/cucumblan-db/pom.xml +++ b/modules/cucumblan-db/pom.xml @@ -4,7 +4,7 @@ cucumblan-db jar cucumblan-db - 0.0.2-SNAPSHOT + 0.1.1-SNAPSHOT 5.5.2 1.1.4 diff --git a/modules/cucumblan-message/pom.xml b/modules/cucumblan-message/pom.xml index 83c9f122..a87874c0 100644 --- a/modules/cucumblan-message/pom.xml +++ b/modules/cucumblan-message/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.virtualan cucumblan-message - 0.0.2-SNAPSHOT + 0.1.1-SNAPSHOT jar cucumblan-message diff --git a/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/core/MsgBaseStepDefinition.java b/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/core/MsgBaseStepDefinition.java index 0208cae0..ab1ef21b 100644 --- a/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/core/MsgBaseStepDefinition.java +++ b/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/core/MsgBaseStepDefinition.java @@ -74,6 +74,7 @@ public void before(Scenario scenario) { * @param resource the resource * @param type the type * @param messages the messages + * @throws MessageNotDefinedException the message not defined exception */ @Given("send message event (.*) in partition (.*) on (.*) with type (.*)$") public void produceMessageWithPartition(String eventName, Integer partition, String resource, @@ -85,13 +86,19 @@ public void produceMessageWithPartition(String eventName, Integer partition, Str scenario.log(builtMessage.toString()); KafkaProducerClient - .sendMessage(resource, topic, builtMessage.getId(), builtMessage.getMessage(), + .sendMessage(resource, topic, builtMessage.getKey(), builtMessage.getMessage(), partition, builtMessage.getHeaders()); } else { Assertions.assertTrue(false, eventName + " is not configured for any topic. or " + type +" is not configured"); } } + /** + * Produce message. + * + * @param sleep the sleep + * @throws InterruptedException the interrupted exception + */ @Given("pause message process for (.*) milliseconds$") public void produceMessage(long sleep) throws InterruptedException { Thread.sleep(sleep); @@ -104,6 +111,7 @@ public void produceMessage(long sleep) throws InterruptedException { * @param resource the resource * @param type the type * @param messages the messages + * @throws MessageNotDefinedException the message not defined exception */ @Given("send message event (.*) on (.*) with type (.*)$") public void produceMessage(String eventName, String resource, String type, @@ -113,9 +121,9 @@ public void produceMessage(String eventName, String resource, String type, if (topic != null && messageType != null) { MessageType builtMessage = messageType.buildProducerMessage(messages); scenario.log(builtMessage.toString()); - if (builtMessage.getId() != null) { + if (builtMessage.getKey() != null) { KafkaProducerClient - .sendMessage(resource, topic, builtMessage.getId(), builtMessage.getMessage(), + .sendMessage(resource, topic, builtMessage.getKey(), builtMessage.getMessage(), null, builtMessage.getHeaders()); } else { KafkaProducerClient @@ -134,6 +142,7 @@ public void produceMessage(String eventName, String resource, String type, * @param resource the resource * @param type the type * @param messages the messages + * @throws MessageNotDefinedException the message not defined exception */ @Given("send inline message event (.*) on (.*) with type (.*)$") public void produceMessage(String eventName, String resource, String type, @@ -143,9 +152,9 @@ public void produceMessage(String eventName, String resource, String type, if (topic != null && messageType != null) { MessageType builtMessage = messageType.buildProducerMessage(messages); scenario.log(builtMessage.toString()); - if (builtMessage.getId() != null) { + if (builtMessage.getKey() != null) { KafkaProducerClient - .sendMessage(resource, topic, builtMessage.getId(), builtMessage.getMessage(), + .sendMessage(resource, topic, builtMessage.getKey(), builtMessage.getMessage(), null, builtMessage.getHeaders()); } else { KafkaProducerClient @@ -164,6 +173,7 @@ public void produceMessage(String eventName, String resource, String type, * @param resource the resource * @param type the type * @param messages the messages + * @throws MessageNotDefinedException the message not defined exception */ @Given("send mapson message event (.*) on (.*) with type (.*)$") public void produceMessageMapson(String eventName, String resource, String type, @@ -173,9 +183,9 @@ public void produceMessageMapson(String eventName, String resource, String type, if (topic != null && messageType != null) { MessageType builtMessage = messageType.buildProducerMessage(messages); scenario.log(builtMessage.toString()); - if (builtMessage.getId() != null) { + if (builtMessage.getKey() != null) { KafkaProducerClient - .sendMessage(resource, topic, builtMessage.getId(), builtMessage.getMessage(), + .sendMessage(resource, topic, builtMessage.getKey(), builtMessage.getMessage(), null, builtMessage.getHeaders()); } else { KafkaProducerClient @@ -195,9 +205,11 @@ public void produceMessageMapson(String eventName, String resource, String type, * @param eventName the event name * @param id the id * @param resource the resource + * @param type the type * @param csvson the csvson - * @throws InterruptedException the interrupted exception - * @throws BadInputDataException bad input data exception + * @throws InterruptedException the interrupted exception + * @throws BadInputDataException bad input data exception + * @throws MessageNotDefinedException the message not defined exception */ @Given("verify (.*) contains (.*) on (.*) with type (.*)$") public void verifyConsumedJSONObject(String eventName, String id, String resource, String type, @@ -228,8 +240,10 @@ public void verifyConsumedJSONObject(String eventName, String id, String resourc * @param eventName the event name * @param id the id * @param resource the resource + * @param type the type * @param keyValue the key value - * @throws InterruptedException interrupted exception + * @throws InterruptedException interrupted exception + * @throws MessageNotDefinedException the message not defined exception */ @Given("verify-by-elements (.*) contains (.*) on (.*) with type (.*)$") public void consumeMessage(String eventName, String id, String resource, String type, diff --git a/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/core/msg/kafka/KafkaConsumerClient.java b/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/core/msg/kafka/KafkaConsumerClient.java index c1e1f80a..39e55811 100644 --- a/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/core/msg/kafka/KafkaConsumerClient.java +++ b/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/core/msg/kafka/KafkaConsumerClient.java @@ -151,9 +151,11 @@ private boolean getMessageType(String eventName, String type, if (messageType != null) { try { obj = messageType.buildConsumerMessage(record, record.key(), record.value()); - if (obj != null) { - MessageContext.setEventContextMap(eventName, String.valueOf(obj.getId()), obj); + if (obj != null && obj.getId() != null) { + MessageContext.setEventContextMap(eventName, obj.getId().toString(), obj); return true; + } else if(obj != null){ + throw new MessageNotDefinedException( "Id is not defined "); } } catch (MessageNotDefinedException e) { LOGGER.warning(record.key() + " is not defined " + e.getMessage()); diff --git a/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/message/type/MessageType.java b/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/message/type/MessageType.java index 03da836b..5c53b0e5 100644 --- a/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/message/type/MessageType.java +++ b/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/message/type/MessageType.java @@ -42,12 +42,19 @@ public interface MessageType { */ String getType(); + /** + * Gets unique identifier of the message + * + * @return the id + */ + Object getId(); + /** * Gets Kafka message key for kafka * * @return the id */ - T getId(); + T getKey(); /** @@ -88,7 +95,7 @@ public interface MessageType { * Build message while consuming the message * for your specific needs Refer io.virtualan.cucumblan.message.typeimpl.JSONMessage * - * @param record ConsumerRecord object available in the context + * @param record ConsumerRecord object available in the context * @param key the kafka message key * @param value the kafka message object * @return the message type used for Pre defined verification steps diff --git a/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/message/typeimpl/JSONMessage.java b/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/message/typeimpl/JSONMessage.java index a57e2eec..7eff5a04 100644 --- a/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/message/typeimpl/JSONMessage.java +++ b/modules/cucumblan-message/src/main/java/io/virtualan/cucumblan/message/typeimpl/JSONMessage.java @@ -72,6 +72,11 @@ public Integer getId() { return id; } + @Override + public Integer getKey() { + return id; + } + @Override public String getMessage() { return body; diff --git a/modules/cucumblan-ui/pom.xml b/modules/cucumblan-ui/pom.xml index 5aace067..3a2a14ae 100644 --- a/modules/cucumblan-ui/pom.xml +++ b/modules/cucumblan-ui/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.virtualan cucumblan-ui - 1.0.4-SNAPSHOT + 1.0.6-SNAPSHOT jar cucumblan-ui diff --git a/pom.xml b/pom.xml index aa5e0d8b..0289db19 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ cucumblan-project pom cucumblan-project - 1.1.7-SNAPSHOT + 1.1.9-SNAPSHOT https://virtualan.io scm:git:ssh://git@github.com/virtualansoftware/cucumblan.git diff --git a/samples/cucumblan-message-testing/pom.xml b/samples/cucumblan-message-testing/pom.xml index 8bb0fb60..42198e28 100644 --- a/samples/cucumblan-message-testing/pom.xml +++ b/samples/cucumblan-message-testing/pom.xml @@ -6,6 +6,7 @@ jar cucumblan-message-testing + 0.0.3-SNAPSHOT 1.1.4 2.7.0 5.5.2 @@ -128,7 +129,7 @@ io.virtualan cucumblan-message - 0.0.2-SNAPSHOT + ${cucumblan-message.version} org.junit.jupiter diff --git a/samples/cucumblan-message-testing/src/test/java/io/virtualan/test/msgtype/impl/JSONMessage.java b/samples/cucumblan-message-testing/src/test/java/io/virtualan/test/msgtype/impl/JSONMessage.java index 9a971ed9..dd5c17e6 100644 --- a/samples/cucumblan-message-testing/src/test/java/io/virtualan/test/msgtype/impl/JSONMessage.java +++ b/samples/cucumblan-message-testing/src/test/java/io/virtualan/test/msgtype/impl/JSONMessage.java @@ -65,6 +65,12 @@ public List
getHeaders() { return null; } + + @Override + public String getKey() { + return null; + } + @Override public String getId() { return id;