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

s1890: unit test fixes

parent 6b3dc505
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -71,11 +71,16 @@ package ca.nrc.cadc.ac.server.web.groups;
import static org.easymock.EasyMock.createMock;
import static org.junit.Assert.fail;

import java.net.URI;
import java.security.Principal;
import java.util.UUID;

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.util.ObjectUtil;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.easymock.EasyMock;
@@ -111,11 +116,14 @@ public class RemoveUserMemberActionTest
    {
        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 userIDType = IdentityType.X500.getValue();
            Principal userPrincipal = AuthenticationUtil.createPrincipal(userID, userIDType);
            User user = new User();
            user.getIdentities().add(userPrincipal);
            Principal x500Principal = AuthenticationUtil.createPrincipal(userID, userIDType);
            user.getIdentities().add(x500Principal);

            Group group = new Group("group");
            User member = new User();
@@ -126,7 +134,7 @@ public class RemoveUserMemberActionTest
            EasyMock.expect(mockGroupPersistence.getGroup("group")).andReturn(group);

            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);

@@ -160,10 +168,13 @@ public class RemoveUserMemberActionTest
    {
        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 userIDType = IdentityType.X500.getValue();
            Principal userPrincipal = AuthenticationUtil.createPrincipal(userID, userIDType);
            User user = new User();
            user.getIdentities().add(new X500Principal(userID));
            user.getIdentities().add(new HttpPrincipal("foo"));

@@ -176,7 +187,7 @@ public class RemoveUserMemberActionTest
            EasyMock.expectLastCall();

            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);

+18 −2
Original line number Diff line number Diff line
@@ -108,11 +108,27 @@ public class UserClientTest
        try
        {
            new UserClient(null);
            Assert.fail("Null base URL should throw an illegalArgumentException.");
            Assert.fail("Null service URI should throw an illegalArgumentException.");
        }
        catch (IllegalArgumentException iae)
        {
            Assert.assertTrue(iae.getMessage().contains("invalid serviceURI"));
            Assert.assertTrue(iae.getMessage().contains("cannot be null"));
        }
        catch (Throwable t)
        {
        	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)
        {