Search in sources :

Example 41 with MutableObject

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project sponge by softelnet.

the class AbstractRuleAdapterRuntime method buildEventTree.

/**
 * Continues building the event tree for the incoming event starting at the specified node.
 *
 * @param node event tree node.
 * @param event incoming event.
 */
protected void buildEventTree(TreeNode<NodeValue> node, Event event) {
    // Check if this event is the first event that starts the rule instance.
    boolean isFirstNode = (node == null);
    // Create a new node for the incoming event and add to the event tree. This node may be removed later when the event doesn't match.
    TreeNode<NodeValue> newNode = new TreeNode<>(new NodeValue(event));
    if (isFirstNode) {
        // First event that starts the rule.
        node = newNode;
        // Add the new node to the event tree as root.
        eventTree.setRoot(node);
    } else {
        // Recursively try to continue building the event tree, but only for modes FIRST, LAST and ALL.
        node.getChildren().forEach(child -> {
            // NONE events are processed in shouldAddToEventTreeForNMode(), not here.
            if (adapter.getEventMode(getEventIndex(child)) != EventMode.NONE) {
                buildEventTree(child, event);
            }
        });
        // Return if reached the last level.
        if (node.getLevel() + 1 >= adapter.getEventCount()) {
            return;
        }
        // Add the new node to the event tree.
        node.addChild(newNode);
    }
    // Should this event be added to the event tree in this place.
    boolean rememberEvent = false;
    EventMode eventMode = getEventMode(newNode);
    if (eventMode != null) {
        switch(eventMode) {
            case FIRST:
            case LAST:
            case ALL:
                rememberEvent = shouldAddToEventTreeForFlaModes(newNode, event);
                break;
            case NONE:
                Mutable<TreeNode<NodeValue>> newNodeHolder = new MutableObject<>(newNode);
                rememberEvent = shouldAddToEventTreeForNMode(node, newNodeHolder, event);
                // shouldAddToEventTreeForNMode() may change newNode.
                newNode = newNodeHolder.getValue();
                break;
            default:
                throw new SpongeException("Unsupported value: " + eventMode);
        }
    }
    // Remove the node for the incoming event if the event doesn't match.
    if (!rememberEvent) {
        if (isFirstNode) {
            eventTree.setRoot(null);
        } else {
            node.removeChild(newNode);
        }
    }
}
Also used : EventMode(org.openksavi.sponge.rule.EventMode) SpongeException(org.openksavi.sponge.SpongeException) TreeNode(org.openksavi.sponge.core.util.TreeNode) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 42 with MutableObject

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project rest-assured by rest-assured.

the class FilterITest method httpClientIsAccessibleFromTheRequestSpecification.

@Test
public void httpClientIsAccessibleFromTheRequestSpecification() {
    // Given
    final MutableObject<HttpClient> client = new MutableObject<HttpClient>();
    // When
    given().filter(new Filter() {

        public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
            client.setValue(requestSpec.getHttpClient());
            return new ResponseBuilder().setStatusCode(200).setContentType("application/json").setBody("{ \"message\" : \"hello\"}").build();
        }
    }).expect().body("message", equalTo("hello")).when().get("/something");
    // Then
    assertThat(client.getValue(), instanceOf(DefaultHttpClient.class));
}
Also used : Response(io.restassured.response.Response) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) ErrorLoggingFilter(io.restassured.filter.log.ErrorLoggingFilter) SpookyGreetJsonResponseFilter(io.restassured.itest.java.support.SpookyGreetJsonResponseFilter) FormAuthFilter(io.restassured.internal.filter.FormAuthFilter) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Filter(io.restassured.filter.Filter) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) MutableObject(org.apache.commons.lang3.mutable.MutableObject) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 43 with MutableObject

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project rest-assured by rest-assured.

the class HttpClientConfigITest method http_client_config_allows_specifying_that_the_http_client_instance_is_reused_in_multiple_requests.

