From e4291f83d04a84cac382d7f2dea5d064248f2115 Mon Sep 17 00:00:00 2001 From: German Quiroga Sottile Date: Thu, 1 Oct 2020 18:24:07 -0300 Subject: [PATCH 1/3] primer commit --- .classpath | 38 +++++ .gitignore | 1 + .project | 23 +++ .settings/org.eclipse.core.resources.prefs | 6 + .settings/org.eclipse.jdt.core.prefs | 8 ++ pom.xml | 133 +++++++++--------- .../java/api/config/EntityConfiguration.java | 14 ++ src/main/java/api/model/Data.java | 18 --- src/main/java/api/model/User.java | 100 ++++++++----- src/main/java/api/model/UserCreated.java | 40 ------ src/main/java/api/model/Users.java | 42 ------ src/main/java/services/AuthorsService.java | 11 ++ .../java/services/EnvironmentService.java | 14 ++ src/main/java/services/UserService.java | 18 +-- src/test/java/ar/steps/UserSteps.java | 80 ++++++----- .../resources/features/ApiExample.feature | 36 ----- .../resources/features/CrowdarApi.feature | 29 ++++ .../resources/jsons/request/authorsCount.json | 8 ++ .../jsons/request/authorsDistinct.json | 8 ++ .../resources/jsons/request/createUser.json | 11 -- .../resources/jsons/request/errorRequest.json | 11 -- .../resources/jsons/request/exampleJson.json | 9 -- src/test/resources/jsons/request/login.json | 11 ++ .../resources/jsons/request/loginFail.json | 11 ++ .../jsons/request/responseHeadersRequest.json | 11 -- 25 files changed, 366 insertions(+), 325 deletions(-) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs delete mode 100644 src/main/java/api/model/Data.java delete mode 100644 src/main/java/api/model/UserCreated.java delete mode 100644 src/main/java/api/model/Users.java create mode 100644 src/main/java/services/AuthorsService.java create mode 100644 src/main/java/services/EnvironmentService.java delete mode 100644 src/test/resources/features/ApiExample.feature create mode 100644 src/test/resources/features/CrowdarApi.feature create mode 100644 src/test/resources/jsons/request/authorsCount.json create mode 100644 src/test/resources/jsons/request/authorsDistinct.json delete mode 100644 src/test/resources/jsons/request/createUser.json delete mode 100644 src/test/resources/jsons/request/errorRequest.json delete mode 100644 src/test/resources/jsons/request/exampleJson.json create mode 100644 src/test/resources/jsons/request/login.json create mode 100644 src/test/resources/jsons/request/loginFail.json delete mode 100644 src/test/resources/jsons/request/responseHeadersRequest.json diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..002ad57 --- /dev/null +++ b/.classpath @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/.project b/.project new file mode 100644 index 0000000..c8b07cf --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + academy-api-exercise + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..29abf99 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..2f5cc74 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/pom.xml b/pom.xml index f117a2e..984c68b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,81 +1,84 @@ - 4.0.0 - - io.lippia - root - 3.2.1.1 - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + io.lippia + root + 3.2.1.1 + - com.Crowdar - lippia-api-example-project - api-rest-automation - jar - http://maven.apache.org + com.Crowdar + lippia-api-example-project + api-rest-automation + jar + http://maven.apache.org - - UTF-8 - https://reqres.in/api/users - --glue ar/steps - --glue com/crowdar/bdd/cukes --glue ar/apiExampleProject/hook - @Success + + UTF-8 + http://vps2.crowdaronline.com:8083 + --glue ar/steps + --glue com/crowdar/bdd/cukes --glue + ar/apiExampleProject/hook + @Smoke --plugin pretty - src/test/resources/features ${cucumber.hooks} ${cucumber.stepsDefinitions} --tags 'not @Ignore' --tags ${cucumber.tags} ${cucumber.reporters} - API + src/test/resources/features ${cucumber.hooks} + ${cucumber.stepsDefinitions} --tags 'not @Ignore' --tags + ${cucumber.tags} ${cucumber.reporters} + API - - - - Secuencial - - - - testng.xml - - - - Paralelo - - true - - - testngParalell.xml - - - - - - io.lippia - core - 3.2.1.1 - - - - - src/main/resources/cucumber.properties - - - - org.apache.maven.plugins + + + + Secuencial + + + + testng.xml + + + + Paralelo + + true + + + testngParalell.xml + + + + + + io.lippia + core + 3.2.1.1 + + + + + src/main/resources/cucumber.properties + + + + org.apache.maven.plugins maven-surefire-plugin 3.0.0-M4 - - - ${apiExample.runner} - - - - - - + + + ${apiExample.runner} + + + + + + crowdarRepo crowdar-repository https://nexus-v3-repositories.automation.crowdaronline.com/repository/maven-public/ - + diff --git a/src/main/java/api/config/EntityConfiguration.java b/src/main/java/api/config/EntityConfiguration.java index 9cbc86f..e553a78 100644 --- a/src/main/java/api/config/EntityConfiguration.java +++ b/src/main/java/api/config/EntityConfiguration.java @@ -2,6 +2,8 @@ import services.ResponseHeadersService; import services.UserService; +import services.AuthorsService; +import services.EnvironmentService; public enum EntityConfiguration { @@ -12,6 +14,18 @@ public Class getEntityService() { } }, + AUTHORS{ + @Override + public Class getEntityService() { + return AuthorsService.class; + } + }, + ENVIRONMENT{ + @Override + public Class getEntityService() { + return EnvironmentService.class; + } + }, RESPONSE_HEADERS { @Override public Class getEntityService() { diff --git a/src/main/java/api/model/Data.java b/src/main/java/api/model/Data.java deleted file mode 100644 index 9f04978..0000000 --- a/src/main/java/api/model/Data.java +++ /dev/null @@ -1,18 +0,0 @@ -package api.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Data { - - @JsonProperty("data") - private User user; - - public User getUser() { - return user; - } - - public void setUser(User user) { - this.user = user; - } - -} diff --git a/src/main/java/api/model/User.java b/src/main/java/api/model/User.java index eccc9bb..3153534 100644 --- a/src/main/java/api/model/User.java +++ b/src/main/java/api/model/User.java @@ -4,56 +4,88 @@ public class User { - @JsonProperty("id") - private int id; - @JsonProperty("email") - private String email; - @JsonProperty("first_name") - private String first_name; - @JsonProperty("last_name") - private String last_name; - @JsonProperty("avatar") - private String avatar; + @JsonProperty("jwt") + private String jwt; + @JsonProperty("expires") + private int expires; + @JsonProperty("username") + private String username; + @JsonProperty("role") + private String[] role; + @JsonProperty("timestamp") + private String timestamp; + @JsonProperty("status") + private int status; + @JsonProperty("error") + private String error; + @JsonProperty("message") + private String message; + @JsonProperty("path") + private String path; + - public int getId() { - return id; + public String getJwt() { + return jwt; } - public void setId(int id) { - this.id = id; + public void setJwt(String jwt) { + this.jwt = jwt; } - public String getEmail() { - return email; + public int getExpires() { + return expires; } - public void setEmail(String email) { - this.email = email; + public void setEmail(int expires) { + this.expires = expires; } - public String getFirst_name() { - return first_name; + public String getUsername() { + return username; } - public void setFirst_name(String first_name) { - this.first_name = first_name; + public void setUsername(String username) { + this.username = username; } - public String getLast_name() { - return last_name; + public String[] getRole() { + return role; } - public void setLast_name(String last_name) { - this.last_name = last_name; - } - - public String getAvatar() { - return avatar; - } - - public void setAvatar(String avatar) { - this.avatar = avatar; + public void setRole(String[] role) { + this.role = role; } + + public String getTimestamp() { + return timestamp; + } + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + public int getStatus() { + return status; + } + public void setStatus(int status) { + this.status = status; + } + public String getError() { + return error; + } + public void setError(String error) { + this.error = error; + } + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + public String getPath() { + return path; + } + public void setPath(String path) { + this.path = path; + } } diff --git a/src/main/java/api/model/UserCreated.java b/src/main/java/api/model/UserCreated.java deleted file mode 100644 index 75addbb..0000000 --- a/src/main/java/api/model/UserCreated.java +++ /dev/null @@ -1,40 +0,0 @@ -package api.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class UserCreated { - - @JsonProperty("name") - private String name; - - @JsonProperty("job") - private String job; - - @JsonProperty("id") - private String id; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getJob() { - return job; - } - - public void setJob(String job) { - this.job = job; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - -} diff --git a/src/main/java/api/model/Users.java b/src/main/java/api/model/Users.java deleted file mode 100644 index cbe2821..0000000 --- a/src/main/java/api/model/Users.java +++ /dev/null @@ -1,42 +0,0 @@ -package api.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; - -public class Users { - - @JsonProperty("data") - List data; - - @JsonProperty("page") - private int page; - - @JsonProperty("total") - private int total; - - public List getData() { - return data; - } - - public void setData(List data) { - this.data = data; - } - - public int getPage() { - return page; - } - - public void setPage(int page) { - this.page = page; - } - - public int getTotal() { - return total; - } - - public void setTotal(int total) { - this.total = total; - } - -} diff --git a/src/main/java/services/AuthorsService.java b/src/main/java/services/AuthorsService.java new file mode 100644 index 0000000..3e3e6f2 --- /dev/null +++ b/src/main/java/services/AuthorsService.java @@ -0,0 +1,11 @@ +package services; +import com.crowdar.api.rest.MethodsService; +import com.crowdar.api.rest.Response; + +public class AuthorsService extends MethodsService { + + public static Response get(String jsonName) { + return get(jsonName, null); + } + +} diff --git a/src/main/java/services/EnvironmentService.java b/src/main/java/services/EnvironmentService.java new file mode 100644 index 0000000..a9ceeec --- /dev/null +++ b/src/main/java/services/EnvironmentService.java @@ -0,0 +1,14 @@ +package services; +import java.util.Map; + +import com.crowdar.api.rest.MethodsService; +import com.crowdar.api.rest.Response; + + +public class EnvironmentService extends MethodsService { + + public static Response get(String jsonName, Map parameters) { + return get(jsonName, null, parameters); + } + +} diff --git a/src/main/java/services/UserService.java b/src/main/java/services/UserService.java index 70a5fcc..b69f449 100644 --- a/src/main/java/services/UserService.java +++ b/src/main/java/services/UserService.java @@ -1,19 +1,19 @@ package services; -import api.model.Data; -import api.model.UserCreated; +import api.model.User; import com.crowdar.api.rest.MethodsService; import com.crowdar.api.rest.Response; - public class UserService extends MethodsService { - public static Response get(String jsonName) { - return get(jsonName, Data.class); - } + public static final ThreadLocal TOKEN = new ThreadLocal(); + + public static Response post(String jsonName) { + return post(jsonName, User.class); + } - public static Response post(String jsonName) { - return post(jsonName, UserCreated.class); - } + public static Response get(String jsonName) { + return get(jsonName, User.class); + } } diff --git a/src/test/java/ar/steps/UserSteps.java b/src/test/java/ar/steps/UserSteps.java index aa50e2d..76c7bc7 100644 --- a/src/test/java/ar/steps/UserSteps.java +++ b/src/test/java/ar/steps/UserSteps.java @@ -1,54 +1,56 @@ package ar.steps; import api.config.EntityConfiguration; -import api.model.Data; +import api.model.User; import com.crowdar.api.rest.APIManager; import com.crowdar.core.PageSteps; -import io.cucumber.java.en.*; -import com.google.api.client.repackaged.com.google.common.base.Splitter; + import cucumber.api.java.en.And; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; -import org.apache.commons.lang.StringUtils; +import services.UserService; + import org.testng.Assert; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Map; +@SuppressWarnings("deprecation") public class UserSteps extends PageSteps { - @When("^I perform a '(.*)' to '(.*)' endpoint with the '(.*)' and '(.*)'$") - public void doRequest(String methodName, String entity, String jsonName, String jsonReplacementValues) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - Class entityService = EntityConfiguration.valueOf(entity).getEntityService(); - Map parameters = getParameters(jsonReplacementValues); - String jsonPath = "request/".concat(jsonName); - if (parameters == null) { - entityService.getMethod(methodName.toLowerCase(), String.class).invoke("", jsonPath); - } else { - entityService.getMethod(methodName.toLowerCase(), String.class, Map.class).invoke("", jsonPath, parameters); - } - } - - private Map getParameters(String jsonReplacementValues) { - Map parameters = null; - if (!StringUtils.isEmpty(jsonReplacementValues)) { - parameters = Splitter.on(",").withKeyValueSeparator(":").split(jsonReplacementValues); - } - return parameters; - } - - @Then("^I will get the proper status code '(.*)'$") - public void iWillGetTheProperStatusCodeStatusCode(String expStatusCode) { - int actualStatusCode = APIManager.getLastResponse().getStatusCode(); - Assert.assertEquals(Integer.parseInt(expStatusCode), actualStatusCode, "The status code are not equals"); - } - - @And("^The proper '(.*)' '(.*)' returned in the response$") - public void theProperIdReturnedInTheResponse(String property, String value) { - if (!value.isEmpty()) { - Data response = (Data) APIManager.getLastResponse().getResponse(); - Assert.assertEquals(String.valueOf(response.getUser().getId()), value, "The " + property + " is not in the response"); - } - } + @SuppressWarnings({ "deprecation" }) + @When("^Realizo una peticion '(.*)' hacia '(.*)' endpoint con el archivo '(.*)'$") + public void doRequest(String methodName, String entity, String jsonName) throws IllegalAccessException, + IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + + EntityConfiguration.valueOf(entity).getEntityService().getMethod(methodName.toLowerCase(), String.class) + .invoke("", jsonName); + + } + + @SuppressWarnings("deprecation") + @Then("^Obtengo el codigo de estado '(.*)'$") + public void iWillGetTheProperStatusCodeStatusCode(String expStatusCode) { + int actualStatusCode = APIManager.getLastResponse().getStatusCode(); + Assert.assertEquals(Integer.parseInt(expStatusCode), actualStatusCode, "The status code are not equals"); + } + + @SuppressWarnings("deprecation") + @And("^El correspondiente '(.*)' con valor '(.*)' como parte de la respuesta$") + public void theProperIdReturnedInTheResponse(String property, String value) { + if (property.equals("username")) { + + User response = (User) APIManager.getLastResponse().getResponse(); + Assert.assertEquals(String.valueOf(response.getUsername()), value, + "La " + property + " no está en el response"); + if (response.getJwt() != null && response.getJwt() != "") { + UserService.TOKEN.set(response.getJwt()); + } + + } else if (property.equals("error")) { + + User response = (User) APIManager.getLastResponse().getResponse(); + Assert.assertEquals(String.valueOf(response.getError()), value, + "La " + property + " no está en el response"); + } + } } diff --git a/src/test/resources/features/ApiExample.feature b/src/test/resources/features/ApiExample.feature deleted file mode 100644 index 9caa5b3..0000000 --- a/src/test/resources/features/ApiExample.feature +++ /dev/null @@ -1,36 +0,0 @@ -Feature: Api example - As an api user I want to execute request in order to get proper responses - - @Example @Success - Scenario Outline: Example scenario for get user data - When I perform a '' to '' endpoint with the '' and '' - Then I will get the proper status code '' - And The proper 'Id' '' returned in the response - - Examples: - | jsonName | statusCode | id | operation | entity | - | exampleJson | 200 | 2 | GET | USER | - | createUser | 201 | | POST | USER | - | createUser | 201 | | POST | USER | - | createUser | 201 | | POST | USER | - - @Example @Fail - Scenario Outline: Example scenario for error - Given As an api user for example endpoint - When I perform a '' to '' endpoint with the '' - Then I will get the proper status code '' - - Examples: - | jsonName | statusCode | operation | entity | - | errorRequest | 500 | GET | USER | - - - @Example @Success - Scenario Outline: Example scenario for input parameters - When I perform a '' to '' endpoint with the '' and '' - Then I will get the proper status code '' - And I will get the proper response in '' - - Examples: - | jsonRequestName | statusCode | operation | entity | inputParameters | jsonResponseName | - | responseHeadersRequest | 200 | GET | RESPONSE_HEADERS | value1:bar1,value2:bar2 | responseHeadersResponse | diff --git a/src/test/resources/features/CrowdarApi.feature b/src/test/resources/features/CrowdarApi.feature new file mode 100644 index 0000000..4a4d712 --- /dev/null +++ b/src/test/resources/features/CrowdarApi.feature @@ -0,0 +1,29 @@ +Feature: Api de Crowdar + Como un usuario de la api quiero ejecutar los requests paara obtener las respuestas correspondientes + + @Login @Smoke + Scenario Outline: Iniciar sesión y obtener token jwt + + When Realizo una peticion '' hacia '' endpoint con el archivo '' + Then Obtengo el codigo de estado '' + And El correspondiente '' con valor '' como parte de la respuesta + + Examples: + | jsonName | statusCode |property | value | operation | entity | + | request/login | 200 |username | admin | POST | USER | + | request/loginFail | 401 |error | Unauthorized | POST | USER | + #| request/login | 404 |error | Not Found | GET | USER | + +# @Authors @Smoke + #Scenario Outline: realizar peticion de Autores + # + #When Realizo una petición '' hacia '' endpoint con el archivo '' + #Then Obtengo el codigo de estado '' + # + #Examples: + #| jsonName | statusCode | operation | entity | + #| request/authorsDistinct | 200 | POST | AUTHORS | + #| request/authorsCount | 401 | POST | AUTHORS | + + + \ No newline at end of file diff --git a/src/test/resources/jsons/request/authorsCount.json b/src/test/resources/jsons/request/authorsCount.json new file mode 100644 index 0000000..29d9a6f --- /dev/null +++ b/src/test/resources/jsons/request/authorsCount.json @@ -0,0 +1,8 @@ +{ + "url": "", + "headers": { + "Authorization": "" + }, + "urlParameters": {}, + "endpoint": "/user/authenticate" +} diff --git a/src/test/resources/jsons/request/authorsDistinct.json b/src/test/resources/jsons/request/authorsDistinct.json new file mode 100644 index 0000000..32b25da --- /dev/null +++ b/src/test/resources/jsons/request/authorsDistinct.json @@ -0,0 +1,8 @@ +{ + "url": "", + "headers": { + "Authorization": "" + }, + "urlParameters": {}, + "endpoint": "/rest/authors/distinct" +} diff --git a/src/test/resources/jsons/request/createUser.json b/src/test/resources/jsons/request/createUser.json deleted file mode 100644 index 67c6b36..0000000 --- a/src/test/resources/jsons/request/createUser.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "url": "", - "headers": { - "Content-Type": "application/json" - }, - "body": { - "name": "test", - "job": "leader" - } -} - diff --git a/src/test/resources/jsons/request/errorRequest.json b/src/test/resources/jsons/request/errorRequest.json deleted file mode 100644 index 996c8f8..0000000 --- a/src/test/resources/jsons/request/errorRequest.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "url": "https://postman-echo.com/", - "endpoint": "status/500", - "headers": { - "Content-Type": "application/json" - }, - "body": "", - "urlParameters": { - } -} - diff --git a/src/test/resources/jsons/request/exampleJson.json b/src/test/resources/jsons/request/exampleJson.json deleted file mode 100644 index 1b6dd91..0000000 --- a/src/test/resources/jsons/request/exampleJson.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "headers": { - "Content-Type": "application/json" - }, - "urlParameters": { - "id": "2" - } -} - diff --git a/src/test/resources/jsons/request/login.json b/src/test/resources/jsons/request/login.json new file mode 100644 index 0000000..4c7e5d1 --- /dev/null +++ b/src/test/resources/jsons/request/login.json @@ -0,0 +1,11 @@ +{ + "url": "", + "headers": { + + }, + "urlParameters": { + "username": "admin", + "password": "password" + }, + "endpoint": "/user/authenticate" +} diff --git a/src/test/resources/jsons/request/loginFail.json b/src/test/resources/jsons/request/loginFail.json new file mode 100644 index 0000000..bdbf5b8 --- /dev/null +++ b/src/test/resources/jsons/request/loginFail.json @@ -0,0 +1,11 @@ +{ + "url": "", + "headers": { + + }, + "urlParameters": { + "username": "unknown", + "password": "random" + }, + "endpoint": "/user/authenticate" +} diff --git a/src/test/resources/jsons/request/responseHeadersRequest.json b/src/test/resources/jsons/request/responseHeadersRequest.json deleted file mode 100644 index 77854cc..0000000 --- a/src/test/resources/jsons/request/responseHeadersRequest.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "url": "https://postman-echo.com/", - "endpoint": "response-headers", - "headers": { - }, - "urlParameters": { - "foo1": "{{value1}}", - "foo2": "{{value2}}" - } -} - From 152adfffe886fa292156ef54b42e580ce3ab4679 Mon Sep 17 00:00:00 2001 From: German Quiroga Sottile Date: Thu, 1 Oct 2020 18:49:11 -0300 Subject: [PATCH 2/3] token --- src/main/java/services/AuthorsService.java | 7 +++- .../java/services/EnvironmentService.java | 6 ++-- src/test/java/ar/steps/UserSteps.java | 27 +++++++++++--- .../resources/features/CrowdarApi.feature | 35 ++++++++++++------- .../resources/jsons/request/authorsCount.json | 7 ++-- .../jsons/request/authorsDistinct.json | 9 +++-- .../jsons/request/environmentSearchBuild.json | 12 +++++++ .../request/environmentSearchBuildFail.json | 12 +++++++ 8 files changed, 90 insertions(+), 25 deletions(-) create mode 100644 src/test/resources/jsons/request/environmentSearchBuild.json create mode 100644 src/test/resources/jsons/request/environmentSearchBuildFail.json diff --git a/src/main/java/services/AuthorsService.java b/src/main/java/services/AuthorsService.java index 3e3e6f2..a9cd9f4 100644 --- a/src/main/java/services/AuthorsService.java +++ b/src/main/java/services/AuthorsService.java @@ -1,11 +1,16 @@ package services; +import java.util.HashMap; +import java.util.Map; + import com.crowdar.api.rest.MethodsService; import com.crowdar.api.rest.Response; public class AuthorsService extends MethodsService { public static Response get(String jsonName) { - return get(jsonName, null); + Map params = new HashMap(); + params.put("token", "Bearer ".concat(UserService.TOKEN.get())); + return get(jsonName, null, params); } } diff --git a/src/main/java/services/EnvironmentService.java b/src/main/java/services/EnvironmentService.java index a9ceeec..6aab62c 100644 --- a/src/main/java/services/EnvironmentService.java +++ b/src/main/java/services/EnvironmentService.java @@ -7,8 +7,8 @@ public class EnvironmentService extends MethodsService { - public static Response get(String jsonName, Map parameters) { - return get(jsonName, null, parameters); + public static Response get(String jsonName, Map params) { + params.put("token", "Bearer ".concat(UserService.TOKEN.get())); + return get(jsonName, null, params); } - } diff --git a/src/test/java/ar/steps/UserSteps.java b/src/test/java/ar/steps/UserSteps.java index 76c7bc7..bbd90c5 100644 --- a/src/test/java/ar/steps/UserSteps.java +++ b/src/test/java/ar/steps/UserSteps.java @@ -4,28 +4,47 @@ import api.model.User; import com.crowdar.api.rest.APIManager; import com.crowdar.core.PageSteps; +import com.google.api.client.repackaged.com.google.common.base.Splitter; import cucumber.api.java.en.And; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; import services.UserService; +import org.apache.commons.lang.StringUtils; import org.testng.Assert; import java.lang.reflect.InvocationTargetException; +import java.util.Map; @SuppressWarnings("deprecation") public class UserSteps extends PageSteps { @SuppressWarnings({ "deprecation" }) - @When("^Realizo una peticion '(.*)' hacia '(.*)' endpoint con el archivo '(.*)'$") - public void doRequest(String methodName, String entity, String jsonName) throws IllegalAccessException, + @When("^Realizo una peticion '(.*)' hacia '(.*)' endpoint con el archivo '(.*)' y parametros '(.*)'$") + public void doRequest(String methodName, String entity, String jsonName, String jsonReplacementValues) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { - EntityConfiguration.valueOf(entity).getEntityService().getMethod(methodName.toLowerCase(), String.class) - .invoke("", jsonName); + Class entityService = EntityConfiguration.valueOf(entity).getEntityService(); + + Map parameters = getParameters(jsonReplacementValues); + + if (parameters == null) { + entityService.getMethod(methodName.toLowerCase(), String.class).invoke("", jsonName); + } else { + entityService.getMethod(methodName.toLowerCase(), String.class, Map.class).invoke("", jsonName, parameters); + } } + + @SuppressWarnings("unused") + private Map getParameters(String jsonReplacementValues) { + Map parameters = null; + if (!StringUtils.isEmpty(jsonReplacementValues)) { + parameters = Splitter.on(",").withKeyValueSeparator(":").split(jsonReplacementValues); + } + return parameters; + } @SuppressWarnings("deprecation") @Then("^Obtengo el codigo de estado '(.*)'$") diff --git a/src/test/resources/features/CrowdarApi.feature b/src/test/resources/features/CrowdarApi.feature index 4a4d712..7acde69 100644 --- a/src/test/resources/features/CrowdarApi.feature +++ b/src/test/resources/features/CrowdarApi.feature @@ -4,7 +4,7 @@ Feature: Api de Crowdar @Login @Smoke Scenario Outline: Iniciar sesión y obtener token jwt - When Realizo una peticion '' hacia '' endpoint con el archivo '' + When Realizo una peticion '' hacia '' endpoint con el archivo '' y parametros '' Then Obtengo el codigo de estado '' And El correspondiente '' con valor '' como parte de la respuesta @@ -12,18 +12,29 @@ Feature: Api de Crowdar | jsonName | statusCode |property | value | operation | entity | | request/login | 200 |username | admin | POST | USER | | request/loginFail | 401 |error | Unauthorized | POST | USER | - #| request/login | 404 |error | Not Found | GET | USER | + | request/login | 404 |error | Not Found | GET | USER | -# @Authors @Smoke - #Scenario Outline: realizar peticion de Autores - # - #When Realizo una petición '' hacia '' endpoint con el archivo '' - #Then Obtengo el codigo de estado '' - # - #Examples: - #| jsonName | statusCode | operation | entity | - #| request/authorsDistinct | 200 | POST | AUTHORS | - #| request/authorsCount | 401 | POST | AUTHORS | + @Authors @Smoke + Scenario Outline: realizar peticion de Autores + + When Realizo una petición '' hacia '' endpoint con el archivo '' y parametros '' + Then Obtengo el codigo de estado '' + + Examples: + | jsonName | statusCode | operation | entity | + | request/authorsDistinct | 200 | POST | AUTHORS | + | request/authorsCount | 401 | POST | AUTHORS | + @Environments @Smoke + Scenario Outline: realizar peticion de Enviromments busquedas + + When Realizo una petición '' hacia '' endpoint con el archivo '' y parametros '' + Then Obtengo el codigo de estado '' + + Examples: + | jsonName | statusCode | operation | params | entity | + | request/enviromentSearchBuild | 200 | GET | name:admin,value:123 | ENVIRONMENT | + | request/enviromentSearchBuildFail | 403 | GET | name:unknown,value:123 | ENVIRONMENT | + \ No newline at end of file diff --git a/src/test/resources/jsons/request/authorsCount.json b/src/test/resources/jsons/request/authorsCount.json index 29d9a6f..d8026ee 100644 --- a/src/test/resources/jsons/request/authorsCount.json +++ b/src/test/resources/jsons/request/authorsCount.json @@ -1,8 +1,11 @@ { "url": "", "headers": { - "Authorization": "" + "Content-Type": "application/json", + "Authorization": "{{token}}" + }, + "urlParameters": { + }, - "urlParameters": {}, "endpoint": "/user/authenticate" } diff --git a/src/test/resources/jsons/request/authorsDistinct.json b/src/test/resources/jsons/request/authorsDistinct.json index 32b25da..30d3d3c 100644 --- a/src/test/resources/jsons/request/authorsDistinct.json +++ b/src/test/resources/jsons/request/authorsDistinct.json @@ -1,8 +1,11 @@ { "url": "", - "headers": { - "Authorization": "" + "headers": { + "Content-Type": "application/json", + "Authorization": "{{token}}" + }, + "urlParameters": { + }, - "urlParameters": {}, "endpoint": "/rest/authors/distinct" } diff --git a/src/test/resources/jsons/request/environmentSearchBuild.json b/src/test/resources/jsons/request/environmentSearchBuild.json new file mode 100644 index 0000000..e81a752 --- /dev/null +++ b/src/test/resources/jsons/request/environmentSearchBuild.json @@ -0,0 +1,12 @@ +{ + "url": "", + "headers": { + "Content-Type": "application/json", + "Authorization": "{{token}}" + }, + "urlParameters": { + "name": "{{name}}", + "value": "{{value}}" + }, + "endpoint": "/rest/environment/search/findBuilds" +} diff --git a/src/test/resources/jsons/request/environmentSearchBuildFail.json b/src/test/resources/jsons/request/environmentSearchBuildFail.json new file mode 100644 index 0000000..e81a752 --- /dev/null +++ b/src/test/resources/jsons/request/environmentSearchBuildFail.json @@ -0,0 +1,12 @@ +{ + "url": "", + "headers": { + "Content-Type": "application/json", + "Authorization": "{{token}}" + }, + "urlParameters": { + "name": "{{name}}", + "value": "{{value}}" + }, + "endpoint": "/rest/environment/search/findBuilds" +} From 6f3ca1dae6f8ad71320afb494dafe7c8f8e400a9 Mon Sep 17 00:00:00 2001 From: German Quiroga Sottile Date: Thu, 1 Oct 2020 19:24:56 -0300 Subject: [PATCH 3/3] andando pom nuevo --- pom.xml | 108 ++++++++---------- pom.xml_bkp | 84 ++++++++++++++ src/test/java/ar/steps/UserSteps.java | 2 +- .../resources/features/CrowdarApi.feature | 2 +- testng.xml_bkp | 9 ++ testngParalell.xml_bkp | 9 ++ 6 files changed, 152 insertions(+), 62 deletions(-) create mode 100644 pom.xml_bkp create mode 100644 testng.xml_bkp create mode 100644 testngParalell.xml_bkp diff --git a/pom.xml b/pom.xml index 984c68b..05d5e0a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,44 +1,32 @@ - 4.0.0 - - io.lippia - root - 3.2.1.1 - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + io.lippia + root + 3.2.1.1 + - com.Crowdar - lippia-api-example-project - api-rest-automation - jar - http://maven.apache.org + com.Crowdar + lippia-api-example-project + api-rest-automation + jar + http://maven.apache.org - - UTF-8 - http://vps2.crowdaronline.com:8083 - --glue ar/steps - --glue com/crowdar/bdd/cukes --glue - ar/apiExampleProject/hook + + UTF-8 + http://vps2.crowdaronline.com:8083 + --glue ar/steps + --glue com/crowdar/bdd/cukes --glue ar/apiExampleProject/hook @Smoke --plugin pretty - src/test/resources/features ${cucumber.hooks} - ${cucumber.stepsDefinitions} --tags 'not @Ignore' --tags - ${cucumber.tags} ${cucumber.reporters} - API - - - - - Secuencial - - - - testng.xml - - - + src/test/resources/features ${cucumber.hooks} ${cucumber.stepsDefinitions} --tags 'not @Ignore' --tags ${cucumber.tags} ${cucumber.reporters} + API + + + Paralelo true @@ -47,38 +35,38 @@ testngParalell.xml - - - - io.lippia - core - 3.2.1.1 - - - - - src/main/resources/cucumber.properties - - - - org.apache.maven.plugins + + + + io.lippia + core + 3.2.1.1 + + + + + src/main/resources/cucumber.properties + + + + org.apache.maven.plugins maven-surefire-plugin 3.0.0-M4 - - - ${apiExample.runner} - - - - - - + + + ${apiExample.runner} + + + + + + crowdarRepo crowdar-repository https://nexus-v3-repositories.automation.crowdaronline.com/repository/maven-public/ - + diff --git a/pom.xml_bkp b/pom.xml_bkp new file mode 100644 index 0000000..984c68b --- /dev/null +++ b/pom.xml_bkp @@ -0,0 +1,84 @@ + + + 4.0.0 + + io.lippia + root + 3.2.1.1 + + + com.Crowdar + lippia-api-example-project + api-rest-automation + jar + http://maven.apache.org + + + UTF-8 + http://vps2.crowdaronline.com:8083 + --glue ar/steps + --glue com/crowdar/bdd/cukes --glue + ar/apiExampleProject/hook + @Smoke + --plugin pretty + src/test/resources/features ${cucumber.hooks} + ${cucumber.stepsDefinitions} --tags 'not @Ignore' --tags + ${cucumber.tags} ${cucumber.reporters} + API + + + + + Secuencial + + + + testng.xml + + + + Paralelo + + true + + + testngParalell.xml + + + + + + io.lippia + core + 3.2.1.1 + + + + + src/main/resources/cucumber.properties + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M4 + + + ${apiExample.runner} + + + + + + + + crowdarRepo + crowdar-repository + https://nexus-v3-repositories.automation.crowdaronline.com/repository/maven-public/ + + + + + diff --git a/src/test/java/ar/steps/UserSteps.java b/src/test/java/ar/steps/UserSteps.java index bbd90c5..5e39fdd 100644 --- a/src/test/java/ar/steps/UserSteps.java +++ b/src/test/java/ar/steps/UserSteps.java @@ -61,7 +61,7 @@ public void theProperIdReturnedInTheResponse(String property, String value) { User response = (User) APIManager.getLastResponse().getResponse(); Assert.assertEquals(String.valueOf(response.getUsername()), value, "La " + property + " no está en el response"); - if (response.getJwt() != null && response.getJwt() != "") { + if (response.getJwt() != null && response.getJwt().equals("")) { UserService.TOKEN.set(response.getJwt()); } diff --git a/src/test/resources/features/CrowdarApi.feature b/src/test/resources/features/CrowdarApi.feature index 7acde69..326dea3 100644 --- a/src/test/resources/features/CrowdarApi.feature +++ b/src/test/resources/features/CrowdarApi.feature @@ -34,7 +34,7 @@ Feature: Api de Crowdar Examples: | jsonName | statusCode | operation | params | entity | | request/enviromentSearchBuild | 200 | GET | name:admin,value:123 | ENVIRONMENT | - | request/enviromentSearchBuildFail | 403 | GET | name:unknown,value:123 | ENVIRONMENT | + | request/enviromentSearchBuild | 403 | GET | name:unknown,value:123 | ENVIRONMENT | \ No newline at end of file diff --git a/testng.xml_bkp b/testng.xml_bkp new file mode 100644 index 0000000..1c918f6 --- /dev/null +++ b/testng.xml_bkp @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/testngParalell.xml_bkp b/testngParalell.xml_bkp new file mode 100644 index 0000000..c02e857 --- /dev/null +++ b/testngParalell.xml_bkp @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file