svn commit: r1027493 - in /lenya/trunk/org.apache.lenya.core.utils: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/lenya/ src/main/java/org/apache/lenya/utils/ src/main/java/org/apache/lenya/utils...

[email protected] Tue, 26 Oct 2010 12:09:44 -0000
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: florent
Date: Tue Oct 26 12:09:43 2010
New Revision: 1027493

URL: http://svn.apache.org/viewvc?rev=1027493&view=rev
Log:
Add an utilities module this module will contain classes that simplify currents operation.
- URLInformation.java will help to retrieve url information from spring container. This aim to suppress spring url retrieving operation from main code
- the o.a.l.utils.test package will provide classes for set up the test environment

Added:
    lenya/trunk/org.apache.lenya.core.utils/   (with props)
    lenya/trunk/org.apache.lenya.core.utils/pom.xml
    lenya/trunk/org.apache.lenya.core.utils/src/
    lenya/trunk/org.apache.lenya.core.utils/src/main/
    lenya/trunk/org.apache.lenya.core.utils/src/main/java/
    lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/
    lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/
    lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/lenya/
    lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/lenya/utils/
    lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/lenya/utils/URLInformation.java
      - copied, changed from r1026387, lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/URLInformation.java
    lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/lenya/utils/test/
    lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/lenya/utils/test/README
    lenya/trunk/org.apache.lenya.core.utils/src/main/resources/
    lenya/trunk/org.apache.lenya.core.utils/src/test/
    lenya/trunk/org.apache.lenya.core.utils/src/test/java/
    lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/
    lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/apache/
    lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/apache/lenya/
    lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/apache/lenya/utils/
    lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/apache/lenya/utils/URLInformationTest.java
      - copied, changed from r1026387, lenya/trunk/org.apache.lenya.core.api/src/test/java/org/apache/lenya/cms/publication/URLInformationTest.java

Propchange: lenya/trunk/org.apache.lenya.core.utils/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Oct 26 12:09:43 2010
@@ -0,0 +1,5 @@
+target
+.project
+.classpath
+.settings
+profiles.xml

Added: lenya/trunk/org.apache.lenya.core.utils/pom.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.utils/pom.xml?rev=1027493&view=auto
==============================================================================
--- lenya/trunk/org.apache.lenya.core.utils/pom.xml (added)
+++ lenya/trunk/org.apache.lenya.core.utils/pom.xml Tue Oct 26 12:09:43 2010
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.lenya</groupId>
+    <artifactId>lenya-parent</artifactId>
+    <version>2.2.0-SNAPSHOT</version>
+    <relativePath>../org.apache.lenya.parent/pom.xml</relativePath>
+  </parent>
+  <groupId>org.apache.lenya</groupId>
+  <artifactId>lenya-core-utils</artifactId>
+  <packaging>jar</packaging>
+  <name>Apache Lenya Utilities</name>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <!-- export our test classes in a separate jar -->
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/*TestCase.class</include>
+            <include>**/*Test.class</include>
+          </includes>
+          <excludes>
+            <exclude>**/Abstract*.class</exclude>
+          </excludes>
+          <!-- currently triggers NPE in surefire plugin
+            <systemProperties>
+            <property>
+            <name>junit.test.loglevel</name>
+            <value>3</value>
+            </property>
+            </systemProperties>
+          -->
+        </configuration>
+      </plugin>
+    </plugins>
+    <!-- <resources> -->
+    <!--   <resource> -->
+    <!--     <directory>src/main/resources</directory> -->
+    <!--     <filtering>false</filtering> -->
+    <!--     <excludes> -->
+    <!--       <exclude>META-INF/cocoon/properties/lenya.properties</exclude> -->
+    <!--     </excludes> -->
+    <!--   </resource> -->
+    <!--   <resource> -->
+    <!--     <directory>src/main/resources</directory> -->
+    <!--     <filtering>true</filtering> -->
+    <!--     <includes> -->
+    <!--       <include>META-INF/cocoon/properties/lenya.properties</include> -->
+    <!--     </includes> -->
+    <!--   </resource> -->
+    <!-- </resources> -->
+  </build>
+  
+  <properties>
+    <lenya.home>${basedir}/..</lenya.home>
+  </properties>
+  
+  <dependencies>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.avalon.framework</groupId>
+      <artifactId>avalon-framework-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-flowscript-impl</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-validator</groupId>
+      <artifactId>commons-validator</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-validation-impl</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-serializers-impl</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-chaperon-impl</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-xsp-impl</artifactId>
+      <version>1.0.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.lenya</groupId>
+      <artifactId>lenya-core-api</artifactId>
+    </dependency>
+    <!-- Tests -->
+     <dependency>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-mock</artifactId>
+        <scope>test</scope>
+      </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-core</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <!-- FIXME: This dependency is transitive and should be obtained automatically
+      see http://jira.codehaus.org/browse/MNG-1378 -->
+    <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-sitemap-impl</artifactId>
+      <scope>test</scope>
+      <type>test-jar</type>
+    </dependency>
+  </dependencies>
+</project>

Copied: lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/lenya/utils/URLInformation.java (from r1026387, lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/URLInformation.java)
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/lenya/utils/URLInformation.java?p2=lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/lenya/utils/URLInformation.java&p1=lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/URLInformation.java&r1=1026387&r2=1027493&rev=1027493&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/URLInformation.java (original)
+++ lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/lenya/utils/URLInformation.java Tue Oct 26 12:09:43 2010
@@ -16,12 +16,11 @@
  *
  */
 
