[jboss-remoting-commits] JBoss Remoting SVN: r5875 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Tue Jun 22 18:30:05 EDT 2010


Author: ron.sigal at jboss.com
Date: 2010-06-22 18:30:04 -0400 (Tue, 22 Jun 2010)
New Revision: 5875

Added:
   remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceRegistrationTestCase.java
Log:
JBREM-1228: Added unit test for configuration of services.

Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceRegistrationTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceRegistrationTestCase.java	                        (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceRegistrationTestCase.java	2010-06-22 22:30:04 UTC (rev 5875)
@@ -0,0 +1,177 @@
+/*
+ * 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;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertSame;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+import org.jboss.remoting3.ClientContext;
+import org.jboss.remoting3.ClientListener;
+import org.jboss.remoting3.Endpoint;
+import org.jboss.remoting3.Registration;
+import org.jboss.remoting3.RemoteExecutionException;
+import org.jboss.remoting3.Remoting;
+import org.jboss.remoting3.RemotingOptions;
+import org.jboss.remoting3.RequestContext;
+import org.jboss.remoting3.RequestListener;
+import org.jboss.remoting3.ServiceRegistrationListener;
+import org.jboss.remoting3.Endpoint.ServiceBuilder;
+import org.jboss.xnio.OptionMap;
+import org.jboss.xnio.Options;
+import org.jboss.xnio.OptionMap.Builder;
+import org.jboss.xnio.log.Logger;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Tests the configuration of services registered with an Endpoint.
+ * 
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jun 22, 2010
+ * @param <O>
+ */
+ at Test(suiteName = "ServiceRegistration")
+public class ServiceRegistrationTestCase<O> {
+
+   private static final Logger log = Logger.getLogger(ServiceRegistrationTestCase.class);
+   private static Object lock = new Object();
+
+   static void enter() {
+      final StackTraceElement e = new Throwable().getStackTrace()[1];
+      log.info("Entering: %s#%s", e.getClassName(), e.getMethodName());
+   }
+
+   static void exit() {
+      final StackTraceElement e = new Throwable().getStackTrace()[1];
+      log.info("Exiting: %s#%s", e.getClassName(), e.getMethodName());
+      log.info("-------------------------------------------------------------");
+   }
+
+   @BeforeMethod
+   public void setUp() {
+   }
+
+   @AfterMethod
+   public void tearDown() throws IOException {
+   }
+
+   @Test
+   public void testRegistration() throws Exception {
+      enter();
+      Endpoint endpoint = Remoting.getConfiguredEndpoint();
+      TestServiceRegistrationListener registrationListener = new TestServiceRegistrationListener();
+      endpoint.addServiceRegistrationListener(registrationListener, null);
+      TestClassLoader testClassLoader = new TestClassLoader();
+      ClientListener<RequestType, ReplyType> testClientListener = new TestClientListener();
+      Registration registration = null;
+      
+      try {
+         ServiceBuilder<RequestType, ReplyType> sb = endpoint.serviceBuilder(RequestType.class, ReplyType.class);
+         sb.setClassLoader(testClassLoader);
+         sb.setInstanceName("instance");
+         sb.setServiceType("service");
+         sb.setRequestType(SuperRequestType.class);
+         sb.setReplyType(SubReplyType.class);
+         OptionMap optionMap = buildOptionMap();
+         sb.setOptionMap(optionMap);
+         sb.setClientListener(testClientListener);
+         registration = sb.register();
+         
+         synchronized (lock) {
+            lock.wait();
+         }
+         assertNotNull(registrationListener.info);
+         assertSame(testClassLoader, registrationListener.info.getServiceClassLoader());
+         assertEquals("instance", registrationListener.info.getInstanceName());
+         assertEquals("service", registrationListener.info.getServiceType());
+         assertEquals(SuperRequestType.class, registrationListener.info.getRequestClass());
+         assertEquals(SubReplyType.class, registrationListener.info.getReplyClass());
+         assertSame(optionMap, registrationListener.info.getOptionMap());
+         
+      } finally {
+         if (registration != null) {
+            registration.close();
+         }
+         if (endpoint != null) {
+            endpoint.close();
+         }
+         exit();
+      }
+   }
+   
+   protected OptionMap buildOptionMap() {
+      Builder builder = OptionMap.builder();
+      builder.set(RemotingOptions.METRIC, 1);
+      builder.setSequence(Options.SASL_MECHANISMS, "EXTERNAL", "DIGEST-MD5");
+      HashMap<Object, Object> map = new HashMap<Object, Object>();
+      map.put(RemotingOptions.REMOTELY_VISIBLE, true);
+      map.put(RemotingOptions.REQUIRE_SECURE, false);
+      builder.add(map);
+      return builder.getMap();
+   }
+   
+   static class TestClassLoader extends ClassLoader {
+   }
+   
+   static class TestRequestListener implements RequestListener<RequestType, ReplyType> {
+      public void handleRequest(RequestContext<ReplyType> context, RequestType request) throws RemoteExecutionException {
+      }
+   }
+
+   static class TestClientListener implements ClientListener<RequestType, ReplyType> {
+      public RequestListener<RequestType, ReplyType> handleClientOpen(final ClientContext clientContext, final OptionMap optionMap) {
+         return new TestRequestListener();
+      }
+   }
+   
+   static class SuperRequestType {
+   }
+
+   static class RequestType extends SuperRequestType {
+   }
+   
+   static class ReplyType {
+   }
+   
+   static class SubReplyType extends ReplyType {
+   }
+   
+   static class TestServiceRegistrationListener implements ServiceRegistrationListener {
+      public ServiceInfo info;
+      
+      public void serviceRegistered(Registration listenerHandle, ServiceInfo info) {
+         this.info = info;
+         synchronized (lock) {
+            lock.notify();
+         }
+      }
+      
+   }
+}



More information about the jboss-remoting-commits mailing list