package org.sagebionetworks.bridge.sdk.integration;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import org.sagebionetworks.bridge.sdk.ResearcherClient;
import org.sagebionetworks.bridge.sdk.Roles;
import org.sagebionetworks.bridge.sdk.integration.TestUserHelper.TestUser;
import org.sagebionetworks.bridge.sdk.models.PagedResourceList;
import org.sagebionetworks.bridge.sdk.models.accounts.AccountSummary;

public class ParticipantsTest {

    private TestUser researcher;
    
    @Before
    public void before() {
        researcher = TestUserHelper.createAndSignInUser(ParticipantsTest.class, false, Roles.RESEARCHER);
    }
    
    @After
    public void after() {
        researcher.signOutAndDeleteUser();
    }
    
    @Test
    public void canRetrieveAndPageThroughParticipants() {
        ResearcherClient client = researcher.getSession().getResearcherClient();
        
        PagedResourceList<AccountSummary> summaries = client.getPagedAccountSummaries(0, 10);

        // Well we know there's at least two accounts... the admin and the researcher.
        assertEquals(0, summaries.getOffsetBy());
        assertEquals(10, summaries.getPageSize());
        assertTrue(summaries.getItems().size() <= summaries.getTotal());
        assertTrue(summaries.getItems().size() > 2);
        
        AccountSummary summary = summaries.getItems().get(0);
        assertNotNull(summary.getFirstName());
        assertNotNull(summary.getLastName());
        assertNotNull(summary.getEmail());
        assertNotNull(summary.getStatus());
    }
    
    @Test(expected = IllegalArgumentException.class)
    public void cannotSetBadOffset() {
        ResearcherClient client = researcher.getSession().getResearcherClient();
        client.getPagedAccountSummaries(-1, 10);
    }
    
    @Test(expected = IllegalArgumentException.class)
    public void cannotSetBadPageSize() {
        ResearcherClient client = researcher.getSession().getResearcherClient();
        client.getPagedAccountSummaries(0, 4);
    }
    
}

@@ -1132,19 +1132,25 @@
 es(0, 10
+, null
 );%0A
-
 %0A       
@@ -1703,24 +1703,507 @@
 tStatus());%0A
+        %0A        for (AccountSummary sum : summaries.getItems()) %7B%0A            System.out.println(%22Email: %22 + sum.getEmail());%0A        %7D%0A        %0A        // Filter to only the researcher%0A        System.out.println(%22Researcher email: %22 + researcher.getEmail());%0A        summaries = client.getPagedAccountSummaries(0, 10, researcher.getEmail());%0A        assertEquals(1, summaries.getItems().size());%0A        assertEquals(researcher.getEmail(), summaries.getItems().get(0).getEmail());%0A
     %7D%0A    %0A 
@@ -2420,16 +2420,22 @@
 s(-1, 10
+, null
 );%0A    %7D
@@ -2607,32 +2607,32 @@
 archerClient();%0A
-
         client.g
@@ -2659,16 +2659,22 @@
 ies(0, 4
+, null
 );%0A    %7D

Verify you can filter search results by a string in email.