use of com.artezio.arttime.services.integration.spi.UserInfo in project ART-TIME by Artezio.
the class KeycloakClientTest method testLoadUserGroups.
@Test
public void testLoadUserGroups() throws NoSuchFieldException {
keycloakClient = createMockBuilder(KeycloakClient.class).addMockedMethod("listGroups", UserRepresentation.class, RealmResource.class).createMock();
setField(keycloakClient, "settings", settings);
String departmentAttribute = "department";
settings.setKeycloakUserDepartmentAttribute(departmentAttribute);
String username1 = "user1";
String username2 = "user2";
String username3 = "user3";
String group1 = "grp1";
String group2 = "grp2";
String group3 = "grp3";
Map<String, List<String>> user1attributes = new HashMap<>();
Map<String, List<String>> user2attributes = new HashMap<>();
Map<String, List<String>> user3attributes = new HashMap<>();
List<String> user1groups = Arrays.asList(group1, group2);
List<String> user2groups = Arrays.asList(group1, group3);
List<String> user3groups = Arrays.asList(group3);
user1attributes.put(departmentAttribute, user1groups);
user2attributes.put(departmentAttribute, user2groups);
user3attributes.put(departmentAttribute, user3groups);
UserRepresentation user1 = new UserRepresentation();
UserRepresentation user2 = new UserRepresentation();
UserRepresentation user3 = new UserRepresentation();
user1.setUsername(username1);
user2.setUsername(username2);
user3.setUsername(username3);
user1.setAttributes(user1attributes);
user2.setAttributes(user2attributes);
user3.setAttributes(user3attributes);
RealmResource mockRealm = mock(RealmResource.class);
expect(keycloakClient.listGroups(user1, mockRealm)).andReturn(new HashSet<>(user1groups));
expect(keycloakClient.listGroups(user2, mockRealm)).andReturn(new HashSet<>(user2groups));
expect(keycloakClient.listGroups(user3, mockRealm)).andReturn(new HashSet<>(user3groups));
replay(keycloakClient);
Map<String, List<UserInfo>> actual = keycloakClient.loadUserGroups(Arrays.asList(user1, user2, user3), mockRealm);
verify(keycloakClient);
assertTrue(actual.containsKey(group1));
assertTrue(actual.containsKey(group2));
assertTrue(actual.containsKey(group3));
List<UserInfo> userInfosGroup1 = actual.get(group1);
List<UserInfo> userInfosGroup2 = actual.get(group2);
List<UserInfo> userInfosGroup3 = actual.get(group3);
assertTrue(userInfosGroup1.stream().anyMatch(u -> u.getUsername().equals(username1)));
assertTrue(userInfosGroup1.stream().anyMatch(u -> u.getUsername().equals(username2)));
assertFalse(userInfosGroup1.stream().anyMatch(u -> u.getUsername().equals(username3)));
assertTrue(userInfosGroup2.stream().anyMatch(u -> u.getUsername().equals(username1)));
assertFalse(userInfosGroup2.stream().anyMatch(u -> u.getUsername().equals(username2)));
assertFalse(userInfosGroup2.stream().anyMatch(u -> u.getUsername().equals(username3)));
assertFalse(userInfosGroup3.stream().anyMatch(u -> u.getUsername().equals(username1)));
assertTrue(userInfosGroup3.stream().anyMatch(u -> u.getUsername().equals(username2)));
assertTrue(userInfosGroup3.stream().anyMatch(u -> u.getUsername().equals(username3)));
}
use of com.artezio.arttime.services.integration.spi.UserInfo in project ART-TIME by Artezio.
the class KeycloakClientTest method testPopulateCache.
@Test
public void testPopulateCache() {
keycloakClient = createMockBuilder(KeycloakClient.class).addMockedMethod("loadUsers", RealmResource.class).addMockedMethod("loadDepartments", List.class).addMockedMethod("loadUserGroups", List.class, RealmResource.class).addMockedMethod("toUserInfo", List.class).addMockedMethod("getRealm").createMock();
RealmResource mockRealm = createMock(RealmResource.class);
List<UserRepresentation> usersList = new ArrayList<>();
Set<String> departments = new HashSet<>();
expect(keycloakClient.getRealm()).andReturn(mockRealm);
expect(keycloakClient.loadUsers(mockRealm)).andReturn(usersList);
expect(keycloakClient.loadDepartments(usersList)).andReturn(departments);
expect(keycloakClient.loadUserGroups(usersList, mockRealm)).andReturn(Collections.emptyMap());
UserInfo userInfo = new UserInfo("username", null, null, null, null);
expect(keycloakClient.toUserInfo(anyObject(List.class))).andReturn(Arrays.asList(userInfo)).anyTimes();
replay(keycloakClient);
keycloakClient.populateCache();
verify(keycloakClient);
}
use of com.artezio.arttime.services.integration.spi.UserInfo in project ART-TIME by Artezio.
the class LdapAdapterTest 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(ldapClient.listUsers()).andReturn(users);
expect(workdaysCalendarRepository.findDefaultCalendar(anyObject())).andReturn(null).anyTimes();
EasyMock.replay(ldapClient, workdaysCalendarRepository);
List<Employee> actual = ldapAdapter.getTeamByDepartment(department);
verify(ldapClient);
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 testGetTeamByGroupCode.
@Test
public void testGetTeamByGroupCode() {
String code = "code";
UserInfo user1 = new UserInfo("2user", "b", "b", null, null);
UserInfo user2 = new UserInfo("1user", "a", "a", null, null);
List<UserInfo> users = Arrays.asList(user2, user1);
expect(keycloakClient.listUsers(code)).andReturn(users);
expect(workdaysCalendarRepository.findDefaultCalendar(anyObject())).andReturn(null).anyTimes();
replay(keycloakClient, workdaysCalendarRepository);
List<Employee> actual = keycloak.getTeamByGroupCode(code);
verify(keycloakClient);
assertEquals(2, actual.size());
assertEquals(user2.getUsername(), actual.get(0).getUserName());
assertEquals(user1.getUsername(), actual.get(1).getUserName());
}
use of com.artezio.arttime.services.integration.spi.UserInfo in project ART-TIME by Artezio.
the class KeycloakAdapterTest method testFindEmployeesByFullName.
@Test
public void testFindEmployeesByFullName() {
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.findEmployeesByFullName("a_lname");
verify(keycloakClient, workdaysCalendarRepository);
assertFalse(actual.isEmpty());
assertEquals("uname1", actual.get(0).getUserName());
assertEquals("uname3", actual.get(1).getUserName());
}
Aggregations