<?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>Pathfinder Software &#187; Ivan Moscoso</title>
	<atom:link href="http://pathfindersoftware.com/author/ivan-moscoso/feed/" rel="self" type="application/rss+xml" />
	<link>http://pathfindersoftware.com</link>
	<description>The Fastest Way to Launch Successful Software</description>
	<lastBuildDate>Thu, 19 Jan 2012 16:31:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Snow Leopard: the Obvious Choice</title>
		<link>http://pathfindersoftware.com/2009/08/snow-leopard-wins/</link>
		<comments>http://pathfindersoftware.com/2009/08/snow-leopard-wins/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 16:00:29 +0000</pubDate>
		<dc:creator>Ivan Moscoso</dc:creator>
				<category><![CDATA[Technologies and Platforms]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=3409</guid>
		<description><![CDATA[When OS X 10.5 (Leopard) was released back in late 2007, I told a colleague at the time that Leopard was, by far, the worst release Apple ever put out. You can pardon a bit of hyperbole there, but after a healthy string of solid releases of OS X that just &#8220;worked&#8221;, the problems produced ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F08%2Fsnow-leopard-wins%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F08%2Fsnow-leopard-wins%2F&amp;source=PathSoft&amp;style=normal&amp;service=bit.ly&amp;service_api=R_8a1154b608af9e55718b231fb0025d40&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="right" src="http://pathfindersoftware.com/wp-content/uploads/snowleopard11.jpg" alt="OS X 10.6" width="150" height="150" /></p>
<p>When OS X 10.5 (Leopard) was released back in late 2007, I told a colleague at the time that Leopard was, by far, the <i>worst release</i> Apple ever put out. You can pardon a bit of hyperbole there, but after a healthy string of solid releases of OS X that just &#8220;worked&#8221;, the problems produced by Leopard were numerous (one might counter that this is all relative&#8211; four to five issues might not sound as numerous to users of other operating systems, but for OS X, these were a pretty big deal, and kept me from switching for months).</p>
<p>By comparison, Snow Leopard marks a great return to the kind of releases the Mac community came to expect.  Yes we still have a month left to wait for its release, and yes there might always be small glitches, but as one long-time Mac user the answer to the question of &#8220;is it <i>really</i> all that?&#8221; the answer is pretty clear to me at least:  &#8220;Yes, yes it totally is.&#8221;<br />
<span id="more-3409"></span></p>
<p>There are two ways of looking at an operating system: the underpinnings of the platform (in the technical sense), or, in the popular sense, the body of applications surrounding and defining a baseline of functionality all users can expect each other to have.  The great thing about Snow Leopard is, without getting into details itself, that there are enough improvements in both areas to make this a must-have upgrade.  And as a footnote, the number of issues I have had with the betas so far have been relatively minor in comparison with 10.5.  There really is no contest.  Whereas the initial release of 10.5 brought some improvements to the operating system at a very large cost for early adopters, 10.6 brings a lot of improvements with much lower risk.</p>
<p>I&#8217;m not going to rehash what&#8217;s new in Snow Leopard, but suffice to say that it proves out the wisdom of Apple&#8217;s strategy to focus on improving the internals &#8216;under the hood&#8217; for this release.  Since the release of 10.5, Mac users have been fortunate enough to see improvements with other technologies on the platform (Safari 4 comes to mind), and hardware that continues to improve both in features and price.  OS X by itself does not need to draw people to the platform&#8211; the iPhone and Mac hardware will do that.  So it seems to me that, thanks to these other factors, the keys to the OS have been given back a bit to the engineers&#8211; and if my instincts are right, it&#8217;s going to be a great release.
<p><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F08%2Fsnow-leopard-wins%2F&amp;linkname=Snow%20Leopard%3A%20the%20Obvious%20Choice" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F08%2Fsnow-leopard-wins%2F&amp;linkname=Snow%20Leopard%3A%20the%20Obvious%20Choice" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F08%2Fsnow-leopard-wins%2F&amp;linkname=Snow%20Leopard%3A%20the%20Obvious%20Choice" title="Digg" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_dzone" href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F08%2Fsnow-leopard-wins%2F&amp;linkname=Snow%20Leopard%3A%20the%20Obvious%20Choice" title="DZone" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F08%2Fsnow-leopard-wins%2F&amp;linkname=Snow%20Leopard%3A%20the%20Obvious%20Choice" title="Reddit" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F08%2Fsnow-leopard-wins%2F&amp;linkname=Snow%20Leopard%3A%20the%20Obvious%20Choice" title="Delicious" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F08%2Fsnow-leopard-wins%2F&amp;linkname=Snow%20Leopard%3A%20the%20Obvious%20Choice" title="Evernote" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F08%2Fsnow-leopard-wins%2F&amp;title=Snow%20Leopard%3A%20the%20Obvious%20Choice" id="wpa2a_2">Share/Bookmark</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pathfindersoftware.com/2009/08/snow-leopard-wins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asterisk-Java Testing with Groovy</title>
		<link>http://pathfindersoftware.com/2009/07/asterisk-and-groovy/</link>
		<comments>http://pathfindersoftware.com/2009/07/asterisk-and-groovy/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 14:03:28 +0000</pubDate>
		<dc:creator>Ivan Moscoso</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[telephony]]></category>
		<category><![CDATA[Test Driven Development]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=2540</guid>
		<description><![CDATA[Recently I have taken a bit of a detour into the world of telephony, working with Asterisk-Java, which by itself is a very valuable tool, and worth knowing a bit about if you are integrating a system with Asterisk. While it is a Java-based library, I am integrating it into a Grails application. We have ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F07%2Fasterisk-and-groovy%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F07%2Fasterisk-and-groovy%2F&amp;source=PathSoft&amp;style=normal&amp;service=bit.ly&amp;service_api=R_8a1154b608af9e55718b231fb0025d40&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="right" src="http://pathfindersoftware.com/wp-content/uploads/asterisk11.png" alt="iPhone in Dock" width="140" height="163" /></p>
<p>Recently I have taken a bit of a detour into the world of telephony, working with <a href="http://asterisk-java.org/">Asterisk-Java</a>, which by itself is a very valuable tool, and worth knowing a bit about if you are integrating a system with Asterisk.  While it is a Java-based library, I am integrating it into a Grails application.</p>
<p>We have a fairly comprehensive suite of unit tests asserting that desired behaviors are triggered upon certain events initiated through the Event API.  This is made even easier, as usual, with Groovy&#8211; specifically on the testing front.  Here I show two hypothetical test cases, followed by supporting code that works specifically with the Asterisk-Java classes&#8230;</p>
<p><span id="more-2540"></span></p>
<pre lang="groovy">
import org.gmock.GMockTestCase
import org.asteriskjava.manager.event.JoinEvent
import org.asteriskjava.manager.event.LeaveEvent

def queueObject = // .... some object representing an internal queue

/*
 * Verifies caller entering a call queue will trigger behavior
 */
void testCallIAddedToQueue() {
  mock(queueObject).add('SIP/123', '3125551234').once()
  dispatchJoinEvent([channel: "SIP/123", callerId: "3125551234"])
}

/*
 * Verifies caller leaving call queue will trigger behavior
 */
void testCallRemovedFromQueue() {
    mock(queueObject).remove("SIP/123").once()
    dispatchLeaveEvent([channel: "SIP/123", dateReceived: new Date()])
}
// ...
</pre>
<p>The testcases above are fairly straightforward, hiding much of the details involved when working with Asterisk-Java.  The &#8216;queueObject&#8217; can be anything, really, as long as it contains behavior which we wired into the event-handling system Asterisk-Java provides.  The important part here is how we can easily bind properties to the underlying Event types, and dispatch them so that our behavior is invoked.</p>
<pre lang="groovy">
private def dispatchJoinEvent(properties) {
  dispatchEvent(JoinEvent, properties)
}

private def dispatchLeaveEvent(properties) {
  dispatchEvent(LeaveEvent, properties)
}

private def dispatchEvent(eventType, eventProperties) {
  def event = eventType.newInstance([:])
  eventProperties.each { name, value -> event."${name}" = value }
  play {
    asteriskService.connection.dispatchEvent(event)
  }
}
</pre>
<p>Here I have a &#8216;service&#8217; class defined in Grails which I call &#8216;asteriskService&#8217;.  It encapsulates access to the Asterisk-Java <a href="http://asterisk-java.org/latest/apidocs/org/asteriskjava/manager/ManagerConnection.html">ManagerConnection</a> instance, which in turn can dispatch specific events.</p>
<p>Of interest to those new with Groovy is the binding of properties within &#8216;dispatchEvent()&#8217;.  It looks perhaps a bit more complex than one would hope, but unfortunately JoinEvent and LeaveEvent do not have default constructors, requiring the code to &#8216;new&#8217; them up with a placeholder argument, and then set any properties on the fly.</p>
<p>Asterisk-Java is worth checking out, but particularly nice is using a bit of Groovy to tie it in nicely.  While this can benefit the application, you can see how it helps ease testing&#8211; particularly as you start using more and more of what the library offers.</p>
<p><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F07%2Fasterisk-and-groovy%2F&amp;linkname=Asterisk-Java%20Testing%20with%20Groovy" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F07%2Fasterisk-and-groovy%2F&amp;linkname=Asterisk-Java%20Testing%20with%20Groovy" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F07%2Fasterisk-and-groovy%2F&amp;linkname=Asterisk-Java%20Testing%20with%20Groovy" title="Digg" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_dzone" href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F07%2Fasterisk-and-groovy%2F&amp;linkname=Asterisk-Java%20Testing%20with%20Groovy" title="DZone" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F07%2Fasterisk-and-groovy%2F&amp;linkname=Asterisk-Java%20Testing%20with%20Groovy" title="Reddit" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F07%2Fasterisk-and-groovy%2F&amp;linkname=Asterisk-Java%20Testing%20with%20Groovy" title="Delicious" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F07%2Fasterisk-and-groovy%2F&amp;linkname=Asterisk-Java%20Testing%20with%20Groovy" title="Evernote" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F07%2Fasterisk-and-groovy%2F&amp;title=Asterisk-Java%20Testing%20with%20Groovy" id="wpa2a_4">Share/Bookmark</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pathfindersoftware.com/2009/07/asterisk-and-groovy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Writing Your Own Protocol With NSURLProtocol</title>
		<link>http://pathfindersoftware.com/2009/06/working-with-nsurlprotocol/</link>
		<comments>http://pathfindersoftware.com/2009/06/working-with-nsurlprotocol/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 02:39:36 +0000</pubDate>
		<dc:creator>Ivan Moscoso</dc:creator>
				<category><![CDATA[Mobile Apps]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[NSURLProtocol]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=2799</guid>
		<description><![CDATA[I have a native iPhone application in development which requires me to interact with a server that uses a stateful protocol over a persistent connection to transfer messages over the wire. This is definitely not a trivial application to write, even though the UI itself is very simple. The Problem Stateful protocols and persistent connections ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F06%2Fworking-with-nsurlprotocol%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F06%2Fworking-with-nsurlprotocol%2F&amp;source=PathSoft&amp;style=normal&amp;service=bit.ly&amp;service_api=R_8a1154b608af9e55718b231fb0025d40&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="right" src="http://pathfindersoftware.com/wp-content/uploads/xcode-apps24.png" alt="iPhone in Dock" width="160" height="158" /></p>
<p>I have a native iPhone application in development which requires me to interact with a server that uses a stateful protocol over a persistent connection to transfer messages over the wire.  This is definitely not a trivial application to write, even though the UI itself is very simple.</p>
<h3>The Problem</h3>
<p>Stateful protocols and persistent connections are often interrelated, but not by design.  My first problem was to divide the original problem in two: how to manage the persistent connection, and how to handle the underlying protocol so that the stateful aspects did not bubble up throughout the UI.</p>
<p><span id="more-2799"></span></p>
<p>Persistent connections can be difficult to manage, particularly when the network topology can change so drastically (such as on mobile devices).  In this sense, there is nothing new here&#8211; while the framework can notify you of connection events, it is still up to the developer to decide on the appropriate action.</p>
<p>The statefulness of the protocol, however, is trickier to deal with.  We must track the state of the connection, and notify the caller of &#8216;certain&#8217; errors.  I say &#8216;certain&#8217; because there is a class of errors that can be dealt with on behalf of the client in a reliable way, affording the rest of the application to treat the protocol <i>as if it were</i> stateless in most cases.</p>
<p>In dealing with the issue of maintaining the persistent connection, I wanted a solution which prevented me from having to manage separate thread(s), run loops, or NSOperationQueue.  It is not that these approaches could not work, only that I wanted fewer failure points in the code, and experience has shown that many times there is a better way.  Synchronous network calls were obviously not an option (if you didn&#8217;t get a visceral reaction upon the very idea, just try and go that route&#8211; it is not a happy place to be).</p>
<h3>Managing the Persistent Connection</h3>
<p>Luckily, <a href="http://code.google.com/p/cocoaasyncsocket/">AsyncSocket</a> can do much of this for you.  It&#8217;s a great library for this sort of work, and I would recommend it over just using the NS connection classes alone.  This library, however, does not do everything for you.  You still have to refer to the connection from your code (either through a shared singleton approach, or as an injected dependency).</p>
<h3>Managing the Stateful Protocol</h3>
<p>I first attempted to create an interface on top of the network protocol, and quickly realized that this path would involve quite a bit of &#8216;target/action&#8217; callbacks.  So the choice was to either create a delegate protocol around my interface, or else use the NSNotification model to notify interested parties when certain events completed.  Again, both of these options are possible, but there was just one problem&#8230;</p>
<p>&#8230;NSURLConnection and NSURLConnectionDelegate provide a lot of this for you.  Knowing this, why <i>wouldn&#8217;t</i> I want to capitalize on the framework?  No synchronous calls, no extra delegate protocols to write.  You get certain faculties for free using this route as well&#8211; an established architecture for managing credentials, caching strategies, and in some cases, a way in which you can write and test your application against <i>stateless</i> protocols (say, HTTP) in a controlled, test environment, before actually testing against your custom, stateful protocol (let&#8217;s presume access to the server is limited).</p>
<p>I was sold.</p>
<p></br></p>
<h3>The Work</h3>
<p>At this point, the problem became one of first developing a URL scheme for my needs, and then subclassing NSURLProtocol.  My own implementation of NSURLProtocol checks the state of the single, persistent connection on each request, and issues an authentication challenge to the caller if the connection could not be created (this gives the user the ability to intercede, enter a password, or just cancel the connection).</p>
<p>The URL scheme is fairly straightforward, as the &#8216;path&#8217; element of NSURL translates directly to commands on the server.  Query parameters represent arguments.</p>
<h3>The Way Forward</h3>
<p>There is still more work to be done, of course, but the architecture is very clear.  As mentioned above, I plan to handle changes in the network connection.  Without this, a slow cellular connection, say, would still be used even when a faster connection type suddenly became available.  Since the handling of the underlying connection is behind the protocol layer, this becomes an easier change to manage than if all parts of the code had to concern themselves with changes in the network connection itself.
</p>
<p>
My experience so far has taught me a few things about both the URL loading system in Cocoa, and how to deploy these kind of apps in the wild.  There are not many examples of NSURLProtocol out there.  This is a common complaint, but the points above, along with the existing sample code, should help steer you in the right direction.
</p>
<p>Related Services:  <a href="http://www.pathf.com/services/iphone-application-development/">iPhone Application Development</a>, <a href="http://www.pathf.com/services">Custom Software Development</a>
<p><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F06%2Fworking-with-nsurlprotocol%2F&amp;linkname=Writing%20Your%20Own%20Protocol%20With%20NSURLProtocol" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F06%2Fworking-with-nsurlprotocol%2F&amp;linkname=Writing%20Your%20Own%20Protocol%20With%20NSURLProtocol" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F06%2Fworking-with-nsurlprotocol%2F&amp;linkname=Writing%20Your%20Own%20Protocol%20With%20NSURLProtocol" title="Digg" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_dzone" href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F06%2Fworking-with-nsurlprotocol%2F&amp;linkname=Writing%20Your%20Own%20Protocol%20With%20NSURLProtocol" title="DZone" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F06%2Fworking-with-nsurlprotocol%2F&amp;linkname=Writing%20Your%20Own%20Protocol%20With%20NSURLProtocol" title="Reddit" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F06%2Fworking-with-nsurlprotocol%2F&amp;linkname=Writing%20Your%20Own%20Protocol%20With%20NSURLProtocol" title="Delicious" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F06%2Fworking-with-nsurlprotocol%2F&amp;linkname=Writing%20Your%20Own%20Protocol%20With%20NSURLProtocol" title="Evernote" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F06%2Fworking-with-nsurlprotocol%2F&amp;title=Writing%20Your%20Own%20Protocol%20With%20NSURLProtocol" id="wpa2a_6">Share/Bookmark</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pathfindersoftware.com/2009/06/working-with-nsurlprotocol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Costs of Building Secure Applications</title>
		<link>http://pathfindersoftware.com/2009/03/security-and-cost/</link>
		<comments>http://pathfindersoftware.com/2009/03/security-and-cost/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 16:50:59 +0000</pubDate>
		<dc:creator>Ivan Moscoso</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1267</guid>
		<description><![CDATA[&#8216;Achieving Balance&#8217; by James Jordan Security is unlike other aspects of software in that it follows a steep value curve: either your system is secure, or it is not. Either it provides its full level of value, or it provides none at all. There is often a tendency to address security up front (even when ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsecurity-and-cost%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsecurity-and-cost%2F&amp;source=PathSoft&amp;style=normal&amp;service=bit.ly&amp;service_api=R_8a1154b608af9e55718b231fb0025d40&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<div class="right">
<p>
	<img src="http://pathfindersoftware.com/wp-content/uploads/balance1.jpg" width="250" height="187" alt="Achieving Balance" class="right">
</p>
<p style="font-size: smaller;">
<a href="http://www.flickr.com/photos/jamesjordan/3022290830/">&#8216;Achieving Balance&#8217;</a> by James Jordan
</p>
</div>
<p>Security is unlike other aspects of software in that it follows a steep value curve: either your system is secure, or it is not.  Either it provides its full level of value, or it provides none at all.  There is often a tendency to address security up front (even when other aspects of the system are built iteratively).  What others sometimes fail to see is how this generates unneeded cost and complexity as the project matures.</p>
<p><span id="more-1267"></span></p>
<h3>Balancing Security &amp; Flexibility</h3>
<p>It is simple to expect our software to be highly secure and highly flexible all the time, but as a product matures the trade-offs become apparent.  Unlike security, other aspects of the application follow a different value curve.  While the organization evolves.  Security may be stuck reflecting an organization that no longer exists.  The reason why this is so is easy: we often build it without the right kind of flexibility in mind.</p>
<p>Imagine a large, hierarchical organization and an application that helps manage it.  We might want to reflect the entire organizational structure in our security model (regions have divisions, divisions have departments, departments have units, etc).  Conventional wisdom says that <em>future functionality</em> will span any given sub-unit of the organizational hierarchy.  Hence, you implement a rigorous security infrastructure, even though your business features are only take advantage of it bit by bit.  This up-front cost is often justified by the notion: &#8220;either my system is secure, or it is not.&#8221;</p>
<p>I have seen examples of this kind of thinking, and it can end up costing more money than you think.  While these initial design is intended to speed up development down the line, they are often predicated on the notion that the organizational structure will either remain static, or be infinitely flexible.  What you get is overhead from day one of being in production.</p>
<p>Addressing all of security up front trades a <em>real, fixed cost</em> for the <em>possibility</em> of increased efficiency at an unknown, future date.  Only in hindsight do many organizations realize how risky this type of proposition can be, since it makes a few dangerous assumptions:</p>
<ul>
<li>&#8220;Will I have the same development team writing those features later on?&#8221;</li>
<li>&#8220;Will I have the budget for those features that take advantage of the security infrastructure?&#8221;</li>
<li>&#8220;Will my vendor relationships change by then?&#8221;</li>
<li>etc.</li>
</ul>
<p></p>
<h3>So What&#8217;s the Answer?</h3>
<p>The needs of security can (and will) change over time.  We strive for flexibility in other aspects of application architecture, but often demand stringency in tackling security.  The right balance between these two concerns can only be found over time, and not up front.  Remind yourself of this early on and challenge any presumptions up front.  Don&#8217;t build in more security measures than you have to, and expect these measures to evolve.  The right development team will understand this as well.</p>
<p>Next, design security around the most important aspects of your organization, not the entire organization all at once.  Decisions you make up front need to reflect idiosyncrasies of the organization, keeping things as simple as possible to lock down the immediate features you have the budget to implement.</p>
<p>One of the benefits of iterative development is that your security model can (and should) evolve along with your features.  Start simple, let the ideas prove themselves out, and you have a much better chance of finding the right balance between keeping your application secure and maximizing its flexibility.</p>
<p><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsecurity-and-cost%2F&amp;linkname=The%20Costs%20of%20Building%20Secure%20Applications" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsecurity-and-cost%2F&amp;linkname=The%20Costs%20of%20Building%20Secure%20Applications" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsecurity-and-cost%2F&amp;linkname=The%20Costs%20of%20Building%20Secure%20Applications" title="Digg" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_dzone" href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsecurity-and-cost%2F&amp;linkname=The%20Costs%20of%20Building%20Secure%20Applications" title="DZone" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsecurity-and-cost%2F&amp;linkname=The%20Costs%20of%20Building%20Secure%20Applications" title="Reddit" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsecurity-and-cost%2F&amp;linkname=The%20Costs%20of%20Building%20Secure%20Applications" title="Delicious" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsecurity-and-cost%2F&amp;linkname=The%20Costs%20of%20Building%20Secure%20Applications" title="Evernote" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsecurity-and-cost%2F&amp;title=The%20Costs%20of%20Building%20Secure%20Applications" id="wpa2a_8">Share/Bookmark</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pathfindersoftware.com/2009/03/security-and-cost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#039;Signature Survey&#039; Revisited</title>
		<link>http://pathfindersoftware.com/2009/03/signature-survey-revisited/</link>
		<comments>http://pathfindersoftware.com/2009/03/signature-survey-revisited/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 04:24:43 +0000</pubDate>
		<dc:creator>Ivan Moscoso</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[agile thinking]]></category>
		<category><![CDATA[data visualization]]></category>

		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1286</guid>
		<description><![CDATA[&#8216;hieroglyphics&#8217; by Em_G One of the things I most admire about Ward Cunningham&#8217;s work is that you can read something like &#8216;Signature Survey&#8216; and still find new things to appreciate, even years later. Ward&#8217;s original article discussed a method to tackle large code bases (based somewhat on Tufte&#8217;s ideas on data visualization). To quote the ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsignature-survey-revisited%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsignature-survey-revisited%2F&amp;source=PathSoft&amp;style=normal&amp;service=bit.ly&amp;service_api=R_8a1154b608af9e55718b231fb0025d40&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<div class="right">
<a href="http://flickr.com/photos/farfalinaem/2791795721/"><img width="220" height="146" border="0" class="right" alt="Hieroglyphics" src="http://pathfindersoftware.com/wp-content/uploads/hieroglyphics1.jpg"></a><br />
<span style="smaller;" class="right"><a href="http://flickr.com/photos/farfalinaem/2791795721/">&#8216;hieroglyphics&#8217; by Em_G</a></span>
</div>
<p>One of the things I most admire about Ward Cunningham&#8217;s work is that you can read something like &#8216;<a href="http://c2.com/doc/SignatureSurvey/">Signature Survey</a>&#8216; and still find new things to appreciate, even years later.</p>
<p>Ward&#8217;s original article discussed a method to tackle large code bases (based somewhat on Tufte&#8217;s ideas on data visualization).  To quote the original article, he summarized the process as the <em>iterative</em> application of two steps:</p>
<blockquote><p>
   1. <b>Inspection</b>. Browse the report looking for startlingly regular or startlingly irregular structure. Examine the source code associated with each (ir)regularity.</p>
<p>   2.   <b>Projection</b>. Modify the summarization program (the cgi script that generates the report) so as to represent aspects of the inspected code that seem relevant to the inquiry at hand.
</p></blockquote>
<p>The real lesson I took years ago from &#8216;Signature Survey&#8217; is that, when dealing with any sufficiently complex problem, knowing which questions to ask may not be obvious.  And rather than approaching each problem with the same set of questions or criteria in mind, it is useful to let the problem itself guide you to the right questions.</p>
<p>All of this should seems obvious right?  It is, after all, a simple idea.  Still, if you have never done so, I would ask you to really give this idea some thought.  Sleep on it.  Think about it during your walk back from lunch tomorrow and take your time with it.  Toy with the idea and some current problem you are working on.  I&#8217;m not kidding&#8211; the exercise will be worthwhile in the end, and will continue to pay off.</p>
<p><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsignature-survey-revisited%2F&amp;linkname=%26%23039%3BSignature%20Survey%26%23039%3B%20Revisited" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsignature-survey-revisited%2F&amp;linkname=%26%23039%3BSignature%20Survey%26%23039%3B%20Revisited" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsignature-survey-revisited%2F&amp;linkname=%26%23039%3BSignature%20Survey%26%23039%3B%20Revisited" title="Digg" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_dzone" href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsignature-survey-revisited%2F&amp;linkname=%26%23039%3BSignature%20Survey%26%23039%3B%20Revisited" title="DZone" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsignature-survey-revisited%2F&amp;linkname=%26%23039%3BSignature%20Survey%26%23039%3B%20Revisited" title="Reddit" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsignature-survey-revisited%2F&amp;linkname=%26%23039%3BSignature%20Survey%26%23039%3B%20Revisited" title="Delicious" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsignature-survey-revisited%2F&amp;linkname=%26%23039%3BSignature%20Survey%26%23039%3B%20Revisited" title="Evernote" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F03%2Fsignature-survey-revisited%2F&amp;title=%26%23039%3BSignature%20Survey%26%23039%3B%20Revisited" id="wpa2a_10">Share/Bookmark</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pathfindersoftware.com/2009/03/signature-survey-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy 1.6 and Per-Instance Metaclass</title>
		<link>http://pathfindersoftware.com/2009/02/groovy-16-and-per-instance-metaclass/</link>
		<comments>http://pathfindersoftware.com/2009/02/groovy-16-and-per-instance-metaclass/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 21:30:29 +0000</pubDate>
		<dc:creator>Ivan Moscoso</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[metaprogramming]]></category>

		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1406</guid>
		<description><![CDATA[One of the new features of Groovy 1.6 includes support for per-instance metaclasses. This is a nice addition to the language, since it allows to change the behavior of objects without affecting all instances of the class as a whole. For testing, it is often useful to mock out specific behavior of an object without ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F02%2Fgroovy-16-and-per-instance-metaclass%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F02%2Fgroovy-16-and-per-instance-metaclass%2F&amp;source=PathSoft&amp;style=normal&amp;service=bit.ly&amp;service_api=R_8a1154b608af9e55718b231fb0025d40&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="right" src="http://pathfindersoftware.com/wp-content/uploads/groovy_medium1.png" alt="Groovy" width="200" height="100" /><br />
One of the new features of <a href="http://groovy.codehaus.org/">Groovy 1.6</a> includes support for per-instance metaclasses.  This is a nice addition to the language, since it allows to change the behavior of objects without affecting all instances of the class as a whole.</p>
<p>For testing, it is often useful to mock out specific behavior of an object without affecting the class as a whole.  While some mocking frameworks already allow this, they usually run through a few hoops (i.e. &#8220;partial mocks&#8221;).  Allowing support directly in the language can simplify this kind of approach.</p>
<p>Another case where per-instance metaprogramming can be useful is in employing template patterns on a per-instance basis.  Picture the case where the domain decides that one of its children is no longer in a valid state.  Most domain models handle this by embedding some sort of state object within the children, so that any object holding a reference to the children know what the child can or can not do.  With a per-instance metaclass, however, the aggregate root can simply add or replace behavior of that instance of the object alone.<br />
<span id="more-1406"></span><br />
Here&#8217;s a made-up example of how this could work.  Picture an online booking engine where a &#8216;Reservation&#8217; handles the domain logic for booking a flight.  Part of this may involve reserving a seat through an external airline booking system.</p>
<pre>
//
// Representation of an airline booking system
//
class ReservationService {
    def name
    def reserveSeat(flightNumber) {
        /* some network call.. */
        return true
    }

    def postProcess() { }
}

class Reservation {
    def bookFlight(flightNumber, service) {
        def confirm = service.reserveSeat(flightNumber)
        if (!confirm) {
            service.metaClass.postProcess = {
                println "Error for provider '${service.name}'"
            }
        }
        service.postProcess()
        return confirm
    }
}

reservation = new Reservation()

delta  = new ReservationService(name: "Delta")
united = new ReservationService(name: "United")

assert true == reservation.bookFlight("1234", delta)
assert true == reservation.bookFlight("1234", united)

// Mock out our connection to Delta
delta.metaClass.reserveSeat = { return false }

// The following prints an error, due to 'postProcess'
assert false == reservation.bookFlight("1234", delta)
</pre>
<p>Clearly this is a made-up example, but as you see from the above code, we have a situation here where we can associate specialized behavior with a specific object at runtime.  I imagine you can use the same approach with things like exceptions which can themselves be called upon to report or behave in certain ways as they are caught further up the stack.  Whether or not this is a good design approach is a separate issue however.
<p><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F02%2Fgroovy-16-and-per-instance-metaclass%2F&amp;linkname=Groovy%201.6%20and%20Per-Instance%20Metaclass" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F02%2Fgroovy-16-and-per-instance-metaclass%2F&amp;linkname=Groovy%201.6%20and%20Per-Instance%20Metaclass" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F02%2Fgroovy-16-and-per-instance-metaclass%2F&amp;linkname=Groovy%201.6%20and%20Per-Instance%20Metaclass" title="Digg" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_dzone" href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F02%2Fgroovy-16-and-per-instance-metaclass%2F&amp;linkname=Groovy%201.6%20and%20Per-Instance%20Metaclass" title="DZone" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F02%2Fgroovy-16-and-per-instance-metaclass%2F&amp;linkname=Groovy%201.6%20and%20Per-Instance%20Metaclass" title="Reddit" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F02%2Fgroovy-16-and-per-instance-metaclass%2F&amp;linkname=Groovy%201.6%20and%20Per-Instance%20Metaclass" title="Delicious" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F02%2Fgroovy-16-and-per-instance-metaclass%2F&amp;linkname=Groovy%201.6%20and%20Per-Instance%20Metaclass" title="Evernote" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F02%2Fgroovy-16-and-per-instance-metaclass%2F&amp;title=Groovy%201.6%20and%20Per-Instance%20Metaclass" id="wpa2a_12">Share/Bookmark</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pathfindersoftware.com/2009/02/groovy-16-and-per-instance-metaclass/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OCMock: Handling Boolean Return Types with NSValue</title>
		<link>http://pathfindersoftware.com/2009/01/ocmock-and-nsvalue/</link>
		<comments>http://pathfindersoftware.com/2009/01/ocmock-and-nsvalue/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 06:35:27 +0000</pubDate>
		<dc:creator>Ivan Moscoso</dc:creator>
				<category><![CDATA[Mobile Apps]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[mock objects]]></category>
		<category><![CDATA[obj-c]]></category>
		<category><![CDATA[ocmock]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1369</guid>
		<description><![CDATA[Testing your iPhone application, you may at some point in time need to stub a method call whose return type is a boolean (or some scalar value, or C based structure). The way to implement this (as described in a discussion on CocoaDev here) is to wrap the boolean in an NSValue using the OCMOCK_VALUE() ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Focmock-and-nsvalue%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Focmock-and-nsvalue%2F&amp;source=PathSoft&amp;style=normal&amp;service=bit.ly&amp;service_api=R_8a1154b608af9e55718b231fb0025d40&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="right" src="http://pathfindersoftware.com/wp-content/uploads/xcode-apps23.png" alt="iPhone in Dock" width="160" height="158" /></p>
<p>Testing your iPhone application, you may at some point in time need to stub a method call whose return type is a boolean (or some scalar value, or C based structure).  The way to implement this (as described in a discussion on CocoaDev <a href="http://www.cocoadev.com/index.pl?UsingMockObjects">here</a>) is to wrap the boolean in an <code><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/nsvalue_Class/Reference/Reference.html">NSValue</a></code> using the <code>OCMOCK_VALUE()</code> macro defined in <code>OCMockRecorder.h</code>.</p>
<p>While this solution technically works, I find that doing this within the test class itself makes the test cases a little less readable along the way.  Instead, I found it useful to extend OCMock to do this type of conversion for me, keeping my test code a bit cleaner as a result.</p>
<p>Let&#8217;s take a look at an example by examining the set up for a simple test case..</p>
<p><span id="more-1369"></span><br />
</p>
<p>Imagine that we have a class (&#8216;<code>MyTreeNode</code>&#8216;), which models a typical tree-like structure.  Each node in the tree must respond to the selector &#8216;<code>hasChildren</code>&#8216;, which returns a boolean of type <code>BOOL</code>.</p>
<p></p>
<h3>Initial Testcase</h3>
<pre>
BOOL yes = YES;
NSValue *wrappedValue = [NSValue valueWithBytes:&amp;yes
                                       objCType:@encode(BOOL)];

id mockRoot = [OCMockObject mockForClass:[MyTreeNode class]];
[[[mockRoot stub] andReturnValue:wrappedValue] hasChildren];
</pre>
<p>(Note that I am using <code>valueWithBytes:objCType:</code> on <code>NSValue</code> instead of <code>value:objCType:</code>, as found in the OCMOCK_VALUE macro.  It&#8217;s a slight difference, but since the API docs for NSValue suggest that the latter may deprecated at a future date, I would use the preferred method call instead).</p>
<p>This test case is all fine and good, but those top two lines have nothing to do with expressing the real intent of this test case.  In the end, it&#8217;s all just noise.  Improving on this, you can encapsulate the creation and use of the <code>NSValue</code> behind the mocking framework.  This is accomplished using a simple category.<br />
</p>
<h3>Extending OCMock</h3>
<p>The interface is defined as follows, in a file I named &#8220;OCMockExtensions.h&#8221;:</p>
<pre>
#import &lt;OCMock/OCMock.h&gt;

@interface OCMockRecorder (BooleanMethods)
- (id) andReturnBoolean:(BOOL)aValue;
@end
</pre>
<p>The implementation itself is also straightforward.  We basically implement the same logic, but hide it behind a new method on <code>OCMockRecorder</code> itself.</p>
<pre>
@implementation OCMockRecorder (BooleanMethods)

- (id) andReturnBoolean:(BOOL)aValue {
    NSValue *wrappedValue = nil;
    wrappedValue = [NSValue valueWithBytes:&amp;aValue
                                  objCType:@encode(BOOL)];

    return [self andReturnValue:wrappedValue];
}

@end
</pre>
<p></p>
<h3>Resulting Testcase</h3>
<p>All of this allows us to stub out our <code>hasChildren</code> method in the original test case using a more readable form.</p>
<pre>
  id mockRoot = [OCMockObject mockForClass:[MyTreeNode class]];
  [[[mockRoot stub] andReturnBoolean:YES] hasChildren];
</pre>
<p>Short and sweet.  There are probably other variations on this theme, each of which might make more sense for you.  But I hope this gets you thinking of how best to handle these types of test scenarios without having to clutter your test method with a lot of set up code for your mocks.  If experience is any guide, set up code for mock objects can easily get out of hand as a code base matures, so anything you can do to reduce this clutter and help the test cases express their intent in a clear and succinct manner can go a long way toward having your tests work for your team.</p>
<p>Related Services:  <a href="http://www.pathf.com/services/iphone-application-development/">iPhone Application Development</a>, <a href="http://www.pathf.com/services">Custom Software Development</a>
<p><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Focmock-and-nsvalue%2F&amp;linkname=OCMock%3A%20Handling%20Boolean%20Return%20Types%20with%20NSValue" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Focmock-and-nsvalue%2F&amp;linkname=OCMock%3A%20Handling%20Boolean%20Return%20Types%20with%20NSValue" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Focmock-and-nsvalue%2F&amp;linkname=OCMock%3A%20Handling%20Boolean%20Return%20Types%20with%20NSValue" title="Digg" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_dzone" href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Focmock-and-nsvalue%2F&amp;linkname=OCMock%3A%20Handling%20Boolean%20Return%20Types%20with%20NSValue" title="DZone" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Focmock-and-nsvalue%2F&amp;linkname=OCMock%3A%20Handling%20Boolean%20Return%20Types%20with%20NSValue" title="Reddit" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Focmock-and-nsvalue%2F&amp;linkname=OCMock%3A%20Handling%20Boolean%20Return%20Types%20with%20NSValue" title="Delicious" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Focmock-and-nsvalue%2F&amp;linkname=OCMock%3A%20Handling%20Boolean%20Return%20Types%20with%20NSValue" title="Evernote" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Focmock-and-nsvalue%2F&amp;title=OCMock%3A%20Handling%20Boolean%20Return%20Types%20with%20NSValue" id="wpa2a_14">Share/Bookmark</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pathfindersoftware.com/2009/01/ocmock-and-nsvalue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone SDK: Testing UIApplicationDelegate with OCMock</title>
		<link>http://pathfindersoftware.com/2009/01/testing-delegate-ocmock/</link>
		<comments>http://pathfindersoftware.com/2009/01/testing-delegate-ocmock/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 20:12:19 +0000</pubDate>
		<dc:creator>Ivan Moscoso</dc:creator>
				<category><![CDATA[Mobile Apps]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[mock objects]]></category>
		<category><![CDATA[ocmock]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1341</guid>
		<description><![CDATA[As I have discussed earlier, you can go very, very far in unit testing your view controllers using the following recipe, without the need to bend over backwards or employ any mocking frameworks: Initialize the view controller in your setup using initWithNibName:bundle:. Force the view to initialize by invoking the controller&#8217;s loadView method within your ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Ftesting-delegate-ocmock%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Ftesting-delegate-ocmock%2F&amp;source=PathSoft&amp;style=normal&amp;service=bit.ly&amp;service_api=R_8a1154b608af9e55718b231fb0025d40&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="right" src="http://pathfindersoftware.com/wp-content/uploads/xcode-apps22.png" alt="iPhone in Dock" width="160" height="158" /><br />
As I have discussed earlier, you can go very, very far in unit testing your view controllers using the following recipe, without the need to bend over backwards or employ any mocking frameworks:</p>
<ol>
<li>Initialize the view controller in your setup using <code>initWithNibName:bundle:</code>.</li>
<li>Force the view to initialize by invoking the controller&#8217;s <code>loadView</code> method within your <code>setUp</code> method.</li>
<li>Write tests to assert dependencies or behavior.</li>
</ol>
<p>This works well enough for view controllers, but when it comes time to test your application delegate, this simple approach can begin to break down.  Unlike <code>UIViewController</code>, your application delegate is only initialized as a by-product of loading the NIB. Thus, to get this code under test I find <a href="http://www.mulle-kybernetik.com/software/OCMock/">OCMock</a> particularly useful.</p>
<p>I show an example unit test below, and discuss how I approached the problem..</p>
<p><span id="more-1341"></span></p>
<p></p>
<h3>Background</h3>
<p>The <code>UIApplicationDelegate</code> protocol defines a series of optional methods which allow you to respond to application-level events.  While the app delegate will not contain much code, the code it contains is certainly important enough to test.  The problem however is that the delegate is initialized as a by-product of <code>UIApplication</code> itself.. something which, if you build your project using one of the predefined templates, is performed as <code>MainWindow.xib</code> is loaded.  Unlike the recipe above, however, you might find issues (this boils down to a chicken &amp; egg problem, as there can only be one instance of <code>UIApplication</code> at a time, so loading <code>MainWindow.xib</code> as part of a test can present problems when you are running in debug mode).</p>
<p></p>
<h3>The Code Under Test</h3>
<p>Let&#8217;s look at a test case that uses mock objects instead.  Here I have chosen to test a simple, navigation-based application.  The default application delegate essentially contains the following code:</p>
<pre>
- (void)applicationDidFinishLaunching:(UIApplication *)application {
	[window addSubview:[navigationController view]];
	[window makeKeyAndVisible];
}
</pre>
<p>If you&#8217;re familiar enough with this example, you&#8217;ll know that this method is invoked by the framework.  It is also the point in time in which you can initialize anything which needs to be initialized on startup (note that <code>navigationController</code> and <code>window</code> are initialized for you via the NIB).  Now then, without adding any more code, there are already two things we would like to test:</p>
<ul>
<li>The <code>UINavigationController</code>&#8216;s view is a sub-view of our window.</li>
<li>The window is made &#8216;key&#8217; and &#8216;visible&#8217; on start.</li>
</ul>
<p></p>
<h3>Assumptions</h3>
<p>Since we are not loading the actual NIB file, we need to set up the following assumptions.</p>
<ul>
<li>The reference to a <code>UINavigationController</code> instance variable is properly set.</li>
<li>The reference to a <code>UIWindow</code> instance variable is set.</li>
</ul>
<p>Making these assumptions means we will not be testing them directly, but it&#8217;s a compromise which is better than not testing our delegate at all.  Moreover, if either of these assumptions are ever invalidated, we can trust that the error will be easily noticeable upon application start up.</p>
<p></p>
<h3>Test Setup</h3>
<p>Here is the <code>setUp</code> method of my test class.  Notice that my mock objects don&#8217;t really come into play yet.</p>
<pre>
- (void) setUp {
	//
	// Create placeholder for controller
	//
	UINavigationController *nav;
	nav = [[UINavigationController alloc] init];
	nav.view = [[UIView alloc] init];

	//
	// Initialize delegate with placeholder
	//
	delegate = [[MyApplicationDelegate alloc] init];
	delegate.navigationController = nav;
}
</pre>
<p>The delegate is missing a reference to it&#8217;s <code>UIWindow</code>.  Rather than setting that dependency in the set up, I choose to add it in the test method below, grouped with expectations on the mock itself before invoking <code>applicationDidFinishLaunching:</code>.</p>
<p></p>
<h3>The Unit Test</h3>
<pre>
- (void) testDelegateInitializesWindowSubview {
	//
	// Mock window on our delegate
	//
	id mockWindow = [OCMockObject mockForClass:[UIWindow class]];
	delegate.window = mockWindow;

	//
	// Set up expectations
	//
	UIView *expectedView = delegate.navigationController.view;
	[[mockWindow expect] addSubview: expectedView];
	[[mockWindow expect] makeKeyAndVisible];

	//
	// Invoke &amp; verify
	//
	id myApp = [OCMockObject mockForClass:[UIApplication class]];
	[delegate applicationDidFinishLaunching:myApp];
	[mockWindow verify];
}
</pre>
<p>Whether or not you set up the mock window object in the test method or <code>setUp</code> is up to you.  I find it good practice to only put code in <code>setUp</code> that applies to all test methods.  Since this is the only test method I expect will exercise the <code>UIWindow</code> dependency, I move it closer to the test case itself.  To leave it in <code>setUp</code> may suggest to another developer that all test cases require this dependency to be set at all times.  Because of the nature of the application delegate, however, that is likely not to be the case.</p>
<p>I hope this shows you a way in which you can test your delegate methods, and more importantly, dispel any notions that the delegate itself is too hard to test.</p>
<p>If you take a look at <code>UIApplicationDelegate</code>, you will quickly find that the methods here are not at all trivial, and relying on manual testing alone is risky.  In this regard, I think using OCMock for this purpose is not only a smart move, but also necessary to avoid any collisions with the bootstrapping of your test environment itself.</p>
<p>Related Services:  <a href="http://www.pathf.com/services/iphone-application-development/">iPhone Application Development</a>, <a href="http://www.pathf.com/services">Custom Software Development</a>
<p><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Ftesting-delegate-ocmock%2F&amp;linkname=iPhone%20SDK%3A%20Testing%20UIApplicationDelegate%20with%20OCMock" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Ftesting-delegate-ocmock%2F&amp;linkname=iPhone%20SDK%3A%20Testing%20UIApplicationDelegate%20with%20OCMock" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Ftesting-delegate-ocmock%2F&amp;linkname=iPhone%20SDK%3A%20Testing%20UIApplicationDelegate%20with%20OCMock" title="Digg" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_dzone" href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Ftesting-delegate-ocmock%2F&amp;linkname=iPhone%20SDK%3A%20Testing%20UIApplicationDelegate%20with%20OCMock" title="DZone" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Ftesting-delegate-ocmock%2F&amp;linkname=iPhone%20SDK%3A%20Testing%20UIApplicationDelegate%20with%20OCMock" title="Reddit" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Ftesting-delegate-ocmock%2F&amp;linkname=iPhone%20SDK%3A%20Testing%20UIApplicationDelegate%20with%20OCMock" title="Delicious" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Ftesting-delegate-ocmock%2F&amp;linkname=iPhone%20SDK%3A%20Testing%20UIApplicationDelegate%20with%20OCMock" title="Evernote" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpathfindersoftware.com%2F2009%2F01%2Ftesting-delegate-ocmock%2F&amp;title=iPhone%20SDK%3A%20Testing%20UIApplicationDelegate%20with%20OCMock" id="wpa2a_16">Share/Bookmark</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pathfindersoftware.com/2009/01/testing-delegate-ocmock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone SDK: Cache Policy &amp; Cookie Handling in NSURLRequest</title>
		<link>http://pathfindersoftware.com/2008/12/iphonesdk-cache-and-cookies/</link>
		<comments>http://pathfindersoftware.com/2008/12/iphonesdk-cache-and-cookies/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 17:21:01 +0000</pubDate>
		<dc:creator>Ivan Moscoso</dc:creator>
				<category><![CDATA[Mobile Apps]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1340</guid>
		<description><![CDATA[I recently ran into an issue building an app which hit an existing (protected) website. Passing credentials along with each request, responses at first appeared to be cached, even after the user credentials changed from within the iPhone app. In sorting through this issue, it gave me a chance to get a bit more familiar ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fiphonesdk-cache-and-cookies%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fiphonesdk-cache-and-cookies%2F&amp;source=PathSoft&amp;style=normal&amp;service=bit.ly&amp;service_api=R_8a1154b608af9e55718b231fb0025d40&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I recently ran into an issue building an app which hit an existing (protected) website.  Passing credentials along with each request, responses at first appeared to be cached, even after the user credentials changed from within the iPhone app.  In sorting through this issue, it gave me a chance to get a bit more familiar with <code>NSURLRequest</code>, and <code>NSURLRequestCachePolicy</code>.  As I later found, however, my problem turned out to be cookie-related..</p>
<p><span id="more-1340"></span></p>
<p>Starting out, I assumed there to be a relationship between setting the cache policy on NSURLRequest and the behavior I would see when implementing <code>connection:willCacheResponse:</code> from within my delegate.  When setting the cache policy to <code>NSURLRequestReloadIgnoringLocalCacheData</code> did not solve my problem, I implemented the latter delegate method in order to intercept any cached response.</p>
<p>I spent an hour or so of looking into this issue, with no success.  Grabbing a late cup of coffee, I <a href="http://www.pathf.com/blogs/2007/09/consider-each-r/">rolled back my changes</a> and took a fresh look at things.</p>
<p>On the one hand, I was convinced by this point that the responses were not actually being cached.  In fact, I felt had the feeling that the problem had nothing to do with cached responses at all.  After double checking to make sure I was not holding on to the original credentials elsewhere in my code (stuffed inside an instance variable perhaps), it finally dawned on me that the problem might be related to the site I was connecting to, and its use of cookies to keep track of the user&#8217;s identity after a successful login.</p>
<p>Fast forward ten minutes and one cup of coffee to the realization that this was indeed the case.  Upon the first successful login, the site sets a cookie which <code>NSURLRequest</code> passes along on subsequent requests, even when the underlying credentials had changed!  The fix here (in my adapter code) seemed pretty straightforward:</p>
<ul>
<li>When the user credentials change, ignore any cached responses</li>
<li>When the user credentials change, invalidate any cookies</li>
</ul>
<p>I changed my HTTP adapter class to expose the underlying &#8216;cachePolicy&#8217;, and to then contain the following code when constructing new instances of NSURLRequest:</p>
<pre>
NSMutableURLRequest *req;
req = [NSMutableURLRequest requestWithURL:url
                              cachePolicy:cachePolicy
                          timeoutInterval:60.0];

if (cachePolicy == NSURLRequestReloadIgnoringCacheData) {
    [req setHTTPShouldHandleCookies:NO];
}
</pre>
<p>This solution is a bit of a stopgap&#8211; the only time I ever need to ignore the cache is when the user credentials change while the application is running.  Every other caller of this class expects the default cache policy.  And this &#8220;fix&#8221; has more to do with the behavior of the existing website I access (and its use of cookies) than NSURLRequest per se.</p>
<p>In short, there is good news and bad news.  The good news is that it works.  The bad news is that I am still not completely happy about the solution.  The only silver lining here is that the implementation did not involve too much hand waving, and should be easy to remove once I find a better way.</p>
<p>While it is good to know that one can disable cookie support on a request-by-request basis, I will probably take the next step and model the user credentials in a way that makes this type of behavior transparent to all other kinds of HTTP requests.</p>
<p>Related Services:  <a href="http://www.pathf.com/services">Custom Software Development</a></p>
<p>Related Services:  <a href="http://www.pathf.com/services/iphone-application-development/">iPhone Application Development</a>, <a href="http://www.pathf.com/services">Custom Software Development</a>
<p><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fiphonesdk-cache-and-cookies%2F&amp;linkname=iPhone%20SDK%3A%20Cache%20Policy%20%26amp%3B%20Cookie%20Handling%20in%20NSURLRequest" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fiphonesdk-cache-and-cookies%2F&amp;linkname=iPhone%20SDK%3A%20Cache%20Policy%20%26amp%3B%20Cookie%20Handling%20in%20NSURLRequest" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fiphonesdk-cache-and-cookies%2F&amp;linkname=iPhone%20SDK%3A%20Cache%20Policy%20%26amp%3B%20Cookie%20Handling%20in%20NSURLRequest" title="Digg" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_dzone" href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fiphonesdk-cache-and-cookies%2F&amp;linkname=iPhone%20SDK%3A%20Cache%20Policy%20%26amp%3B%20Cookie%20Handling%20in%20NSURLRequest" title="DZone" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fiphonesdk-cache-and-cookies%2F&amp;linkname=iPhone%20SDK%3A%20Cache%20Policy%20%26amp%3B%20Cookie%20Handling%20in%20NSURLRequest" title="Reddit" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fiphonesdk-cache-and-cookies%2F&amp;linkname=iPhone%20SDK%3A%20Cache%20Policy%20%26amp%3B%20Cookie%20Handling%20in%20NSURLRequest" title="Delicious" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fiphonesdk-cache-and-cookies%2F&amp;linkname=iPhone%20SDK%3A%20Cache%20Policy%20%26amp%3B%20Cookie%20Handling%20in%20NSURLRequest" title="Evernote" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fiphonesdk-cache-and-cookies%2F&amp;title=iPhone%20SDK%3A%20Cache%20Policy%20%26amp%3B%20Cookie%20Handling%20in%20NSURLRequest" id="wpa2a_18">Share/Bookmark</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pathfindersoftware.com/2008/12/iphonesdk-cache-and-cookies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Continuous Integration Meets Risk-Based Testing</title>
		<link>http://pathfindersoftware.com/2008/12/ci-risk-based-tests/</link>
		<comments>http://pathfindersoftware.com/2008/12/ci-risk-based-tests/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 18:30:57 +0000</pubDate>
		<dc:creator>Ivan Moscoso</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1323</guid>
		<description><![CDATA[A new version of TeamCity is out, and while I have not taken it for a ride yet, I found this feature particularly interesting: Risk Group Tests, Tests Re-ordering TeamCity 4.0 is now able to determine a set of tests which are likely to fail (i.e., recently modified, those with frequent failures history, etc.), and ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fci-risk-based-tests%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fci-risk-based-tests%2F&amp;source=PathSoft&amp;style=normal&amp;service=bit.ly&amp;service_api=R_8a1154b608af9e55718b231fb0025d40&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>A new version of <a href="http://www.jetbrains.com/teamcity/">TeamCity</a> is out, and while I have not taken it for a ride yet, I found this feature particularly interesting:</p>
<blockquote><p><b>Risk Group Tests, Tests Re-ordering</b><br />
TeamCity 4.0 is now able to determine a set of tests which are likely to fail (i.e., recently modified, those with frequent failures history, etc.), and perform those tests first the next time the project builds. This allows teams to confirm potential fixes sooner, reducing feedback time.</p></blockquote>
<p>There are strong cases to be made for <a href="http://en.wikipedia.org/wiki/Risk-based_Testing">risk-based testing</a> in certain environments.  The reason why it is not more commonplace is that implementation is tricky since it requires the CI system to know a few things which are hard to generalize:</p>
<ul>
<li> The type of build and testing framework</li>
<li> Historical perspective across multiple builds</li>
<li> A good set of heuristics along the way</li>
</ul>
<p>Since a risk-based approach may mean skipping certain tests on some builds, this may sound like a step backwards to the agile developer.  But consider it an alternative to improving overall build time (i.e. &#8220;based on very low risk assessment, tests which never failed will not be run every time.&#8221;).  The hard part is defining what &#8220;low risk&#8221; means to your project, and how much value you would get reducing overall build time.</p>
<p>This is obviously not an issue on well-run projects with sub-minute builds, but if you were to be dropped into an existing project with, say, a large code base and a fifty-two minute build (I&#8217;ve seen it), this can become one way to perform triage on an otherwise untenable position.  You don&#8217;t need a new CI system to implement risk-based testing, but having this alternative can&#8217;t hurt.
<p><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fci-risk-based-tests%2F&amp;linkname=Continuous%20Integration%20Meets%20Risk-Based%20Testing" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fci-risk-based-tests%2F&amp;linkname=Continuous%20Integration%20Meets%20Risk-Based%20Testing" title="StumbleUpon" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/stumbleupon.png" width="16" height="16" alt="StumbleUpon"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fci-risk-based-tests%2F&amp;linkname=Continuous%20Integration%20Meets%20Risk-Based%20Testing" title="Digg" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_dzone" href="http://www.addtoany.com/add_to/dzone?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fci-risk-based-tests%2F&amp;linkname=Continuous%20Integration%20Meets%20Risk-Based%20Testing" title="DZone" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/dzone.png" width="16" height="16" alt="DZone"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fci-risk-based-tests%2F&amp;linkname=Continuous%20Integration%20Meets%20Risk-Based%20Testing" title="Reddit" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fci-risk-based-tests%2F&amp;linkname=Continuous%20Integration%20Meets%20Risk-Based%20Testing" title="Delicious" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_evernote" href="http://www.addtoany.com/add_to/evernote?linkurl=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fci-risk-based-tests%2F&amp;linkname=Continuous%20Integration%20Meets%20Risk-Based%20Testing" title="Evernote" rel="nofollow" target="_blank"><img src="http://pathfindersoftware.com/wp-content/plugins/add-to-any/icons/evernote.png" width="16" height="16" alt="Evernote"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpathfindersoftware.com%2F2008%2F12%2Fci-risk-based-tests%2F&amp;title=Continuous%20Integration%20Meets%20Risk-Based%20Testing" id="wpa2a_20">Share/Bookmark</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pathfindersoftware.com/2008/12/ci-risk-based-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (User agent is rejected)
Page Caching using memcached (User agent is rejected)

Served from: pathfindersoftware.com @ 2012-02-09 19:39:16 -->
