Friday, September 25, 2009

Installing internet explorer 7


Doing some website style testing, I need Internet Explorer since we have obviously promised the customers that everything will run fine with it. I however just got this message trying to install IE7. *Arrgh* what now!?

Saturday, September 12, 2009

Decoupling struts actions

Searching Google for struts unit test techniques you find a lot of discussions and blogs on the subject. The only ones I've found are either discussing the StrutsTestCase or how in some other way (manual) setup the entire struts machinery to run unit tests. I have however not found anything about how to test action classes alone.

Testing struts actions with the StrutsTestCase tests much more than just the logic in the action class itself, which is normally what you want to do in a well isolated and simple unit test. I am not interested in whether urls are correctly mapped or request parameters are set on my models by struts. This is something the struts developers do themselves, I assume, and for me it is actually more of an integration test.

So, to my issue. Trying to unit test my actions I ran into a new issue the other day testing an action using the getText(..) method. This particular method, in the end, locates package resources in it's own directory (from the action class) and parent packages until a resource is perhaps finally found. This requires the environment to know about which action class is executing. I've been trying to mock this condition away with combinations of easyMock and the struts bundled mock classes. To no avail.

The problem here is a classic one when you try to unit test. It is because I have extended the bundled ActionSupport (for convenience) and it contains:
private final transient TextProvider textProvider = 
new TextProviderFactory().createInstance(getClass(), this);
private final ValidationAwareSupport validationAware =
new ValidationAwareSupport();

The ValidationAwareSupport is just a datastructure to decrease code size of the validation aware class and has no external dependencies, which makes it a non-issue.
The TextProviderFactory however, is a big issue. Skipping a few details, digging into it, it depends on just about everthing. There are utility methods accessing action context and the valuestack and so forth. Wanting to avoid the execution context, in this case the action context (and possibly more), this should of course be decoupled.

I have already, since long back written my own ActionSupport since I didn't want it to be serializable. And, now decoupling the TextProvider is not very hard. I just add an interceptor that injects the TextProvider into the action during struts invocation. After this I'm free to provide a truly decoupled mock TextProvider in my unit test.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
Object action = invocation.getAction();
if (action instanceof TransientActionSupport) {
if (logger.isDebugEnabled()) {
logger.debug("Setting text provider on action");
}
((TransientActionSupport)action).setTextProvider(
new TextProviderFactory().createInstance(
action.getClass(), (LocaleProvider)action));
}
return invocation.invoke();
}

The next step is just to add the interceptor to your default interceptor stack, and you have the same functionality in your webapp as before.

Tuesday, September 8, 2009

In Redmod, they know how to prevent good programming

I'm not only working on Java... The worst thing with working with microsoft stuff is probably getting used to it, considering .Net fairly "ok", rediscovering the wonderful Java practices and tools and now going back and forth between Java and the disgusting .Net.

Today, I'm doing some Analysis Services coding. Trying to maintain a piece of web application visualizing data from the OLAP. It has once been written by a DBA, which means most logic was once in the database. Databases are like Excel, they can do to many things and are therefore used for things they weren't supposed to.

However, I tried writing a unit for a constructor implemented enourmous method that I'm trying to split up and test. However, it turns out, it's impossible. ADO MD (OLAP client) is written to be impossible to test, by sealing all its data classes. Trying to find out how the use those classes, I found this page, check the community comment!

It's clear. At microsoft, they detest modern practices so much they go to lengths to prevent them!

Sunday, September 6, 2009

Finally some java

After being trapped in a vicious circle of microsoft projects the last year, there is finally an upcoming java project at work. As the lone java/web experienced developer I'll be putting in 50% on the project as a tech support, kinda.

What we're going to do is a portal based on sitevision. Having fresh bad experience from EPiServer i fear the magic Strings tying together interface entered data in some spooky database with our java modules. We'll see what it might give in a couple of weeks.

My first and most obvious task is to build google maps module for the site. This is of course done using a portlet. Having never used portlets before I have some learning to do, starting in a few weeks. I couldn't help myself however... To try out to see how nice such things can done, without outputting html in the portlet code, I plugged the latest struts onto it. And, out of the box, struts with the excellent convention plugin just works.

I've put the code up on github. It's not working ultra smooth, but might give some inspiration, I'll be happy to merge in any improvements.