[portal-commits] JBoss Portal SVN: r5767 - in trunk: common/src/main/org/jboss/portal/common/util core core/src/main/org/jboss/portal/core/model/portal core/src/main/org/jboss/portal/test/core/model/portal

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Tue Dec 5 16:52:53 EST 2006


Author: julien at jboss.com
Date: 2006-12-05 16:52:46 -0500 (Tue, 05 Dec 2006)
New Revision: 5767

Added:
   trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectIdTestCase.java
Modified:
   trunk/common/src/main/org/jboss/portal/common/util/Tools.java
   trunk/core/build.xml
   trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java
Log:
added PortalObjectId tests

Modified: trunk/common/src/main/org/jboss/portal/common/util/Tools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/Tools.java	2006-12-05 18:58:54 UTC (rev 5766)
+++ trunk/common/src/main/org/jboss/portal/common/util/Tools.java	2006-12-05 21:52:46 UTC (rev 5767)
@@ -409,6 +409,11 @@
       return set;
    }
 
+   public static Object[] toArray(Iterator i)
+   {
+      return toList(i).toArray();
+   }
+
    public static List toList(Enumeration e)
    {
       List list = new ArrayList();
@@ -429,7 +434,7 @@
       return set;
    }
 
-   public static Set toSet(final Iterator iterator)
+   public static Set toSet(Iterator iterator)
    {
       HashSet set = new HashSet();
       while (iterator.hasNext())
@@ -439,7 +444,7 @@
       return set;
    }
 
-   public static List toList(final Object[] objects)
+   public static List toList(Object[] objects)
    {
       List list = new ArrayList();
       for (int i = 0; i < objects.length; i++)
@@ -450,7 +455,7 @@
       return list;
    }
 
-   public static List toList(final Iterator iterator)
+   public static List toList(Iterator iterator)
    {
       List list = new ArrayList();
       while (iterator.hasNext())

Modified: trunk/core/build.xml
===================================================================
--- trunk/core/build.xml	2006-12-05 18:58:54 UTC (rev 5766)
+++ trunk/core/build.xml	2006-12-05 21:52:46 UTC (rev 5767)
@@ -556,8 +556,10 @@
       <execute-tests>
          <x-sysproperty>
 
+<!--
             <jvmarg value="-Xdebug"/>
             <jvmarg value="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"/>
+-->
 
             <sysproperty
                key="jboss.aop.path"
@@ -603,6 +605,8 @@
                   name="org.jboss.portal.test.core.deployment.JBossApplicationMetaDataFactoryTestCase"/>
             <test todir="${test.reports}"
                   name="org.jboss.portal.test.core.model.portal.PortalObjectPermissionTestCase"/>
+            <test todir="${test.reports}"
+                  name="org.jboss.portal.test.core.model.portal.PortalObjectIdTestCase"/>
          </x-test>
          <x-classpath>
             <pathelement location="${build.lib}/portal-core-lib.jar"/>

Modified: trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java	2006-12-05 18:58:54 UTC (rev 5766)
+++ trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java	2006-12-05 21:52:46 UTC (rev 5767)
@@ -42,12 +42,20 @@
 
    public PortalObjectId(PortalObjectId that)
    {
+      if (that == null)
+      {
+         throw new IllegalArgumentException();
+      }
       this.names = that.names;
       this.hashCode = that.hashCode;
    }
 
    public PortalObjectId(String[] names)
    {
+      if (names == null)
+      {
+         throw new IllegalArgumentException();
+      }
       this.names = names;
    }
 
@@ -160,6 +168,10 @@
        */
       public final String toString(PortalObjectId id)
       {
+         if (id == null)
+         {
+            throw new IllegalArgumentException("No null id accepted");
+         }
          return toString(id.names);
       }
    }

