Tried your suggestion and still null.
Here is the copied object from Debug...
Code:
module ModuleInfoProxy ModuleInfoProxy (@38ab5b9) ModuleInfoProxy
[inherited] flash.events.EventDispatcher
data null
_data null
error Boolean false Boolean
factory com_srcp_module_application_services_ApplicationServicesModule_mx_core_FlexModuleFactory com_srcp_module_application_services_ApplicationServicesModule_mx_core_FlexModuleFactory (@4869ec1) com_srcp_module_application_services_ApplicationServicesModule_mx_core_FlexModuleFactory
info ModuleInfo ModuleInfo (@4a611a1) ModuleInfo
loaded Boolean true Boolean
ready Boolean true Boolean
referenced Boolean true Boolean
setup Boolean true Boolean
url String "com/srcp/module/application/services/ApplicationServicesModule.swf" String
The URL is correct and by all appearances it is in memory. Using the * for casting didn't seem to make any difference. Let me explain in detail what I am doing and perhaps you can suggest of spot something that didn't leap out in my last post.
I begin by placing 2 flashvars in my index.template.html file...
Code:
var flashvars = {};
flashvars.contextURL = "context/files/application-context.xml";
flashvars.serviceModulePath = "com/srcp/module/application/services/ApplicationServicesModule.swf";
Note that the FB4 template uses a different means of passing variables than the Spring ActionScript docs, but I would throw some Adobe links at the audience instead of trying to keep up.
Why did I do this? Because any Application created for running the test will have those variables, thus FlexUnitApplication.mxml (generated each time I add or subtract a test method) will act as my proxy application for testing flashvars. I have to use an imported script each time the file is regenerated because I have to use the preinitialize event to populate the flashvars into member variables. I tried all other means of doing this that I could think of, and in the end, I needed that html file and to catch the true preinitialize event.
Can you think of any other way to emulate this behavior?
Here is the Imported Script...
Code:
// ActionScript file
// copy and paste the line below into FlexUnitApplcation s:Application Tag
// preinitialize="application1_preinitializeHandler(event)"
// Place the following lines in the FlexUnitApplication.mxml Script block
// include "test/as3/applicationscriptimport/ApplicationTestRunnerImports.as"
import mx.events.FlexEvent;
[Bindable] public var contextURL:String = "";
[Bindable] public var serviceModulePath:String = "";
protected function application1_preinitializeHandler(event:FlexEvent):void
{
this.contextURL = parameters['contextURL'];
this.serviceModulePath = parameters['serviceModulePath'];
}
The test looks like this...
Code:
/**
* Some of these variables must be tied into the Test Runner Application as this is the only context
* available. There are import Scripts located in the test.as3.applicationscriptimport package. to help
* with setup as the FlexUnitApplication is a generated application and you will either have to save it
* off under another name, or connect the code blocks in at testing.
*
**/
package test.as3.unit
{
import com.srcp.view.main.Main;
import flash.events.Event;
import flash.system.ApplicationDomain;
import flash.utils.Dictionary;
import flexunit.framework.Assert;
import mx.core.FlexGlobals;
import mx.events.FlexEvent;
import mx.events.ModuleEvent;
import mx.modules.IModuleInfo;
import mx.modules.Module;
import mx.modules.ModuleManager;
import org.flexunit.asserts.assertEquals;
import org.flexunit.async.Async;
import org.springextensions.actionscript.context.support.FlexXMLApplicationContext;
import org.springextensions.actionscript.module.ISASModule;
import org.springextensions.actionscript.test.context.flexunit4.SpringFlexUnit4ClassRunner;
import spark.components.Application;
[RunWith("org.springextensions.actionscript.test.context.flexunit4.SpringFlexUnit4ClassRunner")]
[ContextConfiguration(locations="context/files/application-context.xml")]
public class ApplicationInitialization
{
private var application:Object = null;
private var _applicationContext:FlexXMLApplicationContext;
private var flashVarLocationPassed:String = "context/files/application-context.xml";
private var flashVarLocationFailed:String = "context/files/application-context";
private var _moduleInfoList:Dictionary = new Dictionary();
private var dummy:SpringFlexUnit4ClassRunner;
private var info:IModuleInfo = null;
public function ApplicationInitialization()
{
super();
}
[Before]
public function setUp():void
{
application = FlexGlobals.topLevelApplication;
}
[After]
public function tearDown():void
{
}
[BeforeClass]
public static function setUpBeforeClass():void
{
}
[AfterClass]
public static function tearDownAfterClass():void
{
}
/**
* Creation Complete Event
* Test that FlashVar Location is populated with Application context filename and path
*
* Test for proper string
*
**/
[Test]
public function testFlashVarLocationFailedResult():void
{
trace("In the flashVarLocationFailedResult");
var contextURL:String = application.contextURL;
Assert.assertEquals(flashVarLocationFailed, contextURL);
}
[Test]
public function testFlashVarLocationPassedResult():void
{
trace("In the flashVarLocationPassedResult");
var contextURL:String = application.contextURL;
Assert.assertEquals(flashVarLocationPassed, contextURL);
}
protected function handleTimeout(passThroughData:Object):void
{
Assert.fail("Timeout occured");
}
/**
* Test 2: Load Application Context File
*
* Test for I/O Error
*
* Register Listener for Load Complete and test for successful and unsuccessful Load Complete
*
**/
[Test(async, timeout="500")]
public function testLoadApplicationContextPassed():void
{
_applicationContext = new FlexXMLApplicationContext(application.contextURL);
_applicationContext.addEventListener(Event.COMPLETE, Async.asyncHandler(this, appContextCompleteHandler, 500, null, handleTimeout));
_applicationContext.load();
}
public function appContextCompleteHandler(event:Event, passThroughData:Object):void
{
_applicationContext.removeEventListener(Event.COMPLETE, Async.asyncHandler);
Assert.assertTrue(_applicationContext is FlexXMLApplicationContext);
/* var info:IModuleInfo = ModuleManager.getModule(application.serviceModulePath);
_moduleInfoList[info] = true;
info.addEventListener(ModuleEvent.READY, Async.asyncHandler(this, handleModuleReady, 15000, null, handleTimeout));
info.addEventListener(ModuleEvent.ERROR, Async.asyncHandler(this, handleModuleError, 15000, null, handleTimeout));
info.load(new ApplicationDomain(ApplicationDomain.currentDomain));*/
}
/* protected function handleModuleReady(event:ModuleEvent, passThroughData:Object):void
{
var info:IModuleInfo = event.module;
delete _moduleInfoList[info];
info.removeEventListener(ModuleEvent.READY, handleModuleReady);
info.removeEventListener(ModuleEvent.ERROR, handleModuleError);
var module:ISASModule = info.factory.create() as ISASModule;
module.applicationContext = _applicationContext;
(module as Module).data = info;
}*/
/**
* Test 3: Load Service Module
*
* Test for I/O Error
*
* Register Listener for Load Complete and test for successful and unsuccessful Load Complete
*
**/
[Test(async, timeout="500")]
public function testLoadServicesModulePassed():void
{
info = ModuleManager.getModule(application.serviceModulePath);
_moduleInfoList[info] = true;
info.addEventListener(ModuleEvent.READY, Async.asyncHandler(this, handleModuleReady, 500, null, handleTimeout));
info.addEventListener(ModuleEvent.ERROR, Async.asyncHandler(this, handleModuleError, 500, null, handleTimeout));
info.load(new ApplicationDomain(ApplicationDomain.currentDomain));
}
protected function handleModuleReady(event:ModuleEvent, passThroughData:Object):void
{
info = event.module;
//cleanupInfo(info);
//var module:ISASModule = info.factory.create() as ISASModule;
var module:* = info.factory.create(); //------------------------------------------- Problem code returns a null
//set the applicationContext property, inside the BasicSASModule this
//will automatically be set as the moduleApplicationContext's parent
module.applicationContext = _applicationContext;
(module as Module).data = info;
}
protected function handleModuleError(event:ModuleEvent, passThroughData:Object):void
{
Assert.fail("Module loading error");
}
/**
* Test 4: Load Default Framework Parameters
*
* Test for Collections existing
*
* Register Listener for Load Complete and test for successful and unsuccessful Load Complete
*
**/
}
}
Curtis