<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Supergloo Code</title>
	<link>http://code.supergloo.com</link>
	<description>Code samples and programming tutorials</description>
	<pubDate>Sat, 09 Feb 2008 14:49:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3</generator>
	<language>en</language>
			<item>
		<title>Consuming FedEx Web Services from Grails using Apache CXF</title>
		<link>http://code.supergloo.com/2008/02/08/consuming-fedex-web-services-from-grails-using-apache-cxf/</link>
		<comments>http://code.supergloo.com/2008/02/08/consuming-fedex-web-services-from-grails-using-apache-cxf/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 22:25:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Grails]]></category>

		<category><![CDATA[Groovy]]></category>

		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://code.supergloo.com/2008/02/08/consuming-fedex-web-services-from-grails-using-apache-cxf/</guid>
		<description><![CDATA[A recent development task was integrating a FedEx web service consumer (client) in a Grails application.  Users require the ability to generate FedEx shipping labels from within the app.  To accomplish this, we call the SOAP based web services provided by FedEx.
I decided to use Apache CXF for the consumer code.
There were a [...]]]></description>
			<content:encoded><![CDATA[<p>A recent development task was integrating a <a href="http://fedex.com/developer" title="FedEx Web Service with Grails">FedEx </a>web service consumer (client) in a <a href="http://grails.org" title="Grails Framework">Grails </a>application.  Users require the ability to generate FedEx shipping labels from within the app.  To accomplish this, we call the SOAP based web services provided by FedEx.</p>
<p>I decided to use <a href="http://incubator.apache.org/cxf/" title="Apache CXF">Apache CXF</a> for the consumer code.</p>
<p>There were a couple of tricky parts:</p>
<p>1) The FedEx sample client code is <a href="http://ws.apache.org/axis/" title="Apache Axis">Axis </a>based.<br />
2) Integrating the Apache CXF code, libraries and configuration into Grails<br />
3) FedEx service is a secure (https) call</p>
<p>Let&#8217;s take a look at how each one of these items can be addressed:</p>
<p>1) The FedEx sample client code is Axis based.<br />
This one is easily solved by using CXF wsdl2java against the FedEx wsdl.  CXF tends to provide List based API instead of Arrays that Axis wsdl2java seems to prefer.  So, if you review the FedEx sample code which is for Axis, you&#8217;ll see much use of Arrays; just switch those over to use Lists.</p>
<p>2) Integrating the CXF code with Grails<br />
Like Grails, CXF also relies on Spring Framework.  Create a cxf.xml file for CXF configuration and drop it in the &#8220;conf/spring&#8221;<br />
directory in your Grails app.</p>
<p>conf/spring/cxf.xml:<br />
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xmlns:sec=&quot;http://cxf.apache.org/configuration/security&quot;
xmlns:http=&quot;http://cxf.apache.org/transports/http/configuration&quot;
xsi:schemalocation=&quot;http://cxf.apache.org/configuration/security
http://cxf.apache.org/schemas/configuration/security.xsd
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd&quot;&gt;
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;import</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;classpath:META-INF/cxf/cxf.xml&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;import</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;classpath:META-INF/cxf/cxf-extension-soap.xml&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;import</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;classpath:META-INF/cxf/cxf-servlet.xml&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;http</span>:conduit <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;{http://fedex.com/ws/ship/v3}ShipServicePort.http-conduit&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;http</span>:tlsclientparameters <span style="color: #000066;">securesocketprotocol</span>=<span style="color: #ff0000;">&quot;SSL&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/http</span>:tlsclientparameters<span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/http</span>:conduit<span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/beans<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre><br />
Include this file from the Grails/Spring conf/spring/resources.xml file:<br />
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;beans<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;import</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;ImageCaptchaFactories.xml&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;import</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;ImageCaptchaService.xml&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;import</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;EmailService.xml&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;import</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;cxf.xml&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/beans<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre><br />
Next, download the <a href="http://groovy.codehaus.org/GroovyWS" title="GroovyWS">GroovyWS </a>library from the Groovy site and drop it in your Grails lib directory.  At the time of this writing it was 0.2.0.  Finally,<br />
add the following jars from the Apache CXF - asm-2.2.3.jar, groovyws-standalone-0.2.0.jar, jaxws-api-2.0.jar, saaj-api-1.3.jar, saaj-impl-1.3.jar to your lib directory.</p>
<p>3) FedEx is a secure (https) call<br />
CXF doesn&#8217;t support SSL web service calls without a little <em><strong>configurary</strong></em>.  Ok, I made the word &#8220;configurary&#8221; up.  I&#8217;m pretty sure you can do that when you&#8217;re a blog author.</p>
<p>Anyhow, you&#8217;ve already seen how to do in step 2:<br />
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;http</span>:conduit <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;{http://fedex.com/ws/ship/v3}ShipServicePort.http-conduit&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;http</span>:tlsclientparameters <span style="color: #000066;">securesocketprotocol</span>=<span style="color: #ff0000;">&quot;SSL&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/http</span>:tlsclientparameters<span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/http</span>:conduit<span style="font-weight: bold; color: black;">&gt;</span></span></pre></p>
<p>For more information on CXF configuration see links [1], [2] below.</p>
<p>Ok, you&#8217;re ready to roll.  You can call the FedEx web service from within Grails.</p>
<p>I wrote this article to try save you some time.  If you see something that can be improved and save me some time, leave a comment.  Pasting XML code is a bit tricky, so hopefully it&#8217;s formatted ok for you.</p>
<p>As you can tell, this article is geared towards configuration rather than code.  Hopefully, it seems easy.  If it does seem easy, then I’ve achieved my objective.</p>
<p>If you want to see some more code that will probably blow-you-away on how technically gifted I am (oh, common, I&#8217;m not serious.  It&#8217;s just another bad joke like &#8220;configurary&#8221;.), let me know.  Or, if you are looking for a <a href="http://www.supergloo.com/contact.htm" title="Grails Developer For Hire">Grails developer</a>, I&#8217;m always interested in hearing about opportunities.</p>
<p>Reference</p>
<p>[1] CXF Site SSL Configuration <a href="http://cwiki.apache.org/CXF20DOC/client-http-transport-including-ssl-support.html">http://cwiki.apache.org/CXF20DOC/client-http-transport-including-ssl-support.html</a></p>
<p>[2] An article that helped with CXF SSL config: <a href="http://techpolesen.blogspot.com/2007/08/using-ssl-with-xfirecxf-battling.html">http://techpolesen.blogspot.com/2007/08/using-ssl-with-xfirecxf-battling.html </a></p>
]]></content:encoded>
			<wfw:commentRss>http://code.supergloo.com/2008/02/08/consuming-fedex-web-services-from-grails-using-apache-cxf/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Radiant CMS Database Form Extension</title>
		<link>http://code.supergloo.com/2007/12/12/radiant-cms-database-form-extension/</link>
		<comments>http://code.supergloo.com/2007/12/12/radiant-cms-database-form-extension/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 15:03:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[CMS]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://code.supergloo.com/2007/12/12/radiant-cms-database-form-extension/</guid>
		<description><![CDATA[With a few tweaks, the Radiant CMS Mailer Extension can be turned into an extension that allows form submissions (with
pre-post validation) to save to a database; e.g.
class DatabaseFormPage &#60; Page
&#160;
  class DatabaseFormError &#60; StandardError; end
&#160;
  attr_reader :form_name, :form_conf, :form_error, :form_data, :tag_attr
    
  # Page processing. If the page has [...]]]></description>
			<content:encoded><![CDATA[<p>With a few tweaks, the Radiant CMS Mailer Extension can be turned into an extension that allows form submissions (with<br />
pre-post validation) to save to a database; e.g.</p>
<p><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> DatabaseFormPage &lt; Page
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">class</span> DatabaseFormError &lt; StandardError; <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  attr_reader :form_name, :form_conf, :form_error, :form_data, :tag_attr
    
  <span style="color:#008000; font-style:italic;"># Page processing. If the page has posted-back, it will try to save to contacts table</span>
  <span style="color:#008000; font-style:italic;"># and redirect to a different page, if specified.</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> process<span style="color:#006600; font-weight:bold;">&#40;</span>request, response<span style="color:#006600; font-weight:bold;">&#41;</span>
    @request, @response = request, response
    @form_name, @form_error = <span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#0000FF; font-weight:bold;">nil</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> request.<span style="color:#9900CC;">post</span>?
      @form_data = request.<span style="color:#9900CC;">parameters</span><span style="color:#006600; font-weight:bold;">&#91;</span>:database<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_hash</span>
      <span style="color:#008000; font-style:italic;"># remove certain fields from hash</span>
      form_data.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Submit&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>  
      form_data.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;ignore&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>  
      @form_name = request.<span style="color:#9900CC;">parameters</span><span style="color:#006600; font-weight:bold;">&#91;</span>:form_name<span style="color:#006600; font-weight:bold;">&#93;</span>
      @form_conf = config<span style="color:#006600; font-weight:bold;">&#91;</span>'form'<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>form_name<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">symbolize_keys</span> || <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> save_form <span style="color:#9966CC; font-weight:bold;">and</span> form_conf.<span style="color:#9900CC;">has_key</span>? :success_page
        response.<span style="color:#9900CC;">redirect</span><span style="color:#006600; font-weight:bold;">&#40;</span> form_conf<span style="color:#006600; font-weight:bold;">&#91;</span>:success_page<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#9966CC; font-weight:bold;">super</span><span style="color:#006600; font-weight:bold;">&#40;</span>request, response<span style="color:#006600; font-weight:bold;">&#41;</span> 
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#9966CC; font-weight:bold;">super</span><span style="color:#006600; font-weight:bold;">&#40;</span>request, response<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Save form data</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> save_form<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">begin</span>
      contact = Contact.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>form_data.<span style="color:#9900CC;">to_hash</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      contact.<span style="color:#9900CC;">save</span>
     <span style="color:#9966CC; font-weight:bold;">rescue</span>
      @form_error = <span style="color:#996600;">&quot;Error encountered while trying to submit form. #{$!}&quot;</span>
      <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> cache?
    <span style="color:#0000FF; font-weight:bold;">false</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  
  <span style="color:#008000; font-style:italic;"># DatabaseForm Tags:</span>
    
    desc %<span style="color:#006600; font-weight:bold;">&#123;</span> This is just <span style="color:#9966CC; font-weight:bold;">for</span> creating the &lt;r:database/&gt; namespace. <span style="color:#006600; font-weight:bold;">&#125;</span>
    tag <span style="color:#996600;">&quot;database&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |tag|
      tag.<span style="color:#9900CC;">expand</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    
    desc %<span style="color:#006600; font-weight:bold;">&#123;</span>    The &lt;r:database:form name=<span style="color:#996600;">&quot;X&quot;</span>&gt;...&lt;/r:database:form&gt; tag is required.
    <span style="color:#9900CC;">It</span> should encompass all of the helper tags <span style="color:#9966CC; font-weight:bold;">for</span> creating form fields.<span style="color:#006600; font-weight:bold;">&#125;</span>
    tag <span style="color:#996600;">&quot;database:form&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |tag|
      @tag_attr = <span style="color:#006600; font-weight:bold;">&#123;</span> :<span style="color:#9966CC; font-weight:bold;">class</span>=&gt;get_class_name<span style="color:#006600; font-weight:bold;">&#40;</span>'form'<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">update</span><span style="color:#006600; font-weight:bold;">&#40;</span> tag.<span style="color:#9900CC;">attr</span>.<span style="color:#9900CC;">symbolize_keys</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
      raise_error_if_name_missing 'database:form'
      <span style="color:#008000; font-style:italic;"># Build the html form tag...</span>
      results = %Q<span style="color:#006600; font-weight:bold;">&#40;</span>&lt;script src=<span style="color:#996600;">&quot;/javascripts/validation.js&quot;</span> type=<span style="color:#996600;">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;<span style="color:#006600; font-weight:bold;">&#41;</span>
      results &lt;&lt; %Q<span style="color:#006600; font-weight:bold;">&#40;</span>&lt;form id=<span style="color:#996600;">&quot;contact-form-id&quot;</span> action=<span style="color:#996600;">&quot;#{ url }&quot;</span> method=<span style="color:#996600;">&quot;post&quot;</span> <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;#{ tag_attr[:class] }&quot;</span> enctype=<span style="color:#996600;">&quot;multipart/form-data&quot;</span>&gt;<span style="color:#006600; font-weight:bold;">&#41;</span>
      results &lt;&lt; %Q<span style="color:#006600; font-weight:bold;">&#40;</span>&lt;div&gt;&lt;input type=<span style="color:#996600;">&quot;hidden&quot;</span> name=<span style="color:#996600;">&quot;form_name&quot;</span> value=<span style="color:#996600;">&quot;#{ tag_attr[:name] }&quot;</span> /&gt;&lt;/div&gt;<span style="color:#006600; font-weight:bold;">&#41;</span>
      results &lt;&lt; %Q<span style="color:#006600; font-weight:bold;">&#40;</span>&lt;div <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;database-error&quot;</span>&gt;<span style="color:#008000; font-style:italic;">#{form_error}&lt;/div&gt;) if form_error</span>
      results &lt;&lt; tag.<span style="color:#9900CC;">expand</span>
      results &lt;&lt; %Q<span style="color:#006600; font-weight:bold;">&#40;</span>&lt;/form&gt;<span style="color:#006600; font-weight:bold;">&#41;</span>
      results &lt;&lt; %Q<span style="color:#006600; font-weight:bold;">&#40;</span>&lt;script&gt;new Validation<span style="color:#006600; font-weight:bold;">&#40;</span>'contact-form-id'<span style="color:#006600; font-weight:bold;">&#41;</span>;&lt;/script&gt;<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># Build tags for all of the &lt;input /&gt; tags...</span>
    %w<span style="color:#006600; font-weight:bold;">&#40;</span>text password file submit reset checkbox radio hidden<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |type|
      desc %<span style="color:#006600; font-weight:bold;">&#123;</span>      Renders a <span style="color:#008000; font-style:italic;">#{type} form control for a database form.}</span>
      tag <span style="color:#996600;">&quot;database:#{type}&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |tag|
        @tag_attr = tag.<span style="color:#9900CC;">attr</span>.<span style="color:#9900CC;">symbolize_keys</span>
        raise_error_if_name_missing <span style="color:#996600;">&quot;database:#{type}&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> %<span style="color:#006600; font-weight:bold;">&#40;</span>submit reset<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9966CC; font-weight:bold;">include</span>? type
        input_tag_html<span style="color:#006600; font-weight:bold;">&#40;</span> type <span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>      
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    desc %<span style="color:#006600; font-weight:bold;">&#123;</span>    A &lt;select&gt;...&lt;/select&gt; tag. <span style="color:#9900CC;">This</span> is compatible with the &lt;r:database:option/&gt; tag as well. <span style="color:#006600; font-weight:bold;">&#125;</span>
    tag 'database:<span style="color:#CC0066; font-weight:bold;">select</span>' <span style="color:#9966CC; font-weight:bold;">do</span> |tag|
      @tag_attr = <span style="color:#006600; font-weight:bold;">&#123;</span> :id=&gt;tag.<span style="color:#9900CC;">attr</span><span style="color:#006600; font-weight:bold;">&#91;</span>'name'<span style="color:#006600; font-weight:bold;">&#93;</span>, :<span style="color:#9966CC; font-weight:bold;">class</span>=&gt;get_class_name<span style="color:#006600; font-weight:bold;">&#40;</span>'<span style="color:#CC0066; font-weight:bold;">select</span>'<span style="color:#006600; font-weight:bold;">&#41;</span>, :size=&gt;'<span style="color:#006666;">1</span>' <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">update</span><span style="color:#006600; font-weight:bold;">&#40;</span> tag.<span style="color:#9900CC;">attr</span>.<span style="color:#9900CC;">symbolize_keys</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
      raise_error_if_name_missing <span style="color:#996600;">&quot;database:select&quot;</span>
      tag.<span style="color:#9900CC;">locals</span>.<span style="color:#9900CC;">parent_tag_name</span> = tag_attr<span style="color:#006600; font-weight:bold;">&#91;</span>:name<span style="color:#006600; font-weight:bold;">&#93;</span>
      tag.<span style="color:#9900CC;">locals</span>.<span style="color:#9900CC;">parent_tag_type</span> = '<span style="color:#CC0066; font-weight:bold;">select</span>'
      results =  %Q<span style="color:#006600; font-weight:bold;">&#40;</span>&lt;select name=<span style="color:#996600;">&quot;database[#{tag_attr[:name]}]&quot;</span> <span style="color:#008000; font-style:italic;">#{add_attrs_to(&quot;&quot;)}&gt;)</span>
      results &lt;&lt; tag.<span style="color:#9900CC;">expand</span>
      results &lt;&lt; <span style="color:#996600;">&quot;&lt;/select&gt;&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    desc %<span style="color:#006600; font-weight:bold;">&#123;</span> A &lt;textarea&gt;...&lt;/textarea&gt; tag, of course <span style="color:#006600; font-weight:bold;">&#125;</span>
    tag 'database:textarea' <span style="color:#9966CC; font-weight:bold;">do</span> |tag|
      @tag_attr = <span style="color:#006600; font-weight:bold;">&#123;</span> :id=&gt;tag.<span style="color:#9900CC;">attr</span><span style="color:#006600; font-weight:bold;">&#91;</span>'name'<span style="color:#006600; font-weight:bold;">&#93;</span>, :<span style="color:#9966CC; font-weight:bold;">class</span>=&gt;get_class_name<span style="color:#006600; font-weight:bold;">&#40;</span>'textarea'<span style="color:#006600; font-weight:bold;">&#41;</span>, :rows=&gt;'<span style="color:#006666;">5</span>', :cols=&gt;'<span style="color:#006666;">35</span>' <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">update</span><span style="color:#006600; font-weight:bold;">&#40;</span> tag.<span style="color:#9900CC;">attr</span>.<span style="color:#9900CC;">symbolize_keys</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
      raise_error_if_name_missing <span style="color:#996600;">&quot;database:textarea&quot;</span>
      results =  %Q<span style="color:#006600; font-weight:bold;">&#40;</span>&lt;textarea name=<span style="color:#996600;">&quot;database[#{tag_attr[:name]}]&quot;</span> <span style="color:#008000; font-style:italic;">#{add_attrs_to(&quot;&quot;)}&gt;)</span>
      results &lt;&lt; tag.<span style="color:#9900CC;">expand</span>
      results &lt;&lt; <span style="color:#996600;">&quot;&lt;/textarea&gt;&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    
    %<span style="color:#006600; font-weight:bold;">&#123;</span>    Special tag <span style="color:#9966CC; font-weight:bold;">for</span> radio groups. <span style="color:#9900CC;">This</span> one works with the &lt;r:database:option/&gt; tag <span style="color:#006600; font-weight:bold;">&#125;</span>
    tag 'database:radiogroup' <span style="color:#9966CC; font-weight:bold;">do</span> |tag|
      @tag_attr = tag.<span style="color:#9900CC;">attr</span>.<span style="color:#9900CC;">symbolize_keys</span>
      raise_error_if_name_missing <span style="color:#996600;">&quot;database:radiogroup&quot;</span>
      tag.<span style="color:#9900CC;">locals</span>.<span style="color:#9900CC;">parent_tag_name</span> = tag_attr<span style="color:#006600; font-weight:bold;">&#91;</span>:name<span style="color:#006600; font-weight:bold;">&#93;</span>
      tag.<span style="color:#9900CC;">locals</span>.<span style="color:#9900CC;">parent_tag_type</span> = 'radiogroup'
      tag.<span style="color:#9900CC;">expand</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    desc %<span style="color:#006600; font-weight:bold;">&#123;</span>    This is a custom tag that will render an &lt;option/&gt; tag <span style="color:#9966CC; font-weight:bold;">if</span> the parent is a 
    &lt;select&gt;...&lt;/select&gt; tag, <span style="color:#9966CC; font-weight:bold;">or</span> it will render an &lt;input type=<span style="color:#996600;">&quot;radio&quot;</span>/&gt; tag <span style="color:#9966CC; font-weight:bold;">if</span> 
    the parent is a &lt;r:database:radiogroup&gt;...&lt;/r:database:radiogroup&gt; <span style="color:#006600; font-weight:bold;">&#125;</span>
    tag 'database:option' <span style="color:#9966CC; font-weight:bold;">do</span> |tag|
      @tag_attr = tag.<span style="color:#9900CC;">attr</span>.<span style="color:#9900CC;">symbolize_keys</span>
      raise_error_if_name_missing <span style="color:#996600;">&quot;database:option&quot;</span>
      result = <span style="color:#996600;">&quot;&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> tag.<span style="color:#9900CC;">locals</span>.<span style="color:#9900CC;">parent_tag_type</span> == '<span style="color:#CC0066; font-weight:bold;">select</span>'
        result &lt;&lt; %Q|&lt;option value=<span style="color:#996600;">&quot;#{tag_attr.delete(:value) || tag_attr[:name]}&quot;</span> <span style="color:#008000; font-style:italic;">#{add_attrs_to(&quot;&quot;)}&gt;#{tag_attr[:name]}&lt;/option&gt;|</span>
      <span style="color:#9966CC; font-weight:bold;">elsif</span> tag.<span style="color:#9900CC;">locals</span>.<span style="color:#9900CC;">parent_tag_type</span> == 'radiogroup'
        tag.<span style="color:#9900CC;">globals</span>.<span style="color:#9900CC;">option_count</span> = tag.<span style="color:#9900CC;">globals</span>.<span style="color:#9900CC;">option_count</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>? ? <span style="color:#006666;">1</span> : tag.<span style="color:#9900CC;">globals</span>.<span style="color:#9900CC;">option_count</span> += <span style="color:#006666;">1</span>
        options = tag_attr.<span style="color:#9900CC;">clone</span>.<span style="color:#9900CC;">update</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>
          :id =&gt; <span style="color:#996600;">&quot;#{tag.locals.parent_tag_name}_#{tag.globals.option_count}&quot;</span>,
          :value =&gt; tag_attr.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span>:value<span style="color:#006600; font-weight:bold;">&#41;</span> || tag_attr<span style="color:#006600; font-weight:bold;">&#91;</span>:name<span style="color:#006600; font-weight:bold;">&#93;</span>,
          :name =&gt; tag.<span style="color:#9900CC;">locals</span>.<span style="color:#9900CC;">parent_tag_name</span>
        <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        result &lt;&lt; input_tag_html<span style="color:#006600; font-weight:bold;">&#40;</span> 'radio', options <span style="color:#006600; font-weight:bold;">&#41;</span>
        result &lt;&lt; %Q|&lt;label <span style="color:#9966CC; font-weight:bold;">for</span>=<span style="color:#996600;">&quot;#{options[:id]}&quot;</span>&gt;<span style="color:#008000; font-style:italic;">#{tag_attr[:name]}&lt;/label&gt;|</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    desc %<span style="color:#006600; font-weight:bold;">&#123;</span>    This is a custom tag that will render an obfuscated email address &lt;option&gt;
    using the email.<span style="color:#9900CC;">js</span> file. <span style="color:#9900CC;">Use</span> nested &lt;r:address&gt;...&lt;/r:address&gt; to specify the email
    address <span style="color:#9966CC; font-weight:bold;">and</span> &lt;r:label&gt;...&lt;/r:label&gt; to specify what the content of the tag should be. <span style="color:#006600; font-weight:bold;">&#125;</span>
    tag 'database:email_option' <span style="color:#9966CC; font-weight:bold;">do</span> |tag|
      hash = tag.<span style="color:#9900CC;">locals</span>.<span style="color:#9900CC;">params</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
      contents = tag.<span style="color:#9900CC;">expand</span>
      address = hash<span style="color:#006600; font-weight:bold;">&#91;</span>'address'<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>? ? contents : hash<span style="color:#006600; font-weight:bold;">&#91;</span>'address'<span style="color:#006600; font-weight:bold;">&#93;</span>
      label = hash<span style="color:#006600; font-weight:bold;">&#91;</span>'label'<span style="color:#006600; font-weight:bold;">&#93;</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> address =~ /<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>\w.%-<span style="color:#006600; font-weight:bold;">&#93;</span>+<span style="color:#006600; font-weight:bold;">&#41;</span>@<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>\w.-<span style="color:#006600; font-weight:bold;">&#93;</span>+<span style="color:#006600; font-weight:bold;">&#41;</span>\.<span style="color:#9900CC;"><span style="color:#006600; font-weight:bold;">&#40;</span></span><span style="color:#006600; font-weight:bold;">&#91;</span>A-z<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">2</span>,<span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>/
        user, domain, tld = $<span style="color:#006666;">1</span>, $<span style="color:#006666;">2</span>, $<span style="color:#006666;">3</span>
        tld_num = TLDS.<span style="color:#9900CC;">index</span><span style="color:#006600; font-weight:bold;">&#40;</span>tld<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">unless</span> label.<span style="color:#9900CC;">blank</span>?
        %<span style="color:#006600; font-weight:bold;">&#123;</span>&lt;script type=<span style="color:#996600;">&quot;text/javascript&quot;</span>&gt;
              // &lt;!<span style="color:#006600; font-weight:bold;">&#91;</span>CDATA<span style="color:#006600; font-weight:bold;">&#91;</span>
              mail4<span style="color:#006600; font-weight:bold;">&#40;</span>'<span style="color:#008000; font-style:italic;">#{user}', '#{domain}', #{tld_num}, &quot;#{label}&quot;);</span>
              // <span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#93;</span>&gt;
              &lt;/script&gt;
        <span style="color:#006600; font-weight:bold;">&#125;</span>
        <span style="color:#9966CC; font-weight:bold;">else</span>
        %<span style="color:#006600; font-weight:bold;">&#123;</span>&lt;script type=<span style="color:#996600;">&quot;text/javascript&quot;</span>&gt;
              // &lt;!<span style="color:#006600; font-weight:bold;">&#91;</span>CDATA<span style="color:#006600; font-weight:bold;">&#91;</span>
              mail4<span style="color:#006600; font-weight:bold;">&#40;</span>'<span style="color:#008000; font-style:italic;">#{user}', '#{domain}', #{tld_num}, '#{user}');</span>
              // <span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#93;</span>&gt;
              &lt;/script&gt;
        <span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>      
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    
    tag <span style="color:#996600;">&quot;database:email_option:label&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |tag|
      tag.<span style="color:#9900CC;">locals</span>.<span style="color:#9900CC;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span>'label'<span style="color:#006600; font-weight:bold;">&#93;</span> = tag.<span style="color:#9900CC;">expand</span>.<span style="color:#9900CC;">strip</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  
    tag <span style="color:#996600;">&quot;database:email_option:address&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |tag|
      tag.<span style="color:#9900CC;">locals</span>.<span style="color:#9900CC;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span>'address'<span style="color:#006600; font-weight:bold;">&#93;</span> = tag.<span style="color:#9900CC;">expand</span>.<span style="color:#9900CC;">strip</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  
    
    desc %<span style="color:#006600; font-weight:bold;">&#123;</span>    <span style="color:#9966CC; font-weight:bold;">For</span> use with email template parts -- retrieves the data posted by the form <span style="color:#006600; font-weight:bold;">&#125;</span>
    tag 'database:get' <span style="color:#9966CC; font-weight:bold;">do</span> |tag|
      name = tag.<span style="color:#9900CC;">attr</span><span style="color:#006600; font-weight:bold;">&#91;</span>'name'<span style="color:#006600; font-weight:bold;">&#93;</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> name
        form_data<span style="color:#006600; font-weight:bold;">&#91;</span>name<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">Array</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? form_data<span style="color:#006600; font-weight:bold;">&#91;</span>name<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_sentence</span> : form_data<span style="color:#006600; font-weight:bold;">&#91;</span>name<span style="color:#006600; font-weight:bold;">&#93;</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        form_data.<span style="color:#9900CC;">to_hash</span>.<span style="color:#9900CC;">to_yaml</span>.<span style="color:#9900CC;">to_s</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>  
&nbsp;
protected
&nbsp;
  <span style="color:#008000; font-style:italic;"># Since several form tags use the &lt;input type=&quot;X&quot; /&gt; format, let's do that work in one place</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> input_tag_html<span style="color:#006600; font-weight:bold;">&#40;</span>type, opts=tag_attr<span style="color:#006600; font-weight:bold;">&#41;</span>
    options = <span style="color:#006600; font-weight:bold;">&#123;</span> :id =&gt; tag_attr<span style="color:#006600; font-weight:bold;">&#91;</span>:name<span style="color:#006600; font-weight:bold;">&#93;</span>, :value =&gt; <span style="color:#996600;">&quot;&quot;</span>, :<span style="color:#9966CC; font-weight:bold;">class</span>=&gt;get_class_name<span style="color:#006600; font-weight:bold;">&#40;</span>type<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">update</span><span style="color:#006600; font-weight:bold;">&#40;</span>opts<span style="color:#006600; font-weight:bold;">&#41;</span>
    results =  %Q<span style="color:#006600; font-weight:bold;">&#40;</span>&lt;input type=<span style="color:#996600;">&quot;#{type}&quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
    results &lt;&lt; %Q<span style="color:#006600; font-weight:bold;">&#40;</span>name=<span style="color:#996600;">&quot;database[#{options[:name]}]&quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> tag_attr<span style="color:#006600; font-weight:bold;">&#91;</span>:name<span style="color:#006600; font-weight:bold;">&#93;</span>
    results &lt;&lt; <span style="color:#996600;">&quot;#{add_attrs_to(&quot;</span><span style="color:#996600;">&quot;, options)}/&gt;&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  
  <span style="color:#9966CC; font-weight:bold;">def</span> add_attrs_to<span style="color:#006600; font-weight:bold;">&#40;</span>results, tag_attrs=tag_attr<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#008000; font-style:italic;"># Well, turns out I stringify the keys so I can sort them so I can test the tag output</span>
    tag_attrs.<span style="color:#9900CC;">stringify_keys</span>.<span style="color:#9900CC;">sort</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |name, value|
      results &lt;&lt; %Q<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#008000; font-style:italic;">#{name.to_s}=&quot;#{value.to_s}&quot; ) unless name == 'name'</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    results
  <span style="color:#9966CC; font-weight:bold;">end</span>
  
  <span style="color:#008000; font-style:italic;"># Get the default css class based on type</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> get_class_name<span style="color:#006600; font-weight:bold;">&#40;</span>type, class_name=<span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    class_name = 'database-form' <span style="color:#9966CC; font-weight:bold;">if</span> class_name.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">and</span> %<span style="color:#006600; font-weight:bold;">&#40;</span>form<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9966CC; font-weight:bold;">include</span>? type
    class_name = 'database-field' <span style="color:#9966CC; font-weight:bold;">if</span> class_name.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">and</span> %<span style="color:#006600; font-weight:bold;">&#40;</span>text password file <span style="color:#CC0066; font-weight:bold;">select</span> textarea<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9966CC; font-weight:bold;">include</span>? type
    class_name = 'database-button' <span style="color:#9966CC; font-weight:bold;">if</span> class_name.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">and</span> %<span style="color:#006600; font-weight:bold;">&#40;</span>submit reset<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9966CC; font-weight:bold;">include</span>? type
    class_name = 'database-option' <span style="color:#9966CC; font-weight:bold;">if</span> class_name.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">and</span> %<span style="color:#006600; font-weight:bold;">&#40;</span>checkbox radio<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9966CC; font-weight:bold;">include</span>? type
    class_name
  <span style="color:#9966CC; font-weight:bold;">end</span>
  
  <span style="color:#008000; font-style:italic;"># Raises a 'name missing' tag error</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> raise_name_error<span style="color:#006600; font-weight:bold;">&#40;</span>tag_name<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">raise</span> DatabaseFormTagError.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;`#{tag_name}' tag requires a `name' attribute&quot;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> raise_error_if_name_missing<span style="color:#006600; font-weight:bold;">&#40;</span>tag_name<span style="color:#006600; font-weight:bold;">&#41;</span>
    raise_name_error<span style="color:#006600; font-weight:bold;">&#40;</span> tag_name <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> tag_attr<span style="color:#006600; font-weight:bold;">&#91;</span>:name<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">or</span> tag_attr<span style="color:#006600; font-weight:bold;">&#91;</span>:name<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">empty</span>?
  <span style="color:#9966CC; font-weight:bold;">end</span>
  
<span style="color:#9966CC; font-weight:bold;">end</span></pre></p>
<p>I<br />
don&#8217;t like how it is hardcoded to use the contacts table.  Any thoughts/ideas<br />
on how to make the table more of dynamic, runtime setting?  As you can imagine,<br />
Contact is simply:
</p>
<p><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> Contact &lt; ActiveRecord::Base
<span style="color:#9966CC; font-weight:bold;">end</span></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://code.supergloo.com/2007/12/12/radiant-cms-database-form-extension/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Automating Fit Tests in Fitnesse Server from Cruise Control, Hudson, Bamboo via Ant</title>
		<link>http://code.supergloo.com/2007/07/28/automating-fit-tests-in-fitnesse-server-from-cruise-control-hudson-bamboo-via-ant/</link>
		<comments>http://code.supergloo.com/2007/07/28/automating-fit-tests-in-fitnesse-server-from-cruise-control-hudson-bamboo-via-ant/#comments</comments>
		<pubDate>Sat, 28 Jul 2007 18:42:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[fit testing]]></category>

		<category><![CDATA[fitnesse]]></category>

		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://code.supergloo.com/2007/07/28/automating-fit-tests-in-fitnesse-server-from-cruise-control-hudson-bamboo-via-ant/</guid>
		<description><![CDATA[Here&#8217;s an example of calling Fit tests defined in Fitnesse from Ant.  This can be called from a continuous integration server like cruise control, hudson, bamboo, luntbuild, pmeasy:
&#60;target name=&#34;fitnesse-tests&#34;
           description=&#34;fitnesse-tests target can be called from CC&#34;
         [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an example of calling Fit tests defined in Fitnesse from Ant.  This can be called from a continuous integration server like cruise control, hudson, bamboo, luntbuild, pmeasy:<br />
<pre class="php">&lt;target name=<span style="color: #ff0000;">&quot;fitnesse-tests&quot;</span>
           description=<span style="color: #ff0000;">&quot;fitnesse-tests target can be called from CC&quot;</span>
           depends=<span style="color: #ff0000;">&quot;custom-init, compile-fit&quot;</span>
&gt;
&nbsp;
 &lt;java classname=<span style="color: #ff0000;">&quot;fitnesse.runner.TestRunner&quot;</span>
           fork=<span style="color: #ff0000;">&quot;true&quot;</span> resultproperty=<span style="color: #ff0000;">&quot;FitRegressionResult&quot;</span>&gt;
    &lt;arg line=<span style="color: #ff0000;">&quot;-results fit-tests/reports/fitnesse-results.html
          10.99.99.99 80 FitnessePageName&quot;</span>/&gt;
    &lt;classpath&gt;&lt;path refid=<span style="color: #ff0000;">&quot;custom.classpath&quot;</span> /&gt;&lt;/classpath&gt;
 &lt;/java&gt;
&lt;!-- xml <a href="http://www.php.net/file"><span style="color: #000066;">file</span></a> processed by cruise control --&gt;
 &lt;java classname=<span style="color: #ff0000;">&quot;fitnesse.runner.FormattingOption&quot;</span> fork=<span style="color: #ff0000;">&quot;true&quot;</span>&gt;
  &lt;arg line=<span style="color: #ff0000;">&quot;fit-tests/reports/fitnesse-results.html xml
             ${fit.report.dir}/fit-results.xml
             10.99.99.99 80 FitnessePageName&quot;</span>/&gt;
  &lt;classpath&gt;&lt;path refid=<span style="color: #ff0000;">&quot;custom.classpath&quot;</span> /&gt;&lt;/classpath&gt;
 &lt;/java&gt;
&nbsp;
 &lt;!-- fail <span style="color: #b1b100;">if</span> any fit test errors --&gt;
 &lt;condition property=<span style="color: #ff0000;">&quot;fit-failures&quot;</span>&gt;
   &lt;equals arg1=<span style="color: #ff0000;">&quot;${FitRegressionResult}&quot;</span> arg2=<span style="color: #ff0000;">&quot;0&quot;</span>/&gt;
 &lt;/condition&gt;
 &lt;fail message=<span style="color: #ff0000;">&quot;${FitRegressionResult} Fitnesse test(s) failed.&quot;</span>
        unless=<span style="color: #ff0000;">&quot;fit-failures&quot;</span> /&gt;
&lt;/target&gt;</pre></p>
<p>Fitnesse is an excellent communication and collaboration tool between developers, QA and clients.  It works well in agile development environments where emphasis and priority is put on automating tests.</p>
<p>If you have any questions, feel free to contact Todd McGrath at <a href="http://www.supergloo.com/contact.htm">http://www.supergloo.com/contact.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://code.supergloo.com/2007/07/28/automating-fit-tests-in-fitnesse-server-from-cruise-control-hudson-bamboo-via-ant/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Unit Testing with StrutsTestCase for JUnit Tutorial</title>
		<link>http://code.supergloo.com/2007/03/30/unit-testing-with-strutstestcase-for-junit-tutorial/</link>
		<comments>http://code.supergloo.com/2007/03/30/unit-testing-with-strutstestcase-for-junit-tutorial/#comments</comments>
		<pubDate>Fri, 30 Mar 2007 19:11:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[java]]></category>

		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://code.supergloo.com/2007/03/30/unit-testing-with-strutstestcase-for-junit-tutorial/</guid>
		<description><![CDATA[As the name implies, StrutsTestCase is a tool for testing your Struts code.  In this article, I&#8217;ll cover:

What is StutsTestCase?
How?
When?
Where?

This article assumes the reader has familiarity and experience with Junit.
&#8220;StrutsTestCase for JUnit is an extension of the standard JUnit TestCase class that provides facilities for testing code based on the Struts framework. StrutsTestCase provides [...]]]></description>
			<content:encoded><![CDATA[<p>As the name implies, StrutsTestCase is a tool for testing your Struts code.  In this article, I&#8217;ll cover:</p>
<ul>
<li>What is StutsTestCase?</li>
<li>How?</li>
<li>When?</li>
<li>Where?</li>
</ul>
<p>This article assumes the reader has familiarity and experience with Junit.</p>
<p>&#8220;StrutsTestCase for JUnit is an extension of the standard JUnit TestCase class that provides facilities for testing code based on the Struts framework. StrutsTestCase provides both a Mock Object approach and a Cactus approach to actually run the Struts ActionServlet, allowing you to test your Struts code with or without a running servlet engine.&#8221; -</p>
<p>In this article, we’ll discuss and examples using the MockObject approach; not Cactus.</p>
<p>StrutsTestCase reads the struts config file and loads up validators, plug-ins, forwards, etc.  In other words, it can mock what happens when a servlet container is started without actually requiring a servlet container.</p>
<p>Just like JUnit – Extend a Class and follow a method naming convention</p>
<p>You have the same access to setUp() and tearDown():<br />
<pre class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestLoginAction <span style="color: #000000; font-weight: bold;">extends</span> MockStrutsTestCase <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setUp<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006600;">setUp</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> tearDown<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006600;">tearDown</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre><br />
Extends JUnit’s TestCase, so access to all the assert*.  Differentiates itself by using verify* methods.</p>
<p>Form validation example:<br />
<pre class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> testNonNumberEntry<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	addRequestParameter<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;txtFlatPercent&quot;</span>, <span style="color: #ff0000;">&quot;arg1&quot;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//add bogus percent</span>
    	setRequestPathInfo<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/calculate&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    	CalculatorValidatorActionForm form = <span style="color: #000000; font-weight: bold;">new</span> CalculatorValidatorActionForm<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    	form.<span style="color: #006600;">setTxtName</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Account Name&quot;</span><span style="color: #66cc66;">&#41;</span>;
    	form.<span style="color: #006600;">setChkOptionRate</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Flat&quot;</span><span style="color: #66cc66;">&#41;</span>;
    	form.<span style="color: #006600;">setTxtAccountVal</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;55000&quot;</span><span style="color: #66cc66;">&#41;</span>;
    	form.<span style="color: #006600;">setTxtFixedPer</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;string&quot;</span><span style="color: #66cc66;">&#41;</span>;
    	setActionForm<span style="color: #66cc66;">&#40;</span>form<span style="color: #66cc66;">&#41;</span>;
&nbsp;
    	actionPerform<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    	verifyActionErrors<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #ff0000;">&quot;prompt.txtFlatPercent&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> testFlatPercentValidationWithOutExceptionRequest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
    	setRequestPathInfo<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/calculate&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    	CalculatorValidatorActionForm form = <span style="color: #000000; font-weight: bold;">new</span> CalculatorValidatorActionForm<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    	form.<span style="color: #006600;">setTxtName</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Account Name&quot;</span><span style="color: #66cc66;">&#41;</span>;
    	form.<span style="color: #006600;">setChkOptionRate</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Flat&quot;</span><span style="color: #66cc66;">&#41;</span>;
    	form.<span style="color: #006600;">setTxtFlatPercent</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;49&quot;</span><span style="color: #66cc66;">&#41;</span>;
    	form.<span style="color: #006600;">setTxtAccountVal</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;500000&quot;</span><span style="color: #66cc66;">&#41;</span>;
    	setActionForm<span style="color: #66cc66;">&#40;</span>form<span style="color: #66cc66;">&#41;</span>;
&nbsp;
    	actionPerform<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    	verifyForward<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;flat&quot;</span><span style="color: #66cc66;">&#41;</span>;
    	assertNull<span style="color: #66cc66;">&#40;</span>getMockRequest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getSession</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getAttribute</span><span style="color: #66cc66;">&#40;</span>ConstantsInterface.<span style="color: #006600;">CONFIRM_EXCEPTION_REQUIRED</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #66cc66;">&#125;</span></pre></p>
<p>Struts Plug-In Validation<br />
<pre class="java"><span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span>
	FeeCalcServiceFactory serviceFactory = <span style="color: #66cc66;">&#40;</span>FeeCalcServiceFactory<span style="color: #66cc66;">&#41;</span>getActionServlet<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getServletContext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getAttribute</span><span style="color: #66cc66;">&#40;</span>ConstantsInterface.<span style="color: #006600;">FEECALC_SERVICE_FACTORY_KEY</span><span style="color: #66cc66;">&#41;</span>;
	assertNotNull<span style="color: #66cc66;">&#40;</span>serviceFactory.<span style="color: #006600;">createService</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Exception</span></a> e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	log.<span style="color: #006600;">error</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>;
	fail<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;testFactory - should not have thrown exception when obtaining service&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> testGetRates<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span>
	FeeCalcServiceFactory serviceFactory = <span style="color: #66cc66;">&#40;</span>FeeCalcServiceFactory<span style="color: #66cc66;">&#41;</span>getActionServlet<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getServletContext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getAttribute</span><span style="color: #66cc66;">&#40;</span>ConstantsInterface.<span style="color: #006600;">FEECALC_SERVICE_FACTORY_KEY</span><span style="color: #66cc66;">&#41;</span>;
	FeeCalcService service = serviceFactory.<span style="color: #006600;">createService</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #808080; font-style: italic;">// should never be empty</span>
	assertTrue<span style="color: #66cc66;">&#40;</span>service.<span style="color: #006600;">getRates</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">size</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> &gt;= <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
   <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Exception</span></a> e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	log.<span style="color: #006600;">error</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>;
	fail<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;testGetRates - should not have thrown exception&quot;</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></p>
<p>StrutsTestCase Compatibility:</p>
<ul>
<li>Struts 1.2, 1.1</li>
<li>Tiles</li>
<li>Sub-applications</li>
<li>Java Servlet 2.2, 2.3, and 2.4 specifications </li>
<li>JUnit 4.0</li>
</ul>
<p>StrutsTestCase Gotchas:</p>
<ul>
<li>WEB-INF - “By default, the Struts ActionServlet will look for the file WEB-INF/struts-config.xml, so you must place the directory that contains WEB-INF in your CLASSPATH. If you would like to use an alternate configuration file, please see the setConfigFile() method for details on how this file is located.”</li>
<li>Does not support Struts 1.3 or 2 </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://code.supergloo.com/2007/03/30/unit-testing-with-strutstestcase-for-junit-tutorial/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Example of Java Acceptance Testing with Fit</title>
		<link>http://code.supergloo.com/2007/03/23/example-of-java-acceptance-testing-with-fit/</link>
		<comments>http://code.supergloo.com/2007/03/23/example-of-java-acceptance-testing-with-fit/#comments</comments>
		<pubDate>Fri, 23 Mar 2007 22:16:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[fit testing]]></category>

		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://code.supergloo.com/2007/03/23/example-of-java-acceptance-testing-with-fit/</guid>
		<description><![CDATA[Fit testing provides a way for non-developers to participate in test driven development.  Fit testing facilitates collaboration  and communication in applications that need to verify results from calculations.  From the Fit testing website, http://fit.c2.com/:
Great software requires collaboration and communication. Fit is a tool for enhancing collaboration in software development. It&#8217;s an invaluable [...]]]></description>
			<content:encoded><![CDATA[<p>Fit testing provides a way for non-developers to participate in test driven development.  Fit testing facilitates collaboration  and communication in applications that need to verify results from calculations.  From the Fit testing website, <a href="http://fit.c2.com/">http://fit.c2.com/</a>:</p>
<blockquote><p>Great software requires collaboration and communication. Fit is a tool for enhancing collaboration in software development. It&#8217;s an invaluable way to collaborate on complicated problems&#8211;and get them right&#8211;early in development.</p></blockquote>
<p>Let&#8217;s run an example of using Fit tests in your Java application.  This example assumes you are using Ant to build.</p>
<p>First, pick up the AntFit ant task from http://www.cmdev.com/antfit/.  This will provide the code to call Fit tests from your Ant build file.</p>
<p><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;taskdef</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;antfit&quot;</span> <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;com.cmdev.fit.ant.FitTask&quot;</span> <span style="color: #000066;">classpathref</span>=<span style="color: #ff0000;">&quot;antfit.classpath&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/taskdef<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></p>
<p>and calling it:<br />
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;test-fit&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;init,compile&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Executes the Fit tests&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;antcall</span> <span style="color: #000066;">target</span>=<span style="color: #ff0000;">&quot;populateDb&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/antcall<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/target<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- This uses a whole different set of folders --&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;our.fit.dir&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${basedir}/../fit&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;our.fit.src.dir&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${our.fit.dir}/src&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;our.fit.test.dir&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${our.fit.dir}/tests&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;our.fit.report.dir&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${our.report.dir}/fit&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${our.fit.report.dir}&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mkdir<span style="font-weight: bold; color: black;">&gt;</span></span></span>  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Now compile the fit tests --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;our.fit.compiled.dir&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${our.work.dir}/compiled-fit&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span>   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${our.fit.compiled.dir}&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;javac</span> <span style="color: #000066;">srcdir</span>=<span style="color: #ff0000;">&quot;${our.fit.src.dir}&quot;</span> <span style="color: #000066;">destdir</span>=<span style="color: #ff0000;">&quot;${our.fit.compiled.dir}&quot;</span> <span style="color: #000066;">target</span>=<span style="color: #ff0000;">&quot;1.4&quot;</span> <span style="color: #000066;">fork</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">memoryMaximumSize</span>=<span style="color: #ff0000;">&quot;512m&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;classpath<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/classpath<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/javac<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mkdir<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;path</span> <span style="color: #000066;">refid</span>=<span style="color: #ff0000;">&quot;our.classpath.buildtime&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/path<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;path</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;${our.test.compiled.dir}&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/path<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Now execute the fit tests --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;antfit</span> <span style="color: #000066;">destdir</span>=<span style="color: #ff0000;">&quot;${our.fit.report.dir}&quot;</span> <span style="color: #000066;">usewiki</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">fork</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;classpath<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/classpath<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/antfit<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;path</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;${our.fit.compiled.dir}&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/path<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;path</span> <span style="color: #000066;">refid</span>=<span style="color: #ff0000;">&quot;our.classpath.buildtime&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/path<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;path</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;${our.test.compiled.dir}&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/path<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${our.fit.test.dir}&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;**/*.html&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/include<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/fileset<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></p>
<p>In this example, we are not going to use a wiki (useWiki=&#8221;false&#8221;) for creating tests.  We can cover that in a later example.Next, let&#8217;s look at some Java source code for Fit tests:<pre class="java"><span style="color: #a1a100;">import java.text.NumberFormat;</span>
<span style="color: #a1a100;">import org.apache.commons.lang.StringUtils;</span>
<span style="color: #a1a100;">import util.RateFetcher;</span>
<span style="color: #a1a100;">import com.feecalc.vo.choice.BlendedResult;</span>
<span style="color: #a1a100;">import fit.ColumnFixture; </span></pre>/**<br />
* Automates testing the standard and discount fee for the standard tiers. Does all of its<br />
* calculations based on Equity, assuming that if the code works for Equity, it will work for any of<br />
* them.<br />
*<br />
* @author robert.c.fischer<br />
*/<br />
public class FeeFixture extends ColumnFixture {</p>
<p>public double customRate;<br />
protected static final String ZERO = &#8220;0&#8243;;<br />
public double value;<br />
public double discount;<br />
public String assetType;</p>
<p>/**<br />
* @return The standard fee.<br />
*/<br />
public String standardFee() {<br />
return moneyToString(generateBlendedResult().getStandardFeeAnnual());<br />
}</p>
<p>/**<br />
* @return The discount fee.<br />
*/<br />
public String discountFee() {<br />
return moneyToString(generateBlendedResult().getDiscountedFeeAnnual());<br />
}</p>
<p>/**<br />
* @return The discount blended rate<br />
*/<br />
public String discountRate() {<br />
return percentToString(generateBlendedResult().getDiscountBlendedRate());<br />
}</p>
<p>/**<br />
* @return The standard blended rate<br />
*/<br />
public String standardRate() {<br />
return percentToString(generateBlendedResult().getStandardBlendedRate());<br />
}</p>
<p>/**<br />
* @return The standard internal fee (post-&#8221;haircut&#8221; amount)<br />
*/<br />
public String internalStandardFee() {<br />
return moneyToString(generateBlendedResult().getStandardRepFeeAnnual());<br />
}</p>
<p>/**<br />
* @return The discounted internal fee (post-&#8221;haircut&#8221; amount)<br />
*/<br />
public String internalDiscountFee() {<br />
return moneyToString(generateBlendedResult().getDiscountedRepFeeAnnual());<br />
}</p>
<p>/**<br />
* @return The standard fee.<br />
*/<br />
public String getProposedClientDiscount() {<br />
return percentToString(generateBlendedResult().getProposedClientDiscount());<br />
}</p>
<p>protected static final String moneyToString(final double value) {<br />
final NumberFormat format = NumberFormat.getInstance();<br />
format.setMinimumFractionDigits(2);<br />
format.setMaximumFractionDigits(2);<br />
format.setGroupingUsed(false);<br />
return format.format(value);<br />
}</p>
<p>protected static final String percentToString(final double value) {<br />
final NumberFormat format = NumberFormat.getInstance();<br />
format.setMinimumFractionDigits(2);<br />
format.setMaximumFractionDigits(2);<br />
format.setGroupingUsed(false);<br />
return format.format(value);<br />
}</p>
<p>protected BlendedResult generateBlendedResult() {</p>
<p>final BlendedResult result = new BlendedResult();</p>
<p>// Set the rates<br />
setEquityRates(result);<br />
setCashRates(result);<br />
setMutualRates(result);</p>
<p>// Set the test values provided by the user<br />
if (StringUtils.isBlank(assetType) || assetType.toLowerCase().startsWith(&#8221;eq&#8221;)) {<br />
result.setEquityDiscount(discount);<br />
result.setEquityAmount(value);<br />
result.setEquityRateTier(5, customRate);<br />
} else {<br />
result.setEquityDiscount(0);<br />
result.setEquityAmount(0);<br />
}<br />
if (StringUtils.isNotBlank(assetType) &amp;&amp; assetType.toLowerCase().startsWith(&#8221;mu&#8221;)) {<br />
result.setMutualAmount(value);<br />
result.setMutualDiscount(discount);<br />
result.setMutualRateTier(5, customRate);<br />
} else {<br />
result.setMutualAmount(0);<br />
result.setMutualDiscount(0);<br />
}<br />
if (StringUtils.isNotBlank(assetType) &amp;&amp; assetType.toLowerCase().equals(&#8221;ca&#8221;)) {<br />
result.setCashAmount(value);<br />
result.setCashDiscount(discount);<br />
result.setCashRateTier(5, customRate);<br />
} else {<br />
result.setCashAmount(0);<br />
result.setCashDiscount(0);<br />
}</p>
<p>return result;<br />
}</p>
<p>private static final void setEquityRates(final BlendedResult result) {<br />
final double[] equityRates = new RateFetcher().getEquityRates();<br />
if (equityRates.length &lt; 4) {<br />
throw new RuntimeException(&#8221;Only have &#8221; + equityRates.length<br />
+ &#8221; equity rates &#8212; need 4&#8243;);<br />
}<br />
for (int i = 0; i &lt; equityRates.length; i++) {<br />
result.setEquityRateTier(i + 1, equityRates[i]);<br />
}<br />
}</p>
<p>private static final void setCashRates(final BlendedResult result) {<br />
final double[] cashRates = new RateFetcher().getCashRates();<br />
if (cashRates.length &lt; 4) {<br />
throw new RuntimeException(&#8221;Only have &#8221; + cashRates.length + &#8221; cash rates &#8212; need 4&#8243;);<br />
}<br />
for (int i = 0; i &lt; cashRates.length; i++) {<br />
result.setCashRateTier(i + 1, cashRates[i]);<br />
}<br />
}</p>
<p>private static final void setMutualRates(final BlendedResult result) {<br />
final double[] mutualRates = new RateFetcher().getMutualRates();<br />
if (mutualRates.length &lt; 4) {<br />
throw new RuntimeException(&#8221;Only have &#8221; + mutualRates.length<br />
+ &#8221; mutual rates &#8212; need 4&#8243;);<br />
}<br />
for (int i = 0; i &lt; mutualRates.length; i++) {<br />
result.setMutualRateTier(i + 1, mutualRates[i]);<br />
}<br />
}<br />
}<br />
Here&#8217;s the source that&#8217;s used in the Fit tests:</p>
<table border="1" cellpadding="0">
<tr>
<td colspan="2" width="177">feecalc.FlatRateFeeFixture</td>
<td colspan="6" width="552">&nbsp;</td>
</tr>
<tr>
<td>cash</td>
<td colspan="2" width="74">equity</td>
<td width="72">mutual</td>
<td>flatRate</td>
<td width="83">assetSum()</td>
<td>flatRateFee()</td>
<td>comparisonFee()</td>
</tr>
<tr>
<td>300000</td>
<td colspan="2" width="74">100000</td>
<td width="72">100000</td>
<td>1</td>
<td width="83">500000</td>
<td>5000.0</td>
<td>4975.0</td>
</tr>
<tr>
<td>4000000</td>
<td colspan="2" width="74">4000000</td>
<td width="72">4000000</td>
<td>0.25</td>
<td width="83">12000000</td>
<td>30000.00</td>
<td>93875.00</td>
</tr>
<tr>
<td>100000</td>
<td colspan="2" width="74">10000</td>
<td width="72">10000</td>
<td>0.50</td>
<td width="83">120000</td>
<td>600.00</td>
<td>850.00</td>
</tr>
<tr>
<td>5000</td>
<td colspan="2" width="74">5000</td>
<td width="72">5000</td>
<td>0.75</td>
<td width="83">15000</td>
<td>112.50</td>
<td>200.00</td>
</tr>
<tr>
<td>130000</td>
<td colspan="2" width="74">100000</td>
<td width="72">10000</td>
<td>1.00</td>
<td width="83">240000</td>
<td>2400.00</td>
<td>2800.00</td>
</tr>
</table>
<p>And here is an example of the results after the Java Fit tests are run:</p>
<table border="1" cellpadding="0">
<tr>
<td colspan="2" width="177">feecalc.FlatRateFeeFixture</td>
<td colspan="6" width="552">&nbsp;</td>
</tr>
<tr>
<td>cash</td>
<td colspan="2" width="74">equity</td>
<td width="72">mutual</td>
<td>flatRate</td>
<td width="83">assetSum()</td>
<td>flatRateFee()</td>
<td>comparisonFee()</td>
</tr>
<tr>
<td>300000</td>
<td colspan="2" width="74">100000</td>
<td width="72">100000</td>
<td>1</td>
<td bgcolor="#cfffcf" width="83">500000</td>
<td bgcolor="#cfffcf">5000.0</td>
<td bgcolor="#cfffcf">4975.0</td>
</tr>
<tr>
<td>4000000</td>
<td colspan="2" width="74">4000000</td>
<td width="72">4000000</td>
<td>0.25</td>
<td bgcolor="#cfffcf" width="83">12000000</td>
<td bgcolor="#cfffcf">30000.00</td>
<td bgcolor="#cfffcf">93875.00</td>
</tr>
<tr>
<td>100000</td>
<td colspan="2" width="74">10000</td>
<td width="72">10000</td>
<td>0.50</td>
<td bgcolor="#cfffcf" width="83">120000</td>
<td bgcolor="#cfffcf">600.00</td>
<td bgcolor="#cfffcf">850.00</td>
</tr>
<tr>
<td>5000</td>
<td colspan="2" width="74">5000</td>
<td width="72">5000</td>
<td>0.75</td>
<td bgcolor="#cfffcf" width="83">15000</td>
<td bgcolor="#cfffcf">112.50</td>
<td bgcolor="#cfffcf">200.00</td>
</tr>
<tr>
<td>130000</td>
<td colspan="2" width="74">100000</td>
<td width="72">10000</td>
<td>1.00</td>
<td bgcolor="#cfffcf" width="83">240000</td>
<td bgcolor="#cfffcf">2400.00</td>
<td bgcolor="#cfffcf">2800.00</td>
</tr>
</table>
<p>Yae, all green.  If there was an incorrect result, the errant result table cell would be red instead of green.</p>
<p>Hat tip to my co-worker Robert Fischer for writing the Java code and Fit test HTML. <a href="http://www.codesponsors.com/blog/contact"></a></p>
<p>More information on Fit testing can be found at:<br />
<a href="http://fit.c2.com/">http://fit.c2.com/</a></p>
<p>And for those that want a physical book:<br />
<iframe src="http://rcm.amazon.com/e/cm?t=subscriptio09-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0321269349&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=FFFFFF&amp;bg1=FFFFFF&amp;f=ifr" style="width: 120px; height: 240px" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://code.supergloo.com/2007/03/23/example-of-java-acceptance-testing-with-fit/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DLL from Java with Jawin</title>
		<link>http://code.supergloo.com/2007/03/20/dll-from-java-with-jawin/</link>
		<comments>http://code.supergloo.com/2007/03/20/dll-from-java-with-jawin/#comments</comments>
		<pubDate>Tue, 20 Mar 2007 16:35:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://code.supergloo.com/2007/03/20/dll-from-java-with-jawin/</guid>
		<description><![CDATA[Do you need to use a Windows DLL from Java? I recommend investigating the open source tool: Jawin.  I found used this tool in order to call a DLL that converts HTML to RTF.  After struggling with various JNI tutorials, Jawin was refreshing.  What makes this tool outstanding is the jawinBrowser.  [...]]]></description>
			<content:encoded><![CDATA[<p>Do you need to use a Windows DLL from Java? I recommend investigating the open source tool: <a href="http://jawinproject.sourceforge.net/">Jawin</a>.  I found used this tool in order to call a DLL that converts HTML to RTF.  After struggling with various JNI tutorials, Jawin was refreshing.  What makes this tool outstanding is the jawinBrowser.  Here&#8217;s a tutorial on calling a DLL from Java:</p>
<p>1. Download Jawin<br />
2. In a command prompt, go to the typebrowser/ directory<br />
3. java -jar jawinBrowser.jar</p>
<p>This will start the jawinBrowser that allows you to generate Java code to interact with the Windows DLL.</p>
<p>4. Start a new project and name it anything you wish<br />
5. Next step is to point to the DLL - click the &#8220;New&#8221; button and select the DLL<br />
6. Highlight the DLL and then double click the configuration options on the left hand side:</p>
<p><img src="/article-images/jawin.gif" alt="Calling DLL from Java with Jawin" /></p>
<p>7. Change the java package name to something appropriate.  In my example, I converted it to com.supergloo.htmlconvert.<br />
8. Specify an output directory; e.lg /tmp or c:/temp</p>
<p>9. Click Ok.</p>
<p>10.  From the menu bar, select Code Generation-&gt;Generate Full Code<br />
11. Next, from the menu bar, select Code Generation-&gt; Save Java Files</p>
<p>You now have java src files to call your DLL methods!  (check the directory you specified in step 8).</p>
<p>Going further, you will have an IConverter class that you can call.  In my case, I used the following:</p>
<p><pre class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> convert<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> htmlString<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> COMException<span style="color: #66cc66;">&#123;</span>
<a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> rtfString = <span style="color: #ff0000;">&quot;&quot;</span>;
<span style="color: #808080; font-style: italic;">//Initialize service COM objects</span>
Ole32.<span style="color: #006600;">CoInitialize</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
IConverter iconv = <span style="color: #000000; font-weight: bold;">new</span> IConverter<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Html2Rtf.Converter&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></p>
<p>//Set properties of coversions. See help for Sautin<br />
iconv.setPreserveTables(true);<br />
iconv.setPreserveNestedTables(true);<br />
iconv.setPreserveTableWidth(true);<br />
iconv.setPreserveImages(true);<br />
iconv.setPreserveFontFace(true);<br />
iconv.setPreserveFontColor(true);<br />
iconv.setRtfLanguage(eLanguage.l_English);<br />
//rtfString = iconv.Convert(htmlString, &#8220;&#8221;, &#8220;&#8221;);<br />
rtfString = iconv.ConvertFileToString(htmlString, &#8220;&#8221;, &#8220;&#8221;);</p>
<p>//UnInitialize service COM objects<br />
Ole32.CoUninitialize();<br />
return rtfString;<br />
}</p>
<p>To use in your Java project, make sure to include jawin.jar and jawin-Stubs.jar in your classpath.</p>
<p>You can drop the Jawin.dll in to %WINDOWS%\system32 or specifically set the PATH and library path when invoking your Java app; e.g. here&#8217;s a .bat file example:</p>
<p><pre class="dos"><a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">set</span></a> <span style="color: #448844;">PATH</span>=%<span style="color: #448888;">PATH</span>%;.\dll
<a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">set</span></a> <span style="color: #448844;">CLASSPATH</span>=.\bin;.\lib\jawin.jar;.\lib\jawin-stubs.jar
java -Djava.library.path=.\dll Test</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://code.supergloo.com/2007/03/20/dll-from-java-with-jawin/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
