use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestComplexKeysResource method testBatchGetEntityEmpty.
@SuppressWarnings("deprecation")
public void testBatchGetEntityEmpty(BatchGetEntityRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> builder) throws Exception {
final Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> request = builder.build();
final FutureCallback<RestResponse> callback = new FutureCallback<RestResponse>();
getClient().sendRestRequest(request, new RequestContext(), callback);
final RestResponse result = callback.get();
final DataMap responseMap = DataMapUtils.readMap(result);
final DataMap resultsMap = responseMap.getDataMap(BatchKVResponse.RESULTS);
Assert.assertNotNull(resultsMap, "Response does not contain results map");
Assert.assertTrue(resultsMap.isEmpty());
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestDebugRequestHandlers method sendRequestAndVerifyParseqTracevisResponse.
private void sendRequestAndVerifyParseqTracevisResponse(RestRequest request) throws InterruptedException, ExecutionException {
Future<RestResponse> restResponseFuture = getDefaultTransportClient().restRequest(request);
RestResponse restResponse = restResponseFuture.get();
Assert.assertEquals(restResponse.getStatus(), 200);
List<String> contentTypeValues = restResponse.getHeaderValues(RestConstants.HEADER_CONTENT_TYPE);
Assert.assertTrue(contentTypeValues.size() == 1);
Assert.assertEquals(contentTypeValues.get(0), HEADER_VALUE_TEXT_HTML);
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestParseqTraceDebugRequestHandler method testResponseStreamingAttachmentsForbidden.
@Test
public void testResponseStreamingAttachmentsForbidden() {
//This test verifies that the ParseqTraceDebugRequestHandler aborts any potential outgoing response attachments
//set by a resource method.
final URI uri = URI.create("http://host/abc/12/__debug/parseqtrace/raw");
ParseqTraceDebugRequestHandler requestHandler = new ParseqTraceDebugRequestHandler();
RestRequestBuilder requestBuilder = new RestRequestBuilder(uri);
RestRequest request = requestBuilder.build();
RequestContext requestContext = new RequestContext();
final RequestExecutionCallback<RestResponse> callback = new RequestExecutionCallback<RestResponse>() {
@Override
public void onError(Throwable e, RequestExecutionReport executionReport, RestLiAttachmentReader requestAttachmentReader, RestLiResponseAttachments responseAttachments) {
Assert.fail("Request execution failed unexpectedly.");
}
@Override
public void onSuccess(RestResponse result, RequestExecutionReport executionReport, RestLiResponseAttachments responseAttachments) {
}
};
final RestLiTestAttachmentDataSource testAttachmentDataSource = RestLiTestAttachmentDataSource.createWithRandomPayload("1");
final RestLiResponseAttachments responseAttachments = new RestLiResponseAttachments.Builder().appendSingleAttachment(testAttachmentDataSource).build();
requestHandler.handleRequest(request, requestContext, new RestLiDebugRequestHandler.ResourceDebugRequestHandler() {
@Override
public void handleRequest(RestRequest request, RequestContext requestContext, RequestExecutionCallback<RestResponse> callback) {
RestResponse response = EasyMock.createMock(RestResponse.class);
//Provide some attachments that should be aborted.
callback.onSuccess(response, new RequestExecutionReportBuilder().build(), responseAttachments);
}
}, null, callback);
Assert.assertTrue(testAttachmentDataSource.dataSourceAborted());
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestParseqTraceDebugRequestHandler method testStaticContent.
/**
* Tests the static content retrieval from the parseq trace debug request handler. It enumerates through all
* files imported into the JAR containing the parseq trace debug request handler, skips the ones that should
* not be served and verifies the rest can be retrieved. This test makes sure all files we import are actually
* servicable by the parseq trace debug request handler.
* @throws IOException
*/
@Test
public void testStaticContent() throws IOException {
ClassLoader classLoader = ParseqTraceDebugRequestHandler.class.getClassLoader();
//Collect all files under tracevis folder in the jar containing the parseq trace debug request handler.
Enumeration<URL> resources = classLoader.getResources(ParseqTraceDebugRequestHandler.class.getName().replace('.', '/') + ".class");
List<String> files = new ArrayList<String>();
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
URLConnection urlConnection = url.openConnection();
if (urlConnection instanceof JarURLConnection) {
JarURLConnection jarURLConnection = (JarURLConnection) urlConnection;
JarFile jar = jarURLConnection.getJarFile();
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry currentEntry = entries.nextElement();
if (!currentEntry.isDirectory()) {
String entry = currentEntry.getName();
if (entry.startsWith("tracevis/")) {
files.add(entry);
}
}
}
}
}
Assert.assertTrue(files.size() > 0);
// All other files should be retrievable from the parseq trace debug request handler.
for (String file : files) {
final String mimeType = determineMediaType(file);
final URI uri = URI.create("http://host/abc/12/__debug/parseqtrace/" + file.substring(file.indexOf('/') + 1));
executeRequestThroughParseqDebugHandler(uri, new RequestExecutionCallback<RestResponse>() {
@Override
public void onError(Throwable e, RequestExecutionReport executionReport, RestLiAttachmentReader requestAttachmentReader, RestLiResponseAttachments responseAttachments) {
Assert.fail("Static content cannot be retrieved for " + uri.toString());
}
@Override
public void onSuccess(RestResponse result, RequestExecutionReport executionReport, RestLiResponseAttachments responseAttachments) {
Assert.assertEquals(result.getHeader(RestConstants.HEADER_CONTENT_TYPE), mimeType);
}
});
}
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestParseqTraceDebugRequestHandler method executeRequestThroughParseqDebugHandler.
private void executeRequestThroughParseqDebugHandler(URI uri, RequestExecutionCallback<RestResponse> callback) {
ParseqTraceDebugRequestHandler requestHandler = new ParseqTraceDebugRequestHandler();
RestRequestBuilder requestBuilder = new RestRequestBuilder(uri);
RestRequest request = requestBuilder.build();
RequestContext requestContext = new RequestContext();
requestHandler.handleRequest(request, requestContext, new RestLiDebugRequestHandler.ResourceDebugRequestHandler() {
@Override
public void handleRequest(RestRequest request, RequestContext requestContext, RequestExecutionCallback<RestResponse> callback) {
RestResponse response = EasyMock.createMock(RestResponse.class);
RequestExecutionReportBuilder executionReportBuilder = new RequestExecutionReportBuilder();
JsonTraceCodec jsonTraceCodec = new JsonTraceCodec();
Trace t = null;
try {
t = jsonTraceCodec.decode(TEST_TRACE);
executionReportBuilder.setParseqTrace(t);
} catch (IOException exc) {
//test will fail later
}
callback.onSuccess(response, executionReportBuilder.build(), null);
}
}, null, callback);
}
Aggregations