@Override public WebClient.Builder defaultRequest(Consumer<WebClient.RequestHeadersSpec<?>> defaultRequest) { this.defaultRequest = this.defaultRequest != null ? this.defaultRequest.andThen(defaultRequest) : defaultRequest; return this; }
/** * Add a Consumer for configuring the global Reactor Netty resources on * startup. When this option is used, {@link #setUseGlobalResources} is also * enabled. * @param consumer the consumer to apply * @see #setUseGlobalResources(boolean) */ public void addGlobalResourcesConsumer(Consumer<HttpResources> consumer) { this.useGlobalResources = true; this.globalResourcesConsumer = this.globalResourcesConsumer != null ? this.globalResourcesConsumer.andThen(consumer) : consumer; }
/** * Add a {@link Consumer} for a {@code ResponseCookieBuilder} that will be invoked * for each cookie being built, just before the call to {@code build()}. * @param initializer consumer for a cookie builder * @since 5.1 */ public void addCookieInitializer(Consumer<ResponseCookie.ResponseCookieBuilder> initializer) { this.cookieInitializer = this.cookieInitializer != null ? this.cookieInitializer.andThen(initializer) : initializer; }
/** * Add a {@link Consumer} for a {@code ResponseCookieBuilder} that will be invoked * for each cookie being built, just before the call to {@code build()}. * @param initializer consumer for a cookie builder * @since 5.1 */ public void addCookieInitializer(Consumer<ResponseCookie.ResponseCookieBuilder> initializer) { this.cookieInitializer = this.cookieInitializer != null ? this.cookieInitializer.andThen(initializer) : initializer; }
/** * Add a Consumer for configuring the global Reactor Netty resources on * startup. When this option is used, {@link #setUseGlobalResources} is also * enabled. * @param consumer the consumer to apply * @see #setUseGlobalResources(boolean) */ public void addGlobalResourcesConsumer(Consumer<HttpResources> consumer) { this.useGlobalResources = true; this.globalResourcesConsumer = this.globalResourcesConsumer != null ? this.globalResourcesConsumer.andThen(consumer) : consumer; }
private void configureAuthenticationHandler(Consumer<Map<String, String>> handler) { if (authenticationHandler == null) { authenticationHandler = handler; } else { authenticationHandler = authenticationHandler.andThen(handler); } } }
public TestPublisher<T> replayOnSubscribe(Consumer<TestPublisher<T>> replay) { if (replayOnSubscribe == null) { replayOnSubscribe = replay; } else { replayOnSubscribe = replayOnSubscribe.andThen(replay); } return this; }
@Override public StepVerifier.ContextExpectations<T> assertThat(Consumer<Context> assertingConsumer) { this.contextExpectations = this.contextExpectations.andThen(assertingConsumer); return this; }
@Override public StepVerifier.ContextExpectations<T> matches(Predicate<Context> predicate, String description) { this.contextExpectations = this.contextExpectations.andThen(c -> { if (!predicate.test(c)) { throw errorFormatter.assertionError( String.format("Context %s doesn't match predicate %s", c, description)); } }); return this; } }
@Override public StepVerifier.ContextExpectations<T> matches(Predicate<Context> predicate) { this.contextExpectations = this.contextExpectations.andThen(c -> { if (!predicate.test(c)) { throw errorFormatter.assertionError( String.format("Context %s doesn't match predicate", c)); } }); return this; }
@Override public StepVerifier.ContextExpectations<T> containsAllOf(Map<?, ?> other) { this.contextExpectations = this.contextExpectations.andThen(c -> { boolean all = other.entrySet() .stream() .allMatch(e -> e.getValue().equals(c.getOrDefault(e.getKey(), null))); if (!all) { throw errorFormatter.assertionError(String.format("Expected Context %s to contain all of %s", c, other)); } }); return this; }
@Override public StepVerifier.ContextExpectations<T> containsAllOf(Context other) { this.contextExpectations = this.contextExpectations.andThen(c -> { boolean all = other.stream().allMatch(e -> e.getValue().equals(c.getOrDefault(e.getKey(), null))); if (!all) { throw errorFormatter.assertionError(String.format("Expected Context %s to contain all of %s", c, other)); } }); return this; }
@Override public Optional<State> applyTo(SemanticGraph tree, State source, SemanticGraphEdge outgoingEdge, SemanticGraphEdge subjectOrNull, SemanticGraphEdge objectOrNull) { return Optional.of(new State( outgoingEdge, subjectOrNull == null ? source.subjectOrNull : subjectOrNull, subjectOrNull == null ? (source.distanceFromSubj + 1) : 0, objectOrNull == null ? source.objectOrNull : objectOrNull, source.thunk.andThen(toModify -> { assert Util.isTree(toModify); simpleClause(toModify, outgoingEdge); addSubtree(toModify, outgoingEdge.getDependent(), "nsubjpass", tree, outgoingEdge.getGovernor(), Collections.singleton(outgoingEdge)); // addWord(toModify, outgoingEdge.getDependent(), "auxpass", mockNode(outgoingEdge.getDependent().backingLabel(), "is", "VBZ")); assert Util.isTree(toModify); }), true )); } });
/** * Mostly just an alias, but make sure our featurizer is serializable! */ public interface Featurizer extends Function<Triple<ClauseSplitterSearchProblem.State, ClauseSplitterSearchProblem.Action, ClauseSplitterSearchProblem.State>, Counter<String>>, Serializable { boolean isSimpleSplit(Counter<String> feats); }
@Test public void fieldLevelJsonView() { JacksonViewBean bean = new JacksonViewBean(); bean.setWithView1("with"); bean.setWithView2("with"); bean.setWithoutView("without"); Mono<JacksonViewBean> input = Mono.just(bean); ResolvableType type = ResolvableType.forClass(JacksonViewBean.class); Map<String, Object> hints = singletonMap(JSON_VIEW_HINT, MyJacksonView1.class); testEncode(input, type, step -> step .consumeNextWith(expectString("{\"withView1\":\"with\"}") .andThen(DataBufferUtils::release)) .verifyComplete(), null, hints); }
@Test public void classLevelJsonView() { JacksonViewBean bean = new JacksonViewBean(); bean.setWithView1("with"); bean.setWithView2("with"); bean.setWithoutView("without"); Mono<JacksonViewBean> input = Mono.just(bean); ResolvableType type = ResolvableType.forClass(JacksonViewBean.class); Map<String, Object> hints = singletonMap(JSON_VIEW_HINT, MyJacksonView3.class); testEncode(input, type, step -> step .consumeNextWith(expectString("{\"withoutView\":\"without\"}") .andThen(DataBufferUtils::release)) .verifyComplete(), null, hints); }
@Test // SPR-15727 public void encodeAsStreamWithCustomStreamingType() { MediaType fooMediaType = new MediaType("application", "foo"); MediaType barMediaType = new MediaType("application", "bar"); this.encoder.setStreamingMediaTypes(Arrays.asList(fooMediaType, barMediaType)); Flux<Pojo> input = Flux.just( new Pojo("foo", "bar"), new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar") ); testEncode(input, ResolvableType.forClass(Pojo.class), step -> step .consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}\n") .andThen(DataBufferUtils::release)) .consumeNextWith(expectString("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n") .andThen(DataBufferUtils::release)) .consumeNextWith(expectString("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n") .andThen(DataBufferUtils::release)) .verifyComplete(), barMediaType, null); }
@Test public void encodeWithType() { Flux<ParentClass> input = Flux.just(new Foo(), new Bar()); testEncode(input, ParentClass.class, step -> step .consumeNextWith(expectString("[{\"type\":\"foo\"},{\"type\":\"bar\"}]") .andThen(DataBufferUtils::release)) .verifyComplete()); }
@Test public void encodeNonStream() { Flux<Pojo> input = Flux.just( new Pojo("foo", "bar"), new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar") ); testEncode(input, Pojo.class, step -> step .consumeNextWith(expectString("[" + "{\"foo\":\"foo\",\"bar\":\"bar\"}," + "{\"foo\":\"foofoo\",\"bar\":\"barbar\"}," + "{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}]") .andThen(DataBufferUtils::release)) .verifyComplete()); }
private void assertExistsRewrittenToAggregationAboveJoin(@Language("SQL") String actual, @Language("SQL") String expected, boolean extraAggregation) { Consumer<Plan> singleStreamingAggregationValidator = plan -> assertEquals(countSingleStreamingAggregations(plan), 1); Consumer<Plan> finalAggregationValidator = plan -> assertEquals(countFinalAggregationNodes(plan), extraAggregation ? 1 : 0); assertions.assertQueryAndPlan(actual, expected, anyTree( aggregation( ImmutableMap.of("COUNT", functionCall("count", ImmutableList.of("NON_NULL"))), SINGLE, node(JoinNode.class, anyTree( node(ValuesNode.class)), anyTree( node(ProjectNode.class, anyTree( node(ValuesNode.class))) .withAlias("NON_NULL", expression("true")))))), singleStreamingAggregationValidator.andThen(finalAggregationValidator)); }