Added: trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectIdTestCase.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectIdTestCase.java	2006-12-05 18:58:54 UTC (rev 5766)
+++ trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectIdTestCase.java	2006-12-05 21:52:46 UTC (rev 5767)
@@ -0,0 +1,172 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.test.core.model.portal;
+
+import junit.framework.TestCase;
+import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.junit.ExtendedAssert;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortalObjectIdTestCase extends TestCase
+{
+
+   public void testIAE()
+   {
+      try
+      {
+         PortalObjectId.parse("/", null);
+         fail();
+      }
+      catch (IllegalArgumentException e)
+      {
+      }
+      try
+      {
+         PortalObjectId.parse(null, PortalObjectId.CANONICAL_FORMAT);
+         fail();
+      }
+      catch (IllegalArgumentException e)
+      {
+      }
+      try
+      {
+         PortalObjectId.parse(null, PortalObjectId.LEGACY_FORMAT);
+         fail();
+      }
+      catch (IllegalArgumentException e)
+      {
+      }
+      try
+      {
+         new PortalObjectId((String[])null);
+         fail();
+      }
+      catch (IllegalArgumentException e)
+      {
+      }
+      try
+      {
+         new PortalObjectId((PortalObjectId)null);
+         fail();
+      }
+      catch (IllegalArgumentException e)
+      {
+      }
+      try
+      {
+         new PortalObjectId(null, PortalObjectId.CANONICAL_FORMAT);
+         fail();
+      }
+      catch (IllegalArgumentException e)
+      {
+      }
+      try
+      {
+         new PortalObjectId(null, PortalObjectId.LEGACY_FORMAT);
+         fail();
+      }
+      catch (IllegalArgumentException e)
+      {
+      }
+      try
+      {
+         new PortalObjectId(new String[0]).toString(null);
+         fail();
+      }
+      catch (IllegalArgumentException e)
+      {
+      }
+   }
+
+   public void testFormatIAE()
+   {
+      testFormatIAE(PortalObjectId.CANONICAL_FORMAT);
+      testFormatIAE(PortalObjectId.LEGACY_FORMAT);
+   }
+
+   private void testFormatIAE(PortalObjectId.Format format)
+   {
+      try
+      {
+         format.toString((String[])null);
+         fail();
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+      try
+      {
+         format.toString((PortalObjectId)null);
+         fail();
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+      try
+      {
+         format.toString(new String[]{"a",null,"b"});
+         fail();
+      }
+      catch (IllegalArgumentException expected)
+      {
+      }
+   }
+
+   public void testCanonicalFormat()
+   {
+      assertEquals(new PortalObjectId(new String[]{}), PortalObjectId.parse("/", PortalObjectId.CANONICAL_FORMAT));
+      assertEquals(new PortalObjectId(new String[]{"a"}), PortalObjectId.parse("/a", PortalObjectId.CANONICAL_FORMAT));
+      assertEquals(new PortalObjectId(new String[]{"a","b"}), PortalObjectId.parse("/a/b", PortalObjectId.CANONICAL_FORMAT));
+   }
+
+   public void testLegacyFormat()
+   {
+      assertEquals(new PortalObjectId(new String[]{}), PortalObjectId.parse("", PortalObjectId.LEGACY_FORMAT));
+      assertEquals(new PortalObjectId(new String[]{"a"}), PortalObjectId.parse("a", PortalObjectId.LEGACY_FORMAT));
+      assertEquals(new PortalObjectId(new String[]{"a","b"}), PortalObjectId.parse("a.b", PortalObjectId.LEGACY_FORMAT));
+   }
+
+   public void testEquals()
+   {
+      assertTrue(new PortalObjectId(new String[]{}).equals(new PortalObjectId(new String[]{})));
+      assertFalse(new PortalObjectId(new String[]{}).equals(new PortalObjectId(new String[]{"a"})));
+      assertFalse(new PortalObjectId(new String[]{}).equals(new PortalObjectId(new String[]{"a","b"})));
+      assertFalse(new PortalObjectId(new String[]{"a"}).equals(new PortalObjectId(new String[]{})));
+      assertTrue(new PortalObjectId(new String[]{"a"}).equals(new PortalObjectId(new String[]{"a"})));
+      assertFalse(new PortalObjectId(new String[]{"a"}).equals(new PortalObjectId(new String[]{"a","b"})));
+      assertFalse(new PortalObjectId(new String[]{"a","b"}).equals(new PortalObjectId(new String[]{})));
+      assertFalse(new PortalObjectId(new String[]{"a","b"}).equals(new PortalObjectId(new String[]{"a"})));
+      assertTrue(new PortalObjectId(new String[]{"a","b"}).equals(new PortalObjectId(new String[]{"a","b"})));
+   }
+
+   public void testIterator()
+   {
+      ExtendedAssert.assertEquals(new Object[]{}, Tools.toArray(new PortalObjectId(new String[]{}).names()));
+      ExtendedAssert.assertEquals(new Object[]{"a"}, Tools.toArray(new PortalObjectId(new String[]{"a"}).names()));
+      ExtendedAssert.assertEquals(new Object[]{"a","b"}, Tools.toArray(new PortalObjectId(new String[]{"a","b"}).names()));
+   }
+}




More information about the portal-commits mailing list