<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>philosophe &#187; groovy</title>
	<atom:link href="http://philosophe.com/tag/groovy/feed/" rel="self" type="application/rss+xml" />
	<link>http://philosophe.com</link>
	<description>A thoughtful approach to stuff.</description>
	<lastBuildDate>Sat, 14 May 2011 20:12:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Setting an entity property as a list with Gaelyk and Google Appengine</title>
		<link>http://philosophe.com/2009/10/setting-an-entity-property-as-a-list-with-gaelyk-and-google-appengine/</link>
		<comments>http://philosophe.com/2009/10/setting-an-entity-property-as-a-list-with-gaelyk-and-google-appengine/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 20:57:39 +0000</pubDate>
		<dc:creator>Derek Sisson</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[gaelyk]]></category>
		<category><![CDATA[Google Appengine]]></category>
		<category><![CDATA[groovy]]></category>

		<guid isPermaLink="false">http://philosophe.com/?p=238</guid>
		<description><![CDATA[As the Gaelyk site says, &#8220;Gaelyk is a lightweight Groovy toolkit for Google App Engine Java.&#8221; Gaelyk makes it easier and Groovier to play with datastore entities, allowing the following syntax for creating and saving Entity: import com.google.appengine.api.datastore.Entity //create the entity Entity student = new Entity("person") //set and populate properties student["name"] = "John Doe" student["grade"] [...]]]></description>
			<content:encoded><![CDATA[<p>As the <a href="http://gaelyk.appspot.com/">Gaelyk</a> site says, &#8220;Gaelyk is a lightweight Groovy toolkit for Google App Engine Java.&#8221;</p>
<p>Gaelyk makes it easier and Groovier to play with datastore entities, allowing the following syntax for creating and saving Entity:</p>
<pre class="snippet">
<code >import com.google.appengine.api.datastore.Entity

//create the entity
Entity student = new Entity("person")

//set and populate properties
student["name"] = "John Doe"
student["grade"] = "8"

student.save()</code>
</pre>
<p>What you can&#8217;t do with this easy syntax is save a property as a list; the following line fails:</p>
<pre class="snippet">
<code >//failed attempt to make the property a list
student["colors"] = ["blue", "green"]</code>
</pre>
<p>Instead, you have reach further down to the Entity class API:</p>
<pre class="snippet">
<code >import com.google.appengine.api.datastore.Entity

//create the entity
Entity student = new Entity("person")

//set and populate properties
student["name"] = "John Doe"
student["grade"] = "8"

//make the property a list first
student.setProperty("colors", [])
student["colors"] = ["blue", "green"]

student.save()</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://philosophe.com/2009/10/setting-an-entity-property-as-a-list-with-gaelyk-and-google-appengine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Canoo Webtest, Groovy, and Maintaining Session with Tests</title>
		<link>http://philosophe.com/2009/08/canoo-webtest-groovy-and-maintaining-session-with-tests/</link>
		<comments>http://philosophe.com/2009/08/canoo-webtest-groovy-and-maintaining-session-with-tests/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 21:21:13 +0000</pubDate>
		<dc:creator>Derek Sisson</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[webtest]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://philosophe.com/?p=215</guid>
		<description><![CDATA[The open source Canoo Webtest is a powerful tool for automating functional and regression tests for your web application. You can script your test steps in XML or in Groovy (or a mix of both), and you can build a comprehensive library of test steps that you combine and reorder into your tests. The documentation [...]]]></description>
			<content:encoded><![CDATA[<p>The open source <a href="http://webtest.canoo.com/webtest/manual/manualOverview.html">Canoo Webtest</a> is a powerful tool for automating functional and regression tests for your web application. You can script your test steps in XML or in Groovy (or a mix of both), and you can build a comprehensive library of test steps that you combine and reorder into your tests.</p>
<p>The documentation for Webtest is a little sparse when it comes to scripting it with Groovy, and I burned some cycles getting the solution, so I&#8217;m documenting it here.</p>
<p>With Webtest tests written in XML, the executable test is the &#8220;webtest&#8221; Ant task. Repeatable sequences of steps are saved in XML files, and included into that test. For example, here&#8217;s a login sequence saved as <em>includeLoginSequence.xml</em>:</p>
<pre class="snippet">
<code >&lt;group description="Successfully Log in"&gt;
    &lt;invoke description="Go to home page" url="${path}"/&gt;
    &lt;selectForm name="login"/&gt;
    &lt;setInputField description="set user name" name="username" value="myname"/&gt;
    &lt;setInputField description="set user password" name="password" value="mypassword"/&gt;
    &lt;clickButton name="login" description="Click the login button"/&gt;
&lt;/group&gt;</code>
</pre>
<p>And that sequence of steps gets included into the Webtest test:</p>
<pre class="snippet">
<code >&lt;webtest name="Log in and go to page 2"&gt;
    <strong>&amp;includeLoginSequence;</strong>
    &lt;invoke description="Go to page 2" url="/page2"/&gt;
&lt;/webtest&gt;</code>
</pre>
<p>Now, this isn&#8217;t all you need to run the test, but the key points here are the mechanism for saving and including &#8220;chunks&#8221; of repeatable step sequences, and the fact that all steps contained within the &#8220;webtest&#8221; ant task are executed within the same session. That last point is crucial: in order to maintain the session across all test steps, they must be in the same <strong>webtest</strong> container. </p>
<p>For Webtest tests written in Groovy, the paradigm is a little different. The tests are in a class that extends <strong>grails.util.WebTest</strong> and ends with the word &#8220;Test&#8221;, with the steps in a method that begins with the word &#8220;test&#8221;. For example:</p>
<pre class="snippet">
<code >class LoginSuccessfulTest extends grails.util.WebTest
{
    protected def loginSuccessful(path="/home") {
        webtest(name:"Log in and go to page 2") {
            group(description: "Successfully Log in") {
                invoke(description:"Go to home page", url:"${path}")
	        selectForm(name:"login")
                setInputField(description:"set user name", name:"username", value:"myname")
                setInputField(description:"set user password", name:"password", value:"mypassword")
 	        clickButton(name:"login", description:"Click the login button")
                invoke(description:"Go to page 2", url:"/page2")
            }
        }
    }
}</code>
</pre>
<p>In order to get a sequence of test steps that is repeatable and can maintain session, you need an inherited class that contains a method with the desired sequence. So start with a class that has the sequence but will not be executed as a test itself:</p>
<pre class="snippet">
<code >public class LoginBase extends grails.util.WebTest
{
    protected def loginSuccessful(path="/home") {
        group(description: "Successfully Log in") {
	    invoke(description:"Go to home page", url:"${path}")
	    selectForm(name:"login")
            setInputField(description:"set user name", name:"username", value:"myname")
            setInputField(description:"set user password", name:"password", value:"mypassword")
 	    clickButton(name:"login", description:"Click the login button")
        }
    }
}    </code>
</pre>
<p>Then extend that class into a class that will be executed as a test:</p>
<pre class="snippet">
<code >class LoginSuccessfulTest extends LoginBase
{
    testSuccessfulLogin() {
        webtest(name:"Log in and go to page 2") {
            <strong>loginSuccessful()</strong>
            group(description: "Go to page 2") {
                invoke(description:"Go to page 2", url:"/page2")
            }
        }
    }
}</code>
</pre>
<p>As you can see, the method <strong>loginSuccessful()</strong> from the parent class <strong>LoginBase</strong> gets called in the test method  <strong>testSuccessfulLogin()</strong>. Again, this is not everything you need to execute the test, but it demonstrates the relationship necessary to get a repeatable sequence of steps included in a way that maintains the session. </p>
]]></content:encoded>
			<wfw:commentRss>http://philosophe.com/2009/08/canoo-webtest-groovy-and-maintaining-session-with-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

