January 2013
3 posts
Best damned pickles in the world.
Up until yesterday, i had not found a good way to test my LDAP client code besides manually testing it, which is simply unacceptable from my standpoint.
But thanks to this stack overflow anwer I was lead to the Unboundid LDAP SDK.
After playing around writing tests with it, I quickly refactored my test code into an annotation based test utility that allows me to easily start up the server and seed it with information. I’ve put the code on Github.
Update 2013-01-28 - ldap-test-utils should be in Maven Central in a day or two. I released version 1.0.0. If you have any feature requests, submit them on github.
September 2012
2 posts
We use Rally at work for managing our development efforts. The tool itself is OK but something as simple as creating a defect can take too long. Some defects were going unreported because it was too cumbersome to enter even very minor cosmetic bugs. A couple of years ago I used a Rally tool for creating defects from screenshots and this was great but apparently it’s no longer maintained. In lieu of creating an entire application I decided to glue together the actions via Apple’s Automator application, some AppleScript and Ruby.
The first thing I did was to use the excellent Rally APIs via the rally_rest_api gem for Ruby. This allows you pretty much full access to all of your information in Rally, even uploading screenshots. I created a simple script called createdefect.rb that uses the API, creates a defect in a project and attaches the screenshot. The script itself takes only three arguments at this point : the defect title, the file name to attach and the Rally project. Here’s an example:
./createdefect.rb “This is my defect” “~/Desktop/bug01.png” “Rizzo”
This creates a defect in the project “Rizzo (new SSO)” with the given title and attachment. The project doesn’t have to match exactly, a downcase.start_with? predicate is used to locate the project.
With Ruby script working, I wanted a way to invoke it using a shortcut key or through the services menu on my Mac. I had used Automator before so I figured I could get it done that way. I created a Service Workflow in automator that invoked the ruby script. Before invocation however, I needed to get some input from the user (me) to pass to the script.
First - the title. I wrote an apple script to get feedback from the user using the ‘display dialog’ commands in AppleScript. Unfortunately, it wasn’t until after completion that I noticed that a simple “Ask for Text” action exists in Automator. Oh well.
Second - the project. I found a nice forum post (sorry i lost the link) that shows how to use the “choose from list” applescript function. This allowed me to supply a list of projects from which to choose.
Third - the image. This is built in to Automator. When you create an automator service, you define the type of input that is accepted. I chose ‘image files’.
So, the entire automator workflow essentially goes like this:
- accept image file(s)
- Set “ImageFile” variable to the input.
- Run AppleScript to get the Defect Title via a dialog box
- Set “Title” variable to AppleScript output
- Run AppleScript to allow the user to choose the project
- Set “RallyProject” to the user choice
- Get Variable (“Title”)
- Get Variable (“RallyProject”)
- Get Variable (“ImageFile”)
- Run Shell Script /Users/trevershick/bin/createdefect.rb “$1” “$3” “$2” | grep “defect created”
- Run AppleScript to display the created defect number






