Commit 4ada8fb9 authored by Dustin Jenkins's avatar Dustin Jenkins
Browse files

Story 1651: Fix GMSClient Test and added getDetails() method to User class.

parent aa5c3e6b
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -143,4 +143,22 @@ public class User<T extends Principal>
        return getClass().getSimpleName() + "[" + userID.getName() + "]";
    }

    public <S extends UserDetails> Set<S> getDetails(
            final Class<S> userDetailsClass)
    {
        final Set<S> matchedDetails = new HashSet<S>();

        for (final UserDetails ud : details)
        {
            if (ud.getClass() == userDetailsClass)
            {
                // This casting shouldn't happen, but it's the only way to
                // do this without a lot of work.
                // jenkinsd 2014.09.26
                matchedDetails.add((S) ud);
            }
        }

        return matchedDetails;
    }
}
+16 −3
Original line number Diff line number Diff line
@@ -67,9 +67,7 @@
 ************************************************************************
 */package ca.nrc.cadc.ac;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

import javax.security.auth.x500.X500Principal;

@@ -200,4 +198,19 @@ public class UserTest
        }
        assertTrue(thrown);
    }

    @Test
    public void getDetails() throws Exception
    {
        final User<HttpPrincipal> testSubject =
                new User<HttpPrincipal>(new HttpPrincipal("test"));

        testSubject.details.add(new PersonalDetails("First", "Last"));

        assertTrue("Should be empty.",
                   testSubject.getDetails(PosixDetails.class).isEmpty());

        assertEquals("Should be 1.", 1,
                     testSubject.getDetails(PersonalDetails.class).size());
    }
}
+6 −3
Original line number Diff line number Diff line
@@ -110,7 +110,8 @@ public class GMSClientTest
            subject.getPrincipals().add(userID);
            
            RegistryClient regClient = new RegistryClient();
            URL baseURL = regClient.getServiceURL(new URI(AC.GMS_SERVICE_URI));
            URL baseURL = regClient.getServiceURL(new URI(AC.GMS_SERVICE_URI),
                                                  "https");
            GMSClient client = new GMSClient(baseURL.toString());

            Assert.assertFalse(client.userIsSubject(null, null));
@@ -148,7 +149,8 @@ public class GMSClientTest
                    public Object run() throws Exception
                    {
                        RegistryClient regClient = new RegistryClient();
                        URL baseURL = regClient.getServiceURL(new URI(AC.GMS_SERVICE_URI));
                        URL baseURL = regClient.getServiceURL(new URI(AC.GMS_SERVICE_URI),
                                                              "https");
                        GMSClient client = new GMSClient(baseURL.toString());

                        List<Group> initial = client.getCachedGroups(userID, Role.MEMBER);
@@ -180,7 +182,8 @@ public class GMSClientTest

            // do the same without a subject
            RegistryClient regClient = new RegistryClient();
            URL baseURL = regClient.getServiceURL(new URI(AC.GMS_SERVICE_URI));
            URL baseURL = regClient.getServiceURL(new URI(AC.GMS_SERVICE_URI),
                                                  "https");
            GMSClient client = new GMSClient(baseURL.toString());

            List<Group> initial = client.getCachedGroups(userID, Role.MEMBER);