Search in sources :

Example 6 with UserInfo

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

the class KeycloakAdapterTest method testFindEmployee_noMatch.

@Test
public void testFindEmployee_noMatch() {
    UserInfo userInfo1 = new UserInfo("uname1", "a_fname", "a_lname", "em1", "dep1");
    UserInfo userInfo3 = new UserInfo("uname3", "c_fname", "a_lname", "em2", "dep2");
    expect(keycloakClient.listUsers()).andReturn(Arrays.asList(userInfo3, userInfo1));
    replay(keycloakClient);
    Employee actual = keycloak.findEmployee("uname2");
    verify(keycloakClient);
    assertNull(actual);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) UserInfo(com.artezio.arttime.services.integration.spi.UserInfo) Test(org.junit.Test)

Example 7 with UserInfo

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

the class LdapClientTest method testListUsersByGroupCode.

@Test
public void testListUsersByGroupCode() throws NoSuchFieldException {
    ldapClient = createMockBuilder(LdapClient.class).addMockedMethod("listUsers", LdapClient.Filter.class).createMock();
    setField(ldapClient, "settings", settings);
    String codes = "code1";
    UserInfo memberOfTeam1 = new UserInfo("uname1", null, null, null, null);
    UserInfo memberOfTeam1and2 = new UserInfo("uname1", null, null, null, null);
    List<UserInfo> team1users = Arrays.asList(memberOfTeam1, memberOfTeam1and2);
    expect(ldapClient.listUsers(anyObject(LdapClient.Filter.class))).andAnswer(() -> {
        LdapClient.Filter filter = (LdapClient.Filter) EasyMock.getCurrentArguments()[0];
        switch((String) filter.getArgs()[0]) {
            case "code1":
                return team1users;
            default:
                return null;
        }
    }).anyTimes();
    replay(ldapClient);
    List<UserInfo> actual = ldapClient.listUsers(codes);
    assertEquals(2, actual.size());
    assertTrue(actual.contains(memberOfTeam1));
    assertTrue(actual.contains(memberOfTeam1and2));
}
Also used : UserInfo(com.artezio.arttime.services.integration.spi.UserInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with UserInfo

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

the class LdapClientTest method testFindUser_userFilterIsNull.

@Test
public void testFindUser_userFilterIsNull() throws NoSuchFieldException {
    settings.setLdapUserFilter(null);
    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 9 with UserInfo

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

the class LdapClientTest method testFindEmployee.

@Test
public void testFindEmployee() throws NoSuchFieldException {
    ldapClient = createMockBuilder(LdapClient.class).addMockedMethod("listUsers", LdapClient.Filter.class).createMock();
    settings.setLdapUserFilter("LDAP-FILTER");
    setField(ldapClient, "settings", settings);
    List<UserInfo> users = Arrays.asList(new UserInfo("uname1", "firstname", "lastname", "email", "department"));
    expect(ldapClient.listUsers(anyObject(LdapClient.Filter.class))).andReturn(users).anyTimes();
    replay(ldapClient);
    UserInfo actual = ldapClient.findUser("uname1");
    assertNotNull(actual);
    assertEquals("uname1", actual.getUsername());
}
Also used : UserInfo(com.artezio.arttime.services.integration.spi.UserInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with UserInfo

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

the class LdapClientTest method testFindUser_noResults.

@Test
public void testFindUser_noResults() throws NoSuchFieldException {
    ldapClient = createMockBuilder(LdapClient.class).addMockedMethod("listUsers", LdapClient.Filter.class).createMock();
    setField(ldapClient, "settings", settings);
    settings.setLdapUserFilter("LDAP-FILTER");
    expect(ldapClient.listUsers(anyObject(LdapClient.Filter.class))).andReturn(Collections.emptyList()).anyTimes();
    replay(ldapClient);
    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)

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