<?xml version="1.0" encoding="UTF-8"?>
<!--Generated by Squarespace V5 Site Server v5.13.166 (http://www.squarespace.com) on Tue, 18 Jun 2013 22:30:04 GMT--><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>Rimple on Tech</title><link>http://www.rimple.com/tech/</link><description></description><lastBuildDate>Mon, 17 Jun 2013 13:55:42 +0000</lastBuildDate><copyright></copyright><language>en-US</language><generator>Squarespace V5 Site Server v5.13.166 (http://www.squarespace.com)</generator><item><title>Spring Roo 1.2.4.RELEASE available now</title><category>News</category><category>Spring Roo</category><category>spring-roo</category><dc:creator>Ken Rimple</dc:creator><pubDate>Mon, 17 Jun 2013 13:50:46 +0000</pubDate><link>http://www.rimple.com/tech/2013/6/17/spring-roo-124release-available-now.html</link><guid isPermaLink="false">325483:3416732:33913238</guid><description><![CDATA[<p>Thanks to <a href="http://twitter.com/alankstewart">@alankstewart</a> and some new contributors from the open source community, Spring Roo 1.2.4 has been released. It is available for <a href="http://www.springsource.org/download/community?project=Spring%2520Roo">download now</a>.</p>

<p>Fifty issues have been <a href="https://jira.springsource.org/issues/?jql=project%20%3D%20ROO%20AND%20fixVersion%20%3D%20%221.2.4.RELEASE%22%20AND%20status%20%3D%20Resolved%20ORDER%20BY%20priority%20DESC">resolved</a> and it looks like the twitter tweet has been removed from the shell. </p>

<p>I'll be digging around with this a bit and posting any tidbits - I am also going to upgrade the code samples for Roo in Action to 1.2.4 this week, and will post any notes on what I find during upgrades.</p>

<p>Ken</p>
]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-33913238.xml</wfw:commentRss></item><item><title>AngularJS Pattern #1 - async service results</title><category>angularjs</category><category>tips and tricks</category><dc:creator>Ken Rimple</dc:creator><pubDate>Fri, 24 May 2013 16:32:56 +0000</pubDate><link>http://www.rimple.com/tech/2013/5/24/angularjs-pattern-1-async-service-results.html</link><guid isPermaLink="false">325483:3416732:33758194</guid><description><![CDATA[<h3>Spring Quizzo ETE sample code</h3>
<p>Hi everyone. If you're looking for examples of potential ways to interact with a Spring app from AngularJS, take a look at the project I worked on with Pivotal's David Turanski for ETE, the Quizzo-ETE application.</p>

<p>It's at <a href="http://github.com/krimple/quizzo-ete" target="_blank">github.com/krimple/quizzo-ete</a>. Highlights:</p>

<p>Now here's something I ended up using (but not as well as in here) for the quiz. It's a way to send a request to a Angular service asynchronously and receive a result via a message back to the component.</p>

<h3>Asynchronous calls to services in Angular</h3>
<p>In Angular, everything is asynchronous as much as possible to provide speed. A call to a <code>$http</code> service, which performs ajax methods, doesn't immediately return a value. If you decide to split up your Angular controllers and services, so you separate your UI from the calls to your backends, you'll quickly find that it becomes hard to get a response without some extra work.</p>

<p>One way to orchestrate calls is to use the Angular messaging framework, built into the <code>$scope</code> object. For example, in our controller we can execute a call to fetch games we're able to play right now, but we won't get the response right away.  So, we can subscribe to a message, sent by our service, which will then come back to us with data. See this simple JSFiddle for an example:

<iframe width="100%" height="300" src="http://jsfiddle.net/krimple/vf5H3/2/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>

<p>The service uses a passed <code>$scope</code> variable. I've also injected a <code>$rootScope</code> into the service. Using that one would allow us to broadcast the message to any interested party.</p>]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-33758194.xml</wfw:commentRss></item><item><title>Spring Roo project updates...</title><category>Spring Roo</category><category>spring-roo</category><dc:creator>Ken Rimple</dc:creator><pubDate>Sat, 04 May 2013 16:00:54 +0000</pubDate><link>http://www.rimple.com/tech/2013/5/4/spring-roo-project-updates.html</link><guid isPermaLink="false">325483:3416732:33557879</guid><description><![CDATA[<p>It's been a while and all has been quiet on my front - I've been buried with day-job work, and enjoying not having to update a book in a while :)</p>

<p>A quick note on Spring Roo - looks like there are plans for a 1.2.4 release sometime in the summer. Alan Stewart tweeted this earlier in the week.  Also, the Roobot, which accepts new <span class="caps">OSG</span>i bundles and also provides for downloading of existing ones, went down for a while, but due to some work recently by Alan it's up and running for internal bundles as of today. </p>

<p>If you're using Roo and need some basic Roo-provided bundles, they are now online. </p>

<p>Alan is working on getting the Roobot stabilized (some project descriptor might be causing trouble, we'll have to see which one - at one point it was mine). Once that's done they can re-populate the repository with the user-contributed ones.</p>

<p>Finally, the download link seems to be broken (the initial Download button works, but once you bypass registration and go to the download form, the real link is not a link), but follow my reply on <a href="http://forum.springsource.org/showthread.php?137026-Download-link-broken">this forum thread</a> for a quick workaround.</p>

<p>Once Roo 1.2.4 gets ready for takeoff, I'll post my notes on it. I've recently submitted a contributor agreement to help Alan with some things here and there, and if they accept it, I'll be able to do a bit more for the community.</p>
]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-33557879.xml</wfw:commentRss></item><item><title>Quizzo - it's baaack - but this time for keeps</title><category>ETE</category><category>angularjs</category><category>quizzo</category><category>quizzo-ete-2013</category><dc:creator>Ken Rimple</dc:creator><pubDate>Sat, 16 Feb 2013 17:00:00 +0000</pubDate><link>http://www.rimple.com/tech/2013/2/16/quizzo-its-baaack-but-this-time-for-keeps.html</link><guid isPermaLink="false">325483:3416732:32816474</guid><description><![CDATA[<p>Hey everybody!</p>

