use of com.linkedin.restli.server.test.EasyMockResourceFactory in project rest.li by linkedin.
the class TestRestLiServer method setUpServer.
private void setUpServer(Engine engine) {
RestLiConfig config = new RestLiConfig();
config.addResourcePackageNames("com.linkedin.restli.server.twitter");
_resourceFactory = new EasyMockResourceFactory();
RestLiDebugRequestHandler debugRequestHandlerA = new RestLiDebugRequestHandler() {
@Override
public void handleRequest(final RestRequest request, final RequestContext context, final ResourceDebugRequestHandler resourceRequestHandler, final RestLiAttachmentReader attachmentReader, final RequestExecutionCallback<RestResponse> callback) {
handleRequestWithCustomResponse(callback, DEBUG_HANDLER_RESPONSE_A);
}
@Override
public String getHandlerId() {
return "a";
}
};
RestLiDebugRequestHandler debugRequestHandlerB = new RestLiDebugRequestHandler() {
@Override
@SuppressWarnings("unchecked")
public void handleRequest(final RestRequest request, final RequestContext context, final ResourceDebugRequestHandler resourceRequestHandler, final RestLiAttachmentReader attachmentReader, final RequestExecutionCallback<RestResponse> callback) {
resourceRequestHandler.handleRequest(request, context, EasyMock.createMock(RequestExecutionCallback.class));
handleRequestWithCustomResponse(callback, DEBUG_HANDLER_RESPONSE_B);
}
@Override
public String getHandlerId() {
return "b";
}
};
config.addDebugRequestHandlers(debugRequestHandlerA, debugRequestHandlerB);
_server = new RestLiServer(config, _resourceFactory, engine);
}
use of com.linkedin.restli.server.test.EasyMockResourceFactory in project rest.li by linkedin.
the class TestRestLiServer method testRequestHandlers.
@Test(dataProvider = "requestHandlersData")
public void testRequestHandlers(URI uri, String expectedResponse) {
RestLiConfig config = new RestLiConfig();
config.addResourcePackageNames("com.linkedin.restli.server.twitter");
config.setDocumentationRequestHandler(new DefaultDocumentationRequestHandler() {
@Override
public void initialize(RestLiConfig config, Map<String, ResourceModel> rootResources) {
/* no-op */
}
@Override
public void handleRequest(RestRequest req, RequestContext ctx, Callback<RestResponse> cb) {
cb.onSuccess(new RestResponseBuilder().setEntity(toByteString(DOCUMENTATION_RESPONSE)).build());
}
});
config.addCustomRequestHandlers(new CustomRequestHandler());
config.addDebugRequestHandlers(new DebugRequestHandler("a", DEBUG_HANDLER_RESPONSE_A), new DebugRequestHandler("b", DEBUG_HANDLER_RESPONSE_B));
RestLiServer server = new RestLiServer(config, new EasyMockResourceFactory(), createMock(Engine.class));
RestRequest restReq = new RestRequestBuilder(uri).build();
server.handleRequest(restReq, createMock(RequestContext.class), new RestResponseAssertionCallback(expectedResponse));
StreamRequest streamReq = new StreamRequestBuilder(uri).build(EntityStreams.emptyStream());
server.handleRequest(streamReq, createMock(RequestContext.class), new StreamResponseAssertionCallback(expectedResponse));
}
use of com.linkedin.restli.server.test.EasyMockResourceFactory in project rest.li by linkedin.
the class TestRestLiServer method setUp.
@BeforeTest
protected void setUp() {
// silence null engine warning and get EasyMock failure if engine is used
Engine fakeEngine = EasyMock.createMock(Engine.class);
_mockFilter = EasyMock.createMock(Filter.class);
_resourceFactory = new EasyMockResourceFactory();
setUpServer(fakeEngine);
setupServerWithFilters(fakeEngine);
setupServerWithCustomErrorResponseConfig(fakeEngine);
setUpServerWithNoExceptionStackTrace(fakeEngine);
replay(fakeEngine);
}
use of com.linkedin.restli.server.test.EasyMockResourceFactory in project rest.li by linkedin.
the class TestRestLiServer method testResourceDefinitionListeners.
@Test
public void testResourceDefinitionListeners() throws Exception {
int[] counts = new int[2];
RestLiConfig config = new RestLiConfig();
config.addResourcePackageNames("com.linkedin.restli.server.twitter");
config.addResourceDefinitionListener(new ResourceDefinitionListener() {
@Override
public void onInitialized(Map<String, ResourceDefinition> definitions) {
int resourceCount = 0;
for (ResourceDefinition definition : definitions.values()) {
resourceCount = resourceCount + 1 + countSubResources(definition);
}
counts[0] = definitions.size();
counts[1] = resourceCount;
}
});
new RestLiServer(config, new EasyMockResourceFactory(), EasyMock.createMock(Engine.class));
assertEquals(counts[0], 18);
assertEquals(counts[1], 25);
}
Aggregations