Package com.google.mockwebserver

Examples of com.google.mockwebserver.MockWebServer


    }
  }

  @Test(dataProvider = "levelToReadTimeoutOutput")
  public void readTimeoutEmits(final Logger.Level logLevel, List<String> expectedMessages) throws IOException, InterruptedException {
    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBytesPerSecond(1).setBody("foo"));
    server.play();


    try {
      SendsStuff api = Feign.create(SendsStuff.class, "http://localhost:" + server.getUrl("").getPort(),
          new LessReadTimeoutModule(), new DefaultModule(logger, logLevel));

      api.login("netflix", "denominator", "password");

      fail();
    } catch (FeignException e) {

      assertMessagesMatch(expectedMessages);

      assertEquals(new String(server.takeRequest().getBody(), UTF_8),
          "{\"customer_name\": \"netflix\", \"user_name\": \"denominator\", \"password\": \"password\"}");
    } finally {
      server.shutdown();
    }
  }
View Full Code Here


    }
  }

  @Test
  public void iterableQueryParams() throws IOException, InterruptedException {
    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody("foo"));
    server.play();

    try {
      TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());

      api.queryParams("user", Arrays.asList("apple", "pear"));
      assertEquals(server.takeRequest().getRequestLine(), "GET /?1=user&2=apple&2=pear HTTP/1.1");
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

    }
  }

  @Test
  public void postTemplateParamsResolve() throws IOException, InterruptedException {
    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody("foo"));
    server.play();

    try {
      TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());

      api.login("netflix", "denominator", "password");
      assertEquals(new String(server.takeRequest().getBody(), UTF_8),
          "{\"customer_name\": \"netflix\", \"user_name\": \"denominator\", \"password\": \"password\"}");
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

    }
  }

  @Test
  public void responseCoercesToStringBody() throws IOException, InterruptedException {
    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody("foo"));
    server.play();

    try {
      TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
          new TestInterface.Module());

      Response response = api.response();
      assertTrue(response.body().isRepeatable());
      assertEquals(response.body().toString(), "foo");
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

    }
  }

  @Test
  public void postFormParams() throws IOException, InterruptedException {
    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody("foo"));
    server.play();

    try {
      TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());

      api.form("netflix", "denominator", "password");
      assertEquals(new String(server.takeRequest().getBody(), UTF_8),
          "customer_name=netflix,user_name=denominator,password=password");
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

    }
  }

  @Test
  public void postBodyParam() throws IOException, InterruptedException {
    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody("foo"));
    server.play();

    try {
      TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());

      api.body(Arrays.asList("netflix", "denominator", "password"));
      RecordedRequest request = server.takeRequest();
      assertEquals(request.getHeader("Content-Length"), "32");
      assertEquals(new String(request.getBody(), UTF_8), "[netflix, denominator, password]");
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

    }
  }

  @Test
  public void postGZIPEncodedBodyParam() throws IOException, InterruptedException {
    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody("foo"));
    server.play();

    try {
      TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());

      api.gzipBody(Arrays.asList("netflix", "denominator", "password"));
      RecordedRequest request = server.takeRequest();
      assertNull(request.getHeader("Content-Length"));
      byte[] compressedBody = request.getBody();
      String uncompressedBody = CharStreams.toString(CharStreams.newReaderSupplier(
          GZIPStreams.newInputStreamSupplier(ByteStreams.newInputStreamSupplier(compressedBody)), UTF_8));
      assertEquals(uncompressedBody, "[netflix, denominator, password]");
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

    }
  }

  @Test
  public void singleInterceptor() throws IOException, InterruptedException {
    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody("foo"));
    server.play();

    try {
      TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
          new TestInterface.Module(), new ForwardedForInterceptor());

      api.post();
      assertEquals(server.takeRequest().getHeader("X-Forwarded-For"), "origin.host.com");
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

    }
  }

  @Test
  public void multipleInterceptor() throws IOException, InterruptedException {
    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody("foo"));
    server.play();

    try {
      TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
          new TestInterface.Module(), new ForwardedForInterceptor(), new UserAgentInterceptor());

      api.post();
      RecordedRequest request = server.takeRequest();
      assertEquals(request.getHeader("X-Forwarded-For"), "origin.host.com");
      assertEquals(request.getHeader("User-Agent"), "Feign");
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

  }

  @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "zone not found")
  public void canOverrideErrorDecoder() throws IOException, InterruptedException {

    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setResponseCode(404).setBody("foo"));
    server.play();

    try {
      TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
          new IllegalArgumentExceptionOn404());

      api.post();
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

TOP

Related Classes of com.google.mockwebserver.MockWebServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.