You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2004/02/23 05:10:41 UTC
cvs commit: jakarta-commons/jelly/src/test/org/apache/commons/jelly import1.jelly suite.jelly
dion 2004/02/22 20:10:41
Modified: jelly/src/test/org/apache/commons/jelly suite.jelly
Added: jelly/src/test/org/apache/commons/jelly import1.jelly
Log:
Add some tests for the import tag
Revision Changes Path
1.16 +295 -272 jakarta-commons/jelly/src/test/org/apache/commons/jelly/suite.jelly
Index: suite.jelly
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/src/test/org/apache/commons/jelly/suite.jelly,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- suite.jelly 7 Mar 2003 12:21:28 -0000 1.15
+++ suite.jelly 23 Feb 2004 04:10:41 -0000 1.16
@@ -1,294 +1,317 @@
<?xml version="1.0"?>
<test:suite
- xmlns:j="jelly:core"
- xmlns:test="jelly:junit">
+ xmlns:j="jelly:core"
+ xmlns:test="jelly:junit">
<test:case name="testSetAndRemove">
-
- <j:set var="x" value="abc"/>
-
- <test:assertEquals expected="abc" actual="${x}"/>
-
- <j:remove var="x"/>
-
- <test:assert test="${x == null}"/>
- <test:assert test="${empty x}"/>
-
+
+ <j:set var="x" value="abc"/>
+
+ <test:assertEquals expected="abc" actual="${x}"/>
+
+ <j:remove var="x"/>
+
+ <test:assert test="${x == null}"/>
+ <test:assert test="${empty x}"/>
+
</test:case>
-
<test:case name="testSetWithDefault">
-
- <j:set var="foo" value="abc"/>
- <j:set var="x" value="${doesNotExist}" defaultValue="${foo}"/>
-
- <test:assertEquals expected="abc" actual="${x}"/>
-
- <j:set var="doesNotExist" value="def"/>
- <j:set var="x" value="${doesNotExist}" defaultValue="${foo}"/>
-
- <test:assertEquals expected="def" actual="${x}"/>
-
+
+ <j:set var="foo" value="abc"/>
+ <j:set var="x" value="${doesNotExist}" defaultValue="${foo}"/>
+
+ <test:assertEquals expected="abc" actual="${x}"/>
+
+ <j:set var="doesNotExist" value="def"/>
+ <j:set var="x" value="${doesNotExist}" defaultValue="${foo}"/>
+
+ <test:assertEquals expected="def" actual="${x}"/>
+
</test:case>
<test:case name="testScope">
- <j:set var="outer" value="def"/>
+ <j:set var="outer" value="def"/>
- <test:assertEquals expected="def" actual="${outer}"/>
-
- <j:scope>
- <j:set var="x" value="abc"/>
-
- <test:assertEquals expected="abc" actual="${x}"/>
- <test:assertEquals expected="def" actual="${outer}"/>
- </j:scope>
-
- <test:assert test="${x == null}"/>
- <test:assert test="${empty x}"/>
-
+ <test:assertEquals expected="def" actual="${outer}"/>
+
+ <j:scope>
+ <j:set var="x" value="abc"/>
+
+ <test:assertEquals expected="abc" actual="${x}"/>
+ <test:assertEquals expected="def" actual="${outer}"/>
+ </j:scope>
+
+ <test:assert test="${x == null}"/>
+ <test:assert test="${empty x}"/>
+
</test:case>
-
+
<test:case name="testChoose">
-
- <j:set var="x" value="abc"/>
-
- <j:choose>
- <j:when test="${x == 'abc'}">
- this should always work
- </j:when>
- <j:when test="${x == 'xyz'}">
- <fail>This should never fail</fail>
- </j:when>
- <j:otherwise>
- <fail>This should never fail</fail>
- </j:otherwise>
- </j:choose>
-
- <j:choose>
- <j:when test="${x == 'xyz'}">
- <fail>This should never fail</fail>
- </j:when>
- <j:when test="${x == 'abc'}">
- this should always work
- </j:when>
- <j:otherwise>
- <fail>This should never fail</fail>
- </j:otherwise>
- </j:choose>
-
-
- <j:choose>
- <j:when test="${x == 'xyz'}">
- <fail>This should never fail</fail>
- </j:when>
- <j:when test="${x == 'zzz'}">
- <fail>This should never fail</fail>
- </j:when>
- <j:otherwise>
- this should always work
- </j:otherwise>
- </j:choose>
-
- </test:case>
-
-
- <test:case name="testIf">
-
- <j:set var="x" value="abc"/>
- <j:set var="worked" value="f"/>
-
- <j:if test="${x == 'abc'}">
- this should always work
- <j:set var="worked" value="t"/>
- </j:if>
-
- <test:assertEquals expected="t" actual="${worked}"/>
-
- <j:if test="${x == 'zzz'}">
- <fail>This should never fail</fail>
- </j:if>
-
- </test:case>
-
- <test:case name="testNewAndSetProperties">
- <j:new className="org.apache.commons.jelly.core.Customer" var="customer"/>
- <j:setProperties object="${customer}" name="James" city="London" />
-
- Created a new bean: ${customer}
-
- <test:assert test="${customer != null}">Created a customer bean</test:assert>
-
- <test:assertEquals
- expected="James"
- actual="${customer.name}"/>
-
- <test:assertEquals
- expected="London"
- actual="${customer.city}"/>
-
- <test:assertEquals
- expected="org.apache.commons.jelly.core.Customer"
- actual="${customer.class.name}"/>
- </test:case>
-
- <test:case name="testUseBean">
- <j:useBean var="customer" class="org.apache.commons.jelly.core.Customer" name="James" city="London" />
-
- Created a new bean: ${customer}
-
- <test:assert test="${customer != null}">Created a customer bean</test:assert>
-
- <test:assertEquals
- expected="James"
- actual="${customer.name}"/>
-
- <test:assertEquals
- expected="London"
- actual="${customer.city}"/>
-
- <test:assertEquals
- expected="org.apache.commons.jelly.core.Customer"
- actual="${customer.class.name}"/>
- </test:case>
-
- <test:case name="testUseBeanWithSetProperties">
- <j:useBean var="customer" class="org.apache.commons.jelly.core.Customer" name="James">
-
- <!-- typically the following tag might be nested inside some conditional logic -->
- <j:setProperties name="Bob" city="Atlanta"/>
- </j:useBean>
-
- Created a new bean: ${customer}
-
- <test:assert test="${customer != null}">Created a customer bean</test:assert>
-
- <test:assertEquals
- expected="Bob"
- actual="${customer.name}"/>
-
- <test:assertEquals
- expected="Atlanta"
- actual="${customer.city}"/>
-
- <test:assertEquals
- expected="org.apache.commons.jelly.core.Customer"
- actual="${customer.class.name}"/>
- </test:case>
-
- <test:case name="testSetWithNoEncoding">
- <j:set var="foo" encode="false">
- <foo x="1">hello</foo>
- </j:set>
-
- <test:assertEquals
- expected='<foo x="1">hello</foo>'
- actual="${foo}"/>
- </test:case>
-
- <test:case name="testFileToVar">
- <j:file var="foo" omitXmlDeclaration="true">
- <foo x="1">hello</foo>
- </j:file>
-
- <test:assertEquals
- expected='<foo x="1">hello</foo>'
- actual="${foo}"/>
- </test:case>
-
-
- <!-- whitespace trimming tests -->
- <test:case name="testTrim">
-
- <j:set var="foo">
- <j:forEach var="i" begin="1" end="3" trim="false"> ${i} </j:forEach>
- </j:set>
-
- <test:assertEquals
- expected=" 1 2 3 "
- actual="${foo}"/>
-
- <j:set var="foo">
- <j:forEach var="i" begin="1" end="3" trim="true"> ${i} </j:forEach>
- </j:set>
-
- <test:assertEquals
- expected="123"
- actual="${foo}"/>
-
- <j:set var="foo">
- <j:forEach var="i" begin="1" end="3" trim="true"> foo ${i} </j:forEach>
- </j:set>
-
- <test:assertEquals
- expected="foo 1foo 2foo 3"
- actual="${foo}"/>
-
- <j:set var="foo">
- <j:forEach var="i" begin="1" end="3" trim="true"> foo ${i} bar </j:forEach>
- </j:set>
-
- <test:assertEquals
- expected="foo 1 barfoo 2 barfoo 3 bar"
- actual="${foo}"/>
+
+ <j:set var="x" value="abc"/>
+
+ <j:choose>
+ <j:when test="${x == 'abc'}">
+ this should always work
+ </j:when>
+ <j:when test="${x == 'xyz'}">
+ <fail>This should never fail</fail>
+ </j:when>
+ <j:otherwise>
+ <fail>This should never fail</fail>
+ </j:otherwise>
+ </j:choose>
+
+ <j:choose>
+ <j:when test="${x == 'xyz'}">
+ <fail>This should never fail</fail>
+ </j:when>
+ <j:when test="${x == 'abc'}">
+ this should always work
+ </j:when>
+ <j:otherwise>
+ <fail>This should never fail</fail>
+ </j:otherwise>
+ </j:choose>
+
+
+ <j:choose>
+ <j:when test="${x == 'xyz'}">
+ <fail>This should never fail</fail>
+ </j:when>
+ <j:when test="${x == 'zzz'}">
+ <fail>This should never fail</fail>
+ </j:when>
+ <j:otherwise>
+ this should always work
+ </j:otherwise>
+ </j:choose>
+
+ </test:case>
+
+
+ <test:case name="testIf">
+
+ <j:set var="x" value="abc"/>
+ <j:set var="worked" value="f"/>
+
+ <j:if test="${x == 'abc'}">
+ this should always work
+ <j:set var="worked" value="t"/>
+ </j:if>
+
+ <test:assertEquals expected="t" actual="${worked}"/>
+
+ <j:if test="${x == 'zzz'}">
+ <fail>This should never fail</fail>
+ </j:if>
+
+ </test:case>
+
+ <test:case name="testNewAndSetProperties">
+ <j:new className="org.apache.commons.jelly.core.Customer" var="customer"/>
+ <j:setProperties object="${customer}" name="James" city="London" />
+
+ Created a new bean: ${customer}
+
+ <test:assert test="${customer != null}">Created a customer bean</test:assert>
+
+ <test:assertEquals
+ expected="James"
+ actual="${customer.name}"/>
+
+ <test:assertEquals
+ expected="London"
+ actual="${customer.city}"/>
+
+ <test:assertEquals
+ expected="org.apache.commons.jelly.core.Customer"
+ actual="${customer.class.name}"/>
+ </test:case>
+
+ <test:case name="testUseBean">
+ <j:useBean var="customer" class="org.apache.commons.jelly.core.Customer" name="James" city="London" />
+
+ Created a new bean: ${customer}
+
+ <test:assert test="${customer != null}">Created a customer bean</test:assert>
+
+ <test:assertEquals
+ expected="James"
+ actual="${customer.name}"/>
+
+ <test:assertEquals
+ expected="London"
+ actual="${customer.city}"/>
+
+ <test:assertEquals
+ expected="org.apache.commons.jelly.core.Customer"
+ actual="${customer.class.name}"/>
+ </test:case>
+
+ <test:case name="testUseBeanWithSetProperties">
+ <j:useBean var="customer" class="org.apache.commons.jelly.core.Customer" name="James">
+
+ <!-- typically the following tag might be nested inside some conditional logic -->
+ <j:setProperties name="Bob" city="Atlanta"/>
+ </j:useBean>
+
+ Created a new bean: ${customer}
+
+ <test:assert test="${customer != null}">Created a customer bean</test:assert>
+
+ <test:assertEquals
+ expected="Bob"
+ actual="${customer.name}"/>
+
+ <test:assertEquals
+ expected="Atlanta"
+ actual="${customer.city}"/>
+
+ <test:assertEquals
+ expected="org.apache.commons.jelly.core.Customer"
+ actual="${customer.class.name}"/>
+ </test:case>
+
+ <test:case name="testSetWithNoEncoding">
+ <j:set var="foo" encode="false">
+ <foo x="1">hello</foo>
+ </j:set>
+
+ <test:assertEquals
+ expected='<foo x="1">hello</foo>'
+ actual="${foo}"/>
+ </test:case>
+
+ <test:case name="testFileToVar">
+ <j:file var="foo" omitXmlDeclaration="true">
+ <foo x="1">hello</foo>
+ </j:file>
+
+ <test:assertEquals
+ expected='<foo x="1">hello</foo>'
+ actual="${foo}"/>
+ </test:case>
+
+
+ <!-- whitespace trimming tests -->
+ <test:case name="testTrim">
+
+ <j:set var="foo">
+ <j:forEach var="i" begin="1" end="3" trim="false"> ${i} </j:forEach>
+ </j:set>
+
+ <test:assertEquals
+ expected=" 1 2 3 "
+ actual="${foo}"/>
+
+ <j:set var="foo">
+ <j:forEach var="i" begin="1" end="3" trim="true"> ${i} </j:forEach>
+ </j:set>
+
+ <test:assertEquals
+ expected="123"
+ actual="${foo}"/>
+
+ <j:set var="foo">
+ <j:forEach var="i" begin="1" end="3" trim="true"> foo ${i} </j:forEach>
+ </j:set>
+
+ <test:assertEquals
+ expected="foo 1foo 2foo 3"
+ actual="${foo}"/>
+
+ <j:set var="foo">
+ <j:forEach var="i" begin="1" end="3" trim="true"> foo ${i} bar </j:forEach>
+ </j:set>
+
+ <test:assertEquals
+ expected="foo 1 barfoo 2 barfoo 3 bar"
+ actual="${foo}"/>
</test:case>
- <test:case name="testBreak">
-
- <j:forEach var="i" begin="1" end="10">
- <j:if test="${i==4}">
- <j:break/>
- </j:if>
- </j:forEach>
-
- <test:assertTrue test="${i==4}"/>
-
- <j:while test="${i != 10}">
- <j:if test="${i==6}">
- <j:break/>
- </j:if>
- <j:set var="i" value="${i+1}"/>
- </j:while>
+ <test:case name="testBreak">
+
+ <j:forEach var="i" begin="1" end="10">
+ <j:if test="${i==4}">
+ <j:break/>
+ </j:if>
+ </j:forEach>
+
+ <test:assertTrue test="${i==4}"/>
+
+ <j:while test="${i != 10}">
+ <j:if test="${i==6}">
+ <j:break/>
+ </j:if>
+ <j:set var="i" value="${i+1}"/>
+ </j:while>
- <test:assertTrue test="${i==6}"/>
-
+ <test:assertTrue test="${i==6}"/>
+
</test:case>
- <test:case name="testBreakWithIf">
-
- <j:forEach var="i" begin="1" end="10">
- <j:break test="${i==4}"/>
- </j:forEach>
-
- <test:assertTrue test="${i==4}"/>
-
- <j:while test="${i != 10}">
- <j:break test="${i==6}"/>
- <j:set var="i" value="${i+1}"/>
- </j:while>
-
- <test:assertTrue test="${i==6}"/>
-
- </test:case>
-
- <test:case name="testVariablesWithDots">
-
- <j:set var="page.name" value="a"/>
- <j:set var="page.foo" value="b"/>
-
-
- <test:assertEquals expected="a" actual="${page.name}"/>
- <test:assertEquals expected="b" actual="${page.foo}"/>
-
- <j:set var="outer" value="def"/>
-
- <test:assertEquals expected="def" actual="${outer}"/>
-
- <j:scope>
- <test:assertEquals expected="a" actual="${page.name}"/>
- <test:assertEquals expected="b" actual="${page.foo}"/>
- </j:scope>
-
+ <test:case name="testBreakWithIf">
+
+ <j:forEach var="i" begin="1" end="10">
+ <j:break test="${i==4}"/>
+ </j:forEach>
+
+ <test:assertTrue test="${i==4}"/>
+
+ <j:while test="${i != 10}">
+ <j:break test="${i==6}"/>
+ <j:set var="i" value="${i+1}"/>
+ </j:while>
+
+ <test:assertTrue test="${i==6}"/>
+
+ </test:case>
+
+ <test:case name="testVariablesWithDots">
+
+ <j:set var="page.name" value="a"/>
+ <j:set var="page.foo" value="b"/>
+
+
+ <test:assertEquals expected="a" actual="${page.name}"/>
+ <test:assertEquals expected="b" actual="${page.foo}"/>
+
+ <j:set var="outer" value="def"/>
+
+ <test:assertEquals expected="def" actual="${outer}"/>
+
+ <j:scope>
+ <test:assertEquals expected="a" actual="${page.name}"/>
+ <test:assertEquals expected="b" actual="${page.foo}"/>
+ </j:scope>
+
+ </test:case>
+
+ <!-- tests to make sure import works -->
+ <test:case name="testImport">
+
+ <j:set var="parentVar" value="12" />
+
+ <!-- imported scripts by default do not inherit parent vars,
+ but export to them -->
+ <j:set var="test1" value="original"/>
+ <j:import uri="import1.jelly"/>
+ <test:assertTrue test="${test1 == null}"/>
+
+ <!-- inherit parent vars, and export to them -->
+ <j:set var="test1" value="original"/>
+ <j:import uri="import1.jelly" inherit="true"/>
+ <test:assertEquals expected="12" actual="${test1}"/>
+
+ <!-- explicitly do not inherit parent vars,
+ but export to them -->
+ <j:set var="test1" value="original"/>
+ <j:import uri="import1.jelly" inherit="false"/>
+ <test:assertTrue test="${test1 == null}"/>
+
</test:case>
</test:suite>
1.1 jakarta-commons/jelly/src/test/org/apache/commons/jelly/import1.jelly
Index: import1.jelly
===================================================================
<jelly xmlns="jelly:core">
<set var="test1" value="${parentVar}"/>
</jelly>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org