[Yanel-commits] rev 22594 - in public/yanel/trunk/src: contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources core/java/org/wyona/yanel/core/util resources/testing-control/src/java/org/wyona/yanel/impl/resources resources/testing-times/src/java/org/wyona/yanel/impl/resources resources/xml/src/java/org/wyona/yanel/impl/resources test/junit/org/wyona/yanel test/junit/org/wyona/yanel/core test/junit/org/wyona/yanel/core/util

josias at wyona.com josias at wyona.com
Mon Feb 12 17:15:13 CET 2007


Author: josias
Date: 2007-02-12 17:15:11 +0100 (Mon, 12 Feb 2007)
New Revision: 22594

Added:
   public/yanel/trunk/src/test/junit/org/wyona/yanel/core/
   public/yanel/trunk/src/test/junit/org/wyona/yanel/core/util/
   public/yanel/trunk/src/test/junit/org/wyona/yanel/core/util/PathUtilTest.java
Modified:
   public/yanel/trunk/src/contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources/AtomEntryResource.java
   public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java
   public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java
   public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/WikiResource.java
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/PathUtil.java
   public/yanel/trunk/src/resources/testing-control/src/java/org/wyona/yanel/impl/resources/TestingControlResource.java
   public/yanel/trunk/src/resources/testing-times/src/java/org/wyona/yanel/impl/resources/TestingTimes.java
   public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java
Log:
centralized back2realm and back2context and added junit tests for PathUtil. fixes bug #5185, thanks to simon.

Modified: public/yanel/trunk/src/contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources/AtomEntryResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources/AtomEntryResource.java	2007-02-12 15:36:26 UTC (rev 22593)
+++ public/yanel/trunk/src/contributions/resources/atom-entry/src/java/org/wyona/yanel/impl/resources/AtomEntryResource.java	2007-02-12 16:15:11 UTC (rev 22594)
@@ -88,8 +88,8 @@
                 Transformer transformer = tf.newTransformer(new StreamSource(getRealm().getRepository().getInputStream(new org.wyona.yarep.core.Path(getXSLTPath().toString()))));
                 transformer.setParameter("yanel.path.name", PathUtil.getName(getPath()));
                 transformer.setParameter("yanel.path", getPath());
-                transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
-                transformer.setParameter("yarep.back2realm", backToRoot());
+                transformer.setParameter("yanel.back2context", PathUtil.backToContext(realm, getPath()));
+                transformer.setParameter("yarep.back2realm", PathUtil.backToRealm(getPath()));
                 // TODO: Is this the best way to generate an InputStream from an OutputStream?
                 java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
 
@@ -219,37 +219,6 @@
     }
 
     /**
-     * @return a String with as many ../ as it needs to go back to from current realm to context
-     */
-    private String backToContext() {
-        String backToContext = "";
-        int steps = realm.getMountPoint().split("/").length - 1;
-
-        for (int i = 0; i < steps; i++) {
-            backToContext = backToContext + "../";
-        }
-        return backToContext;
-    }
-     
-    /**
-     * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
-     */
-    private String backToRoot() {
-        String backToRoot = "";
-        int steps;
-        
-        if (getPath().endsWith("/") && !getPath().equals("/")) {
-            steps =  getPath().split("/").length - 1;
-        } else {
-            steps =  getPath().split("/").length - 2;
-        }
-        for (int i = 0; i < steps; i++) {
-            backToRoot = backToRoot + "../";
-        }
-        return backToRoot;
-    }
-
-    /**
      *
      */
     public boolean delete() throws Exception {

Modified: public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java	2007-02-12 15:36:26 UTC (rev 22593)
+++ public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java	2007-02-12 16:15:11 UTC (rev 22594)
@@ -160,8 +160,8 @@
             transformer = TransformerFactory.newInstance().newTransformer(getXSLTStreamSource(path, repository));
             transformer.setParameter("yanel.path.name", path.getName());
             transformer.setParameter("yanel.path", path.toString());
-            transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
-            transformer.setParameter("yarep.back2realm", backToRoot());
+            transformer.setParameter("yanel.back2context", PathUtil.backToContext(realm, getPath()));
+            transformer.setParameter("yarep.back2realm", PathUtil.backToRealm(getPath()));
  
             byteArrayOutputStream = new ByteArrayOutputStream();
             transformer.transform(new StreamSource(i18nTransformer.getInputStream()), new StreamResult(byteArrayOutputStream));
@@ -400,35 +400,4 @@
    protected RepositoryFactory getRepositoryFactory() {
        return yanel.getRepositoryFactory("DefaultRepositoryFactory");
    }
-   
-   /**
-    * @return a String with as many ../ as it needs to go back to from current realm to context
-    */
-   private String backToContext() {
-       String backToContext = "";
-       int steps = realm.getMountPoint().split("/").length - 1;
-
-       for (int i = 0; i < steps; i++) {
-           backToContext = backToContext + "../";
-       }
-       return backToContext;
-   }
-    
-   /**
-    * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
-    */
-   private String backToRoot() {
-       String backToRoot = "";
-       int steps;
-       
-       if (getPath().endsWith("/") && !getPath().equals("/")) {
-           steps =  getPath().split("/").length - 1;
-       } else {
-           steps =  getPath().split("/").length - 2;
-       }
-       for (int i = 0; i < steps; i++) {
-           backToRoot = backToRoot + "../";
-       }
-       return backToRoot;
-   }
 }
