package org.hisp.dhis.android.core.common;

import android.support.test.InstrumentationRegistry;

import com.facebook.stetho.okhttp3.StethoInterceptor;

import org.hisp.dhis.android.core.D2;
import org.hisp.dhis.android.core.configuration.ConfigurationModel;
import org.hisp.dhis.android.core.data.api.BasicAuthenticatorFactory;
import org.hisp.dhis.android.core.data.database.DatabaseAdapter;

import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

public class D2Factory {
    public static D2 create(String url, DatabaseAdapter databaseAdapter) {
        ConfigurationModel config = ConfigurationModel.builder()
                .serverUrl(HttpUrl.parse(url))
                .build();

        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);

        return new D2.Builder()
                .configuration(config)
                .databaseAdapter(databaseAdapter)
                .okHttpClient(
                        new OkHttpClient.Builder()
                                .addInterceptor(BasicAuthenticatorFactory.create(databaseAdapter))
                                .addInterceptor(loggingInterceptor)
                                .addNetworkInterceptor(new StethoInterceptor())
                                .build()
                )
                .context(InstrumentationRegistry.getTargetContext().getApplicationContext())
                .build();
    }
}
@@ -384,24 +384,63 @@
 seAdapter;%0A%0A
+import java.util.concurrent.TimeUnit;%0A%0A
 import okhtt
@@ -1369,24 +1369,91 @@
 erceptor())%0A
+                                .readTimeout(30, TimeUnit.SECONDS)%0A
             

set wait read response on test to 30 sec.