Nov 09

XML HTTP Request object (and named parameters)

Ajax, Tech No Comments »

Sometimes it can be a little painful, or I should say, restricting working with browsers as a client UI.

Features like XML HTTP Request definitely help out. It is great to be able to shoot off a message on the background and not have to rerender pages all of the time.

Before XMLHttpRequest, we had to do various hacks. Maybe involving opening tiny windows, using Applets, or whatever sneaky tool we can think off.

If you have an app that needs to poke back to the server check it out.

Reading code such as:

xmlhttp.open(”GET”, “test.txt”, true);

again makes me love Named Parameters:

xmlhttp.open(httpmethod:”GET”, url:”test.txt”, asyncFlag: true);

It would help my readability at least.

Nov 08

aUnit: Unit Testing Aspects

Tech No Comments »

Adrian Colyer got me excited when I saw a post to the AspectJ list with the subject Announcing aUnit, a new unit testing tool for aspects.

How do you unit test aspects in isolation, in the same way that we might unit test a class?

Current unit-testing approaches for aspects are lacking in the following
ways:

* you cannot easily unit test an individual aspect in isolation from the rest of the program
* you cannot easily test whether the pointcut expression associated with a piece of advice matches the join points you expect
* you cannot easily test whether the pointcut expression associated with a piece of advice matches unwanted join points
* you cannot easily test the body of advice in isolation from the rest of the program

For example, given the following simple aspect:

public aspect X {

pointcut anInterestingCall() : call(* Account+.do*(..)) && within(org.xzy..*);

before() : anInterestingCall() { … }

}

We would like to write unit tests that verify:
* the pointcut matches a call to Account.doFoo() from within org.xyz.abc
* the pointcut matches a call to SubAccount.doGoo(int x) from within org.xyz.abc.def
* the pointcut does not match a call to Account.doFoo() from within org.qpr
* after matching at a join point, the post-conditions of the advice body are established
* and so on…

and we want to write these tests without necessarily having to create a package “org.qpr” and without having to weave and run external classes (to the one under test) in order to run the test cases.

Enter aUnit, a seamless extension to JUnit that makes it easy to write unit tests for aspects. aUnit works by letting the test programmer specify a sequence of join points (either programmatically, or parsed from a string format) that are then “played back” to the aspect. It is then easy to test after each join point or set of join points whether the aspect has responded as desired. Contextual information at the join points required by any advice (such as the objects bound to this or target, or the values of arguments) can be supplied by the test case programmer – as either “real” objects or as mock objects, in accordance with normal unit testing conventions.

Here’s an example of a simple aUnit test case:

public void testCallMatching() {
String[] jps = new String[]({”call(void Account.doFoo()) within(org.xyz.abc)”});
X x = X.aspectOf();
playBack(jps,x);
assertInvoked(x,”before”,”1″);
// …
}

The exact style of the test cases has yet to be finalized, but this should give you the idea.

But then the kicker came in:

Where can I download a copy of aUnit?

Sadly, you can’t. It doesn’t exist yet. The idea came to me whilst I was out running in the woods this lunchtime.

BUT, aUnit would make a great project for an MSc and/or for open-source development.

<jon stewart mock voice>
damn you adrian! :)
</jon stewart mock voice>

Ron Bodkin stepped up with good ideas (as always). He has done good work on Virtual Mocks with AOP:

I also think the design for a tool like this should be integrated with a similar API style as virtual mocks for objects (e.g., VirtualMock.org and the virtual mock framework in aTrack’s library). Virtual Mock frameworks typically provide means to specify simulated behavior, including simulated return results (which would be important for testing advice too), and allow instrumenting objects under test to determine what methods and arguments were called or executed (just as this code snippet suggests is needed in assertInvoked).

There’s another little fly in the ointment here: because advice is not named, it’s hard to test for a specific piece of advice being invoked. There is a trick available for naming advice: you can use an inner aspect with just one piece of advice to name the advice. When AspectJ supports Java 5.0, hopefully we will be able to annotate advice to give it a name. By the way, are you planning to allow annotations on advice and aspects in the first version of AspectJ with Java 5.0 support?

As we can see, there are definitely areas to explore with unit testing our aspects, and it will be great to have something like aUnit in the future.

Nov 08

The Best Restroom in the USA

Personal No Comments »

I was just at a bar which had the best restroom experience :)

There were TV’s throughout. But, the best part is, that the TV was showing football (soccer).

It was so pleasant to be able to watch the game even when I needed to release the beer that I had been drinking!

Nov 05

AspectJ 1.2.1 now available

Tech 3,727 Comments »

It is cool to see each AspectJ release come out. I also thought it was REALLY cool how the people that produced bug reports were acknowledged. Isn’t open source great?

We are pleased to announce that AspectJ-1.2.1 is now available from the download page at http://eclipse.org/aspectj or directly from http://download.eclipse.org/technology/ajdt/aspectj-1.2.1.jar

we’ve also set up a download mirror at:
http://www.aspectprogrammer.org/dist/aspectj-1.2.1.jar

AspectJ 1.2.1 contains an updated version of the JDT Java compiler, a number of tools improvements, runtime performance optimisations, the ability to split declare error/warning messages across several lines using

the “+” operator, and numerous bug fixes. Detailed release notes for all these updates and more are available at:

http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/README-121.html

