Search in sources :

Example 1 with QATxtImporter

use of org.liberty.android.fantastischmemo.converter.QATxtImporter in project AnyMemo by helloworld1.

the class ImportMergingTest method testMergeQATxtIntoDb.

@SmallTest
@Test
public void testMergeQATxtIntoDb() throws Exception {
    srcFilePath = AMEnv.DEFAULT_ROOT_PATH + "/" + "qa-text-test.txt";
    destFilePath = AMEnv.DEFAULT_ROOT_PATH + "/" + "qa-text-test.db";
    new File(srcFilePath).delete();
    new File(destFilePath).delete();
    AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
    try {
        // Create an new db with some contents
        helper.getCardDao().createCards(newDbCardList);
    } finally {
        AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
    amFileUtil.copyFileFromAsset("qa-text-test.txt", new File(srcFilePath));
    Converter converter = new QATxtImporter(amFileUtil);
    converter.convert(srcFilePath, destFilePath);
    helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
    try {
        List<Card> cards = helper.getCardDao().getAllCards(null);
        assertEquals(4, cards.size());
        assertEquals(1, (int) cards.get(0).getId());
        assertEquals(1, (int) cards.get(0).getOrdinal());
        assertEquals("old question 1", cards.get(0).getQuestion());
        assertEquals("old answer 1", cards.get(0).getAnswer());
        assertEquals(2, (int) cards.get(1).getId());
        assertEquals(2, (int) cards.get(1).getOrdinal());
        assertEquals("old question 2", cards.get(1).getQuestion());
        assertEquals("old answer 2", cards.get(1).getAnswer());
        assertEquals(3, (int) cards.get(2).getId());
        assertEquals(3, (int) cards.get(2).getOrdinal());
        assertEquals("This is question1", cards.get(2).getQuestion());
        assertEquals("Answer1", cards.get(2).getAnswer());
        assertEquals(4, (int) cards.get(3).getId());
        assertEquals(4, (int) cards.get(3).getOrdinal());
        assertEquals("Question2", cards.get(3).getQuestion());
        assertEquals("Answer2", cards.get(3).getAnswer());
    } finally {
        AnyMemoDBOpenHelperManager.releaseHelper(helper);
    }
}
Also used : AnyMemoDBOpenHelper(org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper) QATxtImporter(org.liberty.android.fantastischmemo.converter.QATxtImporter) Converter(org.liberty.android.fantastischmemo.converter.Converter) File(java.io.File) Card(org.liberty.android.fantastischmemo.entity.Card) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) BaseTest(org.liberty.android.fantastischmemo.test.BaseTest) SmallTest(android.support.test.filters.SmallTest)

Aggregations

SmallTest (android.support.test.filters.SmallTest)1 File (java.io.File)1 Test (org.junit.Test)1 AnyMemoDBOpenHelper (org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper)1 Converter (org.liberty.android.fantastischmemo.converter.Converter)1 QATxtImporter (org.liberty.android.fantastischmemo.converter.QATxtImporter)1 Card (org.liberty.android.fantastischmemo.entity.Card)1 BaseTest (org.liberty.android.fantastischmemo.test.BaseTest)1