Search in sources :

Example 1 with RemoteException

use of com.wikia.webdriver.common.remote.RemoteException in project selenium-tests by Wikia.

the class CreateCategory method execute.

public CategoryPill.Data execute(final CreateCategoryContext context) {
    JSONObject jsonObject = new JSONObject(ImmutableMap.builder().put("name", context.getCategoryName()).put("parentId", PARENT_ID).put("siteId", context.getSiteId()).build());
    String response;
    try {
        response = remoteOperation.execute(buildUrl(context), jsonObject);
    } catch (RemoteException e) {
        PageObjectLogging.logError("error: ", e);
        throw new CategoryNotCreated("Could not create a new category.", e);
    }
    DocumentContext json = JsonPath.parse(response);
    CategoryPill.Data data = new CategoryPill.Data(json.read("$.id"), json.read("$.name"));
    data.setDisplayOrder(json.read("$.displayOrder"));
    return data;
}
Also used : JSONObject(org.json.JSONObject) CategoryPill(com.wikia.webdriver.elements.mercury.components.discussions.common.category.CategoryPill) RemoteException(com.wikia.webdriver.common.remote.RemoteException) DocumentContext(com.jayway.jsonpath.DocumentContext)

Example 2 with RemoteException

use of com.wikia.webdriver.common.remote.RemoteException in project selenium-tests by Wikia.

the class BaseRemoteOperation method handleResponse.

String handleResponse(final HttpRequestBase requestBase, final CloseableHttpResponse response) throws IOException {
    String result = StringUtils.EMPTY;
    final HttpEntity entity = response.getEntity();
    if (null != entity) {
        result = EntityUtils.toString(entity);
        if (response.getStatusLine().getStatusCode() >= 400) {
            throw new RemoteException("Error while invoking request. " + " Method: " + requestBase.getMethod() + " Url: " + requestBase.getURI().toString() + " Response: " + result);
        }
    }
    return result;
}
Also used : HttpEntity(org.apache.http.HttpEntity) RemoteException(com.wikia.webdriver.common.remote.RemoteException)

Example 3 with RemoteException

use of com.wikia.webdriver.common.remote.RemoteException in project selenium-tests by Wikia.

the class BaseRemoteOperation method execute.

String execute(final HttpEntityEnclosingRequestBase request, final JSONObject jsonObject) {
    String result = StringUtils.EMPTY;
    try {
        request.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
        request.setEntity(new StringEntity(jsonObject.toString(), ContentType.APPLICATION_JSON));
        result = execute(request);
    } catch (RemoteException ex) {
        PageObjectLogging.log("Request: ", getRequestString(request) + "\n" + request.getEntity(), false);
        PageObjectLogging.log("Error while creating http post entity.", ExceptionUtils.getStackTrace(ex), false);
    }
    return result;
}
Also used : StringEntity(org.apache.http.entity.StringEntity) RemoteException(com.wikia.webdriver.common.remote.RemoteException)

Aggregations

RemoteException (com.wikia.webdriver.common.remote.RemoteException)3 DocumentContext (com.jayway.jsonpath.DocumentContext)1 CategoryPill (com.wikia.webdriver.elements.mercury.components.discussions.common.category.CategoryPill)1 HttpEntity (org.apache.http.HttpEntity)1 StringEntity (org.apache.http.entity.StringEntity)1 JSONObject (org.json.JSONObject)1