forked from sakaiproject/sakai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SAK-32302 Allow entitybroker user aid searches. (sakaiproject#4057)
When looking up a user allow searching by AID as well as EID and ID. If a deployment isn’t
- Loading branch information
Showing
2 changed files
with
97 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...rc/test/org/sakaiproject/entitybroker/providers/UserEntityProviderGetUserByIdEidTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.sakaiproject.entitybroker.providers; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
import org.sakaiproject.entitybroker.DeveloperHelperService; | ||
import org.sakaiproject.user.api.User; | ||
import org.sakaiproject.user.api.UserDirectoryService; | ||
import org.sakaiproject.user.api.UserNotDefinedException; | ||
|
||
public class UserEntityProviderGetUserByIdEidTest { | ||
|
||
private UserEntityProvider provider; | ||
private UserDirectoryService uds; | ||
private DeveloperHelperService dhs; | ||
private User user; | ||
|
||
@Before | ||
public void setUp() { | ||
provider = new UserEntityProvider(); | ||
uds = Mockito.mock(UserDirectoryService.class); | ||
dhs = Mockito.mock(DeveloperHelperService.class); | ||
user = Mockito.mock(User.class); | ||
|
||
provider.setUserDirectoryService(uds); | ||
provider.setDeveloperHelperService(dhs); | ||
} | ||
|
||
@Test | ||
public void testNotFound() throws UserNotDefinedException { | ||
Mockito.when(uds.getUserByAid(Mockito.anyString())).thenThrow(UserNotDefinedException.class); | ||
Mockito.when(uds.getUser(Mockito.anyString())).thenThrow(UserNotDefinedException.class); | ||
Mockito.when(dhs.getConfigurationSetting("user.explicit.id.only", false)).thenReturn(false); | ||
|
||
Assert.assertNull(provider.getUserByIdEid("anything")); | ||
} | ||
|
||
@Test | ||
public void testNotFoundId() throws UserNotDefinedException { | ||
Mockito.when(uds.getUser(Mockito.anyString())).thenThrow(UserNotDefinedException.class); | ||
Mockito.when(dhs.getConfigurationSetting("user.explicit.id.only", false)).thenReturn(false); | ||
|
||
Assert.assertNull(provider.getUserByIdEid("id=1234")); | ||
Mockito.verify(uds, Mockito.never()).getUserByEid(Mockito.anyString()); | ||
} | ||
|
||
@Test | ||
public void testEidFallthrough() throws UserNotDefinedException { | ||
Mockito.when(uds.getUserByAid(Mockito.anyString())).thenThrow(UserNotDefinedException.class); | ||
Mockito.when(uds.getUser("1234")).thenReturn(user); | ||
Mockito.when(dhs.getConfigurationSetting("user.explicit.id.only", false)).thenReturn(false); | ||
|
||
Assert.assertEquals(user, provider.getUserByIdEid("1234")); | ||
} | ||
|
||
@Test | ||
public void testEidFallthroughId() throws UserNotDefinedException { | ||
Mockito.when(uds.getUserByAid(Mockito.anyString())).thenThrow(UserNotDefinedException.class); | ||
Mockito.when(uds.getUser("1234")).thenReturn(user); | ||
Mockito.when(dhs.getConfigurationSetting("user.explicit.id.only", false)).thenReturn(false); | ||
|
||
Assert.assertEquals(user, provider.getUserByIdEid("id=1234")); | ||
} | ||
|
||
@Test | ||
public void testEidFound() throws UserNotDefinedException { | ||
Mockito.when(uds.getUserByAid("1234")).thenReturn(user); | ||
Mockito.when(uds.getUser(Mockito.anyString())).thenThrow(UserNotDefinedException.class); | ||
Mockito.when(dhs.getConfigurationSetting("user.explicit.id.only", false)).thenReturn(false); | ||
|
||
Assert.assertEquals(user, provider.getUserByIdEid("1234")); | ||
} | ||
|
||
@Test | ||
public void testEidOnly() throws UserNotDefinedException { | ||
Mockito.when(uds.getUserByAid("1234")).thenThrow(UserNotDefinedException.class); | ||
Mockito.when(uds.getUser(Mockito.anyString())).thenReturn(user); | ||
Mockito.when(dhs.getConfigurationSetting("user.explicit.id.only", false)).thenReturn(true); | ||
|
||
// Check we don't fallthrough to searching by ID. | ||
// This seems strange as the original bug was that EID searching was slow so why you would want | ||
// to stop ID searching I'm not sure. | ||
Assert.assertNull(provider.getUserByIdEid("1234")); | ||
} | ||
} |