Search in sources :

Example 1 with ActualResult

use of nl.knaw.huygens.concordion.extensions.ActualResult in project timbuctoo by HuygensING.

the class AbstractV2_1EndpointFixture method executeRequestUsingJaxRs.

/**
 * Implements the actual http call for the concordion HTTPCommand.
 */
protected ActualResult executeRequestUsingJaxRs(HttpRequest httpRequest) {
    WebTarget target = returnUrlToMockedOrRealServer(httpRequest.server).path(httpRequest.path);
    for (Map.Entry<String, String> queryParameter : httpRequest.queryParameters.entries()) {
        target = target.queryParam(queryParameter.getKey(), queryParameter.getValue());
    }
    Invocation.Builder request = target.request();
    for (Map.Entry<String, String> header : httpRequest.headers.entries()) {
        request = request.header(header.getKey(), header.getValue());
    }
    Response jerseyResult;
    if (httpRequest.body != null) {
        final String contentType = httpRequest.headers.entries().stream().filter(x -> x.getKey().equalsIgnoreCase("content-type")).map(Map.Entry::getValue).findFirst().orElse("application/json");
        jerseyResult = request.method(httpRequest.method, Entity.entity(httpRequest.body, contentType));
    } else {
        jerseyResult = request.method(httpRequest.method);
    }
    return ActualResult.fromJaxRs(jerseyResult);
}
Also used : Response(javax.ws.rs.core.Response) ExpectedResult(nl.knaw.huygens.concordion.extensions.ExpectedResult) DiffResult(nl.knaw.huygens.contractdiff.diffresults.DiffResult) ValidationResult.xmlResult(nl.knaw.huygens.concordion.extensions.ValidationResult.xmlResult) Tuple(nl.knaw.huygens.timbuctoo.util.Tuple) IOException(java.io.IOException) JsonDiffer.jsonDiffer(nl.knaw.huygens.contractdiff.jsondiff.JsonDiffer.jsonDiffer) Invocation(javax.ws.rs.client.Invocation) Entity(javax.ws.rs.client.Entity) ReplaceEmbeddedStylesheetExtension(nl.knaw.huygens.concordion.extensions.ReplaceEmbeddedStylesheetExtension) HttpCommandExtension(nl.knaw.huygens.concordion.extensions.HttpCommandExtension) XmlEscapers.xmlContentEscaper(com.google.common.xml.XmlEscapers.xmlContentEscaper) Extension(org.concordion.api.extension.Extension) Response(javax.ws.rs.core.Response) Map(java.util.Map) ActualResult(nl.knaw.huygens.concordion.extensions.ActualResult) HttpRequest(nl.knaw.huygens.concordion.extensions.HttpRequest) JsonDiffer(nl.knaw.huygens.contractdiff.jsondiff.JsonDiffer) WebTarget(javax.ws.rs.client.WebTarget) ValidationResult(nl.knaw.huygens.concordion.extensions.ValidationResult) Tuple.tuple(nl.knaw.huygens.timbuctoo.util.Tuple.tuple) ExpectedHeadersAreEqualValidator(nl.knaw.huygens.contractdiff.httpdiff.ExpectedHeadersAreEqualValidator) Invocation(javax.ws.rs.client.Invocation) WebTarget(javax.ws.rs.client.WebTarget) Map(java.util.Map)

Example 2 with ActualResult

use of nl.knaw.huygens.concordion.extensions.ActualResult in project timbuctoo by HuygensING.

the class AuthenticationV2_1EndpointFixture method doLoginWithoutHeader.

public String doLoginWithoutHeader() {
    HttpRequest httpRequest = new HttpRequest("POST", "/v2.1/authenticate");
    ActualResult response = super.executeRequestUsingJaxRs(httpRequest);
    return String.format("%s %s", response.getStatus(), response.getStatusInfo());
}
Also used : HttpRequest(nl.knaw.huygens.concordion.extensions.HttpRequest) ActualResult(nl.knaw.huygens.concordion.extensions.ActualResult)

Example 3 with ActualResult

use of nl.knaw.huygens.concordion.extensions.ActualResult in project timbuctoo by HuygensING.

the class AuthenticationV2_1EndpointFixture method doLoginWithInvalidUsernameAndPassword.

public String doLoginWithInvalidUsernameAndPassword() {
    HttpRequest httpRequest = new HttpRequest("POST", "/v2.1/authenticate").withHeader("Authorization", "Basic dW5rbm93blVzZXI6cGFzc3dvcmQ=");
    ActualResult response = super.executeRequestUsingJaxRs(httpRequest);
    return String.format("%s %s", response.getStatus(), response.getStatusInfo());
}
Also used : HttpRequest(nl.knaw.huygens.concordion.extensions.HttpRequest) ActualResult(nl.knaw.huygens.concordion.extensions.ActualResult)

