use of com.artezio.arttime.services.integration.spi.UserInfo in project ART-TIME by Artezio.
the class KeycloakAdapterTest method testGetTeamByDepartment.
@Test
public void testGetTeamByDepartment() {
String department = "dep1";
String dummyDepartment = "someOtherDepartment";
UserInfo user1 = new UserInfo("a_user", "a", "a", null, department);
UserInfo user2 = new UserInfo("b_user", "b", "b", null, dummyDepartment);
UserInfo user3 = new UserInfo("c_user", "c", "c", null, department);
List<UserInfo> users = Arrays.asList(user2, user3, user1);
expect(keycloakClient.listUsers()).andReturn(users);
expect(workdaysCalendarRepository.findDefaultCalendar(anyObject())).andReturn(null).anyTimes();
replay(keycloakClient, workdaysCalendarRepository);
List<Employee> actual = keycloak.getTeamByDepartment(department);
verify(keycloakClient);
assertEquals(2, actual.size());
assertEquals(user1.getUsername(), actual.get(0).getUserName());
assertEquals(user3.getUsername(), actual.get(1).getUserName());
}
use of com.artezio.arttime.services.integration.spi.UserInfo in project ART-TIME by Artezio.
the class KeycloakAdapterTest method testGetEmployees.
@Test
public void testGetEmployees() {
UserInfo userInfo1 = new UserInfo("uname1", "a_fname", "a_lname", "em1", "dep1");
UserInfo userInfo2 = new UserInfo("uname2", "b_fname", "b_lname", "em2", "dep2");
UserInfo userInfo3 = new UserInfo("uname3", "c_fname", "a_lname", "em2", "dep2");
expect(keycloakClient.listUsers()).andReturn(Arrays.asList(userInfo3, userInfo1, userInfo2));
expect(workdaysCalendarRepository.findDefaultCalendar(anyString())).andReturn(null).times(3);
replay(keycloakClient, workdaysCalendarRepository);
List<Employee> actual = keycloak.getEmployees();
verify(keycloakClient, workdaysCalendarRepository);
assertEquals(3, actual.size());
assertEquals("uname1", actual.get(0).getUserName());
assertEquals("uname3", actual.get(1).getUserName());
assertEquals("uname2", actual.get(2).getUserName());
}
use of com.artezio.arttime.services.integration.spi.UserInfo in project ART-TIME by Artezio.
the class LdapClientTest method testListUsers.
@Test
public void testListUsers() throws Exception {
final String userContextDN = "user-cdn";
final String filterExpression = "filter-expr";
final Object[] filterArgs = new Object[] {};
LdapClient.Filter mockFilter = createMock(LdapClient.Filter.class);
expect(mockFilter.getExpression()).andReturn(filterExpression).anyTimes();
expect(mockFilter.getArgs()).andReturn(filterArgs).anyTimes();
SearchControls mockControls = createMock(SearchControls.class);
InitialLdapContext mockContext = createMock(InitialLdapContext.class);
ldapClient = createMockBuilder(LdapClient.class).addMockedMethod("initializeContext", new Class[] {}).addMockedMethod("makeSearchControls").createMock();
settings.setLdapUserContextDN(userContextDN);
setField(ldapClient, "settings", settings);
setAttributeMapping();
NamingEnumeration enumeration = createMock(NamingEnumeration.class);
SearchResult result1 = createMock(SearchResult.class);
SearchResult result2 = createMock(SearchResult.class);
expect(enumeration.hasMore()).andReturn(true).times(2);
expect(enumeration.hasMore()).andReturn(false).once();
expect(enumeration.next()).andReturn(result1).once();
expect(enumeration.next()).andReturn(result2).once();
enumeration.close();
expectLastCall().andVoid();
Employee expectedEmployee1 = new Employee("uname1", "fname1", "lname1", "email1", "dep1");
Employee expectedEmployee2 = new Employee("uname2", "fname2", "lname2", "email2", "dep2");
expect(result1.getAttributes()).andReturn(getAttributesFor(expectedEmployee1));
expect(result2.getAttributes()).andReturn(getAttributesFor(expectedEmployee2));
expect(ldapClient.makeSearchControls()).andReturn(mockControls);
expect(ldapClient.initializeContext()).andReturn(mockContext);
mockContext.close();
expectLastCall().once().andVoid();
expect(mockContext.search(eq(userContextDN), eq(filterExpression), eq(filterArgs), eq(mockControls))).andReturn(enumeration);
replay(ldapClient, mockContext, mockControls, mockFilter, enumeration, result1, result2);
List<UserInfo> actualList = ldapClient.listUsers(mockFilter);
assertEquals(2, actualList.size());
UserInfo actualUser1 = actualList.stream().filter(e -> e.getUsername().equals(expectedEmployee1.getUserName())).findFirst().get();
UserInfo actualUser2 = actualList.stream().filter(e -> e.getUsername().equals(expectedEmployee2.getUserName())).findFirst().get();
assertTrue(isEmployeeFullyEqualToUserInfo(expectedEmployee1, actualUser1));
assertTrue(isEmployeeFullyEqualToUserInfo(expectedEmployee2, actualUser2));
}
use of com.artezio.arttime.services.integration.spi.UserInfo in project ART-TIME by Artezio.
the class LdapClient method listUsers.
protected List<UserInfo> listUsers(Filter filter) {
List<UserInfo> users = new ArrayList<>();
InitialLdapContext ctx = null;
try {
ctx = initializeContext();
SearchControls controls = makeSearchControls();
NamingEnumeration<SearchResult> answer = ctx.search(settings.getLdapUserContextDN(), filter.getExpression(), filter.getArgs(), controls);
while (answer.hasMore()) {
SearchResult sr = answer.next();
Attributes attrs = sr.getAttributes();
UserInfo user = createUserInfo(attrs);
users.add(user);
}
answer.close();
} catch (NamingException ex) {
throw new RuntimeException("Error listing users ", ex);
} finally {
closeContext(ctx);
}
return users;
}
Aggregations