aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/test/java/com/yahoo/jdisc/handler/RequestDeniedTestCase.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /jdisc_core/src/test/java/com/yahoo/jdisc/handler/RequestDeniedTestCase.java
Publish
Diffstat (limited to 'jdisc_core/src/test/java/com/yahoo/jdisc/handler/RequestDeniedTestCase.java')
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/handler/RequestDeniedTestCase.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/RequestDeniedTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/RequestDeniedTestCase.java
new file mode 100644
index 00000000000..3cfe794dfed
--- /dev/null
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/RequestDeniedTestCase.java
@@ -0,0 +1,70 @@
+// Copyright 2016 Yahoo Inc. 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.NoopSharedResource;
+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.fail;
+import static org.junit.Assert.assertSame;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class RequestDeniedTestCase {
+
+ @Test
+ public void requireThatAccessorsWork() {
+ TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
+ driver.activateContainer(driver.newContainerBuilder());
+ Request request = new Request(driver, URI.create("http://host/path"));
+ RequestDeniedException e = new RequestDeniedException(request);
+ assertSame(request, e.request());
+ request.release();
+ driver.close();
+ }
+
+ @Test
+ public void requireThatRequestDeniedIsThrown() {
+ TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
+ ContainerBuilder builder = driver.newContainerBuilder();
+ RequestHandler requestHandler = new MyRequestHandler();
+ builder.serverBindings().bind("http://host/path", requestHandler);
+ driver.activateContainer(builder);
+ Request request = new Request(driver, URI.create("http://host/path"));
+ try {
+ request.connect(new MyResponseHandler());
+ fail();
+ } catch (RequestDeniedException e) {
+ assertSame(request, e.request());
+ }
+ request.release();
+ driver.close();
+ }
+
+ private static class MyRequestHandler extends NoopSharedResource implements RequestHandler {
+
+ @Override
+ public ContentChannel handleRequest(Request request, ResponseHandler handler) {
+ throw new RequestDeniedException(request);
+ }
+
+ @Override
+ public void handleTimeout(Request request, ResponseHandler handler) {
+
+ }
+ }
+
+ private static class MyResponseHandler implements ResponseHandler {
+
+ @Override
+ public ContentChannel handleResponse(Response response) {
+ return null;
+ }
+ }
+}