See the output from MockMvc.peform()

Lets say you have a unit test on a Spring MVC controller like this:

 * Tests RESTController.getPostcode() with a false postcode and building number
public void PostcodeAndBuilding_FalsePostcodeIsNotGot_Passes() throws Exception {

    mockMvc.perform(get("/postcode/" + test3PostcodeRequest + "/" + test3BuildingNumberRequest))
            .andExpect(jsonPath("$.status", is(404)));


The test is failing, so you want to grab the response for whatever reason.  The simply way of doing this is to return the response of the MockMvc.perform into an MvcResult and run getResponse and getContentAsString on it to turn it into a String:

 * Tests RESTController.getPostcode() with a false postcode and building number
public void PostcodeAndBuilding_FalsePostcodeIsNotGot_Passes() throws Exception {

    MvcResult result = mockMvc.perform(get("/postcode/" + test3PostcodeRequest + "/" + test3BuildingNumberRequest));
            //.andExpect(jsonPath("$.status", is(404)));

    String content = result.getResponse().getContentAsString();


You now have the content stored as String to do with what you wish.


A Zero Byte SSL Key, is Never a Good Thing…

I’ve been working on a side project that exposes the Post Offices PAF data via a REST API.  While securing the site I was getting problems loading the Apache config, after a few seconds of investigation I spot a major problem…

A zero byte SSL key, is never a good thing:

root@jupiter:~/api.postcode.software_ssl# ls -la
total 12
drwxr-xr-x  2 root root 4096 Jan 21 17:23 .
drwx------ 10 root root 4096 Jan 22 11:18 ..
-rw-r--r--  1 root root 1119 Jan 21 17:23
-rw-r--r--  1 root root    0 Jan 21 17:27

Time for a re-issue…

I wouldn’t be so annoyed if the key hadn’t only just been issued after a 12 hour wait.

I’ll post more on the project when its complete (as complete as a side project ever gets!) on this blog.


Maven – Index Downloads are Disabled


When trying to add Maven dependencies to your project you encounter the message “Index downloads are disabled, search results may be incomplete.”, as shown in the following screenshot.

Maven Index Downloads are Disabled


To fix this, enable “Download repository index updates on startup” within the Eclipse preferences, as show in the following screenshot. then restart Eclipse.

Fix Maven Index Downloads are DisabledFix

Detailed Steps

  1. Select the menu item Window->Preferences
  2. Select Maven on the left hand side
  3. Place a tick in the Download repository index updates on startup
  4. Select OK
  5. Select the menu item File->Restart

Darcula for NetBeans IDE

Someone has released a Darcula theme for NetBeans.

Netbeans with the Darcula Theme

Netbeans with the Darcula Theme

I don’t use NetBeans myself, but its one of the IDE’s that I’ve been wanting to take a look at in the future as I’m booked on a Java training course that will use it. When I do get to use it, I’ll be using this theme. Darcula much less stressing on the eye when you are coding all day.


Next course up is…

Java Programming: Arrays, Lists, and Structured Data from Duke University on Coursera.  I expect to fly through this course.

Along side this I’ve started studying for the OCA Java SE 7 and 8 Programmer exams.  I’m using a combination of the official study guides and Enthuware‘s excellent exam simulators.  I’m hoping to sit the two in the same month.


Java Programming: Solving Problems with Software

I’ve passed another Java course on Coursera today.  This course was   Java Programming: Solving Problems with Software.  Overall the course was good.

Java Programming: Solving Problems with Software

Java Programming: Solving Problems with Software

One think I didn’t like was the the way the course was run with an expectation that the student would use BlueJ.  While there is a need for IDE’s like BlueJ the course content was at a level that the student should really be using a real IDE such as Eclipse or IntelliJ IDEA.

You can complete the course using Eclipse with no issues though,  just add the apache-csv.jar and courserajava.jar file to your project build path libraries:

Adding Libraries

Then import the packages at the start of your code:

import edu.duke.*;

You can grab the code in an Eclipse project from my GitHub page.



I’ve had a bit of a poor history with Java.

I first tried programming in Java back when Borland JBuilder 3 was on the cover of nearly every PC magazine, this must have been around 2000.  I thought I’d like the IDE as Borland Delphi was so good, but I couldn’t get on with JBuilder at all.  I suppose one of the real problems was that I didn’t really understand OOP back then.  It was only when I started writing software for BeOS (now Haiku OS) in C++ that I really got to grips with OOP.

EdX had a Java course starting around about the time I’d finished the Scratch course so I enrolled and I’m glad to say that I’ve passed!


The course itself was really good.  It covered all the basics right up to object oriented programming using interfaces and abstract classes.  The programming assignments were challenging and enjoyable at the same time.

I’m really looking forward to Part 2, which has been announced but there isn’t a start date yet.  In the mean time I’m working through some C# and Bootstrap courses Microsoft have on EdX.