<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-31135293</id><updated>2011-07-28T18:09:49.443-07:00</updated><title type='text'>Amit K Gupta</title><subtitle type='html'>Rich Internet Applications, Flex, Java, Spring Framework</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://amitonflex.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31135293/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://amitonflex.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Amit Gupta</name><uri>http://www.blogger.com/profile/07751782115500674723</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://2.bp.blogspot.com/_Ke8Kb9hVbIU/SUbEs-l2scI/AAAAAAAADP4/gruG4uJEWQo/S220/Amit1.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-31135293.post-2468431033122330800</id><published>2010-02-03T19:17:00.000-08:00</published><updated>2010-02-04T16:14:45.877-08:00</updated><title type='text'>Test Driven Development (TDD) for asynchronous method calls in Flex using FlexUnit4</title><content type='html'>I have been using TDD in Java projects for some time now but TDD in Flex was a bit of a challenge until Flash Builder 4 Beta came out with in-built support for FlexUnit4.&lt;br /&gt;&lt;br /&gt;Elad Elrom's article &lt;a href="http://www.adobe.com/devnet/flex/articles/flashbuilder4_tdd.html" target="_blank"&gt;Test Driven Development using Flash Builder 4 Beta and FlexUnit&lt;/a&gt; provides a great overview of how to use TDD for synchronous calls. &lt;br /&gt;&lt;br /&gt;In this blog I will attempt to illustrate the use of TDD for service call to Flickr’s search method. The design pattern used by me here is one I learned in &lt;a href="http://www.amazon.com/Programming-Flex-Comprehensive-Creating-Applications/dp/0596516215/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1265253002&amp;amp;sr=8-1" target="_blank"&gt;Programming Flex 3&lt;/a&gt; by Chafic Kazoun and Joey Lott.&lt;br /&gt;&lt;br /&gt;I use a class that makes an HTTP request and it proxies the response, dispatching an event when the response is returned. I call this class AsyncOperation.as. Though you could write unit tests to test this class, we won’t be doing that here.&lt;br /&gt;&lt;br /&gt;&lt;script type="syntaxhighlighter" class="brush: actionscript3"&gt;&lt;![CDATA[/* AsyncOperation.as */package services { import flash.events.Event; import flash.events.EventDispatcher; import flash.net.URLLoader; import flash.net.URLRequest; import mx.rpc.events.ResultEvent;  public class AsyncOperation extends EventDispatcher {    public static const RESULT : String = "result";  private var _loader : URLLoader;    public function AsyncOperation(url : URLRequest) {   _loader = new URLLoader();   _loader.dataFormat = "e4x";   _loader.addEventListener(Event.COMPLETE, handleComplete);   _loader.load(url);  }    private function handleComplete(event : Event) : void {   var xml : XML = new XML(event.target.data);   dispatchEvent(new ResultEvent(RESULT,false,true,xml));  } }}]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;Business delegate class is Service.as which holds the methods called by Flex application. This is the class we are going to test. Here's how the class looks like before we write any TDD code.&lt;br /&gt;&lt;br /&gt;&lt;script type="syntaxhighlighter" class="brush: actionscript3"&gt;&lt;![CDATA[/* Service.as */package services { public class Service {  private static var _instance : Service;    public function Service() {  }    static public function getInstance() : Service {   if(_instance == null) {    _instance = new Service();   }    return _instance;  } }}]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;You can write unit tests to test the instantiation of Service.as class but we are going to skip that.&lt;br /&gt;&lt;br /&gt;We start with a test that is going to fail or rather not compile&lt;br /&gt;&lt;br /&gt;&lt;script type="syntaxhighlighter" class="brush: actionscript3"&gt;&lt;![CDATA[/*ServiceTest.as*/package flexUnitTests.services{ import flexunit.framework.Assert; import mx.rpc.events.ResultEvent; import org.flexunit.async.Async; import services.AsyncOperation; import services.Service; public class ServiceTest {  public function ServiceTest()  {  }    [Test(async)]  public function searchPhoto() : void {   var asyncOper : AsyncOperation = Service.getInstance().searchPhoto("grand,canyon");   asyncOper.addEventListener(AsyncOperation.RESULT, Async.asyncHandler(this,resultHandler,500));  }    private function resultHandler(event : ResultEvent, object : Object) : void {   var xml : XML = new XML(event.result);   Assert.assertEquals("ok",xml.@stat);  } }}]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;This test won't compile because searchPhoto(text : String) method does not exist in Service.as class. We'll add that method in Service.as shortly. Before that let's look at a couple of things in this unit test. [Test(async)] notifies FlexUnit4 that this is an asynchronous test. Async.asyncHandler() method creates a special class (the AsyncHandler class) that will monitor the test for an asynchronous event. resultHandler() is our handler function where we write our Asserts to make sure we get the desired results.&lt;br /&gt;&lt;br /&gt;Add the following method in Service.as&lt;br /&gt;&lt;br /&gt;&lt;script type="syntaxhighlighter" class="brush: actionscript3"&gt;&lt;![CDATA[public function searchPhoto(searchText : String) : AsyncOperation {   return new AsyncOperation(new URLRequest("http://api.flickr.com/services/rest/?method=flickr.photos.search"));  }]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;The test will compile this time but our Assert statement will fail. Assert.assertEquals("ok",xml.@stat) in resultHandler() of ServiceTest.as checks to make sure service call returned OK. In our case it did not because we did not pass api_key and search parameter.&lt;br /&gt;&lt;br /&gt;Now, let's fix our searchPhoto method to make the unit test pass.&lt;br /&gt;&lt;script type="syntaxhighlighter" class="brush: actionscript3"&gt;&lt;![CDATA[public function searchPhoto(searchText : String) : AsyncOperation {   var url : String = "http://api.flickr.com/services/rest/?method=flickr.photos.search&amp;api_key=0af9cf2f3761f161cd033e42da763182&amp;text=" + searchText;   return new AsyncOperation(new URLRequest(url));  }]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;This time the test will pass. Anytime, you make a change to the method, you should run the test and make sure the service call still returns OK.&lt;br /&gt;&lt;br /&gt;You can now refactor the method to clean it up by putting api_key in a class variable and handling spaces between search terms etc. Make sure you add meaningful asserts in resultHandler. Add code that would make the assert fail first and then refactor to make assert pass.&lt;br /&gt;&lt;br /&gt;It is considered best practice to automate Unit Testing. You can write Ant Tasks or configure Maven to automate unit testing.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31135293-2468431033122330800?l=amitonflex.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://amitonflex.blogspot.com/feeds/2468431033122330800/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amitonflex.blogspot.com/2010/02/test-driven-development-tdd-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31135293/posts/default/2468431033122330800'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31135293/posts/default/2468431033122330800'/><link rel='alternate' type='text/html' href='http://amitonflex.blogspot.com/2010/02/test-driven-development-tdd-for.html' title='Test Driven Development (TDD) for asynchronous method calls in Flex using FlexUnit4'/><author><name>Amit Gupta</name><uri>http://www.blogger.com/profile/07751782115500674723</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://2.bp.blogspot.com/_Ke8Kb9hVbIU/SUbEs-l2scI/AAAAAAAADP4/gruG4uJEWQo/S220/Amit1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31135293.post-3697962358962533843</id><published>2010-01-22T11:09:00.000-08:00</published><updated>2010-01-22T19:15:43.595-08:00</updated><title type='text'>Preparing for Adobe Flex 3 with AIR ACE Exam</title><content type='html'>I have been developing in Flex and Java for several years now and I thought I knew everything about programming in Flex. That was before I decided to become Adobe Certified Expert in Flex. When I looked at the sample questions provided by Adobe for the test, I realized I needed some solid preparation for the test. Fortunately, there is loads of very good material available to help prepare for the test.&lt;br /&gt;&lt;br /&gt;BTW, I did take the test yesterday and scored 90% on it. Here's the section wise breakdown of my score:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Creating a User Interface (UI) : 81%&lt;/li&gt;&lt;li&gt;Flex system architecture and design : 100%&lt;/li&gt;&lt;li&gt;Programming Flex applications with ActionScript : 91%&lt;/li&gt;&lt;li&gt;Interacting with data sources and servers : 100%&lt;/li&gt;&lt;li&gt;Using Flex in the Adobe Integrated Runtime (AIR) : 80%&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;To begin with, go to &lt;a href="http://www.adobe.com/devnet/flex/articles/flex_certification.html" target="_blank"&gt;Adobe Flex 3 with AIR ACE Exam&lt;/a&gt; and download the study guidelines PDF file. This has all the information you'll need to get started.&lt;br /&gt;&lt;br /&gt;To prepare for the test, my main sources were&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.adobe.com/devnet/flex/videotraining/" target="_blank"&gt;Flex in a Week&lt;/a&gt; Video Tutorials&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.amazon.com/Programming-Flex-Comprehensive-Creating-Applications/dp/0596516215/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1264169449&amp;amp;sr=8-1" target="_blank"&gt;Programming Flex 3&lt;/a&gt; by Chafic Kazoun, Joey Lott&lt;/li&gt;&lt;li&gt;&lt;a href="http://livedocs.adobe.com/flex/3/html/help.html?content=Part2_DevApps_1.html" target="_blank"&gt;Flex 3 Developer's Guide&lt;/a&gt;&amp;nbsp; (part of Flex 3 Documentation)&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://livedocs.adobe.com/flex/3/html/help.html?content=Part6_ProgAS_1.html" target="_blank"&gt;Programming Actionscript 3&lt;/a&gt; (part of Flex 3 Documentation)&lt;/li&gt;&lt;li&gt;&lt;a href="http://software.pxldesigns.com/attest/index.php" target="_blank"&gt;Attest Practice Exams&lt;/a&gt; &lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;I highly recommend going through &lt;a href="http://www.adobe.com/devnet/flex/videotraining/" target="_blank"&gt;Flex in a Week&lt;/a&gt; video tutorials. Even if you're a seasoned Flex developer, you'll get a chance to brush up on the fundamentals.&lt;br /&gt;&lt;br /&gt;Programming Flex 3 is a very good book for new as well as seasoned developers. It is well organized and easy to read. I have a &lt;a href="http://www.safaribooks.com/Corporate/Index/" target="_blank"&gt;Safari Books Online&lt;/a&gt; account which helped me scan multiple books on Flex including &lt;a href="http://www.amazon.com/Flex-Cookbook-Code-Recipes-Developers-Developer/dp/0596529856/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1264186038&amp;amp;sr=8-1" target="_blank"&gt;Flex 3 Cookbook &lt;/a&gt;, &lt;a href="http://www.amazon.com/Essential-ActionScript-3-0-Colin-Moock/dp/0596526946/ref=pd_sim_b_1" target="_blank"&gt;Essential Actionscript 3&lt;/a&gt;, &lt;a href="http://www.amazon.com/ActionScript-3-0-Cookbook-Application-Developers/dp/0596526954/ref=pd_sim_b_4" target="_blank"&gt;Actionscript 3 Cookbook&lt;/a&gt;, etc. but I liked Programming Flex 3 the best. There is one chapter on AIR applications which covers all the basics you'll need to get through the test.&lt;br /&gt;&lt;br /&gt;Flex 3 documentation itself is sufficient to prepare for the test. I recommend going through Programming Actionscript 3 documentation to score high on "Programming Flex Application with Actionscript" section of the test. &lt;br /&gt;&lt;br /&gt;I cannot emphasize enough the importance of Attest practice exams. It is a practice exam engine which has 5 mini exams (25 questions) and 3 full exams (50 questions). The application is built on AIR platform and is completely free. These practice tests will give you a pretty good idea of what to expect on the actual test.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Preparation Time&lt;/b&gt;&lt;br /&gt;This depends on the individual. Take a practice test, see what your score is and what your weak areas are. If you do good on practice tests then you perhaps already know enough to pass the ACE Exam.&lt;br /&gt;&lt;b&gt; &lt;/b&gt;&lt;br /&gt;&lt;b&gt; &lt;/b&gt;Lastly, the test is definitely not easy. After all you can't become an &lt;b&gt;Adobe Certified Expert&lt;/b&gt; by passing any easy test. So prepare well.&lt;br /&gt;&lt;br /&gt;Good Luck!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31135293-3697962358962533843?l=amitonflex.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://amitonflex.blogspot.com/feeds/3697962358962533843/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amitonflex.blogspot.com/2010/01/preparing-for-adobe-flex-3-with-air-ace.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31135293/posts/default/3697962358962533843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31135293/posts/default/3697962358962533843'/><link rel='alternate' type='text/html' href='http://amitonflex.blogspot.com/2010/01/preparing-for-adobe-flex-3-with-air-ace.html' title='Preparing for Adobe Flex 3 with AIR ACE Exam'/><author><name>Amit Gupta</name><uri>http://www.blogger.com/profile/07751782115500674723</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='21' height='32' src='http://2.bp.blogspot.com/_Ke8Kb9hVbIU/SUbEs-l2scI/AAAAAAAADP4/gruG4uJEWQo/S220/Amit1.jpg'/></author><thr:total>6</thr:total></entry></feed>