@Test
public void http_client_config_allows_specifying_that_the_http_client_instance_is_reused_in_multiple_requests() {
    final MutableObject<HttpClient> client1 = new MutableObject<HttpClient>();
    final MutableObject<HttpClient> client2 = new MutableObject<HttpClient>();
    RestAssured.config = RestAssuredConfig.newConfig().httpClient(HttpClientConfig.httpClientConfig().reuseHttpClientInstance());
    // When
    try {
        given().param("url", "/hello").filter(new Filter() {

            public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
                client1.setValue(requestSpec.getHttpClient());
                return ctx.next(requestSpec, responseSpec);
            }
        }).expect().body("hello", equalTo("Hello Scalatra")).when().get("/redirect");
        given().header("name", "value").filter((requestSpec, responseSpec, ctx) -> {
            client2.setValue(requestSpec.getHttpClient());
            return ctx.next(requestSpec, responseSpec);
        }).when().post("/reflect");
    } finally {
        RestAssured.reset();
    }
    assertThat(client1.getValue(), sameInstance(client2.getValue()));
}
Also used : Response(io.restassured.response.Response) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) Filter(io.restassured.filter.Filter) SystemDefaultHttpClient(org.apache.http.impl.client.SystemDefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) MutableObject(org.apache.commons.lang3.mutable.MutableObject) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 44 with MutableObject

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project rest-assured by rest-assured.

the class AcceptHeaderITest method accept_headers_are_merged_from_request_spec_and_request_when_configured_to.

@Test
public void accept_headers_are_merged_from_request_spec_and_request_when_configured_to() {
    RequestSpecification spec = new RequestSpecBuilder().setAccept("text/jux").build();
    final MutableObject<List<String>> headers = new MutableObject<List<String>>();
    RestAssured.given().config(RestAssuredConfig.config().headerConfig(HeaderConfig.headerConfig().mergeHeadersWithName("Accept"))).accept(ContentType.JSON).spec(spec).body("{ \"message\" : \"hello world\"}").filter(new Filter() {

        public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
            headers.setValue(requestSpec.getHeaders().getValues("Accept"));
            return ctx.next(requestSpec, responseSpec);
        }
    }).when().post("/jsonBodyAcceptHeader").then().body(equalTo("hello world"));
    assertThat(headers.getValue(), contains("application/json, application/javascript, text/javascript, text/json", "text/jux"));
}
Also used : Response(io.restassured.response.Response) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) Filter(io.restassured.filter.Filter) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) RequestSpecification(io.restassured.specification.RequestSpecification) List(java.util.List) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) MutableObject(org.apache.commons.lang3.mutable.MutableObject) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 45 with MutableObject

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.mutable.MutableObject in project rest-assured by rest-assured.

the class ResultHandlerTest method supports_using_result_handlers_using_the_response_dsl.

@Test
public void supports_using_result_handlers_using_the_response_dsl() {
    MutableObject<Boolean> mutableObject = new MutableObject<Boolean>(false);
    RestAssuredMockMvc.given().header(new Header("headerName", "John Doe")).when().get("/header").then().apply(print(), customResultHandler(mutableObject)).statusCode(200).body("headerName", equalTo("John Doe"));
    assertThat(mutableObject.getValue(), is(true));
}
Also used : Header(io.restassured.http.Header) MutableObject(org.apache.commons.lang3.mutable.MutableObject) Test(org.junit.Test)

Aggregations

MutableObject (org.apache.commons.lang3.mutable.MutableObject)111 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)60 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)58 ArrayList (java.util.ArrayList)55 Mutable (org.apache.commons.lang3.mutable.Mutable)55 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)52 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)49 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)28 Pair (org.apache.hyracks.algebricks.common.utils.Pair)27 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)23 List (java.util.List)22 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)21 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)18 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)17 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)14 Test (org.junit.Test)14 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)13 UnnestingFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression)13 NestedTupleSourceOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator)13 HashSet (java.util.HashSet)12