<p>For my <span class="caps">ETE </span>talk, and our internal Chariot Day conference beforehand, I've taken on client-side Single-Page-Web-Application (SPWA) Javascript programming. I started by attempting to learn Backbone.js, but this poor old server-side programmer with a smattering of front-end talents grounded hard on the shallow waters of confusion.</p>

<p>I was not alone. At SpringOne/2GX 2012, VMware's Craig Walls hosted a talk comparing <span class="caps">SPWA </span>frameworks, and discussed Backbone's lack of a 'day one story' - a starting point example. He was really interested in the Walmart Labs projects <a href="http://walmartlabs.github.com/thorax/" target="_blank" class="offsite-link-inline">Thorax</a> and <a href="http://walmartlabs.github.com/lumbar/" target="_blank" class="offsite-link-inline">Lumbar</a>, which are attempting to bring some higher-level structure and organization to the code base. Also, I ran into the emerging but not yet complete <a href="http://yeoman.io/" target="_blank" class="offsite-link-inline">Yeoman</a>   <br />
Then Chariot's <a href="https://twitter.com/doncoleman">Don Coleman</a> turned me on to Addy Osmani's <a href="http://todomvc.com/" target="_blank" class="offsite-link-inline">TodoMVC project</a> - it implements the same task list use case in oh, about 18+ frameworks.  </p>

<p>I spent time looking at each of them and AngularJS caught my eye. It has two-way instant data synchronization, is agnostic with respect to your models, contains a good basic validation scheme, and uses tags and attributes salted to the templates to expose a 'ViewModel' to the view.</p>

<h3>What is a view model?</h3>

<p>A ViewModel is an element of your <span class="caps">MVC </span>model that should be exposed to the page. Spring <span class="caps">MVC </span>has this concept - we put things in the Model object to show to the users, but rarely do we put true domain objects in there. If  you have web-only beans that you send back-and-forth to the <span class="caps">UI, </span>chances are you're using the ViewModel pattern (please let me know if that is a wrong assumption).</p>

<h3>A sample view</h3>

<p>Let's review some code from our current Quizzo-ETE project, a collaboration with David Turanski of VMware for our upcoming Modern Spring Web Applications talk.  We're using AngularJS and Spring to show enterprise developers  how to leverage their skills in Spring but also quickly get onboard with a very powerful <span class="caps">SPWA </span>framework.</p>

<p>First, a simple view fragment, showing how to emit model elements:</p>



<pre class="brush: html">
&lt;tr&gt;
    &lt;th span=&quot;2&quot;&gt;Statistics&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;th&gt;Score&lt;/th&gt;
    &lt;td&gt;{{statistics.score}}&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;th&gt;Max Score&lt;/th&gt;
    &lt;td&gt;{{statistics.maxScore}}&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;th&gt;% Correct&lt;/th&gt;
    &lt;td&gt;{{statistics.percentCorrect}}&lt;/td&gt;
&lt;/tr&gt;

</pre>



<p>So, you can see the handlebars-style substitutions of ViewModel elements using the <code>{{</code> and <code>}}</code> characters. </p>

<h3>A sample Angular controller </h3>

<p>Here is the Angular controller that put the data in there in the first place:</p>