Patches and contributions were submitted by Martin Lippert, Laurie Hendren, George Harley, Matthew Webster, and Juergen Graf. Discussions and interactions with the abc compiler team also led to several of the improvements contained in the 1.2.1 release. We are always very grateful for these contributions that help improve the compiler and supporting tools.

Easy to reproduce bugs were submitted by Doug Orleans, Ron DiFrango, Ron Bodkin, Antti Karanta, Per Hustad, Oege de Moor, Ganesh Sittampalam, Luzius Meisser, Andriy Palamarchuk, Helmet Zechmann, Matt Chapman, Rohith Ajjampur, Adrian Powell, Marius Marin, Takao Nakaguchi, Torsten Lull, Lasse Nielsen, Pavel Avgustinov, Macneil Shonle, Hristo Stoyanov, and David Pearce. We recognize the difficulty of producing clear minimal test cases from bugs found in large systems and appreciate the work that goes into these reports.

Thanks and stay in touch,
The AspectJ Team

Nov 05

Chaining Constructors and creating Creation Methods

Tech 22 Comments »

Cedric has has opined on Why chaining constructors is bad.

I have always disliked the names that constructors have in Java (e.g. the same name of the class).

I now consider having one constructor (which isn’t public) and then having static creation methods which call the constructor correctly:

Person p = Person.createWithLastName(lastname);

Person p = Person.createWithFullNames(firstname, lastname);

With an example like this, it is probably overkill. But if you find yourself with many constructors, and it is hard to remember which one you should use, then it is is nice to do this.

Of course, you often refactor these methods into a Creation Factory seperately.

Nov 05

Watch out for Hibernate unsaved-value

Tech 23 Comments »

I spent far too much time on a stupid bug of my making.

Part of my model had a simple One to Many relationship.

Everything was fine until when creating a new child in the many side of the house I would see an error:

org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance – save the transient instance before flushing: model.Item

Why was it showing this from time to time?

I studied my Hibernate mapping files. I was using an inverse=”true” relationship, and the cascade options looked good.

Next, I checked over the code, and all seemed well.

It turned out that I had set the unsaved value in a past life:

<id name=”id” column=”id” unsaved-value=”0″>

The problem was occuring ONLY on a parent with the id of 0!

Duh!

What I would give for top class error messages when writing apps.

“Hey you idiot. You have set the unsaved-value to 0. Think that may be the problem?”

:)

Nov 05

The New Map

Personal 1 Comment »

(courtesy of Tim Bray)

Nov 04

Two Americas

Personal No Comments »

I realised why I woke up with such a hollow feeling. It is because I woke up in the wrong America.

Whatever religious believes you may have, one belief that I DO have, is in humanity. I thought that people would stand up and say:

“We don’t want a leader whose mistake has killed 100+ innocent Iraqi’s”

“We don’t want a leader who doesn’t listen to facts”

“We don’t want a leader who lies so easily”

“We don’t want a leader who doesn’t speak or listen to the people”

“We don’t want a leader who keeps giving tax cuts to the wealthy”

I wanted to wake up in that America. I wanted to be proud of living in that America.

America is such a great country in so many ways, but so backwards in others. It has always felt like a young pup, with boundless energy. However, this time the pup didn’t do the right thing.

Now I am embarrassed to be here. I got emails from friends around the world asking “How could you vote him in!”, and “It was bad enough last time, but this time you knew what he was really like!”. I can’t argue with him.

Some have said that I am not open minded to the republican side. That is totally untrue. If this was John McCain, I could get behind him. Heck, I could get behind a lot of republicans. There is a case for small government / fiscal conservatism. But, this guy isn’t a republican in that vein.

This campaign was won on lies. The PIPPA report shows that Bush supporters STILL think that Iraq was in charge of 9/11, and that they have WMD. Still. Today. That is what they have had fed to them.

The people that I know that truly think about the issues, do past FOX NEWS to find out what is going on, are pained at the moment. The people that I know that don’t care, are fine with it.

America has delt with bad presidents in the past though, and I am sure that people will come through. It is sad that the issues that mattered were “moral issues”.

How would you feel if you were gay, or had a family member who was gay, and you woke up to 11 states voting against your way of life. Disgusting. We should be discussing policy on the economy, healthcare, and what about the ENVIRONMENT. But no.

This will be my last post on these issues for awhile. I need a break. But to end on the scariest note of all:

“With a bigger majority, we can do even more exciting things,” said House Majority leader Tom DeLay, a Republican from Texas.

Nov 03

Can I wake up yet?

Personal 3 Comments »

I can’t believe it. I can’t believe that people would vote for this evil regime again.

In 2000, people were voting for someone who seemed like an idiot, but “probably not that harmful”.

In 2004, we know that everything they touch turns to merde.

Yesterday I was out helping the Kerry campaign, and was feeling so good as EVERYONE was out ther voting for him. All the corners had Kerry supporters.

However, my world is distorted based on where I live. I would love to create a new country which consists of the west coast, mid west, and north-east.

I don’t know if I can take 4 more years.

Nov 01

Kerry Rally in Madison

Personal 1 Comment »

There was a rallyin Madison last week. 800 thousand people came out to see Kerry… or maybe just Bruce Springsteen.

I did like it when Kerry said:

When Mr. Bush heard that the BOSS was speaking at this rally, he thought Dick Cheney was coming here!

Here are some pics from the day:

KerryRally1.jpg

KerryRally2.jpg

KerryRally3.jpg

KerryRally4.jpg