Home Adapter
Adapter
Adapter are used to capulate the access to external systems. You can also view the system to be tested as an external system. The advantage of using adapters is that as few places as possible are effected by changes of the interfaces of the external systems that required adaptions in the tests.

A class that provides an adapter must implement the interface Adapter . This interface contains the following methods: 

  • void setContext(AdapterContext context)
  • void close()

Via setContext() a context is given to the adaoter. This is valid for all calls to the adapters' methods. The method close() is called to close an adapter. On this call the adapter should release its resources.

Which further methods an adapter provides is naturally dependent on the type of system or connection the adapter capsulates

Context

The Context of an adapter provides an slightly reduced access to the framework than the context of a unit. Also the methods have a slightly different semantic. Available are: 

  • Error handling
  • Access to parameters
  • Logging

The methods for error handling and logging are the same as those of the unit context.

Concerning the access to parameters the adapter only has access to those parameters that have been provided when the instance was instantiated. The adapter has no access to the parameters that are available to the currently executed unit.

Factories

Adapters are created via factories. A factory must implement the interface AdapterFactory. This contains the method: 

  • Adapter createAdapter(String name, Parameters parameters, Object init)

The created adapter is registered with the framework under the name provided with the parameter name. The parameter parameters contains parameters in the form of name/value pairs. The parameter init may be any object that is necessary for the creation of the adapter. The expected contents of the parameters parameters and init are dependending on the factory. The should be well documented.

When a unit requests an adapter via getAdapter(String name, String adapterName) the framework creates an instance of the factory and calls createAdapter(). For that reason it is necessary, that an instance of the factory can be created via the default constructor.