<pre class="brush: javascript">
myApp.controller('ByeCtrl', function($scope) {
  $scope.statistics = {
    &quot;score&quot;: &quot;130&quot;,
    &quot;maxScore&quot;: &quot;150&quot;,
    &quot;percentCorrect&quot;: &quot;86%&quot;,
    &quot;topScorers&quot;: ['phil', 'joe', 'alex']
  };
</pre>



<p>The <code>$scope</code> object is our ViewModel. We're adding a Javascript object called </p>

<pre>statistics</pre>

<p> to it, hardcoding it for now. </p>

<h3>Two-way databinding</h3>

<p>The cool thing is that if anything on the page changes the objects, the page changes immediately. A click, an event, even a message from the outside world, can trigger a UI update. The same works the other direction with form elements. Consider this fragment:</p>



<pre class="brush: html">
  &lt;form class=&quot;panelform left&quot;&gt;
    &lt;p&gt;
        &lt;label for=&quot;nickname&quot;&gt;&lt;b&gt;Nickname&lt;/b&gt;&lt;/label&gt;
        &lt;input type=&quot;text&quot; 
               ng-model=&quot;nickname&quot;
               ng-change=&quot;verify_nick(nickname)&quot;
               id=&quot;nickname&quot;
                /&gt; 
        &lt;span ng-show=&quot;badNick&quot; class=&quot;error&quot;&gt;
                        Nickname already used...&lt;/span&gt;

    &lt;button id=&quot;join&quot; ng-click=&quot;join_game($location)&quot;
      ng-show=&quot;!badNick &amp;&amp; nickname&quot;&gt;Join&lt;/button&gt;
    &lt;/p&gt;
&lt;/form&gt;
</pre>



<h3>Handling events</h3>

<p>The input tag has some special attributes in it - <code>ng-model</code>, which automatically binds the typed in value (live, no less, not even requiring a submit) to a <code>$scope</code> element called <code>nickname</code>. We trigger verification by calling a controller method called <code>verify_nick</code>, passing the nickname into the call. Here is what the controller looks like:</p>



<pre class="brush: javascript">
myApp.controller('JoinCtrl', function ($scope, $location, PlayerService, QuizManagerService) {

  $scope.verify_nick = function () {
    var result = PlayerService.searchNickName($scope.nickname);
    $scope.badNick = result;
  };

  $scope.join_game = function (nickName, emailAddress) {
    PlayerService.setNickName(nickname);
    QuizManagerService.startQuiz();
    $location.path(&quot;/play&quot;);
  };


});
</pre>



<p>You can see interactions with several objects. For Spring fans, we inject objects in a similar way to how Spring <span class="caps">MVC </span>does it - add it to the function's parameter list and it gets injected. <span class="caps">NICE.</span></p>

<h3>Services </h3>

<p>We inject and use several objects:</p>

<ul>
<li><code>$scope</code> - our ViewModel</li>
<li><code>$location</code> - allows us to change the page fragment we're showing</li>
<li><code>PlayerService, QuizManagerService</code> - these are <em>stateful</em> service objects that live inside of the browser. Think of them as holding your state and calling business methods, and you're on the right track.</li>
</ul>

<p>You should note that in this function, we're adding two other named functions to the <code>ViewModel</code> - <code>verify_nick</code> and <code>join_game</code>. Also, for those Spring developers you'll see us delegating most work to our named Service and built-in Angular objects. Just like a good <span class="caps">MVC, </span>it's just a front-end. The services do all the work.</p>

<h3>Summary </h3>

<p>That's all for now, and if you check out the commit with version <code>33607951b734a0f1cfc8a710b41abd8664cc3e8f</code> you can run the app this way:</p>

<ul>
<li>first, install node.js - 0.8 +</li>
<li>next, do a 'npm install -g express'</li>
<li>cd to ./angular-prototype/app</li>
<li>run the server with <code>node server.js</code></li>
<li>browse to http://localhost:4567</li>
</ul>

<p>It looks <span class="caps">TERRIBLE </span>right now. But it is a working app with several panes. I'm using Twitter bootstrap on the front-end so expect some ugliness until I get that smoothed out.</p>

<p>To re-iterate, our code is online - please feel free to watch our progress and comment away here if you like, but expect lots of silly steps as we move along). It's at <a href="http://github.com/krimple/quizzo-ete" target="_blank" class="offsite-link-inline">http://github.com/krimple/quizzo-ete</a>.</p>
]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-32816474.xml</wfw:commentRss></item><item><title>Philly Emerging Tech 2013 - sold out!!</title><category>Philly ETE</category><dc:creator>Ken Rimple</dc:creator><pubDate>Sat, 16 Feb 2013 15:16:10 +0000</pubDate><link>http://www.rimple.com/tech/2013/2/16/philly-emerging-tech-2013-sold-out.html</link><guid isPermaLink="false">325483:3416732:32816461</guid><description><![CDATA[<p>Perhaps it's a bit expected, but the 2013 Emerging Technologies for the Enterprise conference just sold out yesterday. As before, it sold out at the end of the early bird registration, so everybody saved $75! </p>

<p>We have a <span class="caps">FANTASTIC </span>show coming up. Just look at the website, <a href="http://phillyemergingtech.com" target="_blank" class="offsite-link-inline">phillyemergingtech.com</a>, and you'll see. We have Doug Lea, Cliff Click, Ken Scwaber, Aaron Patterson, the committers of at least five or six javascript single-page and server frameworks, and the list goes on, and on.</p>

<p>As we did last year, we <span class="caps">ARE </span>going to record the screens this year of almost every talk (forgive us if we have a technical glitch or two).  We won't be streaming live, but we will be doing our best to get the talks out when we can. </p>

<p>So, if you aren't able to go, within a few months we should have the talks available online. Watch the @Chariotsolution or @krimple twitter accounts for the announcements. And you can browse all of our other content at our content site, <a href="http://emergingtech.chariotsolutions.com" target="_blank" class="offsite-link-inline">emergingtech.chariotsolutions.com</a>, including just about all of the 2012 talks, our Science of Big Data conference materials, and over 100 podcasts from the past five years.</p>

<p>Ken</p>
]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-32816461.xml</wfw:commentRss></item><item><title>Philly Emerging Tech April 2-3 2013 - Register today!</title><category>ETE</category><category>News</category><dc:creator>Ken Rimple</dc:creator><pubDate>Fri, 04 Jan 2013 16:25:40 +0000</pubDate><link>http://www.rimple.com/tech/2013/1/4/philly-emerging-tech-april-2-3-2013-register-today.html</link><guid isPermaLink="false">325483:3416732:32382630</guid><description><![CDATA[<p>Remember that conference in the spring? Well, it's baaack! Yep, it's 2013, and so we are full-steam ahead, planning for the next <a href="http://phillyemergingtech.com" target="_blank" class="offsite-link-inline">Emerging Technologies for the Enterprise</a> Conference, to be held at the Sheraton Olde City in beautiful Philadelphia on April 2-3.</p>

<p>We have quite the show lined up for you, with keynotes from <a href="https://twitter.com/richhickey" target="_blank" class="offsite-link-inline">Rich Hickey</a>, the creator of the <a href="http://clojure.org/" target="_blank" class="offsite-link-inline">Clojure language</a>, and <a href="http://m6d.com/">Media Six Degrees</a>' Chief Data Scientist, <a href="http://metamarkets.com/2012/data-scientist-profile-claudia-perlich-chief-scientist-at-m6d/" target="_blank" class="offsite-link-inline">Claudia Perlich</a>. Notable speakers include <a href="http://emberjs.com/" target="_blank" class="offsite-link-inline">Ember.js</a> creator (<a href="http://yehudakatz.com/2012/12/07/im-running-to-reform-the-w3cs-tag/" target="_blank" class="offsite-link-inline">among</a> <a href="http://yehudakatz.com/2012/04/13/tokaido-my-hopes-and-dreams/" target="_blank" class="offsite-link-inline">other</a> <a href="http://rubyonrails.org/core" target="_blank" class="offsite-link-inline">things</a>) <a href="http://yehudakatz.com/" target="_blank" class="offsite-link-inline">Yehuda Katz</a>, <a href="http://web.mit.edu/jesstess/" target="_blank" class="offsite-link-inline">Jessica McKellar</a> of the <a href="http://twitter.com/bostonpython" target="_blank" class="offsite-link-inline">Boston Python User Group</a>, <a href="http://twistedmatrix.com/trac/" target="_blank" class="offsite-link-inline">contributor</a> to the Python Twisted async network library, the inimitable <a href="http://tenderlovemaking.com/" target="_blank" class="offsite-link-inline">Aaron Patterson</a> (if you want a laugh, listen to him rib us about our conference name in his <a href="http://wharton6.mediasite.com/mediasite/Play/cc319b19847a40b293cd23ab5db479d91d?catalog=216aac01-e4cb-42cd-8c4e-aaf681778f06" target="_blank" class="offsite-link-inline">Code Chacuterie talk of 2012</a>)... </p>

