Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #29 from sbtqa/14-api-methods-to-const
Browse files Browse the repository at this point in the history
#14 Add constants for api methods
  • Loading branch information
kosteman authored Nov 14, 2017
2 parents 650be3a + 71a1922 commit 6494303
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
23 changes: 9 additions & 14 deletions src/main/java/ru/sbtqa/tag/apifactory/ApiEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.sbtqa.tag.apifactory.annotation.AddBracket;
import ru.sbtqa.tag.apifactory.annotation.ApiAction;
import ru.sbtqa.tag.apifactory.annotation.ApiRequestHeader;
import ru.sbtqa.tag.apifactory.annotation.ApiRequestParam;
import ru.sbtqa.tag.apifactory.annotation.ApiValidationRule;
import ru.sbtqa.tag.apifactory.annotation.DependentResponseParam;
import ru.sbtqa.tag.apifactory.annotation.PutInStash;
import ru.sbtqa.tag.apifactory.annotation.*;
import ru.sbtqa.tag.apifactory.exception.ApiEntryInitializationException;
import ru.sbtqa.tag.apifactory.exception.ApiException;
import ru.sbtqa.tag.apifactory.repositories.Bullet;
import ru.sbtqa.tag.apifactory.rest.HTTP;
import ru.sbtqa.tag.apifactory.rest.Rest;
import ru.sbtqa.tag.apifactory.soap.Soap;
import ru.sbtqa.tag.datajack.Stash;
Expand Down Expand Up @@ -161,7 +156,7 @@ public void prepare() throws ApiException {
*/
public Object fire(String url) throws ApiException {
//Get request method of current api object
String requestMethod = this.getClass().getAnnotation(ApiAction.class).method().toLowerCase();
HTTP requestMethod = this.getClass().getAnnotation(ApiAction.class).method();
String templateName = this.getClass().getAnnotation(ApiAction.class).template();

Bullet response = null;
Expand All @@ -181,30 +176,30 @@ public Object fire(String url) throws ApiException {

Map<String, String> hdrs = getHeaders();
switch (requestMethod) {
case "get":
case GET:
response = (Bullet) rest.get(url, hdrs);
ApiFactory.getApiFactory().addRequestHeadersToRepository(this.getClass(), hdrs);
break;
case "post":
case POST:
response = (Bullet) rest.post(url, hdrs, bd);
request = new Bullet(hdrs, bd.toString());
ApiFactory.getApiFactory().addRequestToRepository(this.getClass(), request);
break;
case "put":
case PUT:
response = (Bullet) rest.put(url, hdrs, bd);
request = new Bullet(hdrs, bd.toString());
ApiFactory.getApiFactory().addRequestToRepository(this.getClass(), request);
break;
case "patch":
case PATCH:
response = (Bullet) rest.patch(url, hdrs, bd);
request = new Bullet(hdrs, bd.toString());
ApiFactory.getApiFactory().addRequestToRepository(this.getClass(), request);
break;
case "delete":
case DELETE:
response = (Bullet) rest.delete(url, hdrs);
ApiFactory.getApiFactory().addRequestHeadersToRepository(this.getClass(), hdrs);
break;
case "soap":
case SOAP:
response = (Bullet) soap.send(url, hdrs, bd, Proxy.NO_PROXY);
request = new Bullet(hdrs, bd.toString());
ApiFactory.getApiFactory().addRequestToRepository(this.getClass(), request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.lang.annotation.Target;
import ru.sbtqa.tag.apifactory.ApiEntry;
import ru.sbtqa.tag.apifactory.EmptyApiEntry;
import ru.sbtqa.tag.apifactory.rest.HTTP;

/**
* This annotation used above ApiEntry class declaration
Expand Down Expand Up @@ -33,9 +34,9 @@
/**
* HTTP method used to execute api method
*
* @return a {@link java.lang.String} object.
* @return a {@link HTTP} object.
*/
public String method();
public HTTP method();

/**
* Body template
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/ru/sbtqa/tag/apifactory/rest/HTTP.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ru.sbtqa.tag.apifactory.rest;

/**
* This enum using in ApiAction annotation, for method type.
*
*/
public enum HTTP {
POST,
GET,
PUT,
DELETE,
PATCH,
SOAP
}

0 comments on commit 6494303

Please sign in to comment.