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);
}
}
}
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));
}
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()));
}
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"));
}
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));
}
Aggregations