use of com.spotify.apollo.Request in project apollo by spotify.
the class RuleRouterTest method route.
/**
* Build a router with a single rule and route a message with it.
*/
private static <T> Optional<RuleMatch<T>> route(final Rule<T> rule, final String method, final String uri) {
final RuleRouter<T> router = RuleRouter.of(ImmutableList.of(rule));
final Request message = Request.forUri(uri, method);
try {
return router.match(message);
} catch (InvalidUriException e) {
throw Throwables.propagate(e);
}
}
use of com.spotify.apollo.Request in project apollo by spotify.
the class ServiceSettingClientTest method decoratorShouldNotOverrideService.
@Test
public void decoratorShouldNotOverrideService() throws Exception {
Request outgoing = Request.forUri("http://downstream").withService("manual");
client.send(outgoing, Optional.empty());
Request sent = sentRequest.getValue();
assertEquals("manual", sent.service().get());
}
use of com.spotify.apollo.Request in project apollo by spotify.
the class StubClientTest method shouldRespectCustomRequestMatcher.
@Test
public void shouldRespectCustomRequestMatcher() throws Exception {
final String mockedUri = "http://ping";
final String effectiveUri = "http://ping?key=value";
Matcher<Request> requestMatcher = uriStartsWith(mockedUri);
stubClient.respond(Responses.constant(HELLO_WORLD)).to(requestMatcher);
final String reply = getString(effectiveUri).toCompletableFuture().get();
assertThat(reply, is("Hello World"));
}
use of com.spotify.apollo.Request in project apollo by spotify.
the class RequestMatchersTest method shouldMatchServiceMatcher.
@Test
public void shouldMatchServiceMatcher() throws Exception {
final Request request = Request.forUri("http://irrelevant");
assertThat(request, RequestMatchers.service(nullValue(String.class)));
assertThat(request.withService("my-service"), RequestMatchers.service(startsWith("my")));
assertThat(request.withService("not-my-service"), not(RequestMatchers.service(endsWith("."))));
}
use of com.spotify.apollo.Request in project apollo by spotify.
the class RequestMatchersTest method shouldMatchService.
@Test
public void shouldMatchService() throws Exception {
final Matcher<Request> serviceMatcher = RequestMatchers.service("my-service");
final Request request = Request.forUri("http://irrelevant");
assertThat("No service", request, not(serviceMatcher));
assertThat("Service matches", request.withService("my-service"), serviceMatcher);
assertThat("Service mismatches", request.withService("not-my-service"), not(serviceMatcher));
}
Aggregations