In the last couple of month I was writing some flows using Spring Webflow 2. I knew that I (in theory) I could test them but I never did. The overall documentation of Webflow 2 is not that great at the moment, so I hope to improve that a little bit.
Spring Webflow 2 supports only JUnit tests so far. I guess this will change at some point but until then you have to pull out that junit.jar again.
Sorry for the awkward line breaks. Spring just does love long method and class names (which is not that bad).
Your Testclass needs to extends AbstractXmlFlowExecutionTests and to implement protected FlowDefinitionResource getResource(FlowDefinitionResourceFactory resourceFactory).
public class MyWebflowTest extends AbstractXmlFlowExecutionTests
protected FlowDefinitionResource getResource(
FlowDefinitionResourceFactory resourceFactory) {
FlowDefinitionResource flowDefinitionResource =
resourceFactory.createResource("flows/administration/skinManagement.flow.xml");
return flowDefinitionResource;
}
If your flow now happen to have a parent flow you are in a bit of trouble. You just can include one flow in the FlowDefinitionResource. The parent tag in your flow points to an id of the parentflow which is usually defined in a webflow configuration file. If this parent flow again has parents as well…yes, same game again.
To get a hold of these flows you need to override getModelResources[].
@Override
protected FlowDefinitionResource[]
getModelResources(FlowDefinitionResourceFactory resourceFactory) {
FlowDefinitionResource[] flowDefinitionResources =
new FlowDefinitionResource[3];
flowDefinitionResources[0] =
resourceFactory.createResource("flows/common.flow.xml");
flowDefinitionResources[1] =
resourceFactory.createResource("flows/common-exceptionHandling.flow.xml");
flowDefinitionResources[2] =
resourceFactory.createResource("flows/common-menu.flow.xml");
return flowDefinitionResources;
}
If one of your flows is using beans you want to mock them in the test. You can do that by registering with the MockFlowBuildContext. The method configureFlowBuilderContext will be called by AbstractXmlFlowExecutionTests
@Override
protected void configureFlowBuilderContext(
MockFlowBuilderContext builderContext) {
builderContext.registerBean("validationExceptionHandler",
new ValidationExceptionHandler());
builderContext.registerBean("infastructureExceptionHandler",
new InfastructureExceptionHandler());
builderContext.registerBean("springSecurityExceptionHandler",
new SpringSecurityExceptionHandler());
}
With this setup you now can start testing the flow.
...
public void testSkinManagementView() {
MockExternalContext mockExternalContext = new MockExternalContext();
startFlow(mockExternalContext);
assertFlowExecutionActive();
assertCurrentStateEquals("showSkinManagementOverview");
}
...
I think the code is pretty self explanatory.
You have several possibilities including start and resume flow and assert certain states. You can test action methods doing something (like calling a service) and making sure the correct flow is executed.
Figuring out the initial setup with the parent flow and beans was the most time consuming task. You need to make sure that you only put flow logic in the definition of the flow since that is what webflow is for. I think with some clever usage of set and result you can make things complicated and a bit tricky.
Until now it was almost impossible to get the GeoLocation of a user browsing your site. You could try to use several services to more or less guess the current position. Most of the time they where using the IP address to tackle the problem. This was not very reliable when it came to mobile devices.
Ever since the iPhone hit the market mobile adoption of the web grew exponentially. Google threw in Android and I’m sure some Windows Mobile phones do have GPS as well. According to some talks at re:publica 09 the big telco carriers such as T-Mobile and Vodafone see their future in the mobile (geolocation aware) web.
Even though these devices had the capabilities to get the current location, website developers are still facing the problem that they can not access the positioning hardware of the phone. There was almost no way for (mobile) web developers to get the location of the user. There are some solution out there but you needed to install extra software which is not always possible on a phone.
Fortunately W3C is working on the HTML 5 standard which includes JavaScript access to the browsers location (at least I hope it will be included). The latest beta of Firefox 3.1 (beta3) already supports that API. If you don’t have a GPS system in your computer you can install an addon to set your location. Rumors has it that Apple will release the upcoming iPhone 3.0 OS with a location aware browser and Google will do the same with one of the next updates of Android.
To test that I wrote a small geolocation aware demo webpage with some JavaScript to pull out the information. If you are accessing it with Firefox 3.1b3+ (plugin installed and configured with your position) you will be prompted for unveiling your location to the website. If you do so it will show you your current position on the map and print out the address.