Example 4 with ActualResult

use of nl.knaw.huygens.concordion.extensions.ActualResult in project timbuctoo by HuygensING.

the class BaseDomainV2_1EndpointFixture method getAuthenticationToken.

public String getAuthenticationToken() {
    if (authenticationToken != null) {
        return authenticationToken;
    }
    HttpRequest loginRequest = new HttpRequest("POST", "/v2.1/authenticate").withHeader("Authorization", "Basic dXNlcjpwYXNzd29yZA==");
    ActualResult response = executeRequestUsingJaxRs(loginRequest);
    authenticationToken = response.getFirstHeader("x_auth_token").orElse("X_AUTH_TOKEN_NOT_RETURNED");
    return authenticationToken;
}
Also used : HttpRequest(nl.knaw.huygens.concordion.extensions.HttpRequest) ActualResult(nl.knaw.huygens.concordion.extensions.ActualResult)

Example 5 with ActualResult

use of nl.knaw.huygens.concordion.extensions.ActualResult in project timbuctoo by HuygensING.

the class RelationSearchV2_1EndpointFixture method getPersonSearchId.

public String getPersonSearchId() {
    HttpRequest postRequest = new HttpRequest("POST", "/v2.1/search/wwpersons", "{}").withHeader("Content-type", "application/json").withHeader("VRE_ID", "WomenWriters");
    ActualResult response = executeRequestUsingJaxRs(postRequest);
    return response.getFirstHeader("Location").map(l -> l.replaceAll("http://[^/]+/", "")).map(l -> l.replaceAll(".*\\/", "")).orElse("");
}
Also used : HttpRequest(nl.knaw.huygens.concordion.extensions.HttpRequest) FullOGNL(org.concordion.api.FullOGNL) TimbuctooConfiguration(nl.knaw.huygens.timbuctoo.server.TimbuctooConfiguration) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) ArrayDiffResult(nl.knaw.huygens.contractdiff.jsondiff.ArrayDiffResult) MissingPropertyDiffResult(nl.knaw.huygens.contractdiff.diffresults.MissingPropertyDiffResult) RunWith(org.junit.runner.RunWith) JsonDiffer.jsonDiffer(nl.knaw.huygens.contractdiff.jsondiff.JsonDiffer.jsonDiffer) RelativeUrlWithoutLeadingSlash(nl.knaw.huygens.timbuctoo.server.endpoints.v2.matchers.RelativeUrlWithoutLeadingSlash) DropwizardMaker.makeTimbuctoo(nl.knaw.huygens.util.DropwizardMaker.makeTimbuctoo) StringUtils(org.apache.commons.lang3.StringUtils) ConcordionRunner(org.concordion.integration.junit4.ConcordionRunner) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ClientBuilder(javax.ws.rs.client.ClientBuilder) DropwizardAppRule(io.dropwizard.testing.junit.DropwizardAppRule) ActualResult(nl.knaw.huygens.concordion.extensions.ActualResult) HttpRequest(nl.knaw.huygens.concordion.extensions.HttpRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonDiffer(nl.knaw.huygens.contractdiff.jsondiff.JsonDiffer) NumericDateWithoutDashes(nl.knaw.huygens.timbuctoo.server.endpoints.v2.matchers.NumericDateWithoutDashes) WebTarget(javax.ws.rs.client.WebTarget) ClassRule(org.junit.ClassRule) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) ActualResult(nl.knaw.huygens.concordion.extensions.ActualResult)

Aggregations

ActualResult (nl.knaw.huygens.concordion.extensions.ActualResult)9 HttpRequest (nl.knaw.huygens.concordion.extensions.HttpRequest)9 WebTarget (javax.ws.rs.client.WebTarget)2 JsonDiffer (nl.knaw.huygens.contractdiff.jsondiff.JsonDiffer)2 JsonDiffer.jsonDiffer (nl.knaw.huygens.contractdiff.jsondiff.JsonDiffer.jsonDiffer)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 XmlEscapers.xmlContentEscaper (com.google.common.xml.XmlEscapers.xmlContentEscaper)1 DropwizardAppRule (io.dropwizard.testing.junit.DropwizardAppRule)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ClientBuilder (javax.ws.rs.client.ClientBuilder)1 Entity (javax.ws.rs.client.Entity)1 Invocation (javax.ws.rs.client.Invocation)1 Response (javax.ws.rs.core.Response)1 ExpectedResult (nl.knaw.huygens.concordion.extensions.ExpectedResult)1 HttpCommandExtension (nl.knaw.huygens.concordion.extensions.HttpCommandExtension)1 ReplaceEmbeddedStylesheetExtension (nl.knaw.huygens.concordion.extensions.ReplaceEmbeddedStylesheetExtension)1