ExtSourcePerun extends ExtSource implements ExtSourceApi { @Override public List<Map<String, String>> getUsersSubjects() { String query = getAttributes().get(UsersManager.USERS_QUERY); setEnviroment(); return convertRichUsersToListOfSubjects(findRichUsers(query)); }  static PerunBlImpl setPerunBlImpl(PerunBlImpl perun); @Override List<Map<String,String>> findSubjectsLogins(String searchString); @Override List<Map<String,String>> findSubjectsLogins(String searchString, int maxResulsts); @Override List<Map<String,String>> findSubjects(String searchString); @Override List<Map<String,String>> findSubjects(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); static final Pattern attributePattern; }
@Test public void getUsersSubjectsTest() throws Exception { System.out.println("getUsersSubjectsTest"); AttributeDefinition attributeDefinition = new AttributeDefinition(); attributeDefinition.setFriendlyName("firstName"); attributeDefinition.setNamespace(AttributesManager.NS_USER_ATTR_DEF); attributeDefinition.setType(String.class.getName()); Attribute attribute = new Attribute(attributeDefinition, "metodej"); ExtSource extSource = new ExtSource(); extSource.setName("extSourceNameForLogin"); UserExtSource userExtSource = new UserExtSource(); userExtSource.setLogin("extSourceNameForLogin"); userExtSource.setExtSource(extSource); RichUser richUser = new RichUser(new User(), Collections.singletonList(userExtSource), Collections.singletonList(attribute)); List<RichUser> richUserList = new ArrayList<>(); richUserList.add(richUser); JsonDeserializer deserializer = mock(JsonDeserializer.class); doReturn(deserializer).when(extSourcePerun).call("usersManager", "findRichUsers", "searchString=query"); doReturn(richUserList).when(deserializer).readList(RichUser.class); Map<String, String> mapOfAttributes = new HashMap<>(); mapOfAttributes.put("usersQuery", "query"); mapOfAttributes.put("perunUrl", "perunUrl"); mapOfAttributes.put("username", "username"); mapOfAttributes.put("password", "password"); mapOfAttributes.put("extSourceNameForLogin", "extSourceNameForLogin"); mapOfAttributes.put("xmlMapping", "firstName={urn:perun:user:attribute-def:def:firstName},\nlogin={login}"); doReturn(mapOfAttributes).when(extSourcePerun).getAttributes(); List<Map<String, String>> expectedSubjects = new ArrayList<>(); Map<String, String> subject = new HashMap<>(); subject.put("login", "extSourceNameForLogin"); subject.put("firstName", "metodej"); expectedSubjects.add(subject); List<Map<String, String>> actualSubjects = extSourcePerun.getUsersSubjects(); assertEquals("subjects should be same", expectedSubjects, actualSubjects); }