Recipe12.6.Generating a Test Data-Entry Web Client


Recipe 12.6. Generating a Test Data-Entry Web Client

Problem

You want to test a process in isolation by entering information in a form and having the information converted into a message that is sent to a process.

Solution

This example generates a test data-entry tool's client side. It takes the shape of an HTML-based form that can be used to enter the fields that make up a message. It specifies that the form data be handled by a CGI that is generated in Recipe 12.7:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">   <xsl:output method="html" />       <xsl:param name="message"/>       <!--Key to locate data types by name -->   <xsl:key name="dataTypes" match="Structure" use="Name" />    <xsl:key name="dataTypes" match="Primitive" use="Name" />    <xsl:key name="dataTypes" match="Array" use="Name" />    <xsl:key name="dataTypes" match="Enumeration" use="Name" />       <xsl:template match="/">     <html>       <head>         <title><xsl:value-of select="$message"/> Entry</title>       </head>       <body bgcolor="#FFFFFF" text="#000000">         <h1><xsl:value-of select="$message"/> Entry</h1>         <form name="{concat($message,'Form')}" method="post"          action="{concat('/cgi-bin/',$message,'Process.pl')}">           <xsl:apply-templates select="*/Messages/Message[Name=$message]"/>           <br/><center><input type="submit" name="Submit" value="Submit"/></center>         </form>       </body>     </html>   </xsl:template>            <xsl:template match="Message">     <xsl:apply-templates select="key('dataTypes',DataTypeName)">       <xsl:with-param name="field" select="Name"/>     </xsl:apply-templates>   </xsl:template>       <xsl:template match="Structure">   <xsl:param name="field"/>   <table width="100%" border="0" cellspacing="1" cellpadding="1">     <tbody>       <xsl:for-each select="Members/Member">         <tr>           <td valign="top"><xsl:value-of select="Name"/></td>           <td>             <xsl:apply-templates select="key('dataTypes',DataTypeName)">               <xsl:with-param name="field"                          select="concat($field,'_',Name)"/>             </xsl:apply-templates>           </td>         </tr>      </xsl:for-each>     </tbody>   </table> </xsl:template>     <xsl:template match="*">   <xsl:param name="field"/>   <input type="text" name="{$field}" size="30"/> </xsl:template>    </xsl:stylesheet>

Discussion

Generating the UI in HTML is one of the easiest ways to auto-generate a test-data front-end; however, it is not the only way. You might also want to generate a text-based front-end that prompts and reads input from stdin. If you feel ambitious, you might generate a GUI front end. One advantage of not using HTML is that you can combine the functionality of this example and Recipe 12.7 into a single application. However, do not be surprised if such a generator is more complex than the generators produced in these examples; the HTML-CGI approach builds on a substantial existing infrastructure present in the browser and web server.

An important extension to this recipe would generate validation code in JavaScript or VBScript. Again, the quality of this validation code depends on what type of metadata is kept in the repository. You might want to extend the repository to store minimum and maximum values and/or regular expressions for use in data validation.




XSLT Cookbook
XSLT Cookbook: Solutions and Examples for XML and XSLT Developers, 2nd Edition
ISBN: 0596009747
EAN: 2147483647
Year: 2003
Pages: 208
Authors: Sal Mangano

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net