Author: ron.sigal(a)jboss.com
Date: 2010-10-05 12:24:55 -0400 (Tue, 05 Oct 2010)
New Revision: 6119
Added:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/spi/
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/spi/SpiUtilsTestCase.java
Log:
JBREM-1228: New unit test.
Added:
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/spi/SpiUtilsTestCase.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/spi/SpiUtilsTestCase.java
(rev 0)
+++
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/spi/SpiUtilsTestCase.java 2010-10-05
16:24:55 UTC (rev 6119)
@@ -0,0 +1,233 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.jboss.remoting3.test.spi;
+
+import static org.testng.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.concurrent.RejectedExecutionException;
+
+import org.jboss.remoting3.ClientContext;
+import org.jboss.remoting3.CloseHandler;
+import org.jboss.remoting3.RequestCancelHandler;
+import org.jboss.remoting3.RequestContext;
+import org.jboss.remoting3.spi.LocalReplyHandler;
+import org.jboss.remoting3.spi.RemoteReplyHandler;
+import org.jboss.remoting3.spi.SpiUtils;
+import org.jboss.remoting3.test.RemotingTestBase;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jun 7, 2010
+ */
+@Test(suiteName = "SpiUtils")
+public class SpiUtilsTestCase extends RemotingTestBase {
+
+ @BeforeMethod
+ public void setUp() {
+ }
+
+ @AfterMethod
+ public void tearDown() throws IOException {
+ }
+
+ @Test
+ public void testSafeHandleExceptionRemote() throws Exception {
+ enter();
+ try {
+ TestRemoteReplyHandler replyHandler = new TestRemoteReplyHandler();
+ SpiUtils.safeHandleException(replyHandler, new IOException());
+ assertTrue(replyHandler.handledException);
+ } finally {
+ exit();
+ }
+ }
+
+ @Test
+ public void testSafeHandleExceptionLocal() throws Exception {
+ enter();
+ try {
+ TestLocalReplyHandler replyHandler = new TestLocalReplyHandler();
+ SpiUtils.safeHandleException(replyHandler, null);
+ assertTrue(replyHandler.handledException);
+ } finally {
+ exit();
+ }
+ }
+
+ @Test
+ public void testSafeHandleReplyRemote() throws Exception {
+ enter();
+ try {
+ TestRemoteReplyHandler replyHandler = new TestRemoteReplyHandler();
+ SpiUtils.safeHandleReply(replyHandler, new IOException());
+ assertTrue(replyHandler.handledReply);
+ } finally {
+ exit();
+ }
+ }
+
+ @Test
+ public void testSafeHandleReplyLocal() throws Exception {
+ enter();
+ try {
+ TestLocalReplyHandler replyHandler = new TestLocalReplyHandler();
+ SpiUtils.safeHandleReply(replyHandler, null);
+ assertTrue(replyHandler.handledReply);
+ } finally {
+ exit();
+ }
+ }
+
+ @Test
+ public void testSafeHandleCancellationRemote() throws Exception {
+ enter();
+ try {
+ TestRemoteReplyHandler replyHandler = new TestRemoteReplyHandler();
+ SpiUtils.safeHandleCancellation(replyHandler);
+ assertTrue(replyHandler.handledCancellation);
+ } finally {
+ exit();
+ }
+ }
+
+ @Test
+ public void testSafeHandleCancellationLocal() throws Exception {
+ enter();
+ try {
+ TestLocalReplyHandler replyHandler = new TestLocalReplyHandler();
+ SpiUtils.safeHandleCancellation(replyHandler);
+ assertTrue(replyHandler.handledCancellation);
+ } finally {
+ exit();
+ }
+ }
+
+
+ @Test
+ public void testSafeNotifyCancellation() throws Exception {
+ enter();
+ try {
+ TestRequestCancelHandler cancelHandler = new TestRequestCancelHandler();
+ SpiUtils.safeNotifyCancellation(cancelHandler, new TestRequestContext());
+ assertTrue(cancelHandler.handledNotifyCancel);
+ } finally {
+ exit();
+ }
+ }
+
+ @Test
+ public void testSafeHandleClose() throws Exception {
+ enter();
+ try {
+ TestCloseHandler closeHandler = new TestCloseHandler();
+ SpiUtils.safeHandleClose(closeHandler, new Object());
+ assertTrue(closeHandler.handledClose);
+ } finally {
+ exit();
+ }
+ }
+
+ static class TestRemoteReplyHandler implements RemoteReplyHandler {
+ public boolean handledException;
+ public boolean handledReply;
+ public boolean handledCancellation;
+
+ public void handleCancellation() throws IOException {
+ handledCancellation = true;
+ throw new IOException("handleCancellation");
+ }
+ public void handleException(IOException exception) throws IOException {
+ handledException = true;
+ throw new IOException("handleException()");
+ }
+ public void handleReply(Object reply) throws IOException {
+ handledReply = true;
+ throw new IOException("handleReply()");
+ }
+ }
+
+ static class TestLocalReplyHandler implements LocalReplyHandler {
+ public boolean handledException;
+ public boolean handledReply;
+ public boolean handledCancellation;
+
+ public ClassLoader getClassLoader() {
+ return null;
+ }
+ public void handleCancellation() {
+ handledCancellation = true;
+ throw new RuntimeException("handleCancellation");
+ }
+ public void handleException(IOException exception) {
+ handledException = true;
+ throw new RuntimeException("handleException()");
+ }
+ public void handleReply(Object reply) {
+ handledReply = true;
+ throw new RuntimeException("handleReply()");
+ }
+ }
+
+ static class TestRequestCancelHandler implements RequestCancelHandler<Object> {
+ public boolean handledNotifyCancel;
+
+ public void notifyCancel(RequestContext<Object> requestContext) {
+ handledNotifyCancel = true;
+ throw new RuntimeException("notifyCancel");
+ }
+ }
+
+ static class TestRequestContext implements RequestContext<Object> {
+ public void addCancelHandler(RequestCancelHandler<Object> handler) {
+ }
+ public void execute(Runnable command) throws RejectedExecutionException {
+ }
+ public ClientContext getContext() {
+ return null;
+ }
+ public boolean isCancelled() {
+ return false;
+ }
+ public void sendCancelled() throws IOException, IllegalStateException {
+ }
+ public void sendFailure(String msg, Throwable cause) throws IOException,
IllegalStateException {
+ }
+ public void sendReply(Object reply) throws IOException, IllegalStateException {
+ }
+ }
+
+ static class TestCloseHandler implements CloseHandler<Object> {
+ public boolean handledClose;
+
+ public void handleClose(Object closed) {
+ handledClose = true;
+ throw new RuntimeException("handledClose");
+ }
+ }
+}