@Test
public void testGetPrincipalRoles() {

    createMockDomain("domain1");
    createMockDomain("domain2");
    createMockDomain("domain3");
    String principal = "user.johndoe";
    List<RoleMember> roleMembers = new ArrayList<>();
    roleMembers.add(new RoleMember().setMemberName("user.test1"));
    roleMembers.add(new RoleMember().setMemberName("user.test2"));
    roleMembers.add(new RoleMember().setMemberName(principal));
    // Create role1 in domain1 with members and principal
    Role role = createRoleObject("domain1", "role1", null, roleMembers);
    zms.dbService.executePutRole(mockDomRsrcCtx, "domain1", "role1", role, "test", "putrole");
    // Create role2 in domain1 with members and principal
    role = createRoleObject("domain1", "role2", null, roleMembers);
    zms.dbService.executePutRole(mockDomRsrcCtx, "domain1", "role2", role, "test", "putrole");
    roleMembers = new ArrayList<>();
    roleMembers.add(new RoleMember().setMemberName("user.test1"));
    roleMembers.add(new RoleMember().setMemberName("user.test2"));
    // Create role1 in domain2 with members but without the principal
    role = createRoleObject("domain2", "role1", null, roleMembers);
    zms.dbService.executePutRole(mockDomRsrcCtx, "domain2", "role1", role, "test", "putrole");
    roleMembers = new ArrayList<>();
    roleMembers.add(new RoleMember().setMemberName(principal));
    // Create role1 in domain3 only principal
    role = createRoleObject("domain3", "role1", null, roleMembers);
    zms.dbService.executePutRole(mockDomRsrcCtx, "domain3", "role1", role, "test", "putrole");
    DomainRoleMember domainRoleMember = zms.dbService.getPrincipalRoles(principal, null);
    MemberRole memberRole0 = new MemberRole();
    memberRole0.setDomainName("domain1");
    memberRole0.setRoleName("role1");
    MemberRole memberRole1 = new MemberRole();
    memberRole1.setDomainName("domain1");
    memberRole1.setRoleName("role2");
    MemberRole memberRole2 = new MemberRole();
    memberRole2.setDomainName("domain3");
    memberRole2.setRoleName("role1");
    assertEquals(domainRoleMember.getMemberName(), principal);
    assertEquals(domainRoleMember.getMemberRoles().size(), 3);
    assertTrue(ZMSTestUtils.verifyDomainRoleMember(domainRoleMember, memberRole0));
    assertTrue(ZMSTestUtils.verifyDomainRoleMember(domainRoleMember, memberRole1));
    assertTrue(ZMSTestUtils.verifyDomainRoleMember(domainRoleMember, memberRole2));
    // Get all roles for a specific domain
    domainRoleMember = zms.dbService.getPrincipalRoles(principal, "domain1");
    assertEquals(domainRoleMember.getMemberName(), principal);
    assertEquals(domainRoleMember.getMemberRoles().size(), 2);
    assertTrue(ZMSTestUtils.verifyDomainRoleMember(domainRoleMember, memberRole0));
    assertTrue(ZMSTestUtils.verifyDomainRoleMember(domainRoleMember, memberRole1));
    zms.dbService.executeDeleteDomain(mockDomRsrcCtx, "domain1", auditRef, "deletedomain");
    zms.dbService.executeDeleteDomain(mockDomRsrcCtx, "domain2", auditRef, "deletedomain");
    zms.dbService.executeDeleteDomain(mockDomRsrcCtx, "domain3", auditRef, "deletedomain");
}