Author: thorsten Date: Thu Sep 11 05:57:52 2008 New Revision: 694233 URL: http://svn.apache.org/viewvc?rev=694233&view=rev Log: Adding test cases to invoke various transformations of a test contract
Added: forrest/trunk/whiteboard/dispatcher/testing/ forrest/trunk/whiteboard/dispatcher/testing/org/ forrest/trunk/whiteboard/dispatcher/testing/org/apache/ forrest/trunk/whiteboard/dispatcher/testing/org/apache/forrest/ forrest/trunk/whiteboard/dispatcher/testing/org/apache/forrest/dispatcher/ forrest/trunk/whiteboard/dispatcher/testing/org/apache/forrest/dispatcher/TestContract.java (with props) forrest/trunk/whiteboard/dispatcher/testing/org/apache/forrest/dispatcher/master.contract.xml - copied, changed from r694158, forrest/trunk/whiteboard/dispatcher/themes/contracts/master.contract.xml Added: forrest/trunk/whiteboard/dispatcher/testing/org/apache/forrest/dispatcher/TestContract.java URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/testing/org/apache/forrest/dispatcher/TestContract.java?rev=694233&view=auto ============================================================================== --- forrest/trunk/whiteboard/dispatcher/testing/org/apache/forrest/dispatcher/TestContract.java (added) +++ forrest/trunk/whiteboard/dispatcher/testing/org/apache/forrest/dispatcher/TestContract.java Thu Sep 11 05:57:52 2008 @@ -0,0 +1,48 @@ +package org.apache.forrest.dispatcher; + +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.StringReader; +import java.util.HashMap; + +import org.apache.forrest.dispatcher.api.Contract; +import org.apache.forrest.dispatcher.impl.XSLContract; +import org.xml.sax.InputSource; + +import junit.framework.TestCase; + +public class TestContract extends TestCase { + + public void testContractWithoutParameter() throws DispatcherException, FileNotFoundException { + Contract contract = new XSLContract(false); + String rawContract = "master.contract.xml"; + InputStream xslStream = this.getClass().getResourceAsStream(rawContract); + contract.initializeFromStream(xslStream); + // testing the transformation without parameters + HashMap<String, String> properties = new HashMap<String, String>(); + contract.execute(null, properties); + } + public void testContractWithParameter() throws DispatcherException, FileNotFoundException { + Contract contract = new XSLContract(false); + String rawContract = "master.contract.xml"; + InputStream xslStream = this.getClass().getResourceAsStream(rawContract); + contract.initializeFromStream(xslStream); + HashMap<String, String> properties = new HashMap<String, String>(); + // testing the transformation with parameters + properties.put("test-inline", this.getClass().getCanonicalName()); + contract.execute(null, properties); + } + public void testContractWithXMLParameter() throws DispatcherException, FileNotFoundException { + Contract contract = new XSLContract(true); + String rawContract = "master.contract.xml"; + InputStream xslStream = this.getClass().getResourceAsStream(rawContract); + contract.initializeFromStream(xslStream); + HashMap<String, InputSource> properties = new HashMap<String, InputSource>(); + // testing the transformation with parameters + String valueString = "<class>"+this.getClass().getCanonicalName()+"</class>"; + InputSource value = new InputSource(new StringReader(valueString)); + properties.put("test-inline-xml", value); + contract.execute(null, properties); + } + +} Propchange: forrest/trunk/whiteboard/dispatcher/testing/org/apache/forrest/dispatcher/TestContract.java ------------------------------------------------------------------------------ svn:eol-style = native Copied: forrest/trunk/whiteboard/dispatcher/testing/org/apache/forrest/dispatcher/master.contract.xml (from r694158, forrest/trunk/whiteboard/dispatcher/themes/contracts/master.contract.xml) URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/testing/org/apache/forrest/dispatcher/master.contract.xml?p2=forrest/trunk/whiteboard/dispatcher/testing/org/apache/forrest/dispatcher/master.contract.xml&p1=forrest/trunk/whiteboard/dispatcher/themes/contracts/master.contract.xml&r1=694158&r2=694233&rev=694233&view=diff ============================================================================== --- forrest/trunk/whiteboard/dispatcher/themes/contracts/master.contract.xml (original) +++ forrest/trunk/whiteboard/dispatcher/testing/org/apache/forrest/dispatcher/master.contract.xml Thu Sep 11 05:57:52 2008 @@ -35,7 +35,8 @@ name="master" inputFormat="xsl"> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> - <xsl:param name="test-inline" select="'test.html'"/> + <xsl:param name="test-inline" select="'No parameter has been passed'"/> + <xsl:param name="test-inline-xml" select="'No xml parameter has been passed'"/> <xsl:template match="/"> <!-- The dispatcher needs a well-formed xml document to work with. The forrest:content element (as root element) can contain as many forrest:part's as you want. --> @@ -44,6 +45,8 @@ If you use no @xpath then we insert content on the current structurer position.--> <forrest:part> Content going to the location defined by the structurer. + $test-inline: <xsl:value-of select="$test-inline"/> + $test-inline-xml: <xsl:copy-of select="$test-inline-xml"/> </forrest:part> <!--If you want to inject the content into a certain DOM position and *not* the current position in the structurer, you can use the @xpath attribute. -->