[jboss-svn-commits] JBoss Common SVN: r3464 - in declarchive/trunk/impl-base/src: test/java/org/jboss/declarchive/impl/base and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Aug 21 02:35:41 EDT 2009


Author: ALRubinger
Date: 2009-08-21 02:35:40 -0400 (Fri, 21 Aug 2009)
New Revision: 3464

Added:
   declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/BasicPath.java
   declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/path/
   declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/path/PathUtilTestCase.java
Removed:
   declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/BasePath.java
   declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PrefixPath.java
   declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/RelativePath.java
   declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/ResourcePath.java
Modified:
   declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PathUtil.java
Log:
[TMPARCH-12] Add a simple Path implementation

Deleted: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/BasePath.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/BasePath.java	2009-08-21 02:30:42 UTC (rev 3463)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/BasePath.java	2009-08-21 06:35:40 UTC (rev 3464)
@@ -1,79 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.declarchive.impl.base.path;
-
-import org.jboss.declarchive.api.Path;
-
-/**
- * BasePath
- * 
- * A {@link Path} which has no namespace and is relative to the
- * root.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- * @version $Revision: $
- */
-public class BasePath extends PrefixPath
-{
-
-   //-------------------------------------------------------------------------------------||
-   // Class Members ----------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   private static final String PREFIX = null;
-
-   //-------------------------------------------------------------------------------------||
-   // Constructor ------------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Creates a new Path representing the 
-    * root context
-    * 
-    * @param context
-    */
-   public BasePath()
-   {
-      this(null);
-   }
-
-   /**
-    * Creates a new Path representing the specified
-    * context.  Null or blank may be used to 
-    * denote the root.
-    * 
-    * @param context
-    */
-   public BasePath(final String context)
-   {
-      super(PathUtil.fixBasePath(context));
-   }
-
-   //-------------------------------------------------------------------------------------||
-   // Required Implementations -----------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * @see org.jboss.declarchive.impl.base.path.PrefixPath#getPrefix()
-    */
-   @Override
-   String getPrefix()
-   {
-      return PREFIX;
-   }
-}

