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

import org.hisp.dhis.android.core.D2;
import org.hisp.dhis.android.core.common.D2Factory;
import org.hisp.dhis.android.core.data.database.AbsStoreTestCase;
import org.hisp.dhis.android.core.data.server.RealServerMother;
import org.junit.Before;

import java.io.IOException;

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

public class DHISVersionsManagerRealIntegrationShould extends AbsStoreTestCase {
    private D2 d2;

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

    //@Test
    public void do_not_have_available_version_before_making_first_system_info_call() {
        d2 = D2Factory.create(RealServerMother.url2_29, databaseAdapter());
        DHISVersionManager versionManager = d2.systemInfoModule().versionManager;
        assertThat(versionManager.getVersion()).isNull();
    }

    //@Test
    public void return_2_29_version_when_connecting_to_2_29_server() throws Exception {
        d2 = D2Factory.create(RealServerMother.url2_29, databaseAdapter());
        DHISVersionManager versionManager = d2.systemInfoModule().versionManager;

        d2.logout().call();
        d2.logIn("android", "Android123").call();
        assertThat(versionManager.getVersion()).isEqualTo(DHISVersion.V2_29);
        assertThat(versionManager.is2_29()).isTrue();
        assertThat(versionManager.is2_30()).isFalse();
    }

    //@Test
    public void return_2_30_version_when_connecting_to_2_30_server() throws Exception {
        d2 = D2Factory.create(RealServerMother.url_dev, databaseAdapter());
        DHISVersionManager versionManager = d2.systemInfoModule().versionManager;

        d2.logout().call();
        d2.logIn("android", "Android123").call();
        assertThat(versionManager.getVersion()).isEqualTo(DHISVersion.V2_30);
        assertThat(versionManager.is2_29()).isFalse();
        assertThat(versionManager.is2_30()).isTrue();
    }
}

@@ -607,76 +607,77 @@
 oid 
-do_not_have_available_version_before_making_first_system_info_call()
+return_2_29_version_when_connecting_to_2_29_server() throws Exception
  %7B%0A 
@@ -763,322 +763,28 @@
     
-DHISVersionManager versionManager = d2.systemInfoModule().versionManager;%0A        assertThat(versionManager.getVersion()).isNull();%0A    %7D%0A%0A    //@Test%0A    public void return_2_29_version_when_connecting_to_2_29_server() throws Exception %7B%0A        d2 = D2Factory.create(RealServerMother.url2_29, databaseAdapter());
+d2.wipeDB().call();%0A
 %0A   
@@ -867,36 +867,8 @@
 r;%0A%0A
-        d2.logout().call();%0A
     
@@ -1275,32 +1275,61 @@
 baseAdapter());%0A
+        d2.wipeDB().call();%0A%0A
         DHISVers
@@ -1399,36 +1399,8 @@
 r;%0A%0A
-        d2.logout().call();%0A
     

fix DHISVersionsManagerRealIntegrationShould