[jboss-cvs] JBossAS SVN: r61683 - in projects/microcontainer/branches/2_0/deployers/src: tests/org/jboss/test/deployers/structure/ear/test and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Mar 25 14:25:28 EDT 2007


Author: scott.stark at jboss.org
Date: 2007-03-25 14:25:28 -0400 (Sun, 25 Mar 2007)
New Revision: 61683

Modified:
   projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/StructureMetaDataImpl.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/structure/ear/test/EARStructureUnitTestCase.java
   projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/structure/main/test/StructureMetaDataUnitTestCase.java
Log:
JBMICROCONT-161, fix the ContextInfo comparator

Modified: projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/StructureMetaDataImpl.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/StructureMetaDataImpl.java	2007-03-25 18:24:28 UTC (rev 61682)
+++ projects/microcontainer/branches/2_0/deployers/src/main/org/jboss/deployers/plugins/structure/StructureMetaDataImpl.java	2007-03-25 18:25:28 UTC (rev 61683)
@@ -41,8 +41,14 @@
 {
    private static final long serialVersionUID = 1;
 
+   /**
+    * The map of vfs relative paths to ContextInfo
+    */
    private HashMap<String, ContextInfo> contextMap =
       new HashMap<String, ContextInfo>();
+   /**
+    * 
+    */
    private TreeSet<ContextInfo> contextSet = new  TreeSet<ContextInfo>(new ContextComparator());
 
    public void addContext(ContextInfo context)
@@ -73,7 +79,9 @@
                context.setParent(parent);
          }
       }
-      contextSet.add(context);
+      // There should not be duplicate contexts
+      if( contextSet.add(context) == false )
+         throw new IllegalStateException("Failed to add: "+context);
    }
 
    public ContextInfo getContext(String vfsPath)
@@ -103,7 +111,10 @@
       return tmp.toString();
    }
 