Copied: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/BasicPath.java (from rev 3461, declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PrefixPath.java)
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/BasicPath.java	                        (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/BasicPath.java	2009-08-21 06:35:40 UTC (rev 3464)
@@ -0,0 +1,187 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.declarchive.impl.base.path;
+
+import java.util.logging.Logger;
+
+import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.impl.base.Validate;
+
+/**
+ * BasicPath
+ * 
+ * A Path which may be optionally prefixed with some common
+ * namespace context at construction time.  Thread-safe.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class BasicPath implements Path, Comparable<Path>
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(BasicPath.class.getName());
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * The context which this path represents; immutable so we're
+    * thread-safe.
+    */
+   private final String context;
+
+   //-------------------------------------------------------------------------------------||
+   // Constructor ------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Creates a new Path with the specified context
+    * 
+    * @param prefix The prefix to prepend to every context returned
+    * in {@link BasicPath#get()}.  May be null or blank
+    * @param context The context which this path represents.  Null or 
+    * blank represents the root.
+    */
+   public BasicPath(final String context)
+   {
+      Validate.notNull(context, "Context must be specified");
+      this.context = context;
+   }
+
+   /**
+    * Creates a new Path using the specified base 
+    * and specified relative context.
+    * 
+    * @param basePath
+    * @param context
+    */
+   public BasicPath(final Path basePath, final Path context)
+   {
+      this(basePath, context.get());
+   }
+
+   /**
+    * Creates a new Path using the specified base 
+    * and specified relative context.
+    * 
+    * @param basePath
+    * @param context
+    */
+   public BasicPath(final Path basePath, final String context)
+   {
+      this(basePath.get(), context);
+   }
+
+   /**
+    * Creates a new Path using the specified base 
+    * and specified relative context.
+    * 
+    * @param basePath
+    * @param context
+    */
+   public BasicPath(final String basePath, String context)
+   {
+      this(PathUtil.composeAbsoluteContext(basePath, context));
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Required Implementations -----------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * @see org.jboss.declarchive.api.Path#get()
+    */
+   @Override
+   public String get()
+   {
+      return context;
+   }
+
+   /**
+    * @see java.lang.Comparable#compareTo(java.lang.Object)
+    */
+   @Override
+   public int compareTo(final Path path)
+   {
+      if (path == null)
+      {
+         return 1;
+      }
+      else
+      {
+         // Compare the contexts
+         return this.get().compareTo(path.get());
+      }
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Overridden Implementations ---------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * @see java.lang.Object#hashCode()
+    */
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((context == null) ? 0 : context.hashCode());
+      return result;
+   }
+
+   /**
+    * @see java.lang.Object#equals(java.lang.Object)
+    */
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      final BasicPath other = (BasicPath) obj;
+      if (context == null)
+      {
+         if (other.context != null)
+            return false;
+      }
+      else if (!context.equals(other.context))
+         return false;
+      return true;
+   }
+
+   /**
+    * @see java.lang.Object#toString()
+    */
+   @Override
+   public String toString()
+   {
+      return this.getClass().getSimpleName() + " [context=" + context + "]";
+   }
+
+}

Modified: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PathUtil.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PathUtil.java	2009-08-21 02:30:42 UTC (rev 3463)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PathUtil.java	2009-08-21 06:35:40 UTC (rev 3464)
@@ -19,66 +19,219 @@
 
 /**
  * PathUtil
+ * 
+ * A series of internal-only path utilities for
+ * adjusting relative forms, removing double-slashes, etc.
+ * Used in correcting inputs in the creation of new Paths
  *
  * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
  */
-public class PathUtil
+class PathUtil
 {
 
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Slash character
+    */
+   static final char SLASH = '/';
+
+   //-------------------------------------------------------------------------------------||
+   // Constructor ------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * No instantiation
+    */
    private PathUtil()
    {
+      throw new UnsupportedOperationException("Constructor should never be invoked; this is a static util class");
    }
 
-   public static String fixRelativePath(String path)
+   //-------------------------------------------------------------------------------------||
+   // Utilities --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Composes an absolute context from a given base and actual context
+    * relative to the base, returning the result.  ie. base of
+    * "base" and context of "context" will
+    * result in form "/base/context".
+    */
+   static String composeAbsoluteContext(final String base, final String context)
    {
+      // Precondition checks
+      assertSpecified(base);
+      assertSpecified(context);
+
+      // Compose
+      final String relative = PathUtil.adjustToAbsoluteDirectoryContext(base);
+      final String reformedContext = PathUtil.removePrecedingSlash(context);
+      final String actual = relative + reformedContext;
+
+      // Return
+      return actual;
+   }
+
+   /**
+    * Adjusts the specified path to relative form:
+    * 
+    * 1) Removes, if present, a preceding slash
+    * 2) Adds, if not present, a trailing slash
+    * 
+    * Null arguments are returned as-is
+    * 
+    * @param path
+    */
+   static String adjustToRelativeDirectoryContext(final String path)
+   {
+      // Return nulls
       if (path == null)
       {
          return path;
       }
-      String removedPrefix = removePrefix(path);
-      String addedPostfix = addPostfix(removedPrefix);
 
+      // Strip absolute form
+      final String removedPrefix = removePrecedingSlash(path);
+      // Add end of context slash
+      final String addedPostfix = optionallyAppendSlash(removedPrefix);
+
+      // Return
       return addedPostfix;
    }
 
-   public static String fixBasePath(String path)
+   /**
+    * Adjusts the specified path to absolute form:
+    * 
+    * 1) Adds, if not present, a preceding slash
+    * 2) Adds, if not present, a trailing slash
+    * 
+    * Null arguments are returned as-is
+    * 
+    * @param path
+    */
+   static String adjustToAbsoluteDirectoryContext(String path)
    {
+      // Return nulls
       if (path == null)
       {
          return path;
       }
-      String prefixedPath = addPrefix(path);
-      String prePostfixedPath = addPostfix(prefixedPath);
 
-      return prePostfixedPath;
+      // Add prefic slash
+      final String prefixedPath = optionallyPrependSlash(path);
+      // Add end of context slash
+      final String addedPostfix = optionallyAppendSlash(prefixedPath);
+
+      // Return
+      return addedPostfix;
    }
 
-   private static String removePrefix(String path)
+   /**
+    * Removes, if present, the absolute slash preceding
+    * the specified path, and returns the adjusted result
+    * 
+    * @param path
+    * @return
+    */
+   static String removePrecedingSlash(final String path)
    {
-      if (path.charAt(0) == '/')
+      // Precondition check
+      assertSpecified(path);
+
+      // Is there's a first character of slash
+      if (isFirstCharSlash(path))
       {
+         // Return everything but first char
          return path.substring(1);
       }
+
+      // Return as-is
       return path;
    }
 
-   private static String addPostfix(String path)
+   /**
+    * Adds, if not already present, the absolute slash following
+    * the specified path, and returns the adjusted result
+    * 
+    * @param path
+    * @return
+    */
+   static String optionallyAppendSlash(final String path)
    {
-      if (path.charAt(path.length() - 1) != '/')
+      // Precondition check
+      assertSpecified(path);
+
+      // If the last character is not a slash
+      if (!isLastCharSlash(path))
       {
-         return path + '/';
+         // Append
+         return path + SLASH;
       }
+
+      // Return as-is
       return path;
    }
 
-   private static String addPrefix(String path)
+   /**
+    * Adds, if not already present, the absolute slash preceding
+    * the specified path, and returns the adjusted result
+    * 
+    * @param path
+    * @return
+    */
+   static String optionallyPrependSlash(final String path)
    {
-      if (path.charAt(0) != '/')
+      // Precondition check
+      assertSpecified(path);
+
+      // If the first character is not a slash
+      if (!isFirstCharSlash(path))
       {
-         return '/' + path;
+         // Prepend the slash
+         return SLASH + path;
       }
+
+      // Return as-is
       return path;
    }
 
+   //-------------------------------------------------------------------------------------||
+   // Internal Helper Methods ------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Returns whether or not the first character in the specified String is
+    * a slash  
+    */
+   private static boolean isFirstCharSlash(final String path)
+   {
+      assertSpecified(path);
+      return path.charAt(0) == SLASH;
+   }
+
+   /**
+    * Returns whether or not the last character in the specified String is
+    * a slash  
+    */
+   private static boolean isLastCharSlash(final String path)
+   {
+      assertSpecified(path);
+      return path.charAt(path.length() - 1) == '/';
+   }
+
+   /**
+    * Ensures the path is specified
+    * @param path
+    */
+   private static void assertSpecified(final String path)
+   {
+      // Precondition check
+      assert path != null : "Path must be specified";
+   }
+
 }

Deleted: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PrefixPath.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PrefixPath.java	2009-08-21 02:30:42 UTC (rev 3463)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/PrefixPath.java	2009-08-21 06:35:40 UTC (rev 3464)
@@ -1,161 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.declarchive.impl.base.path;
-
-import org.jboss.declarchive.api.Path;
-import org.jboss.declarchive.impl.base.Validate;
-
-/**
- * PrefixPath
- * 
- * A Path which may be optionally prefixed with some common
- * namespace
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-abstract class PrefixPath implements Path, Comparable<Path>
-{
-
-   //-------------------------------------------------------------------------------------||
-   // Class Members ----------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Empty String
-    */
-   private static final String EMPTY_STRING = "";
-
-   //-------------------------------------------------------------------------------------||
-   // Instance Members -------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * The context which this path represents
-    */
-   private final String context;
-
-   //-------------------------------------------------------------------------------------||
-   // Constructor ------------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Creates a new Path with the specified context
-    * 
-    * @param prefix The prefix to prepend to every context returned
-    * in {@link PrefixPath#get()}.  May be null or blank
-    * @param context The context which this path represents.  Null or 
-    * blank represents the root.
-    */
-   PrefixPath(final String context)
-   {
-      Validate.notNull(context, "Context must be specified");
-      this.context = context;
-   }
-
-   //-------------------------------------------------------------------------------------||
-   // Required Implementations -----------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * @see org.jboss.declarchive.api.Path#get()
-    */
-   @Override
-   public String get()
-   {
-      // Return the prefix plus the context
-      final String prefix = this.getPrefix();
-      final String prefixToUse = prefix == null ? EMPTY_STRING : prefix;
-      final String resolvedContext = prefixToUse + context;
-      return resolvedContext;
-   }
-
-   /**
-    * @see java.lang.Comparable#compareTo(java.lang.Object)
-    */
-   @Override
-   public int compareTo(final Path path)
-   {
-      if (path == null)
-      {
-         return 1;
-      }
-      else
-      {
-         // Compare the contexts
-         return this.get().compareTo(path.get());
-      }
-   }
-
-   //-------------------------------------------------------------------------------------||
-   // Contracts --------------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Obtains the prefix to prepend to all path contexts
-    */
-   abstract String getPrefix();
-
-   //-------------------------------------------------------------------------------------||
-   // Overridden Implementations ---------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * @see java.lang.Object#hashCode()
-    */
-   @Override
-   public int hashCode()
-   {
-      final int prime = 31;
-      int result = 1;
-      result = prime * result + ((context == null) ? 0 : context.hashCode());
-      return result;
-   }
-
-   /**
-    * @see java.lang.Object#equals(java.lang.Object)
-    */
-   @Override
-   public boolean equals(Object obj)
-   {
-      if (this == obj)
-         return true;
-      if (obj == null)
-         return false;
-      if (getClass() != obj.getClass())
-         return false;
-      final PrefixPath other = (PrefixPath) obj;
-      if (context == null)
-      {
-         if (other.context != null)
-            return false;
-      }
-      else if (!context.equals(other.context))
-         return false;
-      return true;
-   }
-
-   /**
-    * @see java.lang.Object#toString()
-    */
-   @Override
-   public String toString()
-   {
-      return this.getClass().getSimpleName() + " [context=" + context + "]";
-   }
-
-}

Deleted: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/RelativePath.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/RelativePath.java	2009-08-21 02:30:42 UTC (rev 3463)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/RelativePath.java	2009-08-21 06:35:40 UTC (rev 3464)
@@ -1,54 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
-
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.declarchive.impl.base.path;
-
-import org.jboss.declarchive.api.Path;
-
-/**
- * RelativePath
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- * @version $Revision: $
- */
-public class RelativePath extends PrefixPath
-{
-   private Path basePath;
-
-   public RelativePath(Path basePath, Path context)
-   {
-      this(basePath, context.get());
-   }
-
-   public RelativePath(Path basePath, String context)
-   {
-      this(basePath.get(), context);
-   }
-
-   public RelativePath(String basePath, String context)
-   {
-      super(PathUtil.fixRelativePath(context));
-      this.basePath = new BasePath(basePath);
-   }
-
-   @Override
-   String getPrefix()
-   {
-      return basePath.get();
-   }
-
-}

Deleted: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/ResourcePath.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/ResourcePath.java	2009-08-21 02:30:42 UTC (rev 3463)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/path/ResourcePath.java	2009-08-21 06:35:40 UTC (rev 3464)
@@ -1,37 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
-
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.declarchive.impl.base.path;
-
-import org.jboss.declarchive.api.Path;
-
-public class ResourcePath extends PrefixPath
-{
-   private Path basePath;
-
-   public ResourcePath(Path basePath, String resourceName)
-   {
-      super(resourceName);
-      this.basePath = basePath;
-   }
-
-   @Override
-   String getPrefix()
-   {
-      return basePath.get();
-   }
-}

Added: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/path/PathUtilTestCase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/path/PathUtilTestCase.java	                        (rev 0)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/path/PathUtilTestCase.java	2009-08-21 06:35:40 UTC (rev 3464)
@@ -0,0 +1,176 @@
+package org.jboss.declarchive.impl.base.path;
+
+import java.util.logging.Logger;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * PathUtilTestCase
+ * 
+ * Test cases to ensure the path utilities are working as expected
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class PathUtilTestCase
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(PathUtilTestCase.class.getName());
+
+   //-------------------------------------------------------------------------------------||
+   // Tests ------------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Ensures that the preceding slash is removed as requested
+    */
+   @Test
+   public void testRemovePrecedingSlash()
+   {
+      log.info("testRemovePrecedingSlash");
+      final String precedingSlash = "/test/something";
+      final String expected = precedingSlash.substring(1);
+      final String result = PathUtil.removePrecedingSlash(precedingSlash);
+      Assert.assertEquals("Call to remove preceding slash should return everything in input except the first slash",
+            expected, result);
+   }
+
+   /**
+    * Ensures that the preceding slash is removed as requested
+    */
+   @Test
+   public void testRemovePrecedingSlashWithNoPrecedingSlashEqualToInput()
+   {
+      log.info("testRemovePrecedingSlash");
+      final String noPrecedingSlash = "test/something";
+      final String result = PathUtil.removePrecedingSlash(noPrecedingSlash);
+      Assert.assertEquals(
+            "Call to remove preceding slash on input with no preceding slash should return equal by value to input",
+            noPrecedingSlash, result);
+   }
+
+   /**
+    * Ensures that a slash may be prepended to a given String
+    */
+   @Test
+   public void testPrependSlash()
+   {
+      log.info("testRemovePrecedingSlash");
+      final String noPrecedingSlash = "test/something";
+      final String expected = PathUtil.SLASH + noPrecedingSlash;
+      final String result = PathUtil.optionallyPrependSlash(noPrecedingSlash);
+      Assert.assertEquals("Call to prepend a slash failed", expected, result);
+   }
+
+   /**
+    * Ensures that optionally prepending a slash upon
+    * a String already prefixed with one returns a no-op
+    */
+   @Test
+   public void testNoOpPrependSlash()
+   {
+      log.info("testRemovePrecedingSlash");
+      final String precedingSlash = "/test/something";
+      final String result = PathUtil.optionallyPrependSlash(precedingSlash);
+      Assert.assertEquals("Call to optionally prepend a slash upon input with slash prefix should return no-op",
+            precedingSlash, result);
+   }
+
+   /**
+    * Ensures that a slash may be appended to a given String
+    */
+   @Test
+   public void testAppendSlash()
+   {
+      log.info("testRemovePrecedingSlash");
+      final String noFollowingSlash = "test/something";
+      final String expected = noFollowingSlash + PathUtil.SLASH;
+      final String result = PathUtil.optionallyAppendSlash(noFollowingSlash);
+      Assert.assertEquals("Call to append a slash failed", expected, result);
+   }
+
+   /**
+    * Ensures that optionally appending a slash upon
+    * a String already suffixed with one returns a no-op
+    */
+   @Test
+   public void testNoOpAppendSlash()
+   {
+      log.info("testRemovePrecedingSlash");
+      final String followingSlash = "/test/something/";
+      final String result = PathUtil.optionallyAppendSlash(followingSlash);
+      Assert.assertEquals("Call to optionally append a slash upon input with slash suffix should return no-op",
+            followingSlash, result);
+   }
+
+   /**
+    * Ensures that an absolute path may be converted to 
+    * full relative directory form
+    */
+   @Test
+   public void testAdjustToRelativeDirectoryContext()
+   {
+      log.info("testRemovePrecedingSlash");
+      final String absoulteWithoutTrailingSlash = "/test/something";
+      final String expected = absoulteWithoutTrailingSlash.substring(1) + PathUtil.SLASH;
+      final String result = PathUtil.adjustToRelativeDirectoryContext(absoulteWithoutTrailingSlash);
+      Assert.assertEquals("Adjusting to relative form should strip preceding slash and append a trailing one",
+            expected, result);
+   }
+
+   /**
+    * Ensures that a relative path may be converted to 
+    * full absolute directory form
+    */
+   @Test
+   public void testAdjustToAbsoluteDirectoryContext()
+   {
+      log.info("testRemovePrecedingSlash");
+      final String relativeWithoutTrailingSlash = "test/something";
+      final String expected = PathUtil.SLASH + relativeWithoutTrailingSlash + PathUtil.SLASH;
+      final String result = PathUtil.adjustToAbsoluteDirectoryContext(relativeWithoutTrailingSlash);
+      Assert.assertEquals("Adjusting to absolute form should prepend preceding slash and append a trailing one",
+            expected, result);
+   }
+
+   /**
+    * Ensures that an absolute form may be composed
+    * from a relative context and base
+    */
+   @Test
+   public void testComposeAbsoulteContext()
+   {
+      log.info("testComposeAbsoulteContext");
+      final String base = "something";
+      final String context = "somethingunder";
+      final String expected = PathUtil.SLASH + base + PathUtil.SLASH + context;
+      final String result = PathUtil.composeAbsoluteContext(base, context);
+      Assert.assertEquals("Composing an absolute context from base and context did not succeed", expected, result);
+   }
+
+}



More information about the jboss-svn-commits mailing list