\ No newline at end of file

Modified: public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java	2007-02-12 15:36:26 UTC (rev 22593)
+++ public/yanel/trunk/src/contributions/resources/nutch/src/java/org/wyona/yanel/impl/resources/NutchResource.java	2007-02-12 16:15:11 UTC (rev 22594)
@@ -307,10 +307,10 @@
                 // TODO: Remove the trailing slash ...
                 transformer.setParameter("yanel.path", getRealm().getMountPoint() + getPath());
                 log.debug("Yanel Path: " + getRealm().getMountPoint() + getPath());
-                transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
-                log.debug("Back 2 context: " + backToContext()+backToRoot());
-                transformer.setParameter("yarep.back2realm", backToRoot());
-                log.debug("Back 2 realm: " + getPath() + ", " + backToRoot());
+                transformer.setParameter("yanel.back2context", PathUtil.backToContext(realm, getPath()));
+                log.debug("Back 2 context: " + PathUtil.backToContext(realm, getPath()));
+                transformer.setParameter("yarep.back2realm", PathUtil.backToRealm(getPath()));
+                log.debug("Back 2 realm: " + PathUtil.backToRealm(getPath()));
                 transformer.transform(new javax.xml.transform.dom.DOMSource(document), new StreamResult(byteArrayOutputStream));
                 InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
                 i18nTransformer = new I18nTransformer(resourceBundle, language);
@@ -338,8 +338,8 @@
                 transformer = TransformerFactory.newInstance().newTransformer(streamSource);
                 transformer.setParameter("yanel.path.name", PathUtil.getName(getPath()));
                 transformer.setParameter("yanel.path", getPath().toString());
-                transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
-                transformer.setParameter("yarep.back2realm", backToRoot());
+                transformer.setParameter("yanel.back2context", PathUtil.backToContext(realm, getPath()));
+                transformer.setParameter("yarep.back2realm", PathUtil.backToRealm(getPath()));
                 transformer.setParameter("hitsPerPage", "" + hitsPerPage);
                 transformer.setParameter("totalHits", "" + totalHits);
                 transformer.setParameter("query", "" + searchTerm);
@@ -474,39 +474,8 @@
         }
         return null;
     }