<p>Also we have <a href="http://www.infoq.com/author/Cliff-Click" target="_blank" class="offsite-link-inline">Cliff Click</a> (0xdata), author of "<a href="http://www.amazon.com/Java-Performance-Charlie-Hunt/dp/0137142528" target="_blank" class="offsite-link-inline">Java Performance</a>" <a href="https://blogs.oracle.com/javaspotlight/entry/java_spotlight_episode_49_charlie" target="_blank" class="offsite-link-inline">Charlie Hunt</a>, <a href="http://golang.org/" target="_blank" class="offsite-link-inline"></a>Go contributor and creator of <a href="http://www.sinatrarb.com/" target="_blank" class="offsite-link-inline">Sinatra</a> <a href="https://github.com/bmizerany" target="_blank" class="offsite-link-inline">Blake Mizerany</a>, author of "<a href="http://www.amazon.com/The-Culture-Game-Tools-Manager/dp/0984875301" target="_blank" class="offsite-link-inline">The Culture Game - Tools for the Agile Manager</a>" <a href="http://newtechusa.net/dan-mezick/" target="_blank" class="offsite-link-inline">Dan Mezick</a>, <a href="http://www.jurgenappelo.com/" target="_blank" class="offsite-link-inline">Jurgen Appelo</a> (author of <a href="http://www.management30.com/product/management30/" target="_blank" class="offsite-link-inline">Management 3.0</a>), the creator of the <a href="http://scrum.com" target="_blank" class="offsite-link-inline">Scrum process</a>, <a href="http://en.wikipedia.org/wiki/Ken_Schwaber" target="_blank" class="offsite-link-inline">Ken Schwaber</a>, and more are being added every day.</p>

<p>We even have Angluar.js expert Lukas Ruebbelke (see <a href="http://angularjs.org/" target="_blank" class="offsite-link-inline">Angular.js</a>), a Google-sponsored "<a href="http://en.wikipedia.org/wiki/Single-page_application" target="_blank" class="offsite-link-inline">single page Javascript</a>" client-side application framework that uses <span class="caps">JSON</span>/REST and has live two-way data binding. (I didn't even realize we booked him when I published this so ignore my earlier version where I said I am speaking on this topic). And as usual we'll be recording sessions and hopefully podcasting too.</p>

<p>More speakers are being booked each week.  </p>

<p>So, don't delay. Last year we sold out with two months to go, and I think as we add additional awesome speakers the competition for a ticket will get intense. Register today at <a href="http://phillyemergingtech.com" target="_blank" class="offsite-link-inline">phillyemergingtech.com</a>.</p>

<p>If you want more incentives, the early bird registration is just $385, and ends on February 15th. After that prices go up to $450 (still a steal, but why not save and register now, will ya?)</p>
]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-32382630.xml</wfw:commentRss></item><item><title>The future of Web MVC testing</title><category>Tips</category><category>spring</category><category>spring mvc</category><category>testing</category><dc:creator>Ken Rimple</dc:creator><pubDate>Wed, 19 Dec 2012 23:12:12 +0000</pubDate><link>http://www.rimple.com/tech/2012/12/19/the-future-of-web-mvc-testing.html</link><guid isPermaLink="false">325483:3416732:32104260</guid><description><![CDATA[<p>Ok, ok, I'm excited. Right now I just was able to hack my way through a test with Spring 3.2 and the new test web context.</p>

<p>The method I ended up writing looked like this:</p>



<pre class="brush: java">
@Test
public void tryStartQuiz() throws Exception {
   this.mvc.perform(get(&quot;/engine/start/james&quot;))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath(&quot;$.quiz_id&quot;).exists());
}
</pre>



<h3>How did I get here? </h3>

<p>I upgraded to Spring 3.2, which has native support for loading Web contexts (well, not in a separate-but-parent/child way where you can mount the web context and business context separately, that's coming, but in one context).</p>

<p>Here is the top of my test class:</p>



<pre class="brush: java;">

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;

@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
   &quot;file:src/main/webapp/WEB-INF/spring/webmvc-config.xml&quot;, 
   &quot;classpath:/META-INF/spring/applicationContext.xml&quot;})
public class EngineControllerTest {

    @Autowired
    WebApplicationContext context;

    MockMvc mvc;

    @Before
    public void setUp() {
        mvc = webAppContextSetup(this.context).build();
    }

