Apply fix and add test for:
https://issues.apache.org/jira/browse/AMQ-5385