-    
-    /**
-     * @return a String with as many ../ as it needs to go back to from current realm to context
-     */
-    private String backToContext() {
-        String backToContext = "";
-        int steps = realm.getMountPoint().split("/").length - 1;
 
-        for (int i = 0; i < steps; i++) {
-            backToContext = backToContext + "../";
-        }
-        return backToContext;
-    }
-     
     /**
-     * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
-     */
-    private String backToRoot() {
-        String backToRoot = "";
-        int steps;
-        
-        if (getPath().endsWith("/") && !getPath().equals("/")) {
-            steps =  getPath().split("/").length - 1;
-        } else {
-            steps =  getPath().split("/").length - 2;
-        }
-        for (int i = 0; i < steps; i++) {
-            backToRoot = backToRoot + "../";
-        }
-        return backToRoot;
-    }
-    
-    /**
      * This method creates a document for the given searchTerm starting at result <start> 
      * and stores the informations within a xml 
      * @param searchTerm 

Modified: public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/WikiResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/WikiResource.java	2007-02-12 15:36:26 UTC (rev 22593)
+++ public/yanel/trunk/src/contributions/resources/wiki/src/java/org/wyona/yanel/impl/resources/WikiResource.java	2007-02-12 16:15:11 UTC (rev 22594)
@@ -146,8 +146,8 @@
                 transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(dataRepo.getInputStream(new org.wyona.yarep.core.Path(getXSLTPath().toString()))));
                 transformer.setParameter("yanel.path.name", PathUtil.getName(getPath()));
                 transformer.setParameter("yanel.path", getPath());
-                transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
-                transformer.setParameter("yarep.back2realm", backToRoot());
+                transformer.setParameter("yanel.back2context", PathUtil.backToContext(realm, getPath()));
+                transformer.setParameter("yarep.back2realm", PathUtil.backToRealm(getPath()));
                 
                 byteArrayOutputStream = new ByteArrayOutputStream();
                 transformer.transform(new StreamSource(inputStream), new StreamResult(byteArrayOutputStream));    
@@ -165,39 +165,8 @@
         }
         return null;
     }
-    
-    /**
-     * @return a String with as many ../ as it needs to go back to from current realm to context
-     */
-    private String backToContext() {
-        String backToContext = "";
-        int steps = realm.getMountPoint().split("/").length - 1;
 
-        for (int i = 0; i < steps; i++) {
-            backToContext = backToContext + "../";
-        }
-        return backToContext;
-    }
-     
     /**
-     * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
-     */
-    private String backToRoot() {
-        String backToRoot = "";
-        int steps;
-        
-        if (getPath().endsWith("/") && !getPath().equals("/")) {
-            steps =  getPath().split("/").length - 1;
-        } else {
-            steps =  getPath().split("/").length - 2;
-        }
-        for (int i = 0; i < steps; i++) {
-            backToRoot = backToRoot + "../";
-        }
-        return backToRoot;
-    }
-    
-    /**
      * 
      */
     public View getView(HttpServletRequest request, String viewId) {

Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/PathUtil.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/PathUtil.java	2007-02-12 15:36:26 UTC (rev 22593)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/PathUtil.java	2007-02-12 16:15:11 UTC (rev 22594)
@@ -17,6 +17,7 @@
 package org.wyona.yanel.core.util;
 
 import org.apache.log4j.Category;
+import org.wyona.yanel.core.map.Realm;
 
 /**
  *
@@ -46,4 +47,41 @@
        }
        return path + ".yanel-rc";
    }
+   
+   /**
+    * @return a String with as many ../ as it needs to go back to from current realm to context
+    */
+   public static String backToContext(Realm realm) {
+       StringBuffer backToContext = new StringBuffer();
+       int steps = realm.getMountPoint().split("/").length - 1;
+       for (int i = 0; i < steps; i++) {
+           backToContext.append("../");
+       }
+       return backToContext.toString();
+   }
+   
+   /**
+    * @return a String with as many ../ as it needs to go back to from current resource to context
+    */
+   public static String backToContext(Realm realm, String path) {
+       return backToContext(realm) + backToRealm(path);
+   }
+   
+   /**
+    * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
+    */
+   public static String backToRealm(String path) {
+       StringBuffer backToRealm = new StringBuffer();
+       int steps;
+       if (path.endsWith("/") && !path.equals("/")) {
+           steps =  path.split("/").length - 1;
+       } else {
+           steps =  path.split("/").length - 2;
+       }
+       for (int i = 0; i < steps; i++) {
+           backToRealm.append("../");
+       }
+       return backToRealm.toString();
+   }
+   
 }

Modified: public/yanel/trunk/src/resources/testing-control/src/java/org/wyona/yanel/impl/resources/TestingControlResource.java
===================================================================
--- public/yanel/trunk/src/resources/testing-control/src/java/org/wyona/yanel/impl/resources/TestingControlResource.java	2007-02-12 15:36:26 UTC (rev 22593)
+++ public/yanel/trunk/src/resources/testing-control/src/java/org/wyona/yanel/impl/resources/TestingControlResource.java	2007-02-12 16:15:11 UTC (rev 22594)
@@ -385,8 +385,8 @@
                     .newTransformer(new StreamSource(repo.getInputStream(getXSLTPath(path))));
             transformer.setParameter("yanel.path.name", path.getName());
             transformer.setParameter("yanel.path", path.toString());
