www.mockcentral.org mockcentral on sourceforge.net

getting started with MockCentral

The fundamental component of the MockCentral architecture is the MockCentralServer application, which is packaged as a jar file and should be placed on the classpath of the test case classes needing access to the mock objects defined in the configuration files. The server is initialized using an InputStream, a File or path string that is used to load and process the xml data. Once initialized, it can be called to obtain the mock objects (and the generated proxies) for method invocations, creating new objects and for verifications. It can also be used to automatically bind proxies in the NamingContext under JNDI names.

MockCentralServer Fixture instances are used to group collections of mock objects together. Fixtures are a useful organizational tool and also allow an entire group of proxies to be bound at the same time by calling the server's bindFixtureProxies(String) method. Fixtures can also import other fixtures, inheriting their mock object definitions.

The configuration files can be written manually, but testing using MockCentral really comes into its own when the files are created using a MockCentral Editor application, which allows for extremely rapid "point and click" mock object editing. With a MockCentral editor, developers don't have to write any mock object setup code at all and defining complex method expectation behaviour and relationships between mock objects is easy. MockCentral editors are built on top of the mockcentral-editor-core library, which defines interfaces and supplies logic and utility classes for concrete editors. Currently, org.mockcentral offers an Eclipse plug-in version which is ready to go when simply copied into your installation's "plugins" directory. Some of the features of the editor are:

what does the MockCentralServer do?

The MockCentralServer builds mock objects from data stored in mockcentral-config.xml files, which can be of any name but must conform to the mockcentral-config DTD. The server uses the apache.commons Digester to parse the file or stream supplied to it during initialization and generates instances of various classes. Unless you are writing the configuration files by hand, you don't need to know the full details about this process, but it is described here for those interested in how the server builds mock objects and how the program works generally. The above-mentioned classes (in order of increasingly finer granularity) are:

Once all the data is loaded, validation takes place and the mocks objects are built, proxies are created and the server is ready to do its work. You can now fetch, bind and verify the mock objects with simple calls to the MockCentralServer. For example:

    // assign mock dialog factory
    MyApplication.setDialogFactory (IDialogFactory) server.getProxy("dialogFactory");

    // invoke method to open a new IFooDialog
    currentObject.showFooDialog(args);

    // assert "open" method was called on the mock IFooDialog referenced in the mock factory
    server.verifyMock("fooDialog");

method expection value types

When defining mock object method expectations, you can specify method parameters and expected results of 11 different "value type" categories. Depending on the category, you can further assign additional data used to build the signature part, specifying a class name field and/or value field to build the object you need. Again, detailed knowledge of how the server processes the various value types is not required to use MockCentral, but a brief discussion here can help you get started using the application quickly. The various types you can select for method expectation parameters and return types (as well as simple, non-Mock JNDI-bound objects for fixtures), are listed below. Note that the editor application provides easy-to-use editing controls and programmable defaults for all of these types.