@Test
public void testListResourceAccess() throws SQLException {

    
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.next())
        .thenReturn(true)
        .thenReturn(true)
        .thenReturn(true)
        .thenReturn(true)
        .thenReturn(false) // up to here is role principals
        .thenReturn(true)
        .thenReturn(true)
        .thenReturn(true)
        .thenReturn(false) // up to here is role assertions
        .thenReturn(false); // no trusted role
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_NAME))
        .thenReturn("user.user1")
        .thenReturn("user.user2")
        .thenReturn("user.user3")
        .thenReturn("user.user4") // up to here is role principals
        .thenReturn("dom1")
        .thenReturn("dom1")
        .thenReturn("dom2");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_DOMAIN_ID))
        .thenReturn("101")
        .thenReturn("101")
        .thenReturn("102") // up to here is role principals (we'll skip user4 since it's expired)
        .thenReturn("101")
        .thenReturn("101")
        .thenReturn("102");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ROLE_NAME))
        .thenReturn("role1")
        .thenReturn("role1")
        .thenReturn("role3");
    // expired and non-expired timestamps
    java.sql.Timestamp expiredTime = new java.sql.Timestamp(System.currentTimeMillis() - 100000);
    java.sql.Timestamp nonExpiredTime = new java.sql.Timestamp(System.currentTimeMillis() + 1000000);
    Mockito.when(mockResultSet.getTimestamp(ZMSConsts.DB_COLUMN_EXPIRATION))
        .thenReturn(null)
        .thenReturn(nonExpiredTime)
        .thenReturn(null)
        .thenReturn(expiredTime);
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ROLE))
        .thenReturn("role1")
        .thenReturn("role1")
        .thenReturn("role3")
        .thenReturn("role4");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_RESOURCE))
        .thenReturn("resource1")
        .thenReturn("resource2")
        .thenReturn("resource3")
        .thenReturn("resource4");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ACTION))
        .thenReturn("update");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_EFFECT))
        .thenReturn("ALLOW");
    
    ResourceAccessList resourceAccessList = jdbcConn.listResourceAccess(null, "update", "user");
    List<ResourceAccess> resources = resourceAccessList.getResources();
    assertEquals(3, resources.size());
    
    boolean userUser1 = false;
    boolean userUser2 = false;
    boolean userUser3 = false;
    for (ResourceAccess rsrcAccess : resources) {
        
        switch (rsrcAccess.getPrincipal()) {
            case "user.user1":
                userUser1 = true;
                assertEquals(2, rsrcAccess.getAssertions().size());
                break;
            case "user.user2":
                userUser2 = true;
                assertEquals(2, rsrcAccess.getAssertions().size());
                break;
            case "user.user3":
                userUser3 = true;
                assertEquals(1, rsrcAccess.getAssertions().size());
                break;
        }
    }
    assertTrue(userUser1);
    assertTrue(userUser2);
    assertTrue(userUser3);
    jdbcConn.close();
}