    ...

</pre>



<h3>Some analysis...</h3>

<p>The <code>MockMvc</code> object, which I referred to as <code>this.mvc</code> in my test, allows me to mock up the web container request and record expectations. It is created in the <code>@Before</code> method, after Spring injects a test <code>WebApplicationContext</code> object, which is driven via the <code>@WebAppConfiguration</code> above. </p>

<p>The <code>WebApplicationContext</code> object is a web app engine in a test engine. It boots a Spring <span class="caps">MVC </span>platform, mocking the network engine so that you can submit requests with calls like <code>mvc.perform(get(...) ...</code> and chain assertions, using <code>.andExpect</code> statements to build conditions. It's like headless Spring <span class="caps">MVC.</span> This allows you to test by submitting <span class="caps">URL</span>s but without having to configure Jetty or Tomcat in a complex server bootstrapped integration test.</p>

<h3>But where is it looking for my webapp?</h3>

<p>As a nice touch, the default path for the web application is <code>src/main/webapp</code>. If you're not mavenized, or have a test version of your webapp you want to use, you can submit the path to it as the value of the annotation, like:</p>

<code>@WebApplicationContext(&quot;src/test/lightweightwebapp&quot;)</code>

<h3>Assertions and matchers</h3>

<p>There are several static imports that make life easier, as outlined in this great slide show from the <a href="http://rstoyanchev.github.com/spring-32-test-webapps" target="_blank"><span class="caps">MVC </span>team (Rossen and friends)</a>:</p>



<pre class="brush: java;">
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
</pre>



<p>I had to hack a bit with the commands and don't have the <span class="caps">DSL </span>figured out much so far. But it is nice to test through the request dispatcher rather than inject a controller directly. It's more natural and lets you really test the way production will handle your requests/responses.</p>

<h3>What about more sophisticated checks?</h3>

<p>The expect syntax doesn't really allow dicing and slicing of the response as easily as grabbing it in a variable. You can tell the mock <span class="caps">MVC </span>object to return the result, which contains the MockHttpServletResponse. In this example, I'm using FlexJson (from Roo's dependencies) to deserialize the <span class="caps">JSON </span>request into a HashMap of string keys and values, and assert that the data exists in the proper format.</p>



<pre class="brush: java">
@Test
public void tryStartQuiz() throws Exception {
	JSONDeserializer&lt;HashMap&lt;String, String&gt;&gt; deserializer
			= new JSONDeserializer&lt;HashMap&lt;String, String&gt;&gt;();

	MvcResult result = this.mvc.perform(get(&quot;/engine/start/james&quot;))
			.andExpect(status().isOk())
			.andExpect(content().contentType(MediaType.APPLICATION_JSON))
			.andExpect(jsonPath(&quot;$.quiz_id&quot;).exists())
			.andReturn();

	Map&lt;String, String&gt; jsonPayload =
			deserializer.deserialize(
					result.getResponse().getContentAsString());

	assertThat(jsonPayload.containsKey(&quot;quiz_id&quot;), is(true));
	assertThat(jsonPayload.get(&quot;nickname&quot;), is(&quot;james&quot;));

	System.err.println(jsonPayload);


}

</pre>



<h3>Roo and Spring 3.2 </h3>

<p>One more thing - I came from Roo 1.2.2, and as I upgraded the spring.version property to Spring 3.2 (yes, it works just fine) so I had to add one dependency in order for this to work, test scoped:</p>



<pre class="brush: xml;">
&lt;dependency&gt;
	&lt;groupId&gt;com.jayway.jsonpath&lt;/groupId&gt;
	&lt;artifactId&gt;json-path&lt;/artifactId&gt;
	&lt;version&gt;0.8.1&lt;/version&gt;
	&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
</pre>



<p>Roo was just upgraded to version 1.2.3 this week (check it out <a href="http://www.springsource.org/spring-roo">here</a>). I am hoping it uses Spring 3.2 out of the box. </p>

<p>This test will be checked into the next update of Quizzo-Angular-Roo - my current obsession which is using Spring Roo on the backend, and Angular.JS on the front-end, for a single-page JS quiz engine. </p>

<h3>Where to go to view the code?</h3>

<p>Today I've pushed this code (somewhat modified) along with working Jasmine tests, <span class="caps">AND </span>a working Maven test suite that includes automatic Jasmine testing every time I run <code>mvn test</code>. Check it out at <a href="https://github.com/krimple/quizzo-angular-roo">quizzo-angular-roo on GitHub</a>. I warn you, it will be primitive and so far not really doing much, but it will shape up over time.</p>
]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-32104260.xml</wfw:commentRss></item><item><title>todo-txt - very cool GTD task management from anything</title><category>productivity</category><dc:creator>Ken Rimple</dc:creator><pubDate>Wed, 21 Nov 2012 00:46:17 +0000</pubDate><link>http://www.rimple.com/tech/2012/11/20/todo-txt-very-cool-gtd-task-management-from-anything.html</link><guid isPermaLink="false">325483:3416732:31118764</guid><description><![CDATA[<p>So, just I stumbled on Gina Tripani's todo-txt project when searching for a cross-device todo management system. I am switching from an iPhone to an Android device as I'm prepping to provide some Android training for Chariot in the early part of next year. </p>

<p>todo-txt is a very simple format. Described <a href="http://todotxt.com/">here</a> and with a client for virtually anything (including the command-line, vim, Android, iOS, even WebOS) you can use it from anything, even a text editor. The clients are all savvy with Dropbox, so putting it on ~/Dropbox/todo is all you need to do.</p>

<p>Here is a groovy script I just wrote up to play with my todo list...</p>



<pre class="brush: groovy;">
def todoFile = new File('./todo.txt')
def fileReader = new FileReader(todoFile)
def todos = fileReader.readLines()
def projects = [:], contexts = [:]
todos.each { it -&gt;
  println it
  def tokenizer = new StringTokenizer(it)
  while (tokenizer.hasMoreTokens()) {
      def token = tokenizer.nextToken()
      if (token.startsWith(&quot;@&quot;)) {
          def size = contexts[token] ? contexts[token] : 0
          contexts[token] = size + 1
      }
      if (token.startsWith(&quot;+&quot;)) {
          def size = projects[token] ? projects[token] : 0
          projects[token] = size + 1
      }
    
  }
}
fileReader.close()

projects.each { key, value -&gt; 
  println &quot;Project ${key} : ${value} tasks&quot;
}

println &quot;&quot;
contexts.each { key, value -&gt; 
  println &quot;context ${key} : ${value} tasks&quot;
}

</pre>



<p>Fun, eh? Now I can rid myself of the OS X reminders system - although I could really use the ability to store these in my Google calendar as timed events with due dates... Hmm...</p>
]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-31118764.xml</wfw:commentRss></item><item><title>STS 3.1.0.RELEASE - not loving Spock / Groovy for ADJT projects</title><category>SpringSource Roo</category><category>SpringSource Tool Suite</category><category>Technology News</category><category>groovy</category><dc:creator>Ken Rimple</dc:creator><pubDate>Sun, 21 Oct 2012 14:33:37 +0000</pubDate><link>http://www.rimple.com/tech/2012/10/21/sts-310release-not-loving-spock-groovy-for-adjt-projects.html</link><guid isPermaLink="false">325483:3416732:29970718</guid><description><![CDATA[<p>At SpringOne/2GX I tried the updated Springsource Tool Suite, 3.1.0, running a pre-4.0 Eclipse (as the <span class="caps">STS</span> 3.1.0 version is a bit tricky on Eclipse 4 until the 3.x - 4.0 migration bugs settle down).</p>

<p>Turns out there is a new error that shows up if you try to run anything Groovy within a <span class="caps">AJDT </span>project (which is the AspectJ Developer Tools plug-in Roo requires to compile all *.aj files when you're using them in the <span class="caps">IDE</span>).</p>

<p>You'll get:</p>



<pre class="brush: bash;">
Error compiling Groovy project: Either the Groovy-JDT patch is not installed or JavaBuilder is not being used.
</pre>



<p>I realize from talking to one of the developers at SpringOne that there have been some issues with the way Groovy handles AspectJ compiled classes, and that using Groovy within a Spring Roo project as general code it won't work properly, but this puts a damper on Spock at least from within the <span class="caps">STS IDE.</span> I can still run my tests from IntelliJ, however.</p>

<p>I'm going to post a request in the forums that we can turn off this error, so that we can use Spock for testing. So far, at least with Roo add-ons, I have used it to great effect and productivity, so at least for that use case I'd like to have an option to turn it off.</p>

<p>More soon.</p>

<p>Ken</p>
]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-29970718.xml</wfw:commentRss></item><item><title>More Spock love - how I tested complex install scenarios</title><category>Spring Roo</category><category>spring-roo</category><dc:creator>Ken Rimple</dc:creator><pubDate>Thu, 04 Oct 2012 18:29:31 +0000</pubDate><link>http://www.rimple.com/tech/2012/10/4/more-spock-love-how-i-tested-complex-install-scenarios.html</link><guid isPermaLink="false">325483:3416732:29636421</guid><description><![CDATA[<p>I'm in love. Officially. With Spock.</p>

<p>Ok, we've only been hanging out for a little bit, here and there. But one of the things I'm doing is prepping for an updated talk on Spring Roo add-ons at SpringOne/2GX. Rather than repeat the same things again, I wanted to show some practical help for people writing add-ons, things like how to write good tests.</p>

<p>Also, I wanted to point out a few things that need more work, bring up some issues for the <span class="caps">JIRA </span>queue, so that we can improve Roo further after SpringOne. We'll get to that later in this article.</p>

<h3>Testing add-on availability</h3>

<p>Testing whether an add-on setup command is available to expose to the Roo shell can be a bit tricky. For example, in the Spock Roo add-on, I expect that the user's shell is:</p>

<ul>
<li>running in a project context</li>
<li>the project has to contain two maven dependencies for spock-core and spock-spring</li>
<li>the project has to contain one dependency for the gmaven-plugin to run Spock tests</li>
</ul>

<p>So, there are several scenarios to test. I started down the road to testing them all individually. Bad developer. First off, there is a sort of truth table here:</p>


<table><tr><th>installedDependencies</th><th>installedPlugins</th><th>expectedResult</th></tr><tr><td>none</td><td>none</td><td>true</td></tr><tr><td>depa, depb</td><td>none</td><td>true</td></tr><tr><td>depa</td><td>plugin</td><td>true</td></tr><tr><td>baddep</td><td>none</td><td>true</td></tr><tr><td>depa, depb</td><td>plugin</td><td>false</td></tr><tr><td>depabadversion, depb</td><td>plugin</td><td>true</td></tr></table>

<p><strong>Given</strong>:</p>

<ul>
<li>depa and depb = the correct two Maven dependencies, </li>
<li>baddep is a Maven dependency completely unrelated </li>
<li>depabadversion is the same dependency but a different version </li>
<li>plug-in is the gmaven-plugin from codehaus</li>
<li>expectedResult is whether or not we can go ahead and install the add-on (i.e. replace what is there)</li>
</ul>

<p>As I started the third method I saw so much duplication I started to back off. First I removed whatever extra calls I was making to various methods (such as projectOperations.getDependencies()) which made it easier to test (and debug).  Then, I pulled out the data table syntax. </p>

<p>Here is what I ended up with. Totally boss, <span class="caps">BTW</span>:</p>



<pre class="brush: groovy;">
package org.sillyweasel.roo.addons.spock
import org.springframework.roo.project.Dependency
import org.springframework.roo.project.Plugin
import org.springframework.roo.project.ProjectOperations
import org.springframework.roo.project.maven.Pom
import spock.lang.Unroll

class SpockOperationsImplTest extends spock.lang.Specification {

