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..05d5e0a 100644 --- a/pom.xml +++ b/pom.xml @@ -17,33 +17,24 @@ UTF-8 - https://reqres.in/api/users + http://vps2.crowdaronline.com:8083 --glue ar/steps --glue com/crowdar/bdd/cukes --glue ar/apiExampleProject/hook - @Success + @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 - - + Paralelo + + true + + + testngParalell.xml + + 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/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..a9cd9f4 --- /dev/null +++ b/src/main/java/services/AuthorsService.java @@ -0,0 +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) { + 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 new file mode 100644 index 0000000..6aab62c --- /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 params) { + params.put("token", "Bearer ".concat(UserService.TOKEN.get())); + return get(jsonName, null, params); + } +} 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..5e39fdd 100644 --- a/src/test/java/ar/steps/UserSteps.java +++ b/src/test/java/ar/steps/UserSteps.java @@ -1,36 +1,44 @@ 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 services.UserService; + import org.apache.commons.lang.StringUtils; 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); - } - } + @SuppressWarnings({ "deprecation" }) + @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 { + + 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); + } - private Map getParameters(String jsonReplacementValues) { + } + + @SuppressWarnings("unused") + private Map getParameters(String jsonReplacementValues) { Map parameters = null; if (!StringUtils.isEmpty(jsonReplacementValues)) { parameters = Splitter.on(",").withKeyValueSeparator(":").split(jsonReplacementValues); @@ -38,17 +46,30 @@ private Map getParameters(String 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"); - } + @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"); + } - @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") + @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().equals("")) { + 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..326dea3 --- /dev/null +++ b/src/test/resources/features/CrowdarApi.feature @@ -0,0 +1,40 @@ +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 '' y parametros '' + 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 '' 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/enviromentSearchBuild | 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 new file mode 100644 index 0000000..d8026ee --- /dev/null +++ b/src/test/resources/jsons/request/authorsCount.json @@ -0,0 +1,11 @@ +{ + "url": "", + "headers": { + "Content-Type": "application/json", + "Authorization": "{{token}}" + }, + "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..30d3d3c --- /dev/null +++ b/src/test/resources/jsons/request/authorsDistinct.json @@ -0,0 +1,11 @@ +{ + "url": "", + "headers": { + "Content-Type": "application/json", + "Authorization": "{{token}}" + }, + "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/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" +} 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}}" - } -} - 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