CLOUDIFY-2088 Fixed NPE and added unit test.