Commit 110a1a5b authored by Jeff Burke's avatar Jeff Burke
Browse files

s1890: unit test fixes

parent 6b3dc505
...@@ -71,11 +71,16 @@ package ca.nrc.cadc.ac.server.web.groups; ...@@ -71,11 +71,16 @@ package ca.nrc.cadc.ac.server.web.groups;
import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.createMock;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.net.URI;
import java.security.Principal; import java.security.Principal;
import java.util.UUID;
import javax.security.auth.x500.X500Principal; import javax.security.auth.x500.X500Principal;
import ca.nrc.cadc.ac.AC;
import ca.nrc.cadc.ac.InternalID;
import ca.nrc.cadc.auth.HttpPrincipal; import ca.nrc.cadc.auth.HttpPrincipal;
import ca.nrc.cadc.util.ObjectUtil;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.easymock.EasyMock; import org.easymock.EasyMock;
...@@ -111,11 +116,14 @@ public class RemoveUserMemberActionTest ...@@ -111,11 +116,14 @@ public class RemoveUserMemberActionTest
{ {
try try
{ {
User user = new User();
InternalID internalID = new InternalID(new URI(AC.USER_URI + "?" + UUID.randomUUID()));
ObjectUtil.setField(user, internalID, "id");
String userID = "cn=foo,c=ca"; String userID = "cn=foo,c=ca";
String userIDType = IdentityType.X500.getValue(); String userIDType = IdentityType.X500.getValue();
Principal userPrincipal = AuthenticationUtil.createPrincipal(userID, userIDType); Principal x500Principal = AuthenticationUtil.createPrincipal(userID, userIDType);
User user = new User(); user.getIdentities().add(x500Principal);
user.getIdentities().add(userPrincipal);
Group group = new Group("group"); Group group = new Group("group");
User member = new User(); User member = new User();
...@@ -126,7 +134,7 @@ public class RemoveUserMemberActionTest ...@@ -126,7 +134,7 @@ public class RemoveUserMemberActionTest
EasyMock.expect(mockGroupPersistence.getGroup("group")).andReturn(group); EasyMock.expect(mockGroupPersistence.getGroup("group")).andReturn(group);
final UserPersistence mockUserPersistence = EasyMock.createMock(UserPersistence.class); final UserPersistence mockUserPersistence = EasyMock.createMock(UserPersistence.class);
EasyMock.expect(mockUserPersistence.getUser(userPrincipal)).andReturn(user); EasyMock.expect(mockUserPersistence.getAugmentedUser(x500Principal)).andReturn(user);
EasyMock.replay(mockGroupPersistence, mockUserPersistence); EasyMock.replay(mockGroupPersistence, mockUserPersistence);
...@@ -160,10 +168,13 @@ public class RemoveUserMemberActionTest ...@@ -160,10 +168,13 @@ public class RemoveUserMemberActionTest
{ {
try try
{ {
User user = new User();
InternalID internalID = new InternalID(new URI(AC.USER_URI + "?" + UUID.randomUUID()));
ObjectUtil.setField(user, internalID, "id");
String userID = "cn=foo,c=ca"; String userID = "cn=foo,c=ca";
String userIDType = IdentityType.X500.getValue(); String userIDType = IdentityType.X500.getValue();
Principal userPrincipal = AuthenticationUtil.createPrincipal(userID, userIDType); Principal userPrincipal = AuthenticationUtil.createPrincipal(userID, userIDType);
User user = new User();
user.getIdentities().add(new X500Principal(userID)); user.getIdentities().add(new X500Principal(userID));
user.getIdentities().add(new HttpPrincipal("foo")); user.getIdentities().add(new HttpPrincipal("foo"));
...@@ -176,7 +187,7 @@ public class RemoveUserMemberActionTest ...@@ -176,7 +187,7 @@ public class RemoveUserMemberActionTest
EasyMock.expectLastCall(); EasyMock.expectLastCall();
final UserPersistence mockUserPersistence = EasyMock.createMock(UserPersistence.class); final UserPersistence mockUserPersistence = EasyMock.createMock(UserPersistence.class);
EasyMock.expect(mockUserPersistence.getUser(userPrincipal)).andReturn(user); EasyMock.expect(mockUserPersistence.getAugmentedUser(userPrincipal)).andReturn(user);
EasyMock.replay(mockGroupPersistence, mockUserPersistence); EasyMock.replay(mockGroupPersistence, mockUserPersistence);
......
...@@ -108,16 +108,32 @@ public class UserClientTest ...@@ -108,16 +108,32 @@ public class UserClientTest
try try
{ {
new UserClient(null); new UserClient(null);
Assert.fail("Null base URL should throw an illegalArgumentException."); Assert.fail("Null service URI should throw an illegalArgumentException.");
} }
catch (IllegalArgumentException iae) catch (IllegalArgumentException iae)
{ {
Assert.assertTrue(iae.getMessage().contains("invalid serviceURI")); Assert.assertTrue(iae.getMessage().contains("cannot be null"));
} }
catch (Throwable t) catch (Throwable t)
{ {
Assert.fail("Unexpected exception: " + t.getMessage()); Assert.fail("Unexpected exception: " + t.getMessage());
} }
// case 2: serviceURI with a fragment
try
{
URI uri = new URI("http://foo.com/bar?test#fragment");
new UserClient(uri);
Assert.fail("Service URI containing a fragment should throw an illegalArgumentException.");
}
catch (IllegalArgumentException iae)
{
Assert.assertTrue(iae.getMessage().contains("fragment not allowed"));
}
catch (Throwable t)
{
Assert.fail("Unexpected exception: " + t.getMessage());
}
} }
@Test @Test
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment