Friday, May 6, 2011

Mocking jndi for junit tests

SimpleNamingContextBuilder was the perfect match for me when i wanted to mock some jndi-references for my appctx in my junit-tests

@BeforeClass
    public static void mockJndi() throws IllegalStateException, NamingException {
        SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
        builder.bind("java.naming.factory.initial", new org.jnp.interfaces.NamingContextFactory());
        builder.bind("ConnectionFactory", new QueueConnectionFactoryBean());
        builder.bind("queue/someFileQueue", new ActiveMQQueue());
        builder.activate();
    }.

Thanks to http://formatmysourcecode.blogspot.com/ :)

Monday, February 14, 2011

HttpMediaTypeNotAcceptableException

Using spring mvc and the @ResponseBody annotation might give you the HttpMediaTypeNotAcceptableException if you set the "Accept" header to "application/json". To solve this, add jackson-jaxrs to your classpath.  Nothing else needs to be done, spring does it's magic.

In your test , slap on a @Autowired on your AnnotationMethodHandlerAdapter.

Sunday, February 13, 2011

Maven + appengine

This memo is about using maven with your google appengine project.

Prerequisites:
Maven 3.0x
Command line interface
Know how to edit your pom

Howto:
  1. mvn archetype:generate choose gae-jsp and enter your project group/artifactid
  2. cd
  3. edit your pom.xml file to define at least the 1.4.2 version of google appengine, found under the properties tag. 1.4.2
  4. type mvn install to check that everything is ok
  5. type mvn gae:unpack to download and install the gae runtime into your local repository
  6. Edit the src/main/webapp/index.jsp, remove all jsp tags.
  7. type mvn gae:run and open localhost:8080
Congrats, you are now ready to start your GAE project with maven. I suggest
  1. mvn eclipse:eclipse and import the project into eclipse.
  2. Add spring, spring-mvc and spring-jdo or spring-jpa to your projects pom-file.

Update: updated version from 1.4.0 to 1.4.2

Wednesday, November 24, 2010

Setting up your favourites in Eclipse

I have started to use the corematchers from org.hamcrest, and find them very useful and easy to understand. They give a grammatical touch to my assert-statements that the regular assertEquals(...) does not. E.g. assertTrue(a > 0) can be written as assertThat( a , is(greaterThan(0))), which can be easier for non-technical people to understand.

Anyway, to avoid manual static imports, let eclipse do the job for you. Configure it as follows:

Wednesday, November 10, 2010

Remote logging with GWT

Remote logging was introduced in gwt 2.1, but the documentation is still a bit incomplete. To enable remote logging you will have to


  1. Add configuration-stuff in your .gwt.xml file:

    < inherits name="com.google.gwt.logging.Logging" >
    < set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" >
    < /set-property >
    < /inherits >

  2. Add the remote logging servlet in your web.xml (remember to replace YOURPROJECT with your projects name):
    < servlet >
    < servlet-class>com.google.gwt.logging.server.RemoteLoggingServiceImpl </servlet-class >
    < servlet-name >logger < /servlet-name >
    < /servlet >
    < servlet-mapping >
    < servlet-name>logger </servlet-name >
    < url-pattern>/YOURPROJECT/remote_logging </url-pattern >
    < /servlet-mapping >
Happy logging!

Friday, February 5, 2010

Declarative UI programming with GWT

If you have tried programming something on the GWT - 'platform' you should take at declarative UI programming at the guide at DevGuideUiBinder.html .oHowever, you should NOT add the panels with Document.get().appendChild( new MyBrandNewUIWidget().getElement()) as NONE of your events will ever trigger. You should however add your new widgets the old fashioned way with RootPanel.get().add( new MyBrandNewUIWidget());

Happy programming!

(Maybe I should put out an example of how great the new GWT 2.0 is, it's a lot of fun!)

Tuesday, November 3, 2009

Building CUDA examples on Snow Leopard

The usual 'make' command failed for me, but doing  'make clobber && make i386=1' worked perfect :)

Now it's time to learn some serious gpu-programming...