  static def depa = 
    new Dependency(&quot;org.springframework&quot;, &quot;spock-core&quot;, &quot;0.6-groovy-1.8&quot;)
  static def depb = 
    new Dependency (&quot;org.springframework&quot;, &quot;spock-spring&quot;, &quot;0.6-groovy-1.8&quot;)
  static def depabadversion =
    new Dependency(&quot;org.springframework&quot;, &quot;spock-core&quot;, &quot;0.6-groovy-1.0&quot;)
  static def baddep = 
    new Dependency (&quot;org.springframework&quot;, &quot;sbad&quot;, &quot;0.6-groovy-1.8&quot;)
  static def plugin = 
    new Plugin(&quot;org.codehaus.gmaven&quot;, &quot;gmaven-plugin&quot;, &quot;1.4&quot;)


  @Unroll
  def &quot;install check - #situation&quot;() {
    given:
      def pom = Mock(Pom.class)
      def operations = new SpockOperationsImpl()
      def projectOperations = Mock(ProjectOperations.class)
      operations.projectOperations = projectOperations

    when:
      def commandAvailable = operations.isSetupCommandAvailable()

    then:
      1 * projectOperations.isFocusedProjectAvailable() &gt;&gt; true
      1 * projectOperations.getFocusedModule() &gt;&gt; pom
      1 * pom.getDependencies() &gt;&gt; deps
      pom.getBuildPlugins() &gt;&gt; plugins
      assert commandAvailable == res