I had several issues working with Ruby and the Automator. Mainly I had issues because I use rvm and when Automator executes shell scripts, it doesn’t have the benefit of rvm. I worked around this issue by using the stock Ruby install on the mac to test/run the createdefect.rb script which also required gems be installed globally on the mac. Perhaps I could have worked around this by invoking rvm or by installing rvm as the root user but I simply didn’t care enough to do that. The stock ruby install works fine.
Codea simple and easy tip or speeding up Terminal
April 2012
1 post
I do development and sometimes I have to recreate issues with actual data which means using other people’s email addresses. Obviously I don’t want to send them email while i’m testing so I use Apache James as a local only email server.
Here are the steps i use to set this up.
Download and Run James ServerFrom http://james.apache.org/download.cgi or directly from http://mirror.nyi.net/apache//james/server/apache-james-2.3.2.zip and extract to a folder.
As i’m running a mac, I added the following to run.sh. If you’re on a windows machine, this step may not be required.
Start the server…
On a mac
bin/run.sh
On windows
bin/run.bat
$ telnet localhost 4555
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
JAMES Remote Administration Tool 2.3.2
Please enter your login and password
Login id:
root
Password:
root
adduser me me
User me added
Remove the Remote Delivery Mailet
Remove ( or comment out ) the Remote Delivery mailet in <james_home>/apps/james/SAR-INF/config.xml . Open the file and search on ‘class=”RemoteDelivery”’, and comment out the whole stanza.
Forward all email to the local account![]()
It’s very important that you configure the forwarding mailet to be in the same place where the RemoteDelivery mailet was. If you put it too early in the config.xml you may get errors when it attempts to forward a message.
Insert the following mailet in the place where the RemoteDelivery mailet was previously located in ( <james_home>/apps/james/SAR-INF/config.xml ).
Run the ServerSave your changes in the config.xml file and start the server.
On a mac
sudo bin/run.sh
On windows
bin/run.bat
Send an email to me@localhost and use a POP client to ‘get’ the email. You should see it.
Send an email to anywhere@anywhere.net and retrieve the message, it should be redirected to your local inbox.
On a mac I use homebrew ( http://mxcl.github.com/homebrew/ ), and simply run:
brew install mutt
- send a test email by pressing ‘m’ to get started, test me@localhost first
- after the mail is sent, press ‘G’ to get the mail from the pop server, you should have received the email you sent.
- repeat with an external email address - all email flowing to your local server should be redirected to me@localhost .
March 2012
3 posts
So, search.maven.org is a great site, but i don’t want to bring up a browser just to find artifacts. In an effort to bone-up on my groovy I thought i’d create a groovy script that would search for me.
Feel free to use this script, and if you can improve it, fork it and make ur own changes.
In this post i make the claim that you might be an a-hole if you have a variable name longer than ‘in the garden of eden’… Well, ‘yesIKnowItShouldBeSingleton’ is my violation of this rule. wonk wonk…
If your variable name has more syllables than “In the garden of eden” then you might be an a-hole.
Object queryImplUnderConstruction;
February 2012
2 posts
I came across this page today. I was providing some information to these guys and apparently I had put ‘anyhoo’ at the bottom of the page. Made me laugh at least.
This is a short post, i’ll leave it to the image to explain… I will say that i’m glad slf4j is as flexible as it is and allows me to unify the logging, but come on…..
![]()
December 2011
3 posts
I’ve been playing with JQuery Mobile and Rails and I had a problem with a checkbox not working properly. The checkbox would render properly but wouldn’t update my model. My checkbox was rendered within the erb template with the following snippet…
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<%= f.label :interviewer %>
<%= f.check_box :interviewer %>
</fieldset>
</div>
It turns out i had the label and checkbox in the incorrect order.
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<%= f.check_box :interviewer %>
<%= f.label :interviewer %>
</fieldset>
</div>
Why, I haven’t bothered to figure it out, but it’s working now and as i didn’t find anything on google about this problem, i’m posting this entry.
![]()
So, one of our developers was seeing some odd results in his Jenkins cobertura reports. The tests weren’t changing, but the coverage numbers were fluctuating. Reviewing the logs, I found a common issue (shown below).
Results
Instead of typing up everything I tried over the last couple of days, i’ll just put down basic notes :
- Maven : v 3.0.3 (and up)
- Cobertura Maven Plugin : 2.4 - fixes the issue
- Cobertura Maven Plugin : 2.3 - doesn’t work (has issues shown in log above)
- Cobertura Maven Plugin : 2.51 - doesn’t work (has classloader MavenReport issues)
- -Dcobertura.use.java.nio=false - Unnecessary (in my case)
July 2011
8 posts
Recently I had to write some JavaScript for a project and needed a way to test it. My first thought was to have a sample page that uses the JavaScript functions and objects I was creating, and in fact I did create this page. It was a good way for me to determine how I wanted my API and it also provided instant feedback. However, it was manual and it was cumbersome to express my expected outcomes from the API calls. I did a little searching and found that there are a number of Unit Testing frameworks for JavaScript out there in the wild. I personally decided upon JSTestDriver on http://code.google.com . JSTestDriver’s API is very similar to JUnit which I am familiar with and also allows me to drive multiple browsers at the same time. I won’t go thru all the details of how I got this to work, but I will include a few code snippets. Here is the basic process.
- Create your project
- Download JSTestDriver
- Write your JavaScript
- Write your Unit Test - you can do this first but i find it helpful to get the test framework running by creating a test after i have a rudimentary class. THEN i start adding tests to the unit test that force me to implement the functionality in my JavaScript.
- Create the jsTestDriver.conf File
- Locate your browser executables on your machine
- Create your run.bat or run.sh file
- Run your tests
I came across a real unit testing nightmare the other day attempting to write tests for the new SSO system. SiteMinder has it’s own SDK and agent API that you can extend, but it’s all based on JNI. Even though my code was implemented in pure java, I had to implement an interface (com.netegrity.policyserver.smapi.ActiveExpression) and use a class (com.netegrity.policyserver.smapi.ActiveExpressionContext) that had a static initializer loading a native library.
In prior fights with this situation, I have refactored all behavior out into another class that mirrors the API of the offending class and then simply delegated to my nice new shiny testable class. But I don’t like that because it creates more lines of code which are solely for unit testing, and makes the reader of the code say “What’s this for?”. In other words, it smells.
After doing some searching, I came across PowerMock . PowerMock allows me to unit test my class as is by suppressing the static initializer. Here’s a snippet of my code:
PowerMock isn’t perfect. You are forced to run the test with the PowerMock runner instead of the stock Junit runner or even the Spring JUnit runner, but it’s benefits definitely outweigh the drawbacks.
I urge you to take a look at PowerMock. It’s nice.
I’ve created a custom auth scheme and finally got it deployed. It took a while. I finally got to the point where i created a log() method that logs to /tmp/{classname}.log. This is not a long term solution, but it’s helping me during the discovery phase. I instantiated the FileWriter in the init method and then logged to it in the query() method but I was getting errors like : [30651/4042537872][Wed Jul 06 2011 07:28:18][SmAuthServer.cpp:233][ERROR] Failed to query authentication scheme ‘AlwaysAcceptCredentialsFormAuthScheme’ Ultimately, I changed the log() method to do lazy initialization of the file writer and BAM! i started getting log messages. The funny thing is, i NEVER get the init() log message. I don’t think it’s being called. Their documentation says it will be called once for each instance of the custom authentication scheme but i’m never seeing it called, so i’m very confused.
public SmAuthStatus init(String parameter, String secret) {
log("init() called on " +getClass().getName() + " with "
+ secret+ " and " + parameter);
return SmAuthStatus.SMAUTH_SUCCESS;
}
I’ll see if I can figure it out.
Update 2011-07-08 - init() is in fact called. I noticed in my logs that it is being called now. I do not know what changed as I’ve had many changes. I simply was not relying on init() being called so i never noticed when it started.Add the following to your pom.xml. This works from v 0.12 on up it appears.
<properties> <m2eclipse.wtp.contextRoot>the_context</m2eclipse.wtp.contextRoot> </properties>
I was working with a team that was using Hibernate with Oracle and writing ‘unit tests’. My major issue was that the tests were slow when running against Oracle. Unit tests should be as fast as possible. There are different ways to skin this cat such as having a separate module for integration tests but I wanted to make it fairly transparent for the developers. By default I wanted to run the tests with H2 but allow them to switch to Oracle for their tests very easily.
The solution was to use Maven profiles to add database specific configuration files to the test resources in the build. For H2 (default) it would add src/test/h2 and src/test/oracle for Oracle. The file names are identical in these files (spring-test-database-config.xml), so that the unit tests themselves are ignorant which one they’re loading. It seems to work like a champ. I’ll give it some time and report back though. The gist is below that shows the changes to my pom.xml to support this scheme. I’ve also included the database config files for completeness sake.
I’ve also included a video demonstrating how this works within Eclipse using m2eclipse which is our development environment.