PureMVC Architects Lounge

Announcements and General Discussion => Fabrication => Topic started by: jk on September 01, 2009, 04:16:23



Title: Fabrication UnitTestCase
Post by: jk on September 01, 2009, 04:16:23
Hi All,
Im trying to write a testcase for my Loginproxy. My proxy has LoginServiceCallAMF method  to call server API with the corresponding result and fault handler. This is working fine.
:
My Login Proxy extends FabricationProxy
{
public function LoginServiceCallAMF(username:String , password:String):void{
RemoteObject - Call the server method
}
public function resultAMF(data:Object):void{
sendNotification(LOGIN_SUCESS);
}
public function faultAMF(info:Object):void{
sendNotification(LOGIN_FAIL);
}     
}
I got struck while coming into testing. I tried the Mock approach from Fabrication UnitTest source.
Created Mock for Login Proxy.
In the Login Proxy test case
:
override public function setUp():void {
key = methodName + "_setup";

_fabrication = new FabricationMock();
facade = FabricationFacadeMock.getInstance(key);
fabricationModel = new FabricationModel(key);
fabricationModel = FabricationModelMock.getInstance(key);

proxy = (new LoginProxyMock(key) as LoginProxy);
proxy.initializeNotifier(key);

facade.registerProxy(proxy);
}
public function LoginProxyEvent():void{
assertEquals('ConcordanceLoginProxy',facade.retrieveProxy(ConcordanceLoginProxy.NAME).getProxyName())
}
The result I’m getting for this test is
Error #1009: Cannot access a property or method of a null object reference.

I’m not sure that I’m in right track.  Also I tried this in puremvc with the help of the sample provided here http://www.hufkens.net/2009/07/testing-puremvc-code-with-flexunit/. This works perfect.
Could someone help me out to resolve this?

Thanks in advance.
 jk




Title: Re: Fabrication UnitTestCase
Post by: gregbown on September 11, 2009, 11:33:46
Hi JK,

I am working with a modular Fabrication application and I recently added a new proxy to get the swf host information and client capabilities information. When those methods completed I needed to send a notification to the mediator. As soon as I added sendNotification I got the same error you describe.  It seems as though the proxy is instantiated before the fabrication can map the class.  I tried moving the order of the instantiation of the proxy to last without any improvements.  I then added setTimeout(send,1) inside that method instead of just sendNotification() and added the function like so...
      private function send():void {
         sendNotification( CommonConstants.CLIENT_DATA, browser_object );
      }
This fixed the issue although I am not happy with the word fixed since it is more of a hack.


Title: Re: Fabrication UnitTestCase
Post by: gregbown on September 13, 2009, 10:20:42
   After some searching around I found this post http://lowpitch.com/blog/puremvc-multicore-vs-standard-singlecore/ So I thought I would check to see if that method was in FabricationProxy and it was. After adding the method to my proxy all is fine.

   override public function initializeNotifier(key:String):void {
         super.initializeNotifier(key);
         
         initializeProxyNameCache();
         // initialize methods in proxy after this
      }