blob: a72a59c97327fd3faf85e10a74bf15c652530bf0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.handler;
import com.yahoo.jdisc.Request;
import com.yahoo.jdisc.Response;
import com.yahoo.jdisc.application.ContainerBuilder;
import com.yahoo.jdisc.test.TestDriver;
import org.junit.Test;
import java.net.URI;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
*/
public class CallableRequestDispatchTestCase {
@Test
public void requireThatDispatchIsCalled() throws Exception {
final TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ContainerBuilder builder = driver.newContainerBuilder();
Response response = new Response(Response.Status.OK);
builder.serverBindings().bind("http://host/path", new MyRequestHandler(response));
driver.activateContainer(builder);
assertSame(response, new CallableRequestDispatch() {
@Override
protected Request newRequest() {
return new Request(driver, URI.create("http://host/path"));
}
}.call());
assertTrue(driver.close());
}
private static class MyRequestHandler extends AbstractRequestHandler {
final Response response;
MyRequestHandler(Response response) {
this.response = response;
}
@Override
public ContentChannel handleRequest(Request request, ResponseHandler handler) {
ResponseDispatch.newInstance(response).dispatch(handler);
return null;
}
}
}
|