Search in sources :

Example 6 with MockResponse

use of com.squareup.okhttp.mockwebserver.MockResponse in project hadoop by apache.

the class TestACLFeatures method testCheckAccess.

@Test(expected = AccessControlException.class)
public void testCheckAccess() throws URISyntaxException, IOException {
    getMockServer().enqueue(new MockResponse().setResponseCode(200));
    getMockAdlFileSystem().access(new Path("/test1/test2"), FsAction.ALL);
    getMockServer().enqueue(new MockResponse().setResponseCode(200));
    getMockAdlFileSystem().access(new Path("/test1/test2"), FsAction.EXECUTE);
    getMockServer().enqueue(new MockResponse().setResponseCode(200));
    getMockAdlFileSystem().access(new Path("/test1/test2"), FsAction.READ);
    getMockServer().enqueue(new MockResponse().setResponseCode(200));
    getMockAdlFileSystem().access(new Path("/test1/test2"), FsAction.READ_EXECUTE);
    getMockServer().enqueue(new MockResponse().setResponseCode(200));
    getMockAdlFileSystem().access(new Path("/test1/test2"), FsAction.READ_WRITE);
    getMockServer().enqueue(new MockResponse().setResponseCode(200));
    getMockAdlFileSystem().access(new Path("/test1/test2"), FsAction.NONE);
    getMockServer().enqueue(new MockResponse().setResponseCode(200));
    getMockAdlFileSystem().access(new Path("/test1/test2"), FsAction.WRITE);
    getMockServer().enqueue(new MockResponse().setResponseCode(200));
    getMockAdlFileSystem().access(new Path("/test1/test2"), FsAction.WRITE_EXECUTE);
    getMockServer().enqueue(new MockResponse().setResponseCode(403).setBody(TestADLResponseData.getAccessControlException()));
    getMockAdlFileSystem().access(new Path("/test1/test2"), FsAction.WRITE_EXECUTE);
}
Also used : Path(org.apache.hadoop.fs.Path) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) Test(org.junit.Test)

Example 7 with MockResponse

use of com.squareup.okhttp.mockwebserver.MockResponse in project hadoop by apache.

the class TestACLFeatures method testRemoveAcl.

@Test(expected = AccessControlException.class)
public void testRemoveAcl() throws URISyntaxException, IOException {
    getMockServer().enqueue(new MockResponse().setResponseCode(200));
    getMockAdlFileSystem().removeAcl(new Path("/test1/test2"));
    getMockServer().enqueue(new MockResponse().setResponseCode(403).setBody(TestADLResponseData.getAccessControlException()));
    getMockAdlFileSystem().removeAcl(new Path("/test1/test2"));
}
Also used : Path(org.apache.hadoop.fs.Path) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) Test(org.junit.Test)

Example 8 with MockResponse

use of com.squareup.okhttp.mockwebserver.MockResponse in project mbed-cloud-sdk-java by ARMmbed.

the class TestApiClientWrapper method testClient.

/**
 * Tests that the HTTP client wrapper works as expected by spawning a mock server and checking received requests.
 */
@Test
public void testClient() {
    try {
        MockWebServer server = new MockWebServer();
        server.enqueue(new MockResponse().setBody("hello, world!"));
        server.start();
        HttpUrl baseUrl = server.url("");
        ConnectionOptions opt = new ConnectionOptions("apikey");
        opt.setHost(baseUrl.toString());
        ApiClientWrapper clientWrapper = new ApiClientWrapper(opt);
        TestApiService testService = clientWrapper.createService(TestApiService.class);
        assertTrue(testService.getEndpointValue().execute().isSuccessful());
        RecordedRequest request = server.takeRequest();
        assertEquals("/" + AN_ENDPOINT_PATH, request.getPath());
        assertNotNull(request.getHeader("Authorization"));
        assertTrue(request.getHeader("Authorization").contains("Bearer"));
        assertNotNull(request.getHeader("User-Agent"));
        assertTrue(request.getHeader("User-Agent").contains(ApiClientWrapper.UserAgent.MBED_CLOUD_SDK_IDENTIFIER));
        server.shutdown();
    } catch (IOException | InterruptedException e) {
        fail(e.getMessage());
    }
}
Also used : RecordedRequest(com.squareup.okhttp.mockwebserver.RecordedRequest) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) IOException(java.io.IOException) HttpUrl(com.squareup.okhttp.HttpUrl) Test(org.junit.Test)

Example 9 with MockResponse

use of com.squareup.okhttp.mockwebserver.MockResponse in project rest-assured by rest-assured.

the class JsonSchemaValidationITest method json_schema_validator_supports_matching_uri_json_schema_as_string_to_uri.

@Test
public void json_schema_validator_supports_matching_uri_json_schema_as_string_to_uri() throws Exception {
    // Given
    String schema = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("products-schema.json"));
    MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setResponseCode(200).setBody(schema));
    server.play();
    try {
        get("/products").then().assertThat().body(JsonSchemaValidator.matchesJsonSchema(new URI("http://localhost:" + server.getPort())).using(settings().parseUriAndUrlsAsJsonNode(false)));
    } finally {
        server.shutdown();
    }
}
Also used : MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) URI(java.net.URI) Test(org.junit.Test)

Example 10 with MockResponse

use of com.squareup.okhttp.mockwebserver.MockResponse in project stetho by facebook.

the class StethoInterceptorTest method testWithResponseCompression.

@Test
public void testWithResponseCompression() throws IOException {
    ByteArrayOutputStream capturedOutput = hookAlmostRealInterpretResponseStream(mMockEventReporter);
    byte[] uncompressedData = repeat(".", 1024).getBytes();
    byte[] compressedData = compress(uncompressedData);
    MockWebServer server = new MockWebServer();
    server.start();
    server.enqueue(new MockResponse().setBody(new Buffer().write(compressedData)).addHeader("Content-Encoding: gzip"));
    Request request = new Request.Builder().url(server.url("/")).build();
    Response response = mClientWithInterceptor.newCall(request).execute();
    // Verify that the final output and the caller both saw the uncompressed stream.
    assertArrayEquals(uncompressedData, response.body().bytes());
    assertArrayEquals(uncompressedData, capturedOutput.toByteArray());
    // And verify that the StethoInterceptor was able to see both.
    Mockito.verify(mMockEventReporter).dataReceived(anyString(), eq(compressedData.length), eq(uncompressedData.length));
    server.shutdown();
}
Also used : Buffer(okio.Buffer) Response(com.squareup.okhttp.Response) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) Request(com.squareup.okhttp.Request) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

MockResponse (com.squareup.okhttp.mockwebserver.MockResponse)39 Test (org.junit.Test)34 Path (org.apache.hadoop.fs.Path)18 MockWebServer (com.squareup.okhttp.mockwebserver.MockWebServer)10 FileStatus (org.apache.hadoop.fs.FileStatus)6 AclEntry (org.apache.hadoop.fs.permission.AclEntry)5 RecordedRequest (com.squareup.okhttp.mockwebserver.RecordedRequest)4 AbstractMockServerTest (com.stanfy.enroscar.net.test.AbstractMockServerTest)4 ArrayList (java.util.ArrayList)4 Buffer (okio.Buffer)4 HttpUrl (com.squareup.okhttp.HttpUrl)3 URL (java.net.URL)3 URLConnection (java.net.URLConnection)3 Request (com.squareup.okhttp.Request)2 Response (com.squareup.okhttp.Response)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HttpURLConnection (java.net.HttpURLConnection)2 URI (java.net.URI)2