ExtSourceLdap extends ExtSource implements ExtSourceApi { @Override public List<Map<String, String>> getUsersSubjects() { String filter = getAttributes().get(UsersManager.USERS_QUERY); String base = getAttributes().get("base"); if (base == null) { throw new InternalErrorException("base attributes is required"); } return querySource(filter, base, 0); }  static PerunBlImpl setPerunBlImpl(PerunBlImpl perun); @Override List<Map<String,String>> findSubjectsLogins(String searchString); @Override List<Map<String,String>> findSubjectsLogins(String searchString, int maxResults); @Override Map<String, String> getSubjectByLogin(String login); @Override List<Map<String, String>> getGroupSubjects(Map<String, String> attributes); @Override List<Map<String, String>> getUsersSubjects(); @Override void close(); @Override List<Map<String, String>> getSubjectGroups(Map<String, String> attributes); @Override List<Map<String, String>> findSubjects(String searchString); @Override List<Map<String, String>> findSubjects(String searchString, int maxResults);  }
@Test public void getUsersSubjectsTest() throws Exception { System.out.println("getUsersSubjectsTest"); String base = "cn=firstName,dc=dc"; String usersQuery = "dc=cz"; Map<String, String> mapOfAttributes = new HashMap<>(); mapOfAttributes.put("usersQuery", usersQuery); mapOfAttributes.put("base", base); doReturn(mapOfAttributes).when(extSourceLdap).getAttributes(); DirContext dirContext = mock(DirContext.class); doReturn(dirContext).when(extSourceLdap).getContext(); Attribute attribute = new BasicAttribute("firstName", "josef"); Attribute attribute2 = new BasicAttribute("dc", "cz"); Attributes attributes = new BasicAttributes(); attributes.put(attribute); attributes.put(attribute2); NamingEnumeration<SearchResult> namingEnumeration = mock(NamingEnumeration.class); doReturn(namingEnumeration).when(dirContext).search(anyString(), anyString(), any()); doReturn(true,false).when(namingEnumeration).hasMore(); SearchResult searchResult = new SearchResult("name", namingEnumeration, attributes); doReturn(searchResult).when(namingEnumeration).next(); List<Map<String, String>> expectedSubjects = new ArrayList<>(); Map<String, String> subject = new HashMap<>(); subject.put("cn", "josef"); subject.put("dc", "cz"); expectedSubjects.add(subject); List<Map<String, String>> actualSubjects = extSourceLdap.getUsersSubjects(); assertEquals("subjects should be same", expectedSubjects, actualSubjects); }