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);
}
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"));
}
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());
}
}
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();
}
}
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();
}
Aggregations