Allow access to the browsers GeoLocation

Showing the GeoLocation of the Browser
To access this information all you need to do is:
function showMap(position) {
// Show a map centered at
// (position.coords.latitude, position.coords.longitude).
}
// One-shot position request.
navigator.geolocation.getCurrentPosition(showMap);
Once this feature is widely available in mobile browsers (I do hope for this summer) my bet is that we will see a whole bunch of websites doing all sort of crazy things with these information. I’m a big Location Based Services (LBS) fan and I can’t wait to see people taking advantage of this.
Update Firefox 3.5.x uses Google’s Geolocation service if no other way can be used. This is halfway accurate. It gathers information about nearby wireless access points and your computer’s IP address. No more plugin needed.
At Campfire One Google announced their App Engine for Java (this was in the rumor mill for a couple of days already). The first 10,000 developers would get an early look at App Engine’s Java language support. I would have almost missed it. Some tweets reminded me of registering with Google. I heard of AppEngine before but the fact that it was only available for Python did not make it very attractive to me. Now the game changed a bit with introducing Java (and other JVM languages (JRuby, partial Scala …), well Groovy for sure, Ola Bini has more on that).
After registering with my Google ID they wanted to verify my account with a sms text message. Google is just listing 3 countries and then ‘Other’ for sms verification and I expected it would not work with a german cellphone. But it did
.
The Tutorials on their site are working nicely (even if you don’t have Eclipse which they are always referring to). Just follow the instructions step by step, use ant and the command line to get through the examples. Don’t copy the template project, this is not in line with the documentation.
In the last hour or so I went from nothing to a running Guestbook App at Google (try it!). Once you get the environment right, the code is pretty straight forward.
I see a couple of things which I do like about the App Engine.
Support for Google Id and Sign In
AppEngine support sign in with an Google ID with 2! lines of code. Great. I don’t want to worry about that (this generates the Google login page and redirects).
UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser();
Automagic Persistence
With simple annotation you persist your objects. No mapping, no nothing. You can configure if you want to be using JDO or JPA. No database hassle or whatsoever. Of course it needs to be seen how this work with more complex domain models.
@PersistenceCapable(identityType = IdentityType.APPLICATION)
..
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private User author;
@Persistent
private String content;
@Persistent
private Date date;
...
Local Development – Remote Depolyment
Everything works locally. If you deploy it to Google it uses the Google facilities. I don’t have to worry (deployment is one ant command).
Scalability and free Use
If your application is successful you can grow with Google. More Resources at your fingertips. Of course this costs money (but you should make money at this point right?). If you are beyond the free 10 GB bandwidth in/day, 10 GB bandwidth out/day, 5 million pageviews a month, 46.3 cpu h/day and 1000 emails/day you pay:
Monitoring
You get nice and detailed overview of the status of you application. You can upload new version any time and go live on demand.

Google AppEngine Dashboard
This this is limited access and Google titles it ‘early look’ there must be some gotchas but I hope they will get worked out. Of course you will depend on Google’s code but I could imagine with a good abstraction layer you can minimize the dependencies to the AppEngine (although replacing some services you might need to use could be hard).
The downside of using it are (gathered from various sources)
For sure there are some more benefits in hosting with Google (I guess the same goes for Amazon with S3/EC2). In the past I heard from a couple of startups using those kind of services but I never imagined that it would be that easy. As I said, I was up and running in under one hour.
I certainly will use AppEngine for a small application in the near future.
Your IDE does a great job in helping you to program. This includes advanced features like Refactoring, Code completion and support for nifty frameworks. But it can do much more.
Most of the time you actually read the code instead writing it. So how about to make this a bit more pleasant experience (well it was for me at least). Most of the people I see use the standard color scheme of the IDE. I was using it for way to long, that’s for sure. Ever since I tweaked it just a little bit I do find my way around an editor window much more easily.
A couple of things are very easy and provided me with great value.

Coloring your IDE
Several people like to have big fonts for coding. If less text fits on one screen without scrolling you are likely to code smaller methods/classes. I’m not so sure about that one I just find it aesthetically not very pleasing.