Initializing Parsley Framework and Dynamic Short Lived Objects

Parsley framework needs the configuration file for its initalization. This configuration can be written in tradition mxml file or using a xml file. Parsley API provides different configuration builders for initializing the configuration from these files, like FlexContextBuilder and XmlContextBuilder etc. So step to initialize the Parsley are:

  • Create configuration file either in mxml file or in xml file
  • Call appropraiate API by using the above file
    • FlexContextBuilder.build() or
    • XmlContextBuilder.build() etc
  • The build method will always return a context object. 
Generally we need  not to use the context object directly. Parsley itself manage the creation of objects and their relations through injection by using the declared configuration. However in some situations, we may need to interact with the API, like if we are extending the framework for some custom requirement, or for creating the application test environment etc.

Once we build the configuration, the Parsley environment is ready with the context and other configurations mentioned with configuration file. Now suppose if we are preparing a test case and want to fire the events from it so that respective command can be executed based on these events. Here the requirement is to attach the test case object to Parsley context, so that test case object gets the support of event mechanism from Parsley. The way to attach the object with Parsley is to add the object in context. 

Generally for short lived objects, we should use Dynamic Context. Dynamic Context should always be created from default context, so that it can be wired with the other application context. 

dynamicContext as DynamicContext = Context.createDynamicContext();

Now add the test object to this dynamic context. This can be done in setup of the test case. We should consider to remove the object from context after execution of the test methods. Code will be as:

dynamicContext.addObject(testCase);

Now the test case object is linked with Parsley and hence live for Parsley. Now it can participate in all life cycle events and operations of the Parsley like event firing and management. 

People who read this post also read :



0 comments:

Post a Comment