Search in sources :

Example 26 with Request

use of com.spotify.apollo.Request in project apollo by spotify.

the class HttpClientTest method testSendWeirdStatus.

@Test
public void testSendWeirdStatus() throws Exception {
    mockServerClient.when(request().withMethod("GET").withPath("/foo.php")).respond(response().withStatusCode(299));
    String uri = format("http://localhost:%d/foo.php", mockServerRule.getHttpPort());
    Request request = Request.forUri(uri, "GET");
    final Response<ByteString> response = HttpClient.createUnconfigured().send(request, empty()).toCompletableFuture().get();
    assertThat(response.status(), withCode(299));
    assertThat(response.payload(), is(empty()));
}
Also used : ByteString(okio.ByteString) Request(com.spotify.apollo.Request) ByteString(okio.ByteString) Test(org.junit.Test)

Example 27 with Request

use of com.spotify.apollo.Request in project apollo by spotify.

the class HttpClientTest method testTimeoutFail.

@Test
public void testTimeoutFail() throws Exception {
    mockServerClient.when(request().withMethod("GET").withPath("/foo.php")).callback(callback().withCallbackClass(SleepCallback.class.getCanonicalName()));
    String uri = format("http://localhost:%d/foo.php", mockServerRule.getHttpPort());
    Request request = Request.forUri(uri, "GET").withTtl(Duration.ofMillis(200));
    thrown.expect(hasCause(instanceOf(SocketTimeoutException.class)));
    HttpClient.createUnconfigured().send(request, empty()).toCompletableFuture().get();
}
Also used : Request(com.spotify.apollo.Request) ByteString(okio.ByteString) Test(org.junit.Test)

Example 28 with Request

use of com.spotify.apollo.Request in project apollo by spotify.

the class RuleRouterTest method shouldReturnEmptyCollectionOnNonRoute.

@Test
public void shouldReturnEmptyCollectionOnNonRoute() throws Exception {
    Rule<Integer> rule = Rule.fromUri("/foo/bar", "GET", TARGET);
    final RuleRouter<Integer> router = RuleRouter.of(ImmutableList.of(rule));
    final Request message = Request.forUri("/foo/notbar", "GET");
    final Collection<String> methodsForValidRules = router.getMethodsForValidRules(message);
    assertTrue(methodsForValidRules.isEmpty());
}
Also used : Request(com.spotify.apollo.Request) Test(org.junit.Test)

Example 29 with Request

use of com.spotify.apollo.Request in project apollo by spotify.

the class RuleRouterTest method shouldReturnMethodsOnValidRoute.

@Test
public void shouldReturnMethodsOnValidRoute() throws Exception {
    Rule<Integer> rule = Rule.fromUri("/foo/bar", "GET", TARGET);
    final RuleRouter<Integer> router = RuleRouter.of(ImmutableList.of(rule));
    final Request message = Request.forUri("/foo/bar", "POST");
    final Collection<String> methodsForValidRules = router.getMethodsForValidRules(message);
    assertThat(methodsForValidRules, hasItem("GET"));
}
Also used : Request(com.spotify.apollo.Request) Test(org.junit.Test)

Example 30 with Request

use of com.spotify.apollo.Request in project apollo by spotify.

the class RuleRouterTest method shouldThrowInvalidUriExceptionForBadParameterEncoding.

@Test
public void shouldThrowInvalidUriExceptionForBadParameterEncoding() throws Exception {
    Rule<Integer> rule = Rule.fromUri("/bar/<baz>", "GET", TARGET);
    final RuleRouter<Integer> router = RuleRouter.of(ImmutableList.of(rule));
    final Request message = Request.forUri("/bar/c%F6", "GET");
    thrown.expect(InvalidUriException.class);
    router.match(message);
}
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