    where:
    deps          | plugins | res   | situation
    []            | []      | true  | &quot;no installedDependencies or installedPlugin&quot;
    [ depa, depb] | []      | true  | &quot;all installedDependencies...
                                      but no installedPlugin&quot;
    [ depa ]      | [plugin]| true  | &quot;some installedDependencies...
                                       and installedPlugin&quot;
    [ baddep ]    | []      | true  | &quot;a different dependency and no plugins&quot;
    [ depa, depb ]| [plugin]| false | &quot;all installedDependencies and installedPlugin&quot;
    [ depabadversion, depb ] 
                  | [plugin] | true | &quot;bad version of a plugin&quot;
  }
}

</pre>



<h3>What's even better...</h3>

<p>See the method name at the top? It has an embedded hash mark, and uses the `situation` field, plus the `@Unroll` annotation, to turn the method into five separate test methods on the fly at test time.  Niiiice!</p>

<h2>Roo's challenges - addon testing</h2>

<p>Why am I doing all of my testing in Groovy when Roo is a Java-based framework? Three reasons:</p>

<ul>
<li>I want to get rolling on add-ons, </li>
<li>I need to understand the weaknesses of the add-on <span class="caps">API </span>so I can try to help improve it, </li>
<li>I need to make sure I test the most code for the least effort!</li>
</ul>

<p>To the middle point: Roo is based on Maven and Spring. It manages a Maven `pom.xml` file, as well as Spring, Java and other artifacts.</p>

<p>Because the Maven files are managed by some Java wrapper classes, written for the purpose of generating Maven <span class="caps">POM</span>s, they are currently good enough - you can fill them via an Xml <span class="caps">DOM, </span>for example, but they aren't inherently testable.</p>

<p>For example, the Pom class can't be mocked, so I can't inject a fake set of dependencies or plugins. That is, unless I install two Maven test dependencies, both of which <em>Spock told me to use as a helpful hint!</em> They are: `cglib-nodep` for mocking interface-less classes, and `objenesis` for creating instances of classes as Mocks without no-arg constructors. To wit:</p>



<pre class="brush: xml;">
&lt;dependency&gt;
  &lt;groupId&gt;cglib&lt;/groupId&gt;
  &lt;artifactId&gt;cglib-nodep&lt;/artifactId&gt;
  &lt;version&gt;2.2.2&lt;/version&gt;
  &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
  &lt;groupId&gt;org.objenesis&lt;/groupId&gt;
  &lt;artifactId&gt;objenesis&lt;/artifactId&gt;
  &lt;version&gt;1.2&lt;/version&gt;
  &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
</pre>



<p>With that, I can use:</p>



<pre class="brush: groovy;">
def pom = Mock(Pom.class)
</pre>



<h3>See you at SpringOne/2GX</h3>

<p>I'll be talking about this and other techniques at SpringOne/2GX in two weeks, and I'll post my presentation later as well. I hope to see some of you there.</p>
]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-29636421.xml</wfw:commentRss></item><item><title>My Roo add-ons talk at SpringOne/2GX is approved</title><category>chariot-news</category><category>speaking-engagements</category><category>spring-roo</category><category>springone-2gx</category><dc:creator>Ken Rimple</dc:creator><pubDate>Tue, 11 Sep 2012 20:04:03 +0000</pubDate><link>http://www.rimple.com/tech/2012/9/11/my-roo-add-ons-talk-at-springone2gx-is-approved.html</link><guid isPermaLink="false">325483:3416732:28634713</guid><description><![CDATA[<p>Hello there. I'll be speaking about Spring Roo add-ons again at SpringOne/2GX this year. If you're heading to the show and want to talk shop on Roo and other things, seek me out. I'll be happy to chat.</p>

