@Test public void findUsersPaged_lastUserFallsOnPageBoundary() throws Exception { List<LdapUser> pageOne = new ArrayList<>(); pageOne.add(buildUser("jgarcia")); pageOne.add(buildUser("bweir")); pageOne.add(buildUser("plesh")); List<LdapUser> pageTwo = new ArrayList<>(); pageTwo.add(buildUser("plesh")); pageTwo.add(buildUser("bkreutzmann")); pageTwo.add(buildUser("rmckernan")); syncConfig.setSyncPageSize(3); expect(mockLdapTemplate.search( eq(syncConfig.getUserSearchBase()), eq(syncConfig.getAllUsersFilter()), anyObject(SearchControls.class), anyObject(AcmUserContextMapper.class), anyObject(AggregateDirContextProcessor.class))).andReturn(pageOne); expect(mockLdapTemplate.search( eq(syncConfig.getUserSearchBase()), eq(String.format(syncConfig.getAllUsersPageFilter(), pageOne.get(pageOne.size() - 1).getUserId())), anyObject(SearchControls.class), anyObject(AcmUserContextMapper.class), anyObject(AggregateDirContextProcessor.class))).andReturn(pageTwo); expect(mockLdapTemplate.search( eq(syncConfig.getUserSearchBase()), eq(String.format(syncConfig.getAllUsersPageFilter(), pageTwo.get(pageTwo.size() - 1).getUserId())), anyObject(SearchControls.class), anyObject(AcmUserContextMapper.class), anyObject(AggregateDirContextProcessor.class))).andReturn(new ArrayList<>()); replayAll(); List<LdapUser> found = unit.findUsersPaged(mockLdapTemplate, syncConfig, Optional.ofNullable(null)); verifyAll(); assertEquals(pageOne.size() + pageTwo.size() - 1, found.size()); assertTrue(found.stream().anyMatch(u -> u.getUserId().equals("jgarcia"))); assertTrue(found.stream().anyMatch(u -> u.getUserId().equals("bweir"))); assertTrue(found.stream().anyMatch(u -> u.getUserId().equals("plesh"))); assertTrue(found.stream().anyMatch(u -> u.getUserId().equals("bkreutzmann"))); assertTrue(found.stream().anyMatch(u -> u.getUserId().equals("rmckernan"))); }
@Override public List<LdapUser> findUsersPaged(LdapTemplate template, AcmLdapSyncConfig syncConfig, Optional<String> ldapLastSyncDate) { return findUsers(template, syncConfig, syncConfig.getUserSyncAttributes(), ldapLastSyncDate); }
CustomPagedLdapDao implements SpringLdapDao { @Override public List<LdapUser> findUsersPaged(LdapTemplate template, AcmLdapSyncConfig syncConfig, Optional<String> ldapLastSyncDate) { return findUsers(template, syncConfig, syncConfig.getUserSyncAttributes(), ldapLastSyncDate); } }
CustomPagedLdapDao implements SpringLdapDao { @Override public List<LdapUser> findUsersPaged(LdapTemplate template, AcmLdapSyncConfig syncConfig, Optional<String> ldapLastSyncDate) { return findUsers(template, syncConfig, syncConfig.getUserSyncAttributes(), ldapLastSyncDate); }  }
CustomPagedLdapDao implements SpringLdapDao { @Override public List<LdapUser> findUsersPaged(LdapTemplate template, AcmLdapSyncConfig syncConfig, Optional<String> ldapLastSyncDate) { return findUsers(template, syncConfig, syncConfig.getUserSyncAttributes(), ldapLastSyncDate); }  @Override List<LdapUser> findUsersPaged(LdapTemplate template, AcmLdapSyncConfig syncConfig, Optional<String> ldapLastSyncDate); List<LdapUser> findUsers(LdapTemplate template, AcmLdapSyncConfig syncConfig,
            String[] attributes, Optional<String> ldapLastSyncDate); @Override List<LdapGroup> findGroupsPaged(LdapTemplate template, AcmLdapSyncConfig config, Optional<String> ldapLastSyncDate); }
CustomPagedLdapDao implements SpringLdapDao { @Override public List<LdapUser> findUsersPaged(LdapTemplate template, AcmLdapSyncConfig syncConfig, Optional<String> ldapLastSyncDate) { return findUsers(template, syncConfig, syncConfig.getUserSyncAttributes(), ldapLastSyncDate); }  @Override List<LdapUser> findUsersPaged(LdapTemplate template, AcmLdapSyncConfig syncConfig, Optional<String> ldapLastSyncDate); List<LdapUser> findUsers(LdapTemplate template, AcmLdapSyncConfig syncConfig,
            String[] attributes, Optional<String> ldapLastSyncDate); @Override List<LdapGroup> findGroupsPaged(LdapTemplate template, AcmLdapSyncConfig config, Optional<String> ldapLastSyncDate);  }