Search in sources :

Example 11 with Request

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);
    }
}
Also used : Request(com.spotify.apollo.Request)

Example 12 with Request

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());
}
Also used : Request(com.spotify.apollo.Request) Test(org.junit.Test)

Example 13 with Request

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"));
}
Also used : Request(com.spotify.apollo.Request) ByteString(okio.ByteString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 14 with Request

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("."))));
}
Also used : Request(com.spotify.apollo.Request) Test(org.junit.Test)

Example 15 with Request

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));
}
Also used : Request(com.spotify.apollo.Request) Test(org.junit.Test)

Aggregations

Request (com.spotify.apollo.Request)33 Test (org.junit.Test)21 ByteString (okio.ByteString)14 Client (com.spotify.apollo.Client)3 Response (com.spotify.apollo.Response)3 IOException (java.io.IOException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 RequestContext (com.spotify.apollo.RequestContext)2 Album (com.spotify.apollo.example.data.Album)2 Artist (com.spotify.apollo.example.data.Artist)2 AsyncHandler (com.spotify.apollo.route.AsyncHandler)2 JsonSerializerMiddlewares (com.spotify.apollo.route.JsonSerializerMiddlewares)2 Route (com.spotify.apollo.route.Route)2 ArrayList (java.util.ArrayList)2 CompletionStage (java.util.concurrent.CompletionStage)2 Stream (java.util.stream.Stream)2 Before (org.junit.Before)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1