blob: 805cf0fe5cb48f5141d43c14792c24fdb9fb687f [file] [log] [blame]
<?xml version="1.0"?>
<!--
Copyright 2002,2004 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.
-->
<test:suite
xmlns:j="jelly:core"
xmlns:x="jelly:xml"
xmlns:test="jelly:junit"
xmlns:log="jelly:log"
xmlns:define="jelly:define"
xmlns:dynamicTest="dynamicTest">
<test:case name="invoke">
<define:script var="fooScript">
<log:info>Generating some XML</log:info>
<foo id="1">
<bar>some XML</bar>
</foo>
</define:script>
<!-- now lets invoke the script -->
<x:parse var="doc">
<log:info>About to invoke the script!</log:info>
<define:invoke script="${fooScript}"/>
</x:parse>
<x:forEach select="$doc//foo">
<test:assert xpath="bar"/>
</x:forEach>
<test:assert xpath="$doc/foo/bar"/>
</test:case>
<test:case name="dynamicTag">
<!-- Init the new tag. -->
<define:taglib uri="dynamicTest">
<define:jellybean
name="test"
className="org.apache.commons.jelly.tags.define.DynamicTag"
/>
</define:taglib>
<j:set var="output">
<dynamicTest:test>
ignored output to make sure doTag is being called
</dynamicTest:test>
</j:set>
<test:assertEquals
expected="output - ignored body"
actual="${output}"
/>
</test:case>
<test:case name="dynaBeans"
xmlns:dynabean="jelly:dynabean"
xmlns:my="dynamicDynaBeanTest">
<!-- create a DynaClass -->
<dynabean:dynaclass var="CustomerType" name="CustomerDynaClass">
<dynabean:property name="name" type="String" />
<dynabean:property name="address" type="String" />
</dynabean:dynaclass>
<!-- Create a new tag library binding the dynabeans. -->
<define:taglib uri="dynamicDynaBeanTest">
<define:dynaBean
name="customer"
dynaClass="${CustomerType}"
/>
</define:taglib>
<!-- now lets create a customer -->
<my:customer var="customer" name="Customer 1" address="Address of Customer 1" />
<test:assert test="${customer != null}">Created a customer DynaBean</test:assert>
<test:assertEquals
expected="Customer 1"
actual="${customer.name}"/>
<test:assertEquals
expected="Address of Customer 1"
actual="${customer.address}"/>
<test:assertEquals
expected="CustomerDynaClass"
actual="${customer.dynaClass.name}"/>
</test:case>
<test:case name="testTaglibInheritTest" xmlns="taglibInherit">
<define:taglib uri="taglibInherit" inherit="false">
<define:tag name="foo">
bar
</define:tag>
</define:taglib>
<define:taglib uri="taglibInherit" inherit="true">
<define:tag name="foo2">
bar2
</define:tag>
</define:taglib>
<j:set var="output">
<foo/>
</j:set>
<test:assertEquals expected="bar" actual="${output}"/>
</test:case>
<test:case name="testExtend" xmlns="taglibExtend">
<define:taglib uri="taglibExtend" inherit="false">
<define:tag name="foo">
foo
</define:tag>
</define:taglib>
<j:set var="output"><foo/></j:set>
<test:assertEquals expected="foo" actual="${output}"/>
<!-- extend the foo tag -->
<define:taglib uri="taglibExtend" inherit="true">
<define:extend name="foo">
bar
</define:extend>
</define:taglib>
<j:set var="output">
<foo/>
</j:set>
<test:assertEquals expected="bar" actual="${output}"/>
</test:case>
<test:case name="testSuper" xmlns="taglibSuper">
<define:taglib uri="taglibSuper" inherit="false">
<define:tag name="foo">
foo
</define:tag>
</define:taglib>
<!-- extend the foo tag -->
<define:taglib uri="taglibSuper" inherit="true">
<define:extend name="foo">
<define:super/>
bar
</define:extend>
</define:taglib>
<j:set var="output">
<foo/>
</j:set>
<test:assertEquals expected="foobar" actual="${output}"/>
<!-- extend the foo tag -->
<define:taglib uri="taglibSuper" inherit="true">
<define:extend name="foo">
bar
<define:super/>
</define:extend>
</define:taglib>
<j:set var="output">
<foo/>
</j:set>
<test:assertEquals expected="barfoobar" actual="${output}"/>
</test:case>
<test:case name="testOverrideVariablesWithAttributes">
<define:taglib uri="testOverrideVariablesWithAttributes">
<define:tag name="getValueOfVarA">${varA}</define:tag>
</define:taglib>
<j:set var="varA" value="varA valueFromSet"/>
<j:set var="obtained"><getValueOfVarA varA="varA value from attribute"
xmlns="testOverrideVariablesWithAttributes"/></j:set>
<log:info>obtained is ${obtained}</log:info>
<test:assertEquals
expected="varA value from attribute"
actual ="${obtained}"/>
</test:case>
</test:suite>