/*
 * SCIM-Client is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2017, Gluu
 */
package gluu.scim2.client.singleresource;

import gluu.scim2.client.UserBaseTest;
import org.gluu.oxtrust.model.scim2.ListResponse;
import org.gluu.oxtrust.model.scim2.user.UserResource;
import org.testng.annotations.Test;

import javax.ws.rs.core.Response;

import java.util.List;
import java.util.stream.Collectors;

import static javax.ws.rs.core.Response.Status.OK;

import static org.testng.Assert.*;

/**
 * NOTES:
 * Check first if /install/community-edition-setup/templates/test/scim-client/data/scim-test-data.ldif has been loaded to LDAP.
 *
 * Created by jgomer on 2017-11-12.
 */
public class QueryParamRetrievalTest extends UserBaseTest {

    private UserResource user;

    @Test
    public void multipleRetrieval(){
        logger.debug("Retrieving test users...");
        String include="displayName, externalId";

        Response response=client.searchUsers("displayName co \"test\"", null, null, null, null, include, null);
        assertEquals(response.getStatus(), OK.getStatusCode());

        ListResponse listResponse = response.readEntity(ListResponse.class);
        List<UserResource> list=listResponse.getResources().stream().map(usrClass::cast).collect(Collectors.toList());

        //Verify users retrieved contain attributes of interest
        for (UserResource usr : list){
            assertNotNull(usr.getDisplayName());
            assertTrue(usr.getDisplayName().toLowerCase().contains("test"));
            assertNotNull(usr.getExternalId());
        }

    }

    @Test(dependsOnMethods = "multipleRetrieval")
    public void multipleRetrievalExcluding() {
        logger.debug("Retrieving test users...");
        String exclude="displayName, externalId, name, addresses, emails";

        Response response=client.searchUsers("displayName co \"test\"", null, null, null, null, null, exclude);
        assertEquals(response.getStatus(), OK.getStatusCode());

        ListResponse listResponse = response.readEntity(ListResponse.class);
        List<UserResource> list=listResponse.getResources().stream().map(UserResource.class::cast).collect(Collectors.toList());

        //Verify users retrieved do not contain attributes of interest
        for (UserResource usr : list) {
            assertNull(usr.getDisplayName());
            assertNull(usr.getExternalId());
            assertNull(usr.getName());
            assertNull(usr.getAddresses());
            assertNull(usr.getEmails());

            assertNotNull(usr.getSchemas());
            assertNotNull(usr.getId());
        }
        user=list.get(0);

    }

    @Test(dependsOnMethods = "multipleRetrievalExcluding")
    public void singleRetrieval(){

        String include="active";
        Response response=client.getUserById(user.getId(), include, null);
        assertEquals(response.getStatus(), OK.getStatusCode());

        user=response.readEntity(usrClass);

        assertNotNull(user.getActive());
        assertNull(user.getExternalId());
        assertNull(user.getName());
        assertNull(user.getAddresses());
        assertNull(user.getEmails());

    }

    @Test(dependsOnMethods = "multipleRetrievalExcluding")
    public void singleRetrievalExcluding() {

        String exclude="id, externalId";
        Response response=client.getUserById(user.getId(), null, exclude);
        assertEquals(response.getStatus(), OK.getStatusCode());

        user=response.readEntity(usrClass);

        assertNotNull(user.getId());    //Always returned
        assertNull(user.getExternalId());

    }

}

@@ -1583,32 +1583,34 @@
 ));%0A            
+//
 assertNotNull(us

Remove unnecessary check