-/* $Id$  */
-
-package org.apache.lenya.cms.publication;
+package org.apache.lenya.utils;
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.lenya.cms.publication.Publication;
 import org.springframework.web.context.request.RequestAttributes;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
@@ -36,17 +35,12 @@ public class URLInformation {
     private String completeArea = null;
     private String documentUrl = null;
 
-    private String url;
+    private String url = null;
+    
+    private String webappUrl = null;
 
     public URLInformation(){
-    	String webappUrl = getCurrentURI();
-    	setSourceURL(webappUrl);
-    }
-	/**
-     * Ctor.
-     * @param webappUrl A webapp URL (without context prefix).
-     */
-    public URLInformation(String webappUrl) {
+    	webappUrl = getCurrentURI();
     	setSourceURL(webappUrl);
     }
 	
@@ -67,6 +61,24 @@ public class URLInformation {
         this.url = webappUrl.substring(1);
     }
     
+    
+    /**
+     * Return the webapp url (with a / at the beginning
+     */
+    public String getWebappUrl(){
+    	return this.webappUrl;
+    }
+    /**
+     * Returns the publication ID.
+     * @return A string.
+     */
+    public String getPublicationId() {
+        if (this.publicationId == null) {
+            this.publicationId = extractBeforeSlash(this.url);
+        }
+        return this.publicationId;
+    }
+    
     /**
      * Returns the area (without the "webdav" prefix).
      * @return A string.
@@ -116,17 +128,6 @@ public class URLInformation {
         return this.documentUrl;
     }
 
-    /**
-     * Returns the publication ID.
-     * @return A string.
-     */
-    public String getPublicationId() {
-        if (this.publicationId == null) {
-            this.publicationId = extractBeforeSlash(this.url);
-        }
-        return this.publicationId;
-    }
-
     protected String extractBeforeSlash(String remaining) {
 
         if (remaining.length() == 0) {

Added: lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/lenya/utils/test/README
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/lenya/utils/test/README?rev=1027493&view=auto
==============================================================================
--- lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/lenya/utils/test/README (added)
+++ lenya/trunk/org.apache.lenya.core.utils/src/main/java/org/apache/lenya/utils/test/README Tue Oct 26 12:09:43 2010
@@ -0,0 +1 @@
+This package will contain utilities classes for create a complete test environnement
\ No newline at end of file

Copied: lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/apache/lenya/utils/URLInformationTest.java (from r1026387, lenya/trunk/org.apache.lenya.core.api/src/test/java/org/apache/lenya/cms/publication/URLInformationTest.java)
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/apache/lenya/utils/URLInformationTest.java?p2=lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/apache/lenya/utils/URLInformationTest.java&p1=lenya/trunk/org.apache.lenya.core.api/src/test/java/org/apache/lenya/cms/publication/URLInformationTest.java&r1=1026387&r2=1027493&rev=1027493&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.api/src/test/java/org/apache/lenya/cms/publication/URLInformationTest.java (original)
+++ lenya/trunk/org.apache.lenya.core.utils/src/test/java/org/apache/lenya/utils/URLInformationTest.java Tue Oct 26 12:09:43 2010
@@ -1,19 +1,61 @@
-package org.apache.lenya.cms.publication;
+package org.apache.lenya.utils;
 
-import org.junit.Ignore;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
 import org.junit.Test;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpSession;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
 
 public class URLInformationTest {
 	
-	@Ignore("First draft for mock the spring session") @Test
-	public void testSpringSessionSetUp() throws Exception{
-		/**
-		 * see this thread : http://forum.springsource.org/archive/index.php/t-50722.html
-		 * and specially the post of pbdavey ; May 28th, 2008, 03:10 PM
-		 * 
-		 * This issue is reported here : https://jira.springframework.org/browse/SPR-4588
-		 * 	
-		 */
+	String testUrl = "/test/authoring/DocumentTest.html";
+	
+	@Before
+	public void setMockURL(){
+		String mockURL = testUrl;
+		MockHttpServletRequest request = new MockHttpServletRequest("GET", mockURL);
+		MockHttpSession session = new MockHttpSession();
+		request.setSession(session);
+		RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
+	}
+	
+	@Test
+	public void getWebappUrl(){
+		URLInformation urli = new URLInformation();
+		String pubId = urli.getWebappUrl();
+		assertEquals(pubId,testUrl);
 		
 	}
+	
+	@Test
+	public void getPublicationIdTest(){
+		URLInformation urli = new URLInformation();
+		String pubId = urli.getPublicationId();
+		assertEquals(pubId,"test");
+	}
+	
+	@Test
+	public void getAreaTest(){
+		URLInformation urli = new URLInformation();
+		String area = urli.getArea();
+		assertEquals(area, "authoring");
+	}
+	
+	@Test
+	public void getCompleteAreaTest(){
+		URLInformation urli = new URLInformation();
+		String area = urli.getCompleteArea();
+		assertEquals(area, "authoring");
+	}
+	
+	@Test
+	public void getDocumentURL(){
+		URLInformation urli = new URLInformation();
+		String durl = urli.getDocumentUrl();
+		assertEquals(durl, "/DocumentTest.html");
+	}
+	
 }