forked from apple/servicetalk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RedirectingClientAndConnectionFilterTest should leverage AbstractHttp… (
apple#867) __Motivation__ `RedirectingClientAndConnectionFilterTest` could leverage the `AbstractHttpRequesterFilterTest` test tooling. Its approach is closely related to the one in `RedirectingClientAndConnectionFilterTest` and can reuse most of the code. __Modifications__ - `RedirectingClientAndConnectionFilterTest` extends `AbstractHttpRequesterFilterTest` - Add `StrategyInfluencerAwareConversionsTest` for static access to package-private factory methods __Result__ Resolves (apple#396): RedirectingClientAndConnectionFilterTest should leverage AbstractHttpRequesterFilterTest
- Loading branch information
Showing
2 changed files
with
167 additions
and
153 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...talk-http-api/src/testFixtures/java/io/servicetalk/http/api/ConditionalFilterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright © 2019 Apple Inc. and the ServiceTalk project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.servicetalk.http.api; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public final class ConditionalFilterFactory | ||
implements StreamingHttpConnectionFilterFactory, StreamingHttpClientFilterFactory { | ||
private final Predicate<StreamingHttpRequest> predicate; | ||
private final FilterFactory predicateFactory; | ||
|
||
public ConditionalFilterFactory(final Predicate<StreamingHttpRequest> predicate, | ||
final FilterFactory predicateFactory) { | ||
this.predicate = predicate; | ||
this.predicateFactory = predicateFactory; | ||
} | ||
|
||
@Override | ||
public StreamingHttpClientFilter create(final FilterableStreamingHttpClient client) { | ||
return new ConditionalHttpClientFilter(predicate, predicateFactory.create(client), client); | ||
} | ||
|
||
@Override | ||
public StreamingHttpConnectionFilter create(final FilterableStreamingHttpConnection connection) { | ||
return new ConditionalHttpConnectionFilter(predicate, predicateFactory.create(connection), connection); | ||
} | ||
|
||
public FilterFactory append(FilterFactory append) { | ||
StreamingHttpClientFilterFactory clientFactory = append((StreamingHttpClientFilterFactory) append); | ||
StreamingHttpConnectionFilterFactory connectionFactory = append((StreamingHttpConnectionFilterFactory) append); | ||
return new FilterFactory() { | ||
@Override | ||
public StreamingHttpClientFilter create(final FilterableStreamingHttpClient client) { | ||
return clientFactory.create(client); | ||
} | ||
|
||
@Override | ||
public StreamingHttpConnectionFilter create(final FilterableStreamingHttpConnection connection) { | ||
return connectionFactory.create(connection); | ||
} | ||
}; | ||
} | ||
|
||
public interface FilterFactory extends StreamingHttpClientFilterFactory, StreamingHttpConnectionFilterFactory { | ||
|
||
static <FF extends StreamingHttpClientFilterFactory & StreamingHttpConnectionFilterFactory> FilterFactory from( | ||
FF original) { | ||
return new FilterFactory() { | ||
@Override | ||
public StreamingHttpClientFilter create(final FilterableStreamingHttpClient client) { | ||
return original.create(client); | ||
} | ||
|
||
@Override | ||
public StreamingHttpConnectionFilter create(final FilterableStreamingHttpConnection connection) { | ||
return original.create(connection); | ||
} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters