// so using "cn" for this test
@Test
public void testSortByMultiValuedAttribute() throws Exception
{
sk.setAttributeTypeDesc( "cn" );
SearchCursor cursor = con.search( req );
List<String> expectedOrder = new ArrayList<String>();
expectedOrder.add( "uid=user6,ou=parent,ou=system" );
expectedOrder.add( "uid=user0,ou=parent,ou=system" );
expectedOrder.add( "uid=user1,ou=parent,ou=system" );
expectedOrder.add( "uid=person3,ou=parent,ou=system" );
expectedOrder.add( "uid=user2,ou=children,ou=parent,ou=system" );
expectedOrder.add( "uid=user3,ou=children,ou=parent,ou=system" );
expectedOrder.add( "uid=user4,ou=grandchildren,ou=children,ou=parent,ou=system" );
expectedOrder.add( "uid=user5,ou=grandchildren,ou=children,ou=parent,ou=system" );
expectedOrder.add( "uid=user7,ou=parent,ou=system" );
expectedOrder.add( "uid=person1,ou=parent,ou=system" );
expectedOrder.add( "uid=person2,ou=parent,ou=system" );
int expectedCount = expectedOrder.size();
List<String> actualOrder = new ArrayList<String>();
while ( cursor.next() )
{
SearchResultEntry se = ( SearchResultEntry ) cursor.get();
Entry entry = se.getEntry();
actualOrder.add( entry.getDn().getName() );
}
cursor.close();
// remove the LAST 3 entries present in the actualOrder list, they exist on top cause they don't have "sn" attribute
// NOTE: there is no guaranteed order for these LAST 3 entries
actualOrder.remove( actualOrder.size() - 1 );
actualOrder.remove( actualOrder.size() - 1 );
actualOrder.remove( actualOrder.size() - 1 );
assertEquals( expectedCount, actualOrder.size() );
for ( int i = 0; i < expectedOrder.size(); i++ )
{
assertEquals( expectedOrder.get( i ), actualOrder.get( i ) );
}
// check reverse order
actualOrder.clear();
sk.setReverseOrder( true );
cursor = con.search( req );
while ( cursor.next() )
{
SearchResultEntry se = ( SearchResultEntry ) cursor.get();
Entry entry = se.getEntry();
actualOrder.add( entry.getDn().getName() );
}
cursor.close();
// remove the FIRST 3 entries present in the actualOrder list, they exist on top cause they don't have "sn" attribute
// NOTE: there is no guaranteed order for these FIRST 3 entries
actualOrder.remove( 0 );
actualOrder.remove( 0 );