cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@cocoon.zones.apache.org
Subject [DAISY] Updated: Apache Cocoon Tests
Date Sat, 07 Jul 2007 13:14:14 GMT
A document has been updated:

http://cocoon.zones.apache.org/daisy/documentation/636.html

Document ID: 636
Branch: main
Language: default
Name: Apache Cocoon Tests (unchanged)
Document Type: Cocoon Document (unchanged)
Updated on: 7/3/07 6:52:23 PM
Updated by: Grzegorz Kossakowski

A new version has been created, state: publish

Parts
=====

Content
-------
This part has been updated.
Mime type: text/xml (unchanged)
File name:  (unchanged)
Size: 9584 bytes (previous version: 6730 bytes)
Content diff:
(88 equal lines skipped)
    
    <p class="note">It useful to check <tt>S</tt><tt>itemapComponentTestCase</tt>
    and <tt>CocoonTestCase</tt> source code (or Javadocs) to find out what methods
--- are already provided for your convenience.</p>
+++ are already provided for your convenience.<br/>
+++ For example, very convient method for use is <tt>lookup()</tt> that enables
you
+++ to look up for a new instance of Avalon component properly initialized according
+++ to Avalon's lifecycle management.</p>
    
--- <h3>Execute the test</h3>
+++ <h3 id="execute-test-avalon">Execute the test</h3>
    
    <p>As stated earlier Maven will execute all tests every time the build is
    performed so if you want to check if everything is working you can go to root
(24 equal lines skipped)
    
    <h2>How to add more JUnit tests for Spring-managed class</h2>
    
--- <p class="fixme">TO BE DONE (soon)</p>
+++ <p>I suggest to read a section above describing how to write tests for Avalon
+++ components because I will show only focus on differences in particular steps.
+++ This time, we will examine how to write test for classes handling expression
+++ evaluation from <tt>cocoon-expression-language-impl</tt>. Let's assume we
create
+++ test named "Expression".</p>
    
+++ <h3>Components configuration</h3>
+++ 
+++ <p>Instead of creating <tt>*.xtest</tt> file you must create
+++ <tt>*.spring.xml</tt> file to configure Spring beans. First we create
+++ <tt>ExpressionTestCase.spring.xml</tt> file with contents like this:</p>
+++ 
+++ <pre>&lt;beans xmlns="http://www.springframework.org/schema/beans"
+++   xmlns:p="http://www.springframework.org/schema/p"
+++   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+++   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"&gt;
+++   
+++   &lt;import resource="classpath:META-INF/cocoon/spring/DefaultExpressionFactory.xml"/&gt;
+++   &lt;import resource="classpath:META-INF/cocoon/spring/JavaScriptCompiler.xml"/&gt;
+++   &lt;import resource="classpath:META-INF/cocoon/spring/JexlCompiler.xml"/&gt;
+++   &lt;import resource="classpath:META-INF/cocoon/spring/JXPathCompiler.xml"/&gt;
+++   
+++ &lt;/beans&gt;
+++ </pre>
+++ 
+++ <p>As you can see we only import other configuration files that are, in a fact,
+++ ordinar configuration files used in development. This approach is much cleaner
+++ than one used for Avalon class testing because you have to configure particular
+++ bean only one time and reuse this configuration while testing.</p>
+++ 
+++ <h3>Java test-case</h3>
+++ 
+++ <p>As writing test-case class for Spring bean is not much different from writing
+++ corresponding class for Avalon component I'm not going to describe it in detail.
+++ </p>
+++ 
+++ <p>The only difference that I would like to point out is how you should get an
+++ instance of Spring bean. Instead of using lookup method you should use
+++ <tt>getFactoryBean().getBean()</tt> method.</p>
+++ 
+++ <p>Take a look at this method as an example:</p>
+++ 
+++ <pre>public void testFactoryJexl() throws ExpressionException {
+++   ExpressionFactory factory = (ExpressionFactory) this.getBeanFactory().getBean(ExpressionFactory.ROLE);
+++   assertNotNull("Test lookup of expression factory", factory);
+++ 
+++   Expression expression = factory.getExpression("jexl", "1+2");
+++   assertNotNull("Test expression compilation", expression);
+++ 
+++   assertEquals(new Long(3), expression.evaluate(new ExpressionContext()));
+++ }
+++ </pre>
+++ 
+++ <h3>Execute the test</h3>
+++ 
+++ <p>Tests for Spring beans should be executed exactly the same way that tests for
+++ Avalon components are executed so I point you to instructions
+++ <a href="#execute-test-avalon">above</a>.</p>
+++ 
    <h1>htmlunit Tests</h1>
    
    <p class="fixme">I do not know what is the status of htmlunit tests in trunk,
(11 equal lines skipped)


Mime
View raw message