package org.hisp.dhis.android.core;

import org.hisp.dhis.android.core.common.D2Factory;
import org.hisp.dhis.android.core.data.api.OuMode;
import org.hisp.dhis.android.core.data.database.AbsStoreTestCase;
import org.hisp.dhis.android.core.data.server.RealServerMother;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance;
import org.hisp.dhis.android.core.trackedentity.search.TrackedEntityInstanceQuery;
import org.hisp.dhis.android.core.user.User;
import org.junit.Before;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import retrofit2.Response;

import static com.google.common.truth.Truth.assertThat;

public class TrackedEntityInstanceQueryCallRealIntegrationShould extends AbsStoreTestCase {
    private D2 d2;
    private TrackedEntityInstanceQuery.Builder queryBuilder;

    @Before
    @Override
    public void setUp() throws IOException {
        super.setUp();

        d2 = D2Factory.create(RealServerMother.url, databaseAdapter());


        List<String> orgUnits = new ArrayList<>();
        orgUnits.add("O6uvpzGd5pu");

        queryBuilder = TrackedEntityInstanceQuery.builder()
                .paging(true).page(1).pageSize(50)
                .orgUnits(orgUnits).orgUnitMode(OuMode.ACCESSIBLE).program("IpHINAT79UW");
    }

    //@Test
    public void query_tracked_entity_instances_no_filter() throws Exception {
        login();
        List<TrackedEntityInstance> queryResponse = d2.queryTrackedEntityInstances(queryBuilder.build()).call();
        assertThat(queryResponse).isNotEmpty();
    }

    //@Test
    public void query_tracked_entity_instances_filter_name() throws Exception {
        login();

        TrackedEntityInstanceQuery query = queryBuilder.query("jorge").build();
        List<TrackedEntityInstance> queryResponse = d2.queryTrackedEntityInstances(query).call();
        assertThat(queryResponse).isNotEmpty();
    }

    //@Test
    public void query_tracked_entity_instances_one_attribute() throws Exception {
        login();

        List<String> attributeList = new ArrayList<>(1);
        attributeList.add("w75KJ2mc4zz:like:jorge");

        TrackedEntityInstanceQuery query = queryBuilder.attribute(attributeList).build();
        List<TrackedEntityInstance> queryResponse = d2.queryTrackedEntityInstances(query).call();
        assertThat(queryResponse).isNotEmpty();
    }

    private void login() throws Exception {
        d2.logout().call();
        Response<User> loginResponse = d2.logIn("android", "Android123").call();
        assertThat(loginResponse.isSuccessful()).isTrue();
    }
}

@@ -2373,24 +2373,545 @@
 y();%0A    %7D%0A%0A
+    //@Test%0A    public void query_tracked_entity_instances_two_attributes() throws Exception %7B%0A        login();%0A%0A        List%3CString%3E attributeList = new ArrayList%3C%3E(2);%0A        attributeList.add(%22w75KJ2mc4zz:like:Filona%22);%0A        attributeList.add(%22zDhUuAYrxNC:like:Ryder%22);%0A%0A        TrackedEntityInstanceQuery query = queryBuilder.attribute(attributeList).build();%0A        List%3CTrackedEntityInstance%3E queryResponse = d2.queryTrackedEntityInstances(query).call();%0A        assertThat(queryResponse).isNotEmpty();%0A    %7D%0A%0A
     private 

test 2 attributes