[jboss-remoting-commits] JBoss Remoting SVN: r6095 - 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 Sep 7 16:04:56 EDT 2010


Author: ron.sigal at jboss.com
Date: 2010-09-07 16:04:56 -0400 (Tue, 07 Sep 2010)
New Revision: 6095

Added:
   remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceURITestCase.java
Log:
JBREM-1228: New unit test.

Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceURITestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceURITestCase.java	                        (rev 0)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/ServiceURITestCase.java	2010-09-07 20:04:56 UTC (rev 6095)
@@ -0,0 +1,411 @@
+/*
+ * 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.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.net.URI;
+
+import org.jboss.remoting3.ServiceURI;
+import org.jboss.xnio.log.Logger;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright September 5, 2010
+ */
+ at Test(suiteName = "ServiceURI")
+public class ServiceURITestCase extends RemotingRootTestBase {
+
+   private static final Logger log = Logger.getLogger(ServiceURITestCase.class);
+
+   public static int counter;
+
+   @Test
+   public void testServiceURI() throws Exception {
+      enter();
+      try {
+         
+         // Test ServiceURI.isRemotingServiceUri().
+         assertTrue(ServiceURI.isRemotingServiceUri(new URI(ServiceURI.SCHEME + ":scheme-specific-part")));
+         assertFalse(ServiceURI.isRemotingServiceUri(new URI(ServiceURI.SCHEME + ":/scheme-specific-part")));
+         assertFalse(ServiceURI.isRemotingServiceUri(new URI("http:scheme-specific-part")));
+         assertFalse(ServiceURI.isRemotingServiceUri(new URI("noscheme")));
+         
+         // Test ServiceURI.getServiceType().
+         try {
+            ServiceURI.getServiceType(new URI("http:scheme-specific-part"));
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         assertEquals("servicetype", ServiceURI.getServiceType(new URI(ServiceURI.SCHEME + ":servicetype:scheme-specific-part")));
+         assertEquals("servicetype", ServiceURI.getServiceType(new URI(ServiceURI.SCHEME + ":serviceType:scheme-specific-part")));
+         assertEquals("scheme-specific-part", ServiceURI.getServiceType(new URI(ServiceURI.SCHEME + ":scheme-specific-part")));
+         
+         // Test ServiceURI.getInstanceName().
+         try {
+            ServiceURI.getInstanceName(new URI("http:scheme-specific-part"));
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         assertEquals("", ServiceURI.getInstanceName(new URI(ServiceURI.SCHEME + ":scheme-specific-part")));
+         assertEquals("scheme-specific-part", ServiceURI.getInstanceName(new URI(ServiceURI.SCHEME + ":serviceType:scheme-specific-part")));
+         assertEquals("instancename", ServiceURI.getInstanceName(new URI(ServiceURI.SCHEME + ":serviceType:instancename:scheme-specific-part")));        
+         assertEquals("instancename", ServiceURI.getInstanceName(new URI(ServiceURI.SCHEME + ":serviceType:instanceName:scheme-specific-part")));
+   
+         // Test ServiceURI.getEndpointName().
+         try {
+            ServiceURI.getEndpointName(new URI("http:scheme-specific-part"));
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         assertEquals("", ServiceURI.getEndpointName(new URI(ServiceURI.SCHEME + ":scheme-specific-part")));
+         assertEquals("", ServiceURI.getEndpointName(new URI(ServiceURI.SCHEME + ":servicetype:scheme-specific-part")));
+         assertEquals("scheme-specific-part", ServiceURI.getEndpointName(new URI(ServiceURI.SCHEME + ":servicetype:instancename:scheme-specific-part")));        
+         assertEquals("endpointname", ServiceURI.getEndpointName(new URI(ServiceURI.SCHEME + ":servicetype:instancename:endpointname:scheme-specific-part")));
+         assertEquals("endpointname", ServiceURI.getEndpointName(new URI(ServiceURI.SCHEME + ":servicetype:instancename:endpointName:scheme-specific-part")));
+         
+         // Test ServiceURI.create().
+         assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create(null, null, null).toString());
+         assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create(null, null, "").toString());
+         assertEquals(ServiceURI.SCHEME + ":::endpointname", ServiceURI.create(null, null, "endpointname").toString());
+    
+         assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create(null, "", null).toString());
+         assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create(null, "", "").toString()); 
+         assertEquals(ServiceURI.SCHEME + ":::endpointname", ServiceURI.create(null, "", "endpointname").toString()); 
+         
+         assertEquals(ServiceURI.SCHEME + "::instancename:", ServiceURI.create(null, "instancename", null).toString());
+         assertEquals(ServiceURI.SCHEME + "::instancename:", ServiceURI.create(null, "instancename", "").toString()); 
+         assertEquals(ServiceURI.SCHEME + "::instancename:endpointname", ServiceURI.create(null, "instancename", "endpointname").toString()); 
+//
+         assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create("", null, null).toString());
+         assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create("", null, "").toString());
+         assertEquals(ServiceURI.SCHEME + ":::endpointname", ServiceURI.create("", null, "endpointname").toString());
+    
+         assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create("", "", null).toString());
+         assertEquals(ServiceURI.SCHEME + ":::", ServiceURI.create("", "", "").toString()); 
+         assertEquals(ServiceURI.SCHEME + ":::endpointname", ServiceURI.create("", "", "endpointname").toString()); 
+         
+         assertEquals(ServiceURI.SCHEME + "::instancename:", ServiceURI.create("", "instancename", null).toString());
+         assertEquals(ServiceURI.SCHEME + "::instancename:", ServiceURI.create("", "instancename", "").toString()); 
+         assertEquals(ServiceURI.SCHEME + "::instancename:endpointname", ServiceURI.create("", "instancename", "endpointname").toString());          
+//
+         assertEquals(ServiceURI.SCHEME + ":servicetype::", ServiceURI.create("servicetype", null, null).toString());
+         assertEquals(ServiceURI.SCHEME + ":servicetype::", ServiceURI.create("servicetype", null, "").toString());
+         assertEquals(ServiceURI.SCHEME + ":servicetype::endpointname", ServiceURI.create("servicetype", null, "endpointname").toString());
+    
+         assertEquals(ServiceURI.SCHEME + ":servicetype::", ServiceURI.create("servicetype", "", null).toString());
+         assertEquals(ServiceURI.SCHEME + ":servicetype::", ServiceURI.create("servicetype", "", "").toString()); 
+         assertEquals(ServiceURI.SCHEME + ":servicetype::endpointname", ServiceURI.create("servicetype", "", "endpointname").toString()); 
+         
+         assertEquals(ServiceURI.SCHEME + ":servicetype:instancename:", ServiceURI.create("servicetype", "instancename", null).toString());
+         assertEquals(ServiceURI.SCHEME + ":servicetype:instancename:", ServiceURI.create("servicetype", "instancename", "").toString()); 
+         assertEquals(ServiceURI.SCHEME + ":servicetype:instancename:endpointname", ServiceURI.create("servicetype", "instancename", "endpointname").toString()); 
+         
+         // Test ServiceURI.validateServiceType().
+         try {
+            ServiceURI.validateServiceType(null);
+            fail("expected NullPointerException");
+         } catch (NullPointerException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected NullPointerException");
+         }
+         ServiceURI.validateServiceType("_");
+         ServiceURI.validateServiceType("a");
+         ServiceURI.validateServiceType("__");
+         ServiceURI.validateServiceType("_a");
+         ServiceURI.validateServiceType("_0");    
+         ServiceURI.validateServiceType("a_");
+         ServiceURI.validateServiceType("aa");
+         ServiceURI.validateServiceType("a0");
+         ServiceURI.validateServiceType("_a0a");
+         ServiceURI.validateServiceType("_00a");    
+         ServiceURI.validateServiceType("a_0a");
+         ServiceURI.validateServiceType("aa0a");
+         ServiceURI.validateServiceType("a00a");
+         ServiceURI.validateServiceType("a._");     
+         ServiceURI.validateServiceType("a.a");    
+         ServiceURI.validateServiceType("a.__");
+         ServiceURI.validateServiceType("a._a"); 
+         ServiceURI.validateServiceType("a._0"); 
+         ServiceURI.validateServiceType("a.a_");
+         ServiceURI.validateServiceType("a.aa"); 
+         ServiceURI.validateServiceType("a.a0");
+         ServiceURI.validateServiceType("a.a._");
+         ServiceURI.validateServiceType("a.a.a"); 
+         ServiceURI.validateServiceType("a.a.__");
+         ServiceURI.validateServiceType("a.a._a");
+         ServiceURI.validateServiceType("a.a._0");
+         ServiceURI.validateServiceType("a.a.a_");
+         ServiceURI.validateServiceType("a.a.aa");
+         ServiceURI.validateServiceType("a.a.a0");
+         try {
+            ServiceURI.validateServiceType("");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateServiceType("0");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateServiceType("-");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateServiceType("a.");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateServiceType("a.0");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateServiceType("a.a.0");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         
+         // Test ServiceURI.validateInstanceName().        
+         try {
+            ServiceURI.validateInstanceName(null);
+            fail("expected NullPointerException");
+         } catch (NullPointerException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected NullPointerException");
+         }
+         ServiceURI.validateInstanceName("_");
+         ServiceURI.validateInstanceName("a");
+         ServiceURI.validateInstanceName("0");
+         ServiceURI.validateInstanceName("__");
+         ServiceURI.validateInstanceName("_a");
+         ServiceURI.validateInstanceName("_0");    
+         ServiceURI.validateInstanceName("a_");
+         ServiceURI.validateInstanceName("aa");
+         ServiceURI.validateInstanceName("a0");
+         ServiceURI.validateInstanceName("0_");
+         ServiceURI.validateInstanceName("0a");
+         ServiceURI.validateInstanceName("00");
+         ServiceURI.validateInstanceName("_a0a");
+         ServiceURI.validateInstanceName("_00a");    
+         ServiceURI.validateInstanceName("a_0a");
+         ServiceURI.validateInstanceName("aa0a");
+         ServiceURI.validateInstanceName("a00a");
+         ServiceURI.validateInstanceName("0_0a");
+         ServiceURI.validateInstanceName("0a0a");
+         ServiceURI.validateInstanceName("000a");
+         ServiceURI.validateInstanceName("a._");     
+         ServiceURI.validateInstanceName("a.a");   
+         ServiceURI.validateInstanceName("a.0"); 
+         ServiceURI.validateInstanceName("a.__");
+         ServiceURI.validateInstanceName("a._a"); 
+         ServiceURI.validateInstanceName("a._0"); 
+         ServiceURI.validateInstanceName("a.a_");
+         ServiceURI.validateInstanceName("a.aa"); 
+         ServiceURI.validateInstanceName("a.a0");
+         ServiceURI.validateInstanceName("a.0_");
+         ServiceURI.validateInstanceName("a.0a"); 
+         ServiceURI.validateInstanceName("a.00");
+         ServiceURI.validateInstanceName("a.a._");
+         ServiceURI.validateInstanceName("a.a.a"); 
+         ServiceURI.validateInstanceName("a.a.0"); 
+         ServiceURI.validateInstanceName("a.a.__");
+         ServiceURI.validateInstanceName("a.a._a");
+         ServiceURI.validateInstanceName("a.a._0");
+         ServiceURI.validateInstanceName("a.a.a_");
+         ServiceURI.validateInstanceName("a.a.aa");
+         ServiceURI.validateInstanceName("a.a.a0");
+         ServiceURI.validateInstanceName("a.a.0_");
+         ServiceURI.validateInstanceName("a.a.0a");
+         ServiceURI.validateInstanceName("a.a.00");
+         try {
+            ServiceURI.validateInstanceName("");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateInstanceName("-");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateInstanceName("a.");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateInstanceName("a.-");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateInstanceName("a.a.-");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         
+         // Test ServiceURI.validateEndpointName().
+         try {
+            ServiceURI.validateEndpointName(null);
+            fail("expected NullPointerException");
+         } catch (NullPointerException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected NullPointerException");
+         }
+         ServiceURI.validateEndpointName("_");
+         ServiceURI.validateEndpointName("a");
+         ServiceURI.validateEndpointName("__");
+         ServiceURI.validateEndpointName("_a");
+         ServiceURI.validateEndpointName("_0");    
+         ServiceURI.validateEndpointName("a_");
+         ServiceURI.validateEndpointName("aa");
+         ServiceURI.validateEndpointName("a0");
+         ServiceURI.validateEndpointName("_a0a");
+         ServiceURI.validateEndpointName("_00a");    
+         ServiceURI.validateEndpointName("a_0a");
+         ServiceURI.validateEndpointName("aa0a");
+         ServiceURI.validateEndpointName("a00a");
+         ServiceURI.validateEndpointName("a._");     
+         ServiceURI.validateEndpointName("a.a");    
+         ServiceURI.validateEndpointName("a.__");
+         ServiceURI.validateEndpointName("a._a"); 
+         ServiceURI.validateEndpointName("a._0"); 
+         ServiceURI.validateEndpointName("a.a_");
+         ServiceURI.validateEndpointName("a.aa"); 
+         ServiceURI.validateEndpointName("a.a0");
+         ServiceURI.validateEndpointName("a.a._");
+         ServiceURI.validateEndpointName("a.a.a"); 
+         ServiceURI.validateEndpointName("a.a.__");
+         ServiceURI.validateEndpointName("a.a._a");
+         ServiceURI.validateEndpointName("a.a._0");
+         ServiceURI.validateEndpointName("a.a.a_");
+         ServiceURI.validateEndpointName("a.a.aa");
+         ServiceURI.validateEndpointName("a.a.a0");
+         try {
+            ServiceURI.validateEndpointName("");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateEndpointName("0");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateEndpointName("-");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateEndpointName("a.");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateEndpointName("a.0");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         try {
+            ServiceURI.validateEndpointName("a.a.0");
+            fail("expected IllegalArgumentException");
+         } catch (IllegalArgumentException e) {
+            log.info("got expected exception: " + e.getMessage());
+         } catch (Throwable t) {
+            fail("expected IllegalArgumentException");
+         }
+         log.info(getName() + " PASSES");
+      } finally {
+         exit();
+      }
+   }
+}



More information about the jboss-remoting-commits mailing list