<p>Here is a <a href="http://www.springone2gx.com/conference/washington/2012/10/session?id=27797" target="_blank" class="offsite-link-inline">link to the talk</a>.</p>
]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-28634713.xml</wfw:commentRss></item><item><title>Speaking at SpringOne/2GX - topic - Roo add-ons</title><dc:creator>Ken Rimple</dc:creator><pubDate>Thu, 23 Aug 2012 12:24:16 +0000</pubDate><link>http://www.rimple.com/tech/2012/8/23/speaking-at-springone2gx-topic-roo-add-ons.html</link><guid isPermaLink="false">325483:3416732:24733772</guid><description><![CDATA[<p>Hello, viewers. I've just received word that I'll be speaking at SpringOne/2GX this year. No link yet but I'm working on that. I'll be down there all week, so I hope to see you there.</p>
]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-24733772.xml</wfw:commentRss></item><item><title>Watch my SpringSource Roo add-ons video w/Srini Penchikala and SpringSource's Josh Long</title><category>Screencasts</category><category>chariot-news</category><category>spring-roo</category><dc:creator>Ken Rimple</dc:creator><pubDate>Mon, 20 Aug 2012 02:34:40 +0000</pubDate><link>http://www.rimple.com/tech/2012/8/19/watch-my-springsource-roo-add-ons-video-wsrini-penchikala-an.html</link><guid isPermaLink="false">325483:3416732:24127241</guid><description><![CDATA[<iframe width="640" height="360" src="http://www.youtube.com/embed/_VMmzaUxE0c?feature=player_detailpage" frameborder="0" allowfullscreen></iframe>]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-24127241.xml</wfw:commentRss></item><item><title>Spock's data tables are sweet!</title><category>Spock</category><category>Spring Roo</category><category>chariot-news</category><category>chariot-news</category><category>spring-roo</category><category>testing</category><dc:creator>Ken Rimple</dc:creator><pubDate>Sun, 08 Jul 2012 14:18:59 +0000</pubDate><link>http://www.rimple.com/tech/2012/7/8/spocks-data-tables-are-sweet.html</link><guid isPermaLink="false">325483:3416732:17517883</guid><description><![CDATA[<p>I'm working with Spock again for updating my CoffeeScript plugin for Roo 1.2.3.  There have been a few helpful additions to the add-on <span class="caps">API</span>s (unless I missed them in 1.2.2...) and so my code is getting a tad simpler.</p>

<p>The coolest thing is that converting my tests to Spock, I had an easy way to do a truth table testing condition when I wanted to try out a number of scenarios. Check out this snippet, specifically the "where:" block and the values from the where block variables within the test conditions.</p>

<p>I've switched this test to the more formal given: when: then: syntax, and added the where: section for the data tables settings. I think I was using setup: instead of given: and I also didn't put my expectations in the then: section, which they evaluate in regardless. It's more readable this way.</p>

<p><em>Note, the version of the coffeescript add-on listed in the test is irrelevant, as the method called to fetch the plugin ignores it but the Plugin constructor requires a version.</em></p>



<pre class="brush: groovy;">
@Unroll(&quot;evalto #evalto for project available #available, 
         packaging #packaging and pluginList #pluginList&quot;)
def &quot;test isPluginInstalled with scenarios&quot;() {
    given:
    def projectOperations = Mock(ProjectOperations.class)
    coffeescriptOperations.projectOperations = projectOperations
    def pom = Mock(Pom.class)

    when:
    def result = coffeescriptOperations.isPluginInstalled()

    then:
    coffeescriptOperations.projectOperations
            .isFocusedProjectAvailable() &gt;&gt; available
    coffeescriptOperations.projectOperations.getFocusedModule() &gt;&gt; pom
    pom.getPackaging() &gt;&gt; packaging
    pom.getBuildPluginsExcludingVersion(_) &gt;&gt; pluginList

    result == evalto

    where:
    pluginList | available | packaging  | evalto
    [] | false | &quot;foo&quot; | false
    [] | true  | &quot;war&quot; | false
    [] | true  | &quot;pom&quot; | false
    [new Plugin(&quot;com.theoryinpractise&quot;,
            &quot;coffee-maven-plugin&quot;, &quot;1.2.0&quot;) ] | true | &quot;war&quot; | true
    [new Plugin(&quot;com.theoryinpractise&quot;,
            &quot;coffee-maven-plugin&quot;, &quot;1.2.0&quot;)] | true | &quot;pom&quot; | false
}
</pre>



<p>I was able to fold five specific test cases checking whether the project contains the Coffeescript plugin into one test with five data settings (all false except one):</p>

<ul>
<li>The focused project is not available</li>
<li>The packaging is a war, the focused project is available, the add-on is not installed</li>
<li>The packaging is a "pom" and the project is available</li>
<li>The plugin exists, the type is a war, the focused module is available (happy!)</li>
<li>The plugin exists (mounted by hand perhaps) on a pom project which is the current module</li>
</ul>

<p>I used @Unroll to turn the data table results into five separate tests, each of which listed separately in the test results. Note the method name of the test is comprised of literal strings with data from the datatable columns starting with '#'. Nice, eh? </p>

<p>So I was able to collapse five test scenarios into one with the data tables. Nice.</p>

<p>You can pull the git repository for this add-on by using:</p>


<pre>
git clone git://git.cloudbees.com/sillyweasel/coffeescript-roo-addon.git
</pre>
]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-17517883.xml</wfw:commentRss></item><item><title>Now on java.net : my article on WebFlow and Roo from the "Cutting Room Floor" of Roo in Action</title><category>SpringSource Roo</category><category>chariot-news</category><dc:creator>Ken Rimple</dc:creator><pubDate>Thu, 21 Jun 2012 13:30:26 +0000</pubDate><link>http://www.rimple.com/tech/2012/6/21/now-on-javanet-my-article-on-webflow-and-roo-from-the-cuttin.html</link><guid isPermaLink="false">325483:3416732:16877553</guid><description><![CDATA[<p>You can read my first <a href="http://java.net">java.net</a> article, posted on our behalf from Manning's author articles series, entitled <a href="http://today.java.net/article/2012/06/19/spring-roo-and-webflow-ken-rimple-co-author-spring-roo-action?force=551" target="_blank">Spring Roo and WebFlow</a>, on Java.Net's technical articles series starting today.</p>

<p>Thanks to Manning's Nermina Miller for helping me get it finished, java.net's Kevin Farnham for publishing it, and Manning's Candace Gillhooley for getting the project going.</p>

<p>I anticipate a few more "cutting room floor" articles, since the book took some twisty turns while Srini and I were formulating the content for the final book.</p>
]]></description><wfw:commentRss>http://www.rimple.com/tech/rss-comments-entry-16877553.xml</wfw:commentRss></item></channel></rss>