-   private class ContextComparator implements Comparator<ContextInfo>
+   /**
+    * Compare ContextInfo by depth and then leaf name.
+    */
+   public static class ContextComparator implements Comparator<ContextInfo>
    {
       public int compare(ContextInfo o1, ContextInfo o2)
       {
@@ -115,16 +126,21 @@
          else
          {
             // Sort by depth and then name
-            ContextInfo p1 = o1.getParent();
-            ContextInfo p2 = o2.getParent();
-            if( p1 != p2 )
+            String[] p1 = o1.getVfsPath().split("/");
+            String[] p2 = o2.getVfsPath().split("/");
+            compare = p1.length - p2.length;
+            if( compare == 0 )
             {
-               compare = compare(p1, p2);
+               for(int n = 0; n < p1.length; n ++)
+               {
+                  String p1p = p1[n];
+                  String p2p = p2[n];
+                  compare = p1p.compareTo(p2p);
+                  if( compare != 0 )
+                     break;
+               }
+               
             }
-            else if( p1 != null )
-            {
-               compare = o1.getVfsPath().compareTo(o2.getVfsPath());
-            }
          }
          return compare;
       }

Modified: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/structure/ear/test/EARStructureUnitTestCase.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/structure/ear/test/EARStructureUnitTestCase.java	2007-03-25 18:24:28 UTC (rev 61682)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/structure/ear/test/EARStructureUnitTestCase.java	2007-03-25 18:25:28 UTC (rev 61683)
@@ -229,6 +229,53 @@
    }
 
    /**
+    * Same as testComplexWithAppXml, but the URL for the ear VFS is the ear
+    * itself. This leads to the ear having an "" empty vfs relative path.
+    * @throws Exception
+    */
+   public void testComplexWithAppXmlEmptyRootPath() throws Exception
+   {      
+      DeploymentContext ear = assertValidContext("/structure/ear/complexwithappxml.ear", "");
+      List<VirtualFile> classpath = ear.getClassPath();
+      assertNotNull("classpath", classpath);
+      assertEquals("classpath.size = 1", 1, classpath.size());
+      VirtualFile earFile = ear.getRoot();
+      VirtualFile j0 = earFile.findChild("lib/lib0.jar");
+      // Should be in classpath due to default ear lib logic
+      assertTrue("lib/lib0.jar in classpath", classpath.contains(j0));
+      // Validate that the expected module contexts exist
+      HashSet<String> expected = new HashSet<String>();
+      URL rootURL = ear.getRoot().toURL();
+      expected.add("module-service.xml");
+      expected.add("module-bean1ejb.jar/");
+      expected.add("module-bean2.ejb3/");
+      expected.add("module-client1.jar/");
+      expected.add("module-mbean1.sar/");
+      expected.add("module-mcf1-ds.xml");
+      expected.add("module-mcf1.rar/");
+      expected.add("module-web1.war/");
+      expected.add("subdir/relative.jar/");
+      Set<DeploymentContext> children = ear.getChildren();
+      Set<String> childPaths = super.createDeploymentPathSet(children, rootURL);
+      assertEquals("ear child DeploymentContext paths", expected, childPaths);
+      // lib/lib0.jar should not have a DeploymentContext
+      assertFalse("lib/lib0.jar is not a DeploymentContext", childPaths.contains("lib/lib0.jar"));
+
+      // Validate that the expected module subdeployments are there
+      Map<String, DeploymentContext> pathMap = createDeploymentPathMap(ear);
+      DeploymentContext extensionsAop = pathMap.get("module-mbean1.sar/extensions.aop");
+      assertNotNull("module-mbean1.sar/extensions.aop/", extensionsAop);
+      DeploymentContext submbean1 = pathMap.get("module-mbean1.sar/submbean.sar");
+      assertEquals("submbean.sar", "module-mbean1.sar/submbean.sar", submbean1.getRelativePath());
+      assertEquals("submbean.sar", "submbean.sar", submbean1.getSimpleName());
+      assertNotNull("submbean.sar", submbean1);
+      DeploymentContext submbean2 = pathMap.get("module-mbean1.sar/submbean2-service.xml");
+      assertNotNull("submbean2-service.xml", submbean2);
+      assertEquals("submbean2-service.xml", "module-mbean1.sar/submbean2-service.xml", submbean2.getRelativePath());
+      assertEquals("submbean2-service.xml", "submbean2-service.xml", submbean2.getSimpleName());
+   }
+
+   /**
     * Basic getMetaDataFile/getFile tests.
     * 
     * @throws Exception

Modified: projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/structure/main/test/StructureMetaDataUnitTestCase.java
===================================================================
--- projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/structure/main/test/StructureMetaDataUnitTestCase.java	2007-03-25 18:24:28 UTC (rev 61682)
+++ projects/microcontainer/branches/2_0/deployers/src/tests/org/jboss/test/deployers/structure/main/test/StructureMetaDataUnitTestCase.java	2007-03-25 18:25:28 UTC (rev 61683)
@@ -152,35 +152,57 @@
       assertNotNull("top/root/sub2/sub21", sub21Jar);
       assertSame(sub2, sub21Jar.getParent());
    }
+   /**
+    * JBMICROCONT-161 test for missing websubdir/relative.jar context info.
+    * @throws Exception
+    */
+   public void testStructureMetaDataParentChildRelativeMC161()
+      throws Exception
+   {
+      StructureMetaData metaData = new StructureMetaDataImpl();
+      ContextInfo c0 = getContextInfo("");
+      metaData.addContext(c0);
+      ContextInfo c1 = getContextInfo("wars/notjbosstest-web.war");
+      metaData.addContext(c1);
+      ContextInfo c2 = getContextInfo("cts.jar");
+      metaData.addContext(c2);
+      ContextInfo c3 = getContextInfo("jbosstest-web-ejbs.jar");
+      metaData.addContext(c3);
+      ContextInfo c4 = getContextInfo("jbosstest-web.war");
+      metaData.addContext(c4);
+      ContextInfo c5 = getContextInfo("root-web.war");
+      metaData.addContext(c5);
+      ContextInfo c6 = getContextInfo("jbosstest-web-ejbs.jar/roles.properties");
+      metaData.addContext(c6);
+      ContextInfo c7 = getContextInfo("jbosstest-web-ejbs.jar/users.properties");
+      metaData.addContext(c7);
+      ContextInfo c8 = getContextInfo("websubdir/relative.jar");
 
+      StructureMetaDataImpl.ContextComparator compare = new StructureMetaDataImpl.ContextComparator();
+      assertFalse(compare.compare(c0, c8) == 0);
+      assertFalse(compare.compare(c1, c8) == 0);
+      assertFalse(compare.compare(c2, c8) == 0);
+      assertFalse(compare.compare(c3, c8) == 0);
+      assertFalse(compare.compare(c4, c8) == 0);
+      assertFalse(compare.compare(c5, c8) == 0);
+      assertFalse(compare.compare(c6, c8) == 0);
+      assertFalse(compare.compare(c7, c8) == 0);
+      metaData.addContext(c8);
+
+      assertEquals("context count is 9", 9, metaData.getContexts().size());
+      assertNotNull("wars/notjbosstest-web.war", metaData.getContext("wars/notjbosstest-web.war"));
+      assertNotNull("cts.jar", metaData.getContext("cts.jar"));
+      assertNotNull("jbosstest-web-ejbs.jar", metaData.getContext("jbosstest-web-ejbs.jar"));
+      assertNotNull("jbosstest-web.war", metaData.getContext("jbosstest-web.war"));
+      assertNotNull("root-web.war", metaData.getContext("root-web.war"));
+      assertNotNull("jbosstest-web-ejbs.jar/roles.properties", metaData.getContext("jbosstest-web-ejbs.jar/roles.properties"));
+      assertNotNull("jbosstest-web-ejbs.jar/users.properties", metaData.getContext("jbosstest-web-ejbs.jar/users.properties"));
+      assertNotNull("websubdir/relative.jar", metaData.getContext("websubdir/relative.jar"));
+   }
+
    public void testSortedSet()
    {
-      Comparator<ContextInfo> c = new Comparator<ContextInfo>()
-      {
-         public int compare(ContextInfo o1, ContextInfo o2)
-         {
-            int compare = 0;
-            if( o1 == null && o2 != null )
-               compare = -1;
-            else if( o1 != null && o2 == null )
-               compare = 1;
-            else
-            {
-               // Sort by depth and then name
-               ContextInfo p1 = o1.getParent();
-               ContextInfo p2 = o2.getParent();
-               if( p1 != p2 )
-               {
-                  compare = compare(p1, p2);
-               }
-               else if( p1 != null )
-               {
-                  compare = o1.getVfsPath().compareTo(o2.getVfsPath());
-               }
-            }
-            return compare;
-         }
-      };
+      StructureMetaDataImpl.ContextComparator c = new StructureMetaDataImpl.ContextComparator();
       TreeSet<ContextInfo> info = new TreeSet<ContextInfo>(c);
 
       ArrayList<ContextInfo> order = new ArrayList<ContextInfo>();
@@ -197,11 +219,12 @@
       metaData.addContext(context);
       info.add(context);
       order.add(context);
-      context = getContextInfo("top/root/subdir/sub3.jar");
+      context = getContextInfo("top/root/subdir");
       metaData.addContext(context);
       info.add(context);
       order.add(context);
 
+      // sub2 < subd
       context = getContextInfo("top/root/sub2/sub21");
       metaData.addContext(context);
       info.add(context);
@@ -210,17 +233,25 @@
       metaData.addContext(context);
       info.add(context);
       order.add(context);
-      metaData.addContext(context);
       context = getContextInfo("top/root/sub2/sub21.war");
       metaData.addContext(context);
       info.add(context);
       order.add(context);
 
+      context = getContextInfo("top/root/subdir/sub2.jar");
+      metaData.addContext(context);
+      info.add(context);
+      order.add(context);
+      context = getContextInfo("top/root/subdir/sub3.jar");
+      metaData.addContext(context);
+      info.add(context);
+      order.add(context);
+
       int count = 0;
       for(ContextInfo ci : info)
       {
          ContextInfo expected = order.get(count);
-         assertSame("At: "+count, ci, expected);
+         assertSame("At: "+count, expected, ci);
          count ++;
       }
    }
@@ -240,9 +271,6 @@
       context = getContextInfo("top/root/sub2");
       metaData.addContext(context);
       order.add(context);
-      context = getContextInfo("top/root/subdir/sub3.jar");
-      metaData.addContext(context);
-      order.add(context);
 
       // top/root/sub2 children
       context = getContextInfo("top/root/sub2/sub21");
@@ -255,11 +283,16 @@
       metaData.addContext(context);
       order.add(context);
 
+      // top/root/subdir children
+      context = getContextInfo("top/root/subdir/sub3.jar");
+      metaData.addContext(context);
+      order.add(context);
+
       int count = 0;
       for(ContextInfo ci : metaData.getContexts())
       {
          ContextInfo expected = order.get(count);
-         assertSame("At: "+count, ci, expected);
+         assertSame("At: "+count, expected, ci);
          count ++;
       }      
    }




More information about the jboss-cvs-commits mailing list