Mock OpenFire Server? For Junit Testing Plugin

Curious, if anyone out there has already mocked up an OpenFire server? I’d like to run some Junit tests on my plugin, but really can’t get to it without the Server.

Kit

Hey Kit,

When we add new functionality or modify existing functionality of our Smack library (client side) we just use a real Openfire server for our tests. Creating a server mock up is probably a very big task.

Regards,

– Gato

1 Like

I have also been playing with this idea. It’s very useful to run unit tests stand alone, without having to start-up a server. This would give you a good platform for test-driven development.

Although writing one enormous ‘mock’ server isn’t an option (what is the difference of a mock server that provides all functionality and the normal server anyway?), It could be possible to create mock parts of the server. Unit tests usually test one specific feature - they usuall do not require a full-fledged implementation.

There’s a nice paper on unit testing with mock objects available at http://www.connextra.com/aboutUs/mockobjects.pdf

1 Like

Thanks Guus, for expanding on the concept.

All I really want is the ability to test that my Plugin is really a plugin…and get access to some of the core server pieces. ServerInfo, UserManger, RosterManager, etc.

If the server can be launched programmatically, I’m willing to start putting something together. Maybe just need a few of the config files to launch it, right?

Kit

I did some JUnit testing of my plugin but I didn’t need very core functionality of OF server. I wrote additional constructor for my plugin so I passed flag that is during test and then I omit use of some key server featureres which I didn’t need to test or where I had to use very special Mock objects.

I wrote Mock PluginManager and Mock GroupManager which extened original one. I added another initialize method

public void intializePluginForTest(final PluginManager manager,

  •        final ComponentManager compManager, final GroupManagerXMPPMock mock)+
    

because I was easier to do code branch

if (whileInTest) {

  • useMock();+

} else {

  • useOriginal();+

}

My plugin does some kind of auto-chat with client and I had to check if my plugin sends proper responses to client, so I put a packet collector in MockComponentManger, so in my Tests I could check all packets send back by plugin.

Summarizing plugin Unit testing is always VERY GOOD IDEA and it can be done with proper mock-enviroment set. If you can’t create mock object extending original one maybe AspectJ will be helpful, I did that too.

Best regards,

Bartek