Wednesday, 28 March 2012

Cucumber-jvm - a first very tentative dabble

Before I start getting in to the meat of BDD & what on earth to do with it I wanted to create a basic standalone project and get the tests working.

I decided to take a look at cucumber-jvm because I have heard good things about it from the Ruby world.
Here is Cucumber-jvm on github from cukes.info.

The git hub link points to the whole shebang & is all maven based. I can't say I am a fan of maven at all.

So I have stripped out the hello world application and just included the jars that are needed for that application.
It can be found here on my github repository.

Included is all you need to run this as an eclipse project except the jars. I use ivy to download the required jars so they are defined in the ivy.xml file.  If you want to know more about ivy see this post I wrote a while ago.

Now I need to delve further in to the world of BDD & work out what I need to do to apply it to my current & new projects. Wish me luck.

Friday, 10 February 2012

hibernate fixes SQLServer char(n) mapping bug in 3.6.8

Hibernate have had an annoying bug where SQLServer columns mapped as char(n) where n > 1 are returned as a char instead of String.

varchar(n) columns are fine.

The hibernate bug is https://hibernate.onjira.com/browse/HHH-2304

It is fixed in 3.6.8 however 3.6.10 is already out so I have just downloaded & tried that.
excellent it works.

Hibernate4 is also out. I have not tried that yet but no doubt will be soon.

Wednesday, 4 January 2012

Multiple search windows in eclipse

This is a really simple but cute little feature.

If you pin one search window using the pin icon at the right hand end of buttons then the next time you do a search eclipse will open up a new Search window.

There is also a search history that you can look through just to the left of the pin icon.

Friday, 23 September 2011

finding the correct spring jar for a known class

With Spring 3 you now have to get all the individual jars that you need for an application.

One solution is obviously to download the lot.

But what if you just want to install what is needed.
How do you easily find which jar a class is in ?

Well I have just found this Spring Bundle Search tool.

You can enter just the class name or the class with its full package name.

Wednesday, 31 August 2011

windows7 Administrator mode from the command line

Type 'cmd' in the Run window as normal but instead of simply hitting the return key, use Ctrl-Shift-Return

Monday, 4 July 2011

Auditing using AOP and annotations in Spring

Lord, how I dislike the old XML configuration for AOP (among other things).

I have not given myself the opportunity to try out Spring's annotation based AOP in spring, until now and boy is it easy (with one minor gotcha).

Here are the building blocks:

1) Make your own Annotation. This is a simple way to mark all methods you want to audit.

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ParmsAudit
{
  ActionAuditType  auditType();
}


2) ActionAuditType is an enum that will be used to identify the thing being audited.

public enum ActionAuditType {
USER_LOGGED_IN("User Logged In"),
USER_LOGGED_OUT("User Logged Out");

private String mDescription;
  private ActionAuditType(String aDescription) {
 mDescription = aDescription;
}


public String getDescription() {
 return mDescription;
}
public void setDescription(String aDescription) {
 mDescription = aDescription;
}
}

3) Create an Aspect. This is the code that is run when the method marked by the annotation is called.

Here is the minor gotcha - well for me atleast.
I had to list the full package path to the Annotation in the @Before statement.


@Aspect
public class AuditAspect {

@Before(value="execution(@uk.co.billcomer.audit.ParmsAudit * *(..)) &&   @annotation(parmsAudit)", argNames="parmsAudit")
public void logTheAuditActivity(JoinPoint aPoint, ParmsAudit parmsAudit) {
 String userName = getUserName();
 mlogger.info("Parms Auditing User Name: " + userName);
 mlogger.info("auditType:" + parmsAudit.auditType().getDescription());

 String arguments = getArgs(aPoint.getArgs());

 if (arguments.length() > 0) {
 mlogger.info("args-" + arguments);
 }
}

private String getArgs(Object[] args) {
 String arguments = "";
 int argCount = 0;

 for (Object object : args) {
   if (argCount > 0) {
     arguments += ", ";
   }
   arguments += "arg[" + ++argCount + "]=" + "[" + object + "]";
 }
 return arguments;
}

private String getUserName() {
 try {
   return SecurityContextHolder.getContext().getAuthentication().getName();
 } catch (NullPointerException npe) {
   return "Unknown User";
 }
}
}

4) Mark the method to be audited.


@Service("parms.DummyAuditThing")
public class DummyAuditThing implements DummyAudit {

@Override
@ParmsAudit(auditType = ActionAuditType.USER_LOGGED_IN)
public void aspectAuditMethodTwoParams(String param1, Long param2) {
 mlogger.info("In method to be audited param1[" + param1 + "], p2[" + param2 + "]");
}
}


5) Context configuration
This is needed to speed up the compilation process. Essentially it tells the compiler what classes will have Aspects
   
   <aop:aspectj-autoproxy proxy-target-class="true"/>   
   
   <bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"/>
   <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
   
   <bean id="bill.auditAspect" class="uk.co.billcomer.audit.AuditAspect" />

Wednesday, 1 June 2011

android phone calendar not synching

The other day the calendar on my android phone stopped synching correctly to my google calendars.

It was partly way there. It new about the calendars but would not display any of the data.

I found this which did not describe my solution 100% but put me on the right track.

Go to Settings->Applications->Manage Applications->Calendar and select 'Clear data'.
This will give you a pop up box saying all the applications data willbe deleted permanently. Do not worry & select the the 'OK'.

Now go back to your calendar app and you will find all your calendars restored.