Added a test case to test various permutations of role mapping and also minor fixes for issues detected by the test.