Search in sources :

Example 11 with UserInfo

use of com.artezio.arttime.services.integration.spi.UserInfo in project ART-TIME by Artezio.

the class LdapClientTest method testFindUser_userFilterIsEmpty.

@Test
public void testFindUser_userFilterIsEmpty() throws NoSuchFieldException {
    settings.setLdapUserFilter("");
    UserInfo actual = ldapClient.findUser("uname1");
    assertNull(actual);
}
Also used : UserInfo(com.artezio.arttime.services.integration.spi.UserInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with UserInfo

use of com.artezio.arttime.services.integration.spi.UserInfo in project ART-TIME by Artezio.

the class KeycloakClientTest method testToUserInfo.

@Test
public void testToUserInfo() {
    String username = "username";
    String firstName = "fname";
    String lastName = "lname";
    String email = "email";
    String departmentAttrribute = "department";
    String departmentValue = "dep";
    Map<String, List<String>> attributes = new HashMap<>();
    attributes.put(departmentAttrribute, Arrays.asList(departmentValue));
    UserRepresentation userRepresentation = mock(UserRepresentation.class);
    expect(userRepresentation.getUsername()).andReturn(username);
    expect(userRepresentation.getFirstName()).andReturn(firstName);
    expect(userRepresentation.getLastName()).andReturn(lastName);
    expect(userRepresentation.getEmail()).andReturn(email);
    expect(userRepresentation.getAttributes()).andReturn(attributes).times(2);
    replay(userRepresentation);
    settings.setKeycloakUserDepartmentAttribute(departmentAttrribute);
    UserInfo actual = keycloakClient.toUserInfo(userRepresentation);
    verify(userRepresentation);
    assertEquals(username, actual.getUsername());
    assertEquals(firstName, actual.getFirstName());
    assertEquals(lastName, actual.getLastName());
    assertEquals(email, actual.getEmail());
    assertEquals(departmentValue, actual.getDepartment());
}
Also used : UserInfo(com.artezio.arttime.services.integration.spi.UserInfo) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test)

Example 13 with UserInfo

use of com.artezio.arttime.services.integration.spi.UserInfo in project ART-TIME by Artezio.

the class LdapAdapterTest method testGetEmployees.

@Test
public void testGetEmployees() {
    UserInfo user1 = createUserInfo("b_user");
    UserInfo user2 = createUserInfo("a_user");
    expect(ldapClient.listUsers()).andReturn(Arrays.asList(user2, user1));
    expect(workdaysCalendarRepository.findDefaultCalendar(anyObject())).andReturn(null).anyTimes();
    replay(ldapClient, workdaysCalendarRepository);
    List<Employee> actual = ldapAdapter.getEmployees();
    verify(ldapClient);
    assertEquals(2, actual.size());
    assertEquals(user2.getUsername(), actual.get(0).getUserName());
    assertEquals(user1.getUsername(), actual.get(1).getUserName());
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) UserInfo(com.artezio.arttime.services.integration.spi.UserInfo) Test(org.junit.Test)

Example 14 with UserInfo

use of com.artezio.arttime.services.integration.spi.UserInfo in project ART-TIME by Artezio.

the class KeycloakAdapterTest method testCreateEmployee.

@Test
public void testCreateEmployee() {
    UserInfo userInfo = new UserInfo("username", "firstname", "lastname", "email", "department");
    Employee actual = keycloak.createEmployee(userInfo);
    assertEmployeeEqualsUserInfo(actual, userInfo);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) UserInfo(com.artezio.arttime.services.integration.spi.UserInfo) Test(org.junit.Test)

Example 15 with UserInfo

use of com.artezio.arttime.services.integration.spi.UserInfo in project ART-TIME by Artezio.

the class KeycloakAdapterTest method testFindEmployee.

@Test
public void testFindEmployee() {
    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));
    replay(keycloakClient);
    Employee actual = keycloak.findEmployee("uname2");
    verify(keycloakClient);
    assertNotNull(actual);
    assertEmployeeEqualsUserInfo(actual, userInfo2);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) UserInfo(com.artezio.arttime.services.integration.spi.UserInfo) Test(org.junit.Test)

Aggregations

UserInfo (com.artezio.arttime.services.integration.spi.UserInfo)19 Test (org.junit.Test)18 Employee (com.artezio.arttime.datamodel.Employee)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)3 SearchControls (javax.naming.directory.SearchControls)2 SearchResult (javax.naming.directory.SearchResult)2 InitialLdapContext (javax.naming.ldap.InitialLdapContext)2 RealmResource (org.keycloak.admin.client.resource.RealmResource)2 Setting (com.artezio.arttime.config.Setting)1 Settings (com.artezio.arttime.config.Settings)1 Duration (java.time.Duration)1 java.util (java.util)1 Timer (javax.ejb.Timer)1 TimerConfig (javax.ejb.TimerConfig)1 TimerService (javax.ejb.TimerService)1 NamingEnumeration (javax.naming.NamingEnumeration)1 NamingException (javax.naming.NamingException)1 Attributes (javax.naming.directory.Attributes)1 PrivateAccessor.setField (junitx.util.PrivateAccessor.setField)1