You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2006/08/12 20:02:17 UTC
svn commit: r431061 - in /jakarta/httpcomponents/httpasync/trunk/src/test:
java/ java/org/ java/org/apache/ java/org/apache/http/
java/org/apache/http/async/ org/
Author: rolandw
Date: Sat Aug 12 11:02:16 2006
New Revision: 431061
URL: http://svn.apache.org/viewvc?rev=431061&view=rev
Log:
first tests for HttpAsync - I love Clover :-)
Added:
jakarta/httpcomponents/httpasync/trunk/src/test/java/
jakarta/httpcomponents/httpasync/trunk/src/test/java/org/
jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/
jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/
jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/
jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockAsyncHttpProcessor.java (with props)
jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpDispatcher.java (with props)
jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpHandle.java (with props)
jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpNotificationHandler.java (with props)
jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpDispatcher.java (with props)
jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpHandle.java (with props)
jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAll.java (with props)
Removed:
jakarta/httpcomponents/httpasync/trunk/src/test/org/
Added: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockAsyncHttpProcessor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockAsyncHttpProcessor.java?rev=431061&view=auto
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockAsyncHttpProcessor.java (added)
+++ jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockAsyncHttpProcessor.java Sat Aug 12 11:02:16 2006
@@ -0,0 +1,92 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ *
+ * Copyright 1999-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.async;
+
+
+import org.apache.http.HttpClientConnection;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolException;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpExecutionContext;
+import org.apache.http.protocol.HttpRequestExecutor;
+
+
+public class MockAsyncHttpProcessor extends AsyncHttpProcessor {
+
+ protected int count_prepare;
+ protected int count_send;
+ protected int count_receive;
+ protected int count_finish;
+
+
+ public MockAsyncHttpProcessor(HttpContext context) {
+ super(context);
+ reset();
+ }
+
+
+ public void reset() {
+ count_prepare = 0;
+ count_send = 0;
+ count_receive = 0;
+ count_finish = 0;
+ }
+
+
+ protected HttpContext asyncPrepareRequest(HttpRequest request,
+ HttpHost target,
+ HttpContext context) {
+ count_prepare++;
+ return null;
+ }
+
+ protected void asyncSendRequest(HttpRequest request,
+ HttpClientConnection connection,
+ HttpContext context) {
+ count_send++;
+ }
+
+ protected
+ HttpResponse doReceiveResponse(HttpRequest request,
+ HttpClientConnection connection,
+ HttpContext context) {
+ count_receive++;
+ return null;
+ }
+
+ protected void doFinishResponse(HttpResponse response,
+ HttpContext context) {
+ count_finish++;
+ }
+
+} // class MockAsyncHttpProcessor
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockAsyncHttpProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockAsyncHttpProcessor.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockAsyncHttpProcessor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpDispatcher.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpDispatcher.java?rev=431061&view=auto
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpDispatcher.java (added)
+++ jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpDispatcher.java Sat Aug 12 11:02:16 2006
@@ -0,0 +1,112 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ *
+ * Copyright 1999-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.async;
+
+
+import java.util.Collection;
+
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpException;
+import org.apache.http.protocol.HttpContext;
+
+
+public class MockHttpDispatcher extends AbstractHttpDispatcher {
+
+ protected int count_postprocess;
+ protected int count_close;
+ protected int count_abort;
+ protected int count_send;
+ protected int count_getcontext;
+ protected int count_abortall;
+
+ protected AbstractHttpHandle mock_handle; // to be returned
+ protected AbstractHttpHandle last_handle;
+ protected HttpResponse last_response;
+
+
+ public MockHttpDispatcher(Collection linked) {
+ super(linked);
+ reset();
+ }
+
+ public void reset() {
+ count_postprocess = 0;
+ count_close = 0;
+ count_abort = 0;
+ count_send = 0;
+ count_getcontext = 0;
+ count_abortall = 0;
+
+ mock_handle = null;
+ last_handle = null;
+ last_response = null;
+ }
+
+
+ protected void postprocessResponse(AbstractHttpHandle handle,
+ HttpResponse response) {
+ count_postprocess++;
+ last_handle = handle;
+ last_response = response;
+ }
+
+
+ protected void closeHandle(AbstractHttpHandle handle, boolean abort) {
+ if (abort)
+ count_abort++;
+ else
+ count_close++;
+ last_handle = handle;
+ }
+
+
+ public HttpHandle sendRequest(HttpRequest req,
+ HttpHost target,
+ HttpContext ctxt) {
+ count_send++;
+ return mock_handle;
+ }
+
+
+ public HttpContext getDefaultContext() {
+ count_getcontext++;
+ return null;
+ }
+
+
+ public void abortAll() {
+ count_abortall++;
+ last_handle = null;
+ mock_handle = null;
+ }
+
+
+} // class MockHttpDispatcher
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpDispatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpDispatcher.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpDispatcher.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpHandle.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpHandle.java?rev=431061&view=auto
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpHandle.java (added)
+++ jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpHandle.java Sat Aug 12 11:02:16 2006
@@ -0,0 +1,85 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ *
+ * Copyright 1999-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.async;
+
+
+import java.io.IOException;
+
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpException;
+import org.apache.http.protocol.HttpContext;
+
+
+public class MockHttpHandle extends AbstractHttpHandle {
+
+ protected HttpResponse mock_response;
+
+ protected int count_response;
+ protected int count_await;
+
+ public MockHttpHandle(AbstractHttpDispatcher dispatcher,
+ HttpRequest request,
+ HttpContext context) {
+ super(dispatcher, request, context);
+ reset();
+ }
+
+
+ public void reset() {
+ mock_response = null;
+ count_response = 0;
+ count_await = 0;
+ }
+
+
+ public HttpResponse getResponse() {
+ count_response++;
+ return mock_response;
+ }
+
+ public HttpResponse awaitResponse() {
+ count_await++;
+ return mock_response;
+ }
+
+ public void close() throws HttpException, IOException {
+ dispatcherCloseHandle(false);
+ }
+
+ public void abort() {
+ try {
+ dispatcherCloseHandle(true);
+ } catch (Exception x) {
+ throw new RuntimeException(x);
+ }
+ }
+
+} // class MockHttpHandle
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpHandle.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpHandle.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpHandle.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpNotificationHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpNotificationHandler.java?rev=431061&view=auto
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpNotificationHandler.java (added)
+++ jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpNotificationHandler.java Sat Aug 12 11:02:16 2006
@@ -0,0 +1,84 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ *
+ * Copyright 1999-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.async;
+
+
+import org.apache.http.HttpResponse;
+import org.apache.http.protocol.HttpContext;
+
+
+public class MockHttpNotificationHandler implements HttpNotificationHandler {
+
+ protected int count_response;
+ protected int count_easy_error;
+ protected int count_fatal_error;
+
+ protected HttpHandle last_handle;
+ protected HttpResponse last_response;
+ protected Throwable last_problem;
+
+ protected boolean do_proceed;
+
+
+ public void reset() {
+
+ count_response = 0;
+ count_easy_error = 0;
+ count_fatal_error = 0;
+
+ last_handle = null;
+ last_response = null;
+ last_problem = null;
+ }
+
+
+ public void notifyResponse(HttpHandle handle, HttpResponse nqrsp) {
+
+ count_response++;
+
+ last_handle = handle;
+ last_response = nqrsp;
+ }
+
+
+ public boolean notifyProblem(HttpHandle handle, Throwable problem,
+ boolean nonfatal) {
+
+ if (nonfatal)
+ count_easy_error++;
+ else
+ count_fatal_error++;
+
+ last_handle = handle;
+ last_problem = problem;
+
+ return do_proceed;
+ }
+
+} // class MockHttpNotificationHandler
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpNotificationHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpNotificationHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/MockHttpNotificationHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpDispatcher.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpDispatcher.java?rev=431061&view=auto
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpDispatcher.java (added)
+++ jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpDispatcher.java Sat Aug 12 11:02:16 2006
@@ -0,0 +1,96 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ *
+ * Copyright 1999-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.async;
+
+
+import java.util.List;
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+
+public class TestAbstractHttpDispatcher extends TestCase {
+
+ // public default constructor
+
+
+ public void testCreateNull() throws Exception {
+ AbstractHttpDispatcher ahd = new MockHttpDispatcher(null);
+ assertNotNull("no collection of handles", ahd.linked_handles);
+ }
+
+
+ public void testCreateList() throws Exception {
+ List l = new ArrayList();
+ AbstractHttpDispatcher ahd = new MockHttpDispatcher(l);
+ assertNotNull("no collection of handles", ahd.linked_handles);
+ assertTrue("wrong collection of handles", ahd.linked_handles == l);
+ }
+
+
+ public void testPepareRequest() throws Exception {
+ MockAsyncHttpProcessor mahp = new MockAsyncHttpProcessor(null);
+ AbstractHttpDispatcher.prepareRequest(mahp, null, null, null);
+ assertEquals("prepare not invoked", 1, mahp.count_prepare);
+ assertEquals("send invoked", 0, mahp.count_send);
+ assertEquals("receive invoked", 0, mahp.count_receive);
+ assertEquals("finish invoked", 0, mahp.count_finish);
+ }
+
+
+ public void testTransmitRequestTo() throws Exception {
+ MockAsyncHttpProcessor mahp = new MockAsyncHttpProcessor(null);
+ AbstractHttpDispatcher.transmitRequestTo(mahp, null, null, null);
+ assertEquals("prepare invoked", 0, mahp.count_prepare);
+ assertEquals("send not invoked", 1, mahp.count_send);
+ assertEquals("receive invoked", 0, mahp.count_receive);
+ assertEquals("finish invoked", 0, mahp.count_finish);
+ }
+
+
+ public void testObtainResponse() throws Exception {
+ MockAsyncHttpProcessor mahp = new MockAsyncHttpProcessor(null);
+ AbstractHttpDispatcher.obtainResponse(mahp, null, null, null);
+ assertEquals("prepare invoked", 0, mahp.count_prepare);
+ assertEquals("send invoked", 0, mahp.count_send);
+ assertEquals("receive not invoked", 1, mahp.count_receive);
+ assertEquals("finish invoked", 0, mahp.count_finish);
+ }
+
+
+ public void testFinishResponse() throws Exception {
+ MockAsyncHttpProcessor mahp = new MockAsyncHttpProcessor(null);
+ AbstractHttpDispatcher.finishResponse(mahp, null, null);
+ assertEquals("prepare invoked", 0, mahp.count_prepare);
+ assertEquals("send invoked", 0, mahp.count_send);
+ assertEquals("receive invoked", 0, mahp.count_receive);
+ assertEquals("finish not invoked", 1, mahp.count_finish);
+ }
+
+} // class TestAbstractHttpDispatcher
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpDispatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpDispatcher.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpDispatcher.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpHandle.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpHandle.java?rev=431061&view=auto
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpHandle.java (added)
+++ jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpHandle.java Sat Aug 12 11:02:16 2006
@@ -0,0 +1,271 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ *
+ * Copyright 1999-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.async;
+
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpException;
+import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpExecutionContext;
+
+
+public class TestAbstractHttpHandle extends TestCase {
+
+ // public default constructor
+
+
+ public void testCreateNull() throws Exception {
+
+ MockHttpDispatcher mhd = new MockHttpDispatcher(null);
+ HttpRequest req =
+ new BasicHttpRequest("GET", "http://jakarta.apache.org/");
+ HttpContext ctx = new HttpExecutionContext(null);
+
+ // for reference, create with all arguments
+ MockHttpHandle mhh = new MockHttpHandle(mhd, req, ctx);
+ mhh.checkDispatcher(mhd);
+ assertEquals("wrong request", req, mhh.getRequest());
+ assertEquals("wrong context", ctx, mhh.getContext());
+
+ // this one is supposed to work
+ mhh = new MockHttpHandle(null, req, ctx);
+ mhh.checkDispatcher(null);
+ assertEquals("wrong request", req, mhh.getRequest());
+ assertEquals("wrong context", ctx, mhh.getContext());
+
+ Throwable axe = null;
+ mhh = null;
+ try {
+ mhh = new MockHttpHandle(mhd, null, ctx);
+ } catch (Throwable t) {
+ axe = t;
+ }
+ assertNotNull("null request not detected", axe);
+ assertTrue("wrong exception class for null request",
+ axe instanceof IllegalArgumentException);
+
+ axe = null;
+ mhh = null;
+ try {
+ mhh = new MockHttpHandle(mhd, req, null);
+ } catch (Throwable t) {
+ axe = t;
+ }
+ assertNotNull("null context not detected", axe);
+ assertTrue("wrong exception class for null context",
+ axe instanceof IllegalArgumentException);
+
+ } // testCreateNull
+
+
+ public void testLinked() throws Exception {
+
+ MockHttpHandle mhh = createHandle(null);
+ assertTrue("initially not linked", mhh.isLinked());
+
+ mhh.setLinked(true);
+ assertTrue("not linked (1)", mhh.isLinked());
+
+ mhh.setLinked(false);
+ assertFalse("still linked (1)", mhh.isLinked());
+
+ mhh.setLinked(true);
+ assertTrue("not linked (2)", mhh.isLinked());
+
+ mhh.setLinked(false);
+ assertFalse("still linked (2)", mhh.isLinked());
+ }
+
+
+ public void testError() throws Exception {
+
+ MockHttpHandle mhh = createHandle(null);
+ assertNull("initially with error", mhh.getError());
+ mhh.checkError();
+
+ Throwable stone = new IOException();
+ mhh.setError(stone);
+ assertSame("wrong error (IOX)", stone, mhh.getError());
+ Throwable axe = null;
+ try {
+ mhh.checkError();
+ } catch (Throwable t) {
+ axe = t;
+ }
+ assertNotNull("error not checked (IOX)", axe);
+ assertSame("wrong error checked (IOX)", stone, axe);
+
+ stone = new HttpException();
+ mhh.setError(stone);
+ assertSame("wrong error (HTTP)", stone, mhh.getError());
+ axe = null;
+ try {
+ mhh.checkError();
+ } catch (Throwable t) {
+ axe = t;
+ }
+ assertNotNull("error not checked (HTTP)", axe);
+ assertSame("wrong error checked (HTTP)", stone, axe);
+
+ stone = new NullPointerException();
+ mhh.setError(stone);
+ assertSame("wrong error (null)", stone, mhh.getError());
+ axe = null;
+ try {
+ mhh.checkError();
+ } catch (Throwable t) {
+ axe = t;
+ }
+ assertNotNull("error not checked (null)", axe);
+ assertTrue("wrong exception class", axe instanceof HttpException);
+ assertSame("wrong error wrapped", stone, axe.getCause());
+
+ } // testError
+
+
+ public void testCheckDispatcher() throws Exception {
+
+ MockHttpDispatcher mhd1 = new MockHttpDispatcher(null);
+ MockHttpDispatcher mhd2 = new MockHttpDispatcher(null);
+
+ MockHttpHandle mhh = createHandle(mhd1);
+
+ mhh.checkDispatcher(mhd1);
+
+ Throwable axe = null;
+ try {
+ mhh.checkDispatcher(mhd2);
+ } catch (Throwable t) {
+ axe = t;
+ }
+ assertNotNull("wrong dispatcher not detected", axe);
+ assertTrue("wrong exception class",
+ axe instanceof IllegalArgumentException);
+
+ axe = null;
+ try {
+ mhh.checkDispatcher(null);
+ } catch (Throwable t) {
+ axe = t;
+ }
+ assertNotNull("null dispatcher not detected", axe);
+ assertTrue("wrong exception class",
+ axe instanceof IllegalArgumentException);
+
+ } // testCheckDispatcher
+
+
+ public void testNotificationHandler() throws Exception {
+
+ MockHttpHandle mhh = createHandle(null);
+ assertNull("has notification handler",
+ mhh.getNotificationHandler());
+
+ HttpRequest req =
+ new BasicHttpRequest("GET", "http://jakarta.apache.org/");
+
+ HttpContext ctx = new HttpExecutionContext(null);
+ MockHttpNotificationHandler mhnh = new MockHttpNotificationHandler();
+ ctx.setAttribute(HttpNotificationHandler.CTXT_NOTIFICATION_HANDLER,
+ mhnh);
+
+ mhh = new MockHttpHandle(null, req, ctx);
+ HttpNotificationHandler hnh = mhh.getNotificationHandler();
+ assertNotNull("missing notification handler", hnh);
+ assertSame("wrong notification handler", mhnh, hnh);
+
+ // notification handler must not change during handle lifetime
+ ctx.removeAttribute(HttpNotificationHandler.CTXT_NOTIFICATION_HANDLER);
+ hnh = mhh.getNotificationHandler();
+ assertNotNull("vanished notification handler", hnh);
+ assertSame("wrong notification handler", mhnh, hnh);
+
+ } // testNotificationHandler
+
+
+ public void testCloseAbort() throws Exception {
+
+ MockHttpDispatcher mhd = new MockHttpDispatcher(null);
+
+ MockHttpHandle mhh = createHandle(mhd);
+ mhh.close();
+ assertEquals("close didn't close", 1, mhd.count_close);
+ assertEquals("close did abort", 0, mhd.count_abort);
+
+ mhd.reset();
+ mhh = createHandle(mhd);
+ mhh.abort();
+ assertEquals("abort did close", 0, mhd.count_close);
+ assertEquals("abort didn't abort", 1, mhd.count_abort);
+
+ // make sure there are no exceptions without dispatcher
+ MockHttpHandle mhh0 = createHandle(null);
+ mhh0.close();
+ mhh0.abort();
+
+ } // testCloseAbort
+
+
+ public void testPostprocess() throws Exception {
+
+ MockHttpDispatcher mhd = new MockHttpDispatcher(null);
+ MockHttpHandle mhh = createHandle(mhd);
+
+ HttpResponse rsp = new BasicHttpResponse();
+ mhh.dispatcherPostprocess(rsp);
+ assertEquals("not postprocessed", mhd.count_postprocess, 1);
+ assertSame("wrong handle", mhh, mhd.last_handle);
+ assertSame("wrong response", rsp, mhd.last_response);
+
+ // missing dispatcher must not trigger exception
+ mhh = createHandle(null);
+ mhh.dispatcherPostprocess(rsp);
+
+ } // testPostprocess
+
+
+
+ private MockHttpHandle createHandle(AbstractHttpDispatcher dispatcher) {
+
+ HttpRequest req =
+ new BasicHttpRequest("GET", "http://jakarta.apache.org/");
+ HttpContext ctx =
+ new HttpExecutionContext(null);
+
+ return new MockHttpHandle(dispatcher, req, ctx);
+ }
+
+} // class TestAbstractHttpHandle
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpHandle.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpHandle.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAbstractHttpHandle.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAll.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAll.java?rev=431061&view=auto
==============================================================================
--- jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAll.java (added)
+++ jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAll.java Sat Aug 12 11:02:16 2006
@@ -0,0 +1,54 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ *
+ * Copyright 1999-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.async;
+
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+
+public class TestAll extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+
+ suite.addTestSuite(TestAbstractHttpDispatcher.class);
+ suite.addTestSuite(TestAbstractHttpHandle.class);
+
+ return suite;
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestAll.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+}
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAll.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAll.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpasync/trunk/src/test/java/org/apache/http/async/TestAll.java
------------------------------------------------------------------------------
svn:mime-type = text/plain