/** * Creates a new async search listener. * * @param request ldap search request */ public AsyncSearchListener(final SearchRequest request) { searchRequest = request; searchResult = new SearchResult(searchRequest.getSortBehavior()); }
/** * Creates a new async search listener. * * @param request ldap search request */ public AsyncSearchListener(final SearchRequest request) { searchRequest = request; searchResult = new SearchResult(searchRequest.getSortBehavior()); }
/** * Creates a new async search listener. * * @param request ldap search request */ public AsyncSearchListener(final SearchRequest request) { searchRequest = request; searchResult = new SearchResult(searchRequest.getSortBehavior()); }
/** * Returns a portion of this result between the specified fromIndex, inclusive, and toIndex, exclusive. If fromIndex * and toIndex are equal, the return result is empty. The result of this method is undefined for unordered results. * * @param fromIndex low endpoint of the search result (inclusive) * @param toIndex high endpoint of the search result (exclusive) * * @return portion of this search result * * @throws IndexOutOfBoundsException for illegal index values */ public SearchResult subResult(final int fromIndex, final int toIndex) { if (fromIndex < 0 || toIndex > resultEntries.size() || fromIndex > toIndex) { throw new IndexOutOfBoundsException("Illegal index value"); } final SearchResult result = new SearchResult(getSortBehavior()); if (resultEntries.isEmpty() || fromIndex == toIndex) { return result; } int i = 0; for (Map.Entry<String, LdapEntry> e : resultEntries.entrySet()) { if (i >= fromIndex && i < toIndex) { result.addEntry(e.getValue()); } i++; } return result; }
/** * Returns a portion of this result between the specified fromIndex, inclusive, and toIndex, exclusive. If fromIndex * and toIndex are equal, the return result is empty. The result of this method is undefined for unordered results. * * @param fromIndex low endpoint of the search result (inclusive) * @param toIndex high endpoint of the search result (exclusive) * * @return portion of this search result * * @throws IndexOutOfBoundsException for illegal index values */ public SearchResult subResult(final int fromIndex, final int toIndex) { if (fromIndex < 0 || toIndex > resultEntries.size() || fromIndex > toIndex) { throw new IndexOutOfBoundsException("Illegal index value"); } final SearchResult result = new SearchResult(getSortBehavior()); if (resultEntries.isEmpty() || fromIndex == toIndex) { return result; } int i = 0; for (Map.Entry<String, LdapEntry> e : resultEntries.entrySet()) { if (i >= fromIndex && i < toIndex) { result.addEntry(e.getValue()); } i++; } return result; }
/** * Returns a portion of this result between the specified fromIndex, inclusive, and toIndex, exclusive. If fromIndex * and toIndex are equal, the return result is empty. The result of this method is undefined for unordered results. * * @param fromIndex low endpoint of the search result (inclusive) * @param toIndex high endpoint of the search result (exclusive) * * @return portion of this search result * * @throws IndexOutOfBoundsException for illegal index values */ public SearchResult subResult(final int fromIndex, final int toIndex) { if (fromIndex < 0 || toIndex > resultEntries.size() || fromIndex > toIndex) { throw new IndexOutOfBoundsException("Illegal index value"); } final SearchResult result = new SearchResult(getSortBehavior()); if (resultEntries.isEmpty() || fromIndex == toIndex) { return result; } int i = 0; for (Map.Entry<String, LdapEntry> e : resultEntries.entrySet()) { if (i >= fromIndex && i < toIndex) { result.addEntry(e.getValue()); } i++; } return result; }
/** * Creates a search result that corresponds to the supplied DSML document. * * @param doc DSML to parse * * @return search result */ protected SearchResult createSearchResult(final Document doc) { final SearchResult result = new SearchResult(sortBehavior); if (doc != null && doc.hasChildNodes()) { final NodeList nodes = doc.getElementsByTagName("dsml:entry"); for (int i = 0; i < nodes.getLength(); i++) { final LdapEntry le = createLdapEntry((Element) nodes.item(i)); result.addEntry(le); } } return result; }
/** * Creates a search result that corresponds to the supplied DSML document. * * @param doc DSML to parse * * @return search result */ protected SearchResult createSearchResult(final Document doc) { final SearchResult result = new SearchResult(sortBehavior); if (doc != null && doc.hasChildNodes()) { final NodeList nodes = doc.getElementsByTagName("dsml:entry"); for (int i = 0; i < nodes.getLength(); i++) { final LdapEntry le = createLdapEntry((Element) nodes.item(i)); result.addEntry(le); } } return result; }
/** * Creates a search result that corresponds to the supplied DSML document. * * @param doc DSML to parse * * @return search result */ protected SearchResult createSearchResult(final Document doc) { final SearchResult result = new SearchResult(sortBehavior); if (doc != null && doc.hasChildNodes()) { final NodeList nodes = doc.getElementsByTagName("dsml:entry"); for (int i = 0; i < nodes.getLength(); i++) { final LdapEntry le = createLdapEntry((Element) nodes.item(i)); result.addEntry(le); } } return result; }
@Override public SearchResult deserialize(final JsonElement json, final Type type, final JsonDeserializationContext context) throws JsonParseException { final SearchResult result = new SearchResult(sortBehavior); final JsonArray jsonResult = json.getAsJsonArray(); for (JsonElement jsonEntry : jsonResult) { final LdapEntry entry = new LdapEntry(sortBehavior); for (Map.Entry<String, JsonElement> jsonAttr : jsonEntry.getAsJsonObject().entrySet()) { if ("dn".equals(jsonAttr.getKey())) { entry.setDn(jsonAttr.getValue().getAsString()); } else { final LdapAttribute attr = new LdapAttribute(sortBehavior); attr.setName(jsonAttr.getKey()); jsonAttr.getValue().getAsJsonArray().forEach(i -> attr.addStringValue(i.getAsString())); entry.addAttribute(attr); } } result.addEntry(entry); } return result; } }
@Override public SearchResult deserialize(final JsonElement json, final Type type, final JsonDeserializationContext context) throws JsonParseException { final SearchResult result = new SearchResult(sortBehavior); final JsonArray jsonResult = json.getAsJsonArray(); for (JsonElement jsonEntry : jsonResult) { final LdapEntry entry = new LdapEntry(sortBehavior); for (Map.Entry<String, JsonElement> jsonAttr : jsonEntry.getAsJsonObject().entrySet()) { if ("dn".equals(jsonAttr.getKey())) { entry.setDn(jsonAttr.getValue().getAsString()); } else { final LdapAttribute attr = new LdapAttribute(sortBehavior); attr.setName(jsonAttr.getKey()); jsonAttr.getValue().getAsJsonArray().forEach(i -> attr.addStringValue(i.getAsString())); entry.addAttribute(attr); } } result.addEntry(entry); } return result; } }
/** @throws Exception On test failure. */ @Test(groups = {"cache"}, threadPoolSize = 5, invocationCount = 100, timeOut = 60000) public void get() throws Exception { SearchResult result = cache.get(new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=3"))); AssertJUnit.assertEquals(new SearchResult(new LdapEntry("uid=3,ou=test,dc=ldaptive,dc=org")), result); result = cache.get(new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=4"))); AssertJUnit.assertEquals(new SearchResult(new LdapEntry("uid=4,ou=test,dc=ldaptive,dc=org")), result); result = cache.get(new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=5"))); AssertJUnit.assertEquals(new SearchResult(new LdapEntry("uid=5,ou=test,dc=ldaptive,dc=org")), result); }
/** * Tests ordered sort behavior. * * @param entry1 ldap entry * @param entry2 ldap entry */ @Test(groups = {"bean"}, dataProvider = "entries") public void orderedSortBehavior(final LdapEntry entry1, final LdapEntry entry2) { final SearchResult sr = new SearchResult(SortBehavior.ORDERED); AssertJUnit.assertEquals(SortBehavior.ORDERED, sr.getSortBehavior()); sr.addEntry(entry2, entry1); final LdapEntry[] entries = sr.getEntries().toArray(new LdapEntry[2]); AssertJUnit.assertEquals(entry2, entries[0]); AssertJUnit.assertEquals(entry1, entries[1]); sr.clear(); AssertJUnit.assertEquals(0, sr.size()); }
/** * Tests sorted sort behavior. * * @param entry1 ldap entry * @param entry2 ldap entry */ @Test(groups = {"bean"}, dataProvider = "entries") public void sortedSortBehavior(final LdapEntry entry1, final LdapEntry entry2) { final SearchResult sr = new SearchResult(SortBehavior.SORTED); AssertJUnit.assertEquals(SortBehavior.SORTED, sr.getSortBehavior()); sr.addEntry(entry2, entry1); final LdapEntry[] entries = sr.getEntries().toArray(new LdapEntry[2]); AssertJUnit.assertEquals(entry1, entries[0]); AssertJUnit.assertEquals(entry2, entries[1]); sr.clear(); AssertJUnit.assertEquals(0, sr.size()); }
/** Tests default sort behavior. */ @Test(groups = {"bean"}) public void defaultSortBehavior() { final SearchResult sr = new SearchResult(); AssertJUnit.assertEquals(SortBehavior.getDefaultSortBehavior(), sr.getSortBehavior()); AssertJUnit.assertEquals(0, sr.size()); AssertJUnit.assertNull(sr.getEntry()); sr.clear(); AssertJUnit.assertEquals(0, sr.size()); }
/** * Tests create with a collection. * * @param entry1 ldap entry * @param entry2 ldap entry */ @Test(groups = {"bean"}, dataProvider = "entries") public void createCollection(final LdapEntry entry1, final LdapEntry entry2) { final Set<LdapEntry> s = new HashSet<>(); s.add(entry1); final SearchResult sr = new SearchResult(s); sr.addEntry(entry2); AssertJUnit.assertEquals(entry1, sr.getEntry("UID=1")); AssertJUnit.assertEquals(entry2, sr.getEntry("uid=2")); AssertJUnit.assertEquals(2, sr.getEntryDns().length); AssertJUnit.assertEquals(2, sr.size()); AssertJUnit.assertEquals(sr, new SearchResult(entry1, entry2)); sr.removeEntry("UID=1"); AssertJUnit.assertEquals(1, sr.size()); sr.clear(); AssertJUnit.assertEquals(0, sr.size()); }
/** * Tests create with one entry. * * @param entry1 ldap entry * @param entry2 ldap entry */ @Test(groups = {"bean"}, dataProvider = "entries") public void createOne(final LdapEntry entry1, final LdapEntry entry2) { final SearchResult sr = new SearchResult(entry1); AssertJUnit.assertEquals(entry1, sr.getEntry()); AssertJUnit.assertEquals(entry1, sr.getEntry("uid=1")); AssertJUnit.assertEquals(entry1, sr.getEntry("UID=1")); AssertJUnit.assertEquals("uid=1", sr.getEntryDns()[0]); AssertJUnit.assertEquals(1, sr.size()); AssertJUnit.assertEquals(sr, new SearchResult(entry1)); sr.clear(); AssertJUnit.assertEquals(0, sr.size()); }
/** * Tests create with two entries. * * @param entry1 ldap entry * @param entry2 ldap entry */ @Test(groups = {"bean"}, dataProvider = "entries") public void createTwo(final LdapEntry entry1, final LdapEntry entry2) { final SearchResult sr = new SearchResult(entry2, entry1); AssertJUnit.assertEquals(entry1, sr.getEntry("uid=1")); AssertJUnit.assertEquals(entry2, sr.getEntry("UID=2")); AssertJUnit.assertEquals(2, sr.getEntryDns().length); AssertJUnit.assertEquals(2, sr.size()); AssertJUnit.assertEquals(sr, new SearchResult(entry1, entry2)); sr.removeEntry(entry2); AssertJUnit.assertEquals(1, sr.size()); sr.clear(); AssertJUnit.assertEquals(0, sr.size()); }
/** @throws Exception On test failure. */ @Test(groups = {"cache"}) public void put() throws Exception { AssertJUnit.assertEquals(5, cache.size()); cache.put( new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=%s", new Object[] {"101"})), new SearchResult(new LdapEntry("uid=101,ou=test,dc=ldaptive,dc=org"))); cache.put( new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=102")), new SearchResult(new LdapEntry("uid=102,ou=test,dc=ldaptive,dc=org"))); AssertJUnit.assertEquals(5, cache.size()); SearchResult result = cache.get( new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=%s", new Object[] {"101"}))); AssertJUnit.assertEquals(new SearchResult(new LdapEntry("uid=101,ou=test,dc=ldaptive,dc=org")), result); result = cache.get(new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=102"))); AssertJUnit.assertEquals(new SearchResult(new LdapEntry("uid=102,ou=test,dc=ldaptive,dc=org")), result); AssertJUnit.assertNull(cache.get(new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=1")))); }
/** Fills the cache with data. */ private void fillCache() { cache.put( new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=1")), new SearchResult(new LdapEntry("uid=1,ou=test,dc=ldaptive,dc=org"))); cache.put( new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=2")), new SearchResult(new LdapEntry("uid=2,ou=test,dc=ldaptive,dc=org"))); cache.put( new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=3")), new SearchResult(new LdapEntry("uid=3,ou=test,dc=ldaptive,dc=org"))); cache.put( new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=4")), new SearchResult(new LdapEntry("uid=4,ou=test,dc=ldaptive,dc=org"))); cache.put( new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=5")), new SearchResult(new LdapEntry("uid=5,ou=test,dc=ldaptive,dc=org"))); // ensure uid=1 and uid=2 get evicted first cache.get(new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=3"))); cache.get(new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=4"))); cache.get(new SearchRequest("dc=ldaptive,dc=org", new SearchFilter("uid=5"))); } }