You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2006/07/24 16:43:43 UTC

svn commit: r425074 - in /lenya/docu/src/documentation/content/xdocs: 1_4/reference/tests.xml site.xml

Author: andreas
Date: Mon Jul 24 07:43:43 2006
New Revision: 425074

URL: http://svn.apache.org/viewvc?rev=425074&view=rev
Log:
Added documentation for 1.4 tests

Added:
    lenya/docu/src/documentation/content/xdocs/1_4/reference/tests.xml
Modified:
    lenya/docu/src/documentation/content/xdocs/site.xml

Added: lenya/docu/src/documentation/content/xdocs/1_4/reference/tests.xml
URL: http://svn.apache.org/viewvc/lenya/docu/src/documentation/content/xdocs/1_4/reference/tests.xml?rev=425074&view=auto
==============================================================================
--- lenya/docu/src/documentation/content/xdocs/1_4/reference/tests.xml (added)
+++ lenya/docu/src/documentation/content/xdocs/1_4/reference/tests.xml Mon Jul 24 07:43:43 2006
@@ -0,0 +1,155 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright 1999-2006 The Apache Software Foundation
+
+  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.
+-->
+<!-- $Id: metadata.xml 55543 2004-10-26 00:14:59Z gregor $ -->
+<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" 
+  "http://forrest.apache.org/dtd/document-v20.dtd">
+<document>
+  <header>
+    <title>Writing Tests</title>
+  </header>
+  <body>
+    
+    <section>
+      <title>Running Tests</title>
+      <ul>
+        <li><p>To run all tests:</p>
+          <code>./build.sh test</code>
+          <br/><br/>
+        </li>
+        <li><p>To run all module tests:</p>
+          <code>./build.sh modules.test</code>
+          <br/><br/>
+        </li>
+        <li><p>To run the tests of a single module:</p>
+          <code>./build.sh module.test -Dmodule=org.myproject.lenya.modules.MyModule</code>
+          <br/><br/>
+        </li>
+      </ul>
+    </section>
+    
+    <section>
+      <title>Adding Tests to Modules</title>
+      <p>
+        Adding unit tests to a module is very simple - you just have to put
+        a Java file in the <code>{yourmodule}/java/test</code>. The most
+        convenient way to get started is to extend <code>AbstractAccessControlTest</code>.
+        This class provides the infrastructure to create a session and invoke
+        operations on documents.
+      </p>
+      <p>
+        Here's an example:
+      </p>
+      
+      <source xml:space="preserve"><![CDATA[mymodule/java/test/MyModuleTest.java]]></source>
+      
+      <p>The source code:</p>
+      
+      <source xml:space="preserve"><![CDATA[package org.myproject.lenya;
+
+import org.apache.lenya.ac.impl.AbstractAccessControlTest;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentFactory;
+import org.apache.lenya.cms.publication.DocumentUtil;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationUtil;
+import org.apache.lenya.cms.repository.RepositoryUtil;
+import org.apache.lenya.cms.repository.Session;
+
+public class MetaDataTest extends AbstractAccessControlTest {
+
+    /**
+     * Tests my module.
+     */
+    public void testMyModule() throws Exception {
+        Session session = RepositoryUtil.getSession(getManager(), getRequest());
+        DocumentFactory factory = DocumentUtil.createDocumentIdentityMap(getManager(), session);
+
+        Publication publication = PublicationUtil.getPublication(getManager(), "test");
+        Document doc = factory.get(publication, Publication.AUTHORING_AREA, "/index", "en");
+
+        assertNotNull(doc);
+        ...        
+    }
+}]]></source>
+      
+    </section>
+    
+    <section>
+      <title>Testing Usecases</title>
+      <p>To implement a unit test for a usecase, you can extend the class
+        <code>AbstractUsecaseTest</code> and override the following methods:
+      </p>
+      <ul>
+        <li><code>String getUsecaseName()</code> - return the name of the usecase to test</li>
+        <li><code>void prepareUsecase()</code> - setup the initial envorionment</li>
+        <li><code>Map getParameters()</code> - return a map containing the usecase parameters</li>
+        <li><code>void checkPostconditions()</code> - check the post conditions after the usecase was executed</li>
+      </ul>
+      <p>  
+        Here's an example:
+      </p>
+      <source xml:space="preserve"><![CDATA[package org.apache.lenya.cms.ac.usecases;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cocoon.environment.Session;
+import org.apache.lenya.ac.AccessControlException;
+import org.apache.lenya.ac.Identity;
+import org.apache.lenya.ac.User;
+import org.apache.lenya.cms.usecase.AbstractUsecaseTest;
+
+/**
+ * Login test.
+ */
+public class LoginTest extends AbstractUsecaseTest {
+
+    protected static final String USER_ID = "lenya";
+    protected static final String PASSWORD = "levi";
+
+    protected Map getRequestParameters() {
+        return getParameters();
+    }
+    
+    protected Map getParameters() {
+        Map params = new HashMap();
+        params.put(Login.USERNAME, USER_ID);
+        params.put(Login.PASSWORD, PASSWORD);
+        return params;
+    }
+
+    protected String getUsecaseName() {
+        return "ac.login";
+    }
+
+    protected void checkPostconditions() {
+        Session session = getRequest().getSession();
+        Identity identity = (Identity) session.getAttribute(Identity.class.getName());
+        User user = identity.getUser();
+        assertNotNull(user);
+        assertEquals(user.getId(), USER_ID);
+    }
+    
+    protected void login() throws AccessControlException {
+        getAccessController().setupIdentity(getRequest());
+    }
+
+}]]></source>
+    </section>
+    
+  </body>
+</document>
\ No newline at end of file

Modified: lenya/docu/src/documentation/content/xdocs/site.xml
URL: http://svn.apache.org/viewvc/lenya/docu/src/documentation/content/xdocs/site.xml?rev=425074&r1=425073&r2=425074&view=diff
==============================================================================
--- lenya/docu/src/documentation/content/xdocs/site.xml (original)
+++ lenya/docu/src/documentation/content/xdocs/site.xml Mon Jul 24 07:43:43 2006
@@ -137,6 +137,7 @@
       <link-management href="link-management.html" label="Link Management"/>
       <notification href="notification.html" label="Notification"/>
       <repository href="repository/index.html" label="Repository"/>
+      <tests14 href="tests.html" label="Writing Tests"/>
     </reference>
     
     <javadoc1.4 href="../../../../apidocs/1.4/index.html" label="1.4 API (Javadoc)"/>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org