<?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:test="jelly:junit" xmlns:mock="jelly:define" xmlns:log="jelly:log"> | |
<!-- lets create some mock tags and test a sample script that it evaluates the | |
|| mock tags as we'd expect | |
--> | |
<test:case name="testMockTags"> | |
<!-- lets create the Mock Tags to simulate the database and the web service --> | |
<!-- note that the mock library will only be in effiect in this JellyContext. | |
|| Each test:case has its own context | |
--> | |
<j:set var="foodKind" value="pizza"/> | |
<!-- <mock:taglib uri="jelly:sql"> | |
<mock:tag name="query"> | |
--> | |
<!-- generate a mock result set | |
<sql:resultSet var="results"> | |
<sql:row id="abc"/> | |
<sql:row id="def"/> | |
</sql:resultSet> | |
--> | |
<!-- since we are inside a Tag Context, lets export the results variable to the parent context | |
<j:set var="${var}" scope="parent" value="${results}"/>--> | |
<!-- </mock:tag> | |
<mock:tag name="param"> | |
<test:equals expects="pizza" value="${value}"/> | |
</mock:tag> | |
</mock:taglib> | |
--> | |
<mock:taglib uri="myFoodWebService"> | |
<mock:tag name="eat"> | |
<log:info>Invoking the eat web service with ${cheese}</log:info> | |
<!-- increment the counter, in the parent scope so not to use a local variable --> | |
<j:set var="eatServiceCount" scope="parent" value="${1+eatServiceCount}"/> | |
<j:choose> | |
<j:when test="${eatServiceCount == 1}"> | |
<test:assertEquals expected="abc" actual="${cheese}"/> | |
</j:when> | |
<j:when test="${eatServiceCount == 2}"> | |
<test:assertEquals expected="def" actual="${cheese}"/> | |
</j:when> | |
<j:otherwise> | |
<test:fail>Invoked eat web service too many times!</test:fail> | |
</j:otherwise> | |
</j:choose> | |
</mock:tag> | |
</mock:taglib> | |
<!-- now lets invoke the service using the Mock Tags --> | |
<j:include uri="service.jelly"/> | |
<!-- lets assert that the mock objects have been invoked correctly --> | |
<test:assert test="${eatServiceCount == 2}">Should have invoked the eat web service twice</test:assert> | |
</test:case> | |
</test:suite> |