blob: 5ea20a41ebff8145609edb3a39611b8a058b3708 [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:mytags="jelly:org.apache.commons.jelly.tags.bean.MyTagLibrary"
xmlns:mytags2="jelly:org.apache.commons.jelly.tags.bean.MyBeanTagLibrary"
xmlns="jelly:bean"
xmlns:test="jelly:junit"
xmlns:log="jelly:log">
<!-- need to do this so the bean taglib recognizes the customer root tag. For nested
tags, the object type is inferred from the available accessor methods. This definition
is used by the testNestedBeanTag and testBeanList cases. The nesting level at
which it appears does not play any role - it becomes globally visible after it is executed -->
<beandef name="customer" className="org.apache.commons.jelly.tags.bean.Customer"/>
<beandef name="manager" className="org.apache.commons.jelly.tags.bean.Manager" methodName="run"/>
<test:case name="testNestedBeanTag">
<customer var="c1" name="James" location="London" >
<order amount="100" price="2.99">
<product id="p1" name="Beer"/>
</order>
<order amount="200" price="4.99">
<product id="p2" name="Pizza"/>
</order>
</customer>
<log:info>Created a customer with name: ${c1.name} and location: ${c1.location}</log:info>
<log:info>Customer has orders ${c1.orders}</log:info>
<test:assertEquals expected="James" actual="${c1.name}"/>
<test:assertEquals expected="London" actual="${c1.location}"/>
<test:assert test="${size(c1.orders) == 2}"/>
<test:assert test="${c1.orders[0].amount == 100}"/>
<test:assert test="${c1.orders[0].price == 2.99}"/>
<test:assert test="${c1.orders[1].amount == 200}"/>
<test:assert test="${c1.orders[1].price == 4.99}"/>
<test:assert test="${c1.orders[0].product != null}"/>
<test:assert test="${c1.orders[1].product != null}"/>
<test:assertEquals expected="p1" actual="${c1.orders[0].product.id}"/>
<test:assertEquals expected="Beer" actual="${c1.orders[0].product.name}"/>
<test:assertEquals expected="p2" actual="${c1.orders[1].product.id}"/>
<test:assertEquals expected="Pizza" actual="${c1.orders[1].product.name}"/>
</test:case>
<test:case name="testNestedBeanPropertyTag">
<!--
|| This test uses a custom library which has the customer tag registered
|| Therefore, the beandef is not required
-->
<mytags:customer var="c1" name="James" location="London" >
<order amount="100" price="2.99">
<product id="p1" name="Beer"/>
</order>
<order amount="200" price="4.99">
<product id="p2" name="Pizza"/>
</order>
</mytags:customer>
<log:info>Created a customer with name: ${c1.name} and location: ${c1.location}</log:info>
<log:info>Customer has orders ${c1.orders}</log:info>
<test:assertEquals expected="James" actual="${c1.name}"/>
<test:assertEquals expected="London" actual="${c1.location}"/>
<test:assert test="${size(c1.orders) == 2}"/>
<test:assert test="${c1.orders[0].amount == 100}"/>
<test:assert test="${c1.orders[0].price == 2.99}"/>
<test:assert test="${c1.orders[1].amount == 200}"/>
<test:assert test="${c1.orders[1].price == 4.99}"/>
<test:assert test="${c1.orders[0].product != null}"/>
<test:assert test="${c1.orders[1].product != null}"/>
<test:assertEquals expected="p1" actual="${c1.orders[0].product.id}"/>
<test:assertEquals expected="Beer" actual="${c1.orders[0].product.name}"/>
<test:assertEquals expected="p2" actual="${c1.orders[1].product.id}"/>
<test:assertEquals expected="Pizza" actual="${c1.orders[1].product.name}"/>
</test:case>
<test:case name="testNestedBeanPropertyTag2">
<!--
|| as above but uses a non-BeanTagLibrary library.
|| i.e. just reusing the BeanTag and BeanPropertyTag
-->
<mytags2:customer var="c1" name="James" location="London" >
<order amount="100" price="2.99">
<product id="p1" name="Beer"/>
</order>
<order amount="200" price="4.99">
<product id="p2" name="Pizza"/>
</order>
</mytags2:customer>
<log:info>Created a customer with name: ${c1.name} and location: ${c1.location}</log:info>
<log:info>Customer has orders ${c1.orders}</log:info>
<test:assertEquals expected="James" actual="${c1.name}"/>
<test:assertEquals expected="London" actual="${c1.location}"/>
<test:assert test="${size(c1.orders) == 2}"/>
<test:assert test="${c1.orders[0].amount == 100}"/>
<test:assert test="${c1.orders[0].price == 2.99}"/>
<test:assert test="${c1.orders[1].amount == 200}"/>
<test:assert test="${c1.orders[1].price == 4.99}"/>
<test:assert test="${c1.orders[0].product != null}"/>
<test:assert test="${c1.orders[1].product != null}"/>
<test:assertEquals expected="p1" actual="${c1.orders[0].product.id}"/>
<test:assertEquals expected="Beer" actual="${c1.orders[0].product.name}"/>
<test:assertEquals expected="p2" actual="${c1.orders[1].product.id}"/>
<test:assertEquals expected="Pizza" actual="${c1.orders[1].product.name}"/>
</test:case>
<test:case name="testBeanList">
<j:useList var="list">
<customer name="James" location="London">
<order amount="100" price="2.99">
<product id="p1" name="Beer"/>
</order>
<order amount="200" price="4.99">
<product id="p2" name="Pizza"/>
</order>
</customer>
<customer name="Bob" location="Atlanta">
<order amount="200" price="2.99">
<product id="p1" name="Beer"/>
</order>
</customer>
</j:useList>
<log:info>Created a list of customers ${list}</log:info>
<test:assert test="${size(list) == 2}"/>
<test:assertEquals expected="James" actual="${list[0].name}"/>
<test:assertEquals expected="London" actual="${list[0].location}"/>
<test:assert test="${size(list[0].orders) == 2}"/>
<test:assert test="${list[0].orders[0].amount == 100}"/>
<test:assert test="${list[0].orders[0].price == 2.99}"/>
<test:assert test="${list[0].orders[1].amount == 200}"/>
<test:assert test="${list[0].orders[1].price == 4.99}"/>
<test:assert test="${list[0].orders[0].product != null}"/>
<test:assert test="${list[0].orders[1].product != null}"/>
<test:assertEquals expected="p1" actual="${list[0].orders[0].product.id}"/>
<test:assertEquals expected="Beer" actual="${list[0].orders[0].product.name}"/>
<test:assertEquals expected="p2" actual="${list[0].orders[1].product.id}"/>
<test:assertEquals expected="Pizza" actual="${list[0].orders[1].product.name}"/>
<test:assertEquals expected="Bob" actual="${list[1].name}"/>
<test:assertEquals expected="Atlanta" actual="${list[1].location}"/>
</test:case>
<test:case name="testInvokeMethod">
<manager var="foo">
<customer name="James" location="London">
<order amount="100" price="2.99">
<product id="p1" name="Beer"/>
</order>
<order amount="200" price="4.99">
<product id="p2" name="Pizza"/>
</order>
</customer>
<customer name="Bob" location="Atlanta">
<order amount="200" price="2.99">
<product id="p1" name="Beer"/>
</order>
</customer>
</manager>
<test:assert test="${foo.isInvoked()}"/>
<test:assert test="${size(foo.customers) == 2}"/>
</test:case>
<test:case name="testCollectionTag" xmlns="jelly:org.apache.commons.jelly.tags.bean.MyBeanTagLibrary">
<myContainer var="list">
<customer name="James" location="London">
<order amount="100" price="2.99">
<product id="p1" name="Beer"/>
</order>
<order amount="200" price="4.99">
<product id="p2" name="Pizza"/>
</order>
</customer>
<customer name="Bob" location="Atlanta">
<order amount="200" price="2.99">
<product id="p1" name="Beer"/>
</order>
</customer>
</myContainer>
<test:assert test="${size(list) == 2}"/>
Created list: ${list}
<test:assertEquals expected="James" actual="${list[0].name}"/>
<test:assertEquals expected="London" actual="${list[0].location}"/>
<test:assert test="${list[0].orders[0].amount == 100}"/>
<test:assert test="${list[0].orders[0].price == 2.99}"/>
<test:assert test="${list[0].orders[1].amount == 200}"/>
<test:assert test="${list[0].orders[1].price == 4.99}"/>
<test:assert test="${list[0].orders[0].product != null}"/>
<test:assert test="${list[0].orders[1].product != null}"/>
<test:assertEquals expected="p1" actual="${list[0].orders[0].product.id}"/>
<test:assertEquals expected="Beer" actual="${list[0].orders[0].product.name}"/>
<test:assertEquals expected="p2" actual="${list[0].orders[1].product.id}"/>
<test:assertEquals expected="Pizza" actual="${list[0].orders[1].product.name}"/>
<test:assertEquals expected="Bob" actual="${list[1].name}"/>
<test:assertEquals expected="Atlanta" actual="${list[1].location}"/>
</test:case>
</test:suite>