-            transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
-            transformer.setParameter("yarep.back2realm", backToRoot());
+            transformer.setParameter("yanel.back2context", PathUtil.backToContext(realm, getPath()));
+            transformer.setParameter("yarep.back2realm", PathUtil.backToRealm(getPath()));
             return transformer;
         } else {
             Transformer transformer = TransformerFactory.newInstance().newTransformer();
@@ -414,37 +414,6 @@
     }
 
     /**
-     * @return a String with as many ../ as it needs to go back to from current realm to context
-     */
-    private String backToContext() {
-        String backToContext = "";
-        int steps = realm.getMountPoint().split("/").length - 1;
-
-        for (int i = 0; i < steps; i++) {
-            backToContext = backToContext + "../";
-        }
-        return backToContext;
-    }
-     
-    /**
-     * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
-     */
-    private String backToRoot() {
-        String backToRoot = "";
-        int steps;
-        
-        if (getPath().endsWith("/") && !getPath().equals("/")) {
-            steps =  getPath().split("/").length - 1;
-        } else {
-            steps =  getPath().split("/").length - 2;
-        }
-        for (int i = 0; i < steps; i++) {
-            backToRoot = backToRoot + "../";
-        }
-        return backToRoot;
-    }
-
-    /**
      * get Tests.
      * @param htmlOrJunit type of tests should be selected. can be htmlunit or junit.
      * @return an array with the aviable tests.

Modified: public/yanel/trunk/src/resources/testing-times/src/java/org/wyona/yanel/impl/resources/TestingTimes.java
===================================================================
--- public/yanel/trunk/src/resources/testing-times/src/java/org/wyona/yanel/impl/resources/TestingTimes.java	2007-02-12 15:36:26 UTC (rev 22593)
+++ public/yanel/trunk/src/resources/testing-times/src/java/org/wyona/yanel/impl/resources/TestingTimes.java	2007-02-12 16:15:11 UTC (rev 22594)
@@ -403,8 +403,8 @@
                     .newTransformer(new StreamSource(repo.getInputStream(getXSLTPath())));
             transformer.setParameter("yanel.path.name", path.getName());
             transformer.setParameter("yanel.path", path.toString());
-            transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
-            transformer.setParameter("yarep.back2realm", backToRoot());
+            transformer.setParameter("yanel.back2context", PathUtil.backToContext(realm, getPath()));
+            transformer.setParameter("yarep.back2realm", PathUtil.backToRealm(getPath()));
             return transformer;
         } else {
             Transformer transformer = TransformerFactory.newInstance().newTransformer();
@@ -423,37 +423,6 @@
         return null;
     }
     
-    /**
-     * @return a String with as many ../ as it needs to go back to from current realm to context
-     */
-    private String backToContext() {
-        String backToContext = "";
-        int steps = realm.getMountPoint().split("/").length - 1;
-
-        for (int i = 0; i < steps; i++) {
-            backToContext = backToContext + "../";
-        }
-        return backToContext;
-    }
-     
-    /**
-     * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
-     */
-    private String backToRoot() {
-        String backToRoot = "";
-        int steps;
-        
-        if (getPath().endsWith("/") && !getPath().equals("/")) {
-            steps =  getPath().split("/").length - 1;
-        } else {
-            steps =  getPath().split("/").length - 2;
-        }
-        for (int i = 0; i < steps; i++) {
-            backToRoot = backToRoot + "../";
-        }
-        return backToRoot;
-    }
-    
     private RepoPath contentRepo() throws Exception {
         return new YarepUtil().getRepositoryPath(new org.wyona.yarep.core.Path(path.toString()),
                 getRepositoryFactory());

Modified: public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java
===================================================================
--- public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java	2007-02-12 15:36:26 UTC (rev 22593)
+++ public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java	2007-02-12 16:15:11 UTC (rev 22594)
@@ -110,8 +110,8 @@
                 Transformer transformer = tf.newTransformer(new StreamSource(repo.getNode(xsltPath).getInputStream()));
                 transformer.setParameter("yanel.path.name", PathUtil.getName(getPath()));
                 transformer.setParameter("yanel.path", getPath());
-                transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
-                transformer.setParameter("yarep.back2realm", backToRoot());
+                transformer.setParameter("yanel.back2context", PathUtil.backToContext(realm, getPath()));
+                transformer.setParameter("yarep.back2realm", PathUtil.backToRealm(getPath()));
                 String userAgent = getRequest().getHeader("User-Agent");
                 String os = getOS(userAgent);
                 if (os != null) transformer.setParameter("os", os);
@@ -284,38 +284,8 @@
         return null;
     }
 
-    /**
-     * @return a String with as many ../ as it needs to go back to from current realm to context
-     */
-    private String backToContext() {
-        String backToContext = "";
-        int steps = realm.getMountPoint().split("/").length - 1;
 
-        for (int i = 0; i < steps; i++) {
-            backToContext = backToContext + "../";
-        }
-        return backToContext;
-    }
-     
     /**
-     * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
-     */
-    private String backToRoot() {
-        String backToRoot = "";
-        int steps;
-        
-        if (getPath().endsWith("/") && !getPath().equals("/")) {
-            steps =  getPath().split("/").length - 1;
-        } else {
-            steps =  getPath().split("/").length - 2;
-        }
-        for (int i = 0; i < steps; i++) {
-            backToRoot = backToRoot + "../";
-        }
-        return backToRoot;
-    }
-
-    /**
      *
      */
     public boolean delete() throws Exception {

Added: public/yanel/trunk/src/test/junit/org/wyona/yanel/core/util/PathUtilTest.java
===================================================================
--- public/yanel/trunk/src/test/junit/org/wyona/yanel/core/util/PathUtilTest.java	2007-02-12 15:36:26 UTC (rev 22593)
+++ public/yanel/trunk/src/test/junit/org/wyona/yanel/core/util/PathUtilTest.java	2007-02-12 16:15:11 UTC (rev 22594)
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2006 Wyona
+ *
+ *  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.wyona.org/licenses/APACHE-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.wyona.yanel.impl.map;
+
+import org.wyona.yanel.core.util.PathUtil;
+import org.wyona.yanel.core.map.Realm;
+import org.wyona.yanel.junit.AbstractYanelTest;
+
+/**
+ * Simple test for the map implementation.
+ */
+public class PathUtilTest extends AbstractYanelTest {
+
+
+    public void setUp() throws Exception {
+        super.setUp();
+        this.testName = "Test for the PathUtil";
+    }
+
+    /**
+     * Tests if the PathUtil.getRTIPath returns the correct RTIPath for a given path.
+     */
+    public void testRTIPath() throws Exception {
+        String path = "/yanel-website/en/about.html";
+        String RTIPath = PathUtil.getRTIPath(path);
+        assertEquals("Incorrect RTIPath for path: " + path.toString(), "/yanel-website/en/about.html.yanel-rti", RTIPath);
+        
+        path = "/";
+        RTIPath = PathUtil.getRTIPath(path);
+        assertEquals("Incorrect RTIPath for path: " + path.toString(), "/.yanel-rti", RTIPath);
+
+        path = "";
+        RTIPath = PathUtil.getRTIPath(path);
+        assertEquals("Incorrect RTIPath for path: " + path.toString(), ".yanel-rti", RTIPath);
+    }
+
+    /**
+     * Tests if the PathUtil.getRCPath returns the correct RCPath for a given path.
+     */
+    public void testRCPath() throws Exception {
+        String path = "/en/about.html";
+        String RCPath = PathUtil.getRCPath(path);
+        assertEquals("Incorrect RCPath for path: " + path.toString(), "/en/about.html.yanel-rc", RCPath);
+        
+        path = "/";
+        RCPath = PathUtil.getRCPath(path);
+        assertEquals("Incorrect RCPath for path: " + path.toString(), "/.yanel-rc", RCPath);
+
+        path = "";
+        RCPath = PathUtil.getRCPath(path);
+        assertEquals("Incorrect RCPath for path: " + path.toString(), ".yanel-rc", RCPath);
+    }
+    
+    
+    /**
+     * Tests if the PathUtil.backToContext returns the correct amount of "../" for a given path.
+     */
+    public void testBackToContext() throws Exception {
+        Realm realm = new Realm("test", "test", "/");
+        String backToContextPath = PathUtil.backToContext(realm);
+        assertEquals("Incorrect backToContextPath for realm mount point: " + realm.getMountPoint(), "", backToContextPath);
+        
+        realm = new Realm("test", "test", "/test/usecase/");
+        backToContextPath = PathUtil.backToContext(realm);
+        assertEquals("Incorrect backToContextPath for realm mount point: " + realm.getMountPoint(), "../../", backToContextPath);
+        
+        realm = new Realm("test", "test", "/yanel-website/");
+        backToContextPath = PathUtil.backToContext(realm);
+        assertEquals("Incorrect backToContextPath for realm mount point: " + realm.getMountPoint(), "../", backToContextPath);
+        
+    }
+    
+    /**
+     * Tests if the map returns the correct rti for a given path.
+     */
+    public void testBackToRealm() throws Exception {
+        String path = "/en/about.html";
+        String backToRealmPath = PathUtil.backToRealm(path);
+        assertEquals("Incorrect backToRealmPath for path: " + path.toString(), "../", backToRealmPath);
+
+        path = "/en/";
+        backToRealmPath = PathUtil.backToRealm(path);
+        assertEquals("Incorrect backToRealmPath for path: " + path.toString(), "../", backToRealmPath);
+
+        path = "/";
+        backToRealmPath = PathUtil.backToRealm(path);
+        assertEquals("Incorrect backToRealmPath for path: " + path.toString(), "", backToRealmPath);
+    }
+}




More information about the Yanel-commits mailing list