package org.commcare.android.tests.processing;

import org.commcare.android.CommCareTestRunner;
import org.commcare.android.database.HybridFileBackedSqlStorage;
import org.commcare.android.database.StoreFixturesOnFilesystemTests;
import org.commcare.dalvik.BuildConfig;
import org.commcare.dalvik.application.CommCareApplication;
import org.javarosa.core.model.instance.FormInstance;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;

/**
 * @author Phillip Mates (pmates@dimagi.com).
 */
@Config(application = org.commcare.dalvik.application.CommCareTestApplication.class,
        constants = BuildConfig.class)
@RunWith(CommCareTestRunner.class)
public class FixtureLoadingTest {

    @Before
    public void setup() {
        StoreFixturesOnFilesystemTests.installAppWithFixtureData(this.getClass(), "odk_level_ipm_restore_with_empty_fixture.xml");
    }

    /**
     * Ensure parsing doesn't stop at empty fixtures, but continues on,
     * committing subsequent fixtures
     */
    @Test
    public void testEmptyFixtureFollowedByNormalFixture() {
        HybridFileBackedSqlStorage<FormInstance> userFixtureStorage =
                CommCareApplication._().getFileBackedUserStorage("fixture", FormInstance.class);
        FormInstance form = userFixtureStorage.getRecordForValues(new String[]{FormInstance.META_ID},
                new String[]{"commtrack:locations"});
        form.setName("fake");

        form = userFixtureStorage.getRecordForValues(new String[]{FormInstance.META_ID},
                new String[]{"commtrack:programs"});
        form.setName("fake");
    }
}

@@ -41,16 +41,48 @@
 ssing;%0A%0A
+import junit.framework.Assert;%0A%0A
 import o
@@ -121,16 +121,16 @@
 Runner;%0A
-
 import o
@@ -900,16 +900,32 @@
 Class(),
+%0A               
  %22odk_le
@@ -1500,35 +1500,46 @@
         
-form.setName(%22fake%22
+Assert.assertTrue(form != null
 );%0A%0A    
@@ -1688,27 +1688,38 @@
     
-form.setName(%22fake%22
+Assert.assertTrue(form != null
 );%0A 

add some asserts