Search in sources :

Example 1 with BookNamesake

use of com.orgzly.android.sync.BookNamesake in project orgzly-android by orgzly.

the class SyncTest method testDummyShouldNotBeSavedWhenHavingOneRepo.

@Test
public void testDummyShouldNotBeSavedWhenHavingOneRepo() {
    shelfTestUtils.setupRepo("mock://repo-a");
    shelfTestUtils.setupRepo("mock://repo-b");
    shelfTestUtils.setupRook("mock://repo-a", "mock://repo-a/booky.org", "", "1abcdef", 1400067155);
    shelfTestUtils.setupRook("mock://repo-b", "mock://repo-b/booky.org", "", "2abcdef", 1400067156);
    Book book;
    Map<String, BookNamesake> namesakes;
    namesakes = shelf.sync();
    book = shelf.getBook("booky");
    assertEquals(BookSyncStatus.DUMMY_WITHOUT_LINK_AND_MULTIPLE_ROOKS, namesakes.get("booky").getStatus());
    assertTrue(book.isDummy());
    shelfTestUtils.deleteRepo("mock://repo-a");
    shelfTestUtils.deleteRepo("mock://repo-b");
    shelfTestUtils.setupRepo("mock://repo-c");
    namesakes = shelf.sync();
    book = shelf.getBook("booky");
    // TODO: We should delete it, no point of having a dummy and no remote book
    assertEquals(BookSyncStatus.ONLY_DUMMY, namesakes.get("booky").getStatus());
    assertTrue(book.isDummy());
}
Also used : Book(com.orgzly.android.Book) BookNamesake(com.orgzly.android.sync.BookNamesake) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 2 with BookNamesake

use of com.orgzly.android.sync.BookNamesake in project orgzly-android by orgzly.

the class Shelf method sync.

// TODO: Used by tests only for now
public Map<String, BookNamesake> sync() {
    try {
        Map<String, BookNamesake> nameGroups = groupAllNotebooksByName();
        for (BookNamesake group : nameGroups.values()) {
            BookAction action = syncNamesake(group);
            setBookStatus(group.getBook(), group.getStatus().toString(), action);
        }
        return nameGroups;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : BookNamesake(com.orgzly.android.sync.BookNamesake) IOException(java.io.IOException)

Example 3 with BookNamesake

use of com.orgzly.android.sync.BookNamesake in project orgzly-android by orgzly.

the class ShelfTest method testShelfAndRepo.

@Test
public void testShelfAndRepo() throws IOException {
    assertEquals("Starting with empty shelf", 0, shelf.getBooks().size());
    Book book;
    book = shelf.createBook("local-book-1");
    assertEquals("local-book-1", book.getName());
    assertNull(book.getLastSyncedToRook());
    book = shelf.createBook("common-book-1");
    assertEquals("common-book-1", book.getName());
    assertNull(book.getLastSyncedToRook());
    book = shelf.createBook("common-book-2");
    assertEquals("common-book-2", book.getName());
    assertNull(book.getLastSyncedToRook());
    /* Setup mock repo. */
    shelfTestUtils.setupRepo("mock://repo-a");
    shelfTestUtils.setupRook("mock://repo-a", "mock://repo-a/remote-book-2.org", "", "1abcdef", 1400412756000L);
    shelfTestUtils.setupRook("mock://repo-a", "mock://repo-a/common-book-1.org", "", "2abcdef", 1400671956000L);
    shelfTestUtils.setupRook("mock://repo-a", "mock://repo-a/common-book-2.org", "", "3abcdef", 1400671956000L);
    shelfTestUtils.setupRook("mock://repo-a", "mock://repo-a/remote-book-1.org", "", "0abcdef", 1400067156000L);
    Map<String, BookNamesake> groups = shelf.groupAllNotebooksByName();
    assertEquals(5, groups.size());
    for (BookNamesake group : groups.values()) {
        String name = group.getName();
        if (name.equals("local-book-1")) {
            assertFalse(group.getBook().isDummy());
            assertEquals(0, group.getRooks().size());
        } else if (name.equals("common-book-1")) {
            assertFalse(group.getBook().isDummy());
            assertEquals(1, group.getRooks().size());
        } else if (name.equals("common-book-2")) {
            assertFalse(group.getBook().isDummy());
            assertEquals(1, group.getRooks().size());
        } else if (name.equals("remote-book-1")) {
            assertTrue(group.getBook().isDummy());
            assertEquals(1, group.getRooks().size());
        } else if (name.equals("remote-book-2")) {
            assertTrue(group.getBook().isDummy());
            assertEquals(1, group.getRooks().size());
        } else {
            fail("unexpected name " + name);
        }
    }
}
Also used : Book(com.orgzly.android.Book) BookNamesake(com.orgzly.android.sync.BookNamesake) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 4 with BookNamesake

use of com.orgzly.android.sync.BookNamesake in project orgzly-android by orgzly.

the class ShelfTest method testCompareWithRepo.

@Test
public void testCompareWithRepo() throws IOException {
    assertEquals("Starting with empty shelf", 0, shelf.getBooks().size());
    shelfTestUtils.setupRepo("mock://repo-a");
    shelfTestUtils.setupRook("mock://repo-a", "mock://repo-a/remote-book-1.org", "", "0abcdef", 1400067156);
    shelfTestUtils.setupRook("mock://repo-a", "mock://repo-a/remote-book-2.org", "", "1abcdef", 1400412756);
    shelfTestUtils.setupRook("mock://repo-a", "mock://repo-a/remote-book-3.org", "", "2abcdef", 1400671956);
    Map<String, BookNamesake> groups = shelf.groupAllNotebooksByName();
    assertEquals(3, groups.size());
    for (BookNamesake group : groups.values()) {
        String name = group.getName();
        assertTrue("Book name " + name + " not expected", name.equals("remote-book-1") || name.equals("remote-book-2") || name.equals("remote-book-3"));
        assertTrue(group.getBook().isDummy());
        assertEquals(1, group.getRooks().size());
    }
}
Also used : BookNamesake(com.orgzly.android.sync.BookNamesake) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 5 with BookNamesake

use of com.orgzly.android.sync.BookNamesake in project orgzly-android by orgzly.

the class SyncTest method testDeletedRepoShouldStayAsBookLink.

@Test
public void testDeletedRepoShouldStayAsBookLink() {
    shelfTestUtils.setupRepo("mock://repo-a");
    shelfTestUtils.setupRepo("mock://repo-b");
    shelfTestUtils.setupRook("mock://repo-a", "mock://repo-a/booky.org", "", "1abcdef", 1400067155);
    Book book;
    Map<String, BookNamesake> namesakes;
    namesakes = shelf.sync();
    book = shelf.getBook("booky");
    assertEquals(BookSyncStatus.DUMMY_WITHOUT_LINK_AND_ONE_ROOK, namesakes.get("booky").getStatus());
    assertFalse(book.isDummy());
    assertEquals("mock://repo-a", book.getLinkRepo().toString());
    assertEquals("mock://repo-a", book.getLastSyncedToRook().getRepoUri().toString());
    shelfTestUtils.deleteRepo("mock://repo-a");
    shelfTestUtils.deleteRepo("mock://repo-b");
    shelfTestUtils.setupRepo("mock://repo-c");
    // TODO: Don't use namesakes, be consistent and use book.status like in some methods
    namesakes = shelf.sync();
    book = shelf.getBook("booky");
    assertEquals(BookSyncStatus.ONLY_BOOK_WITHOUT_LINK_AND_ONE_REPO, namesakes.get("booky").getStatus());
    assertFalse(book.isDummy());
    assertEquals("mock://repo-c", book.getLinkRepo().toString());
    assertEquals("mock://repo-c", book.getLastSyncedToRook().getRepoUri().toString());
}
Also used : Book(com.orgzly.android.Book) BookNamesake(com.orgzly.android.sync.BookNamesake) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Aggregations

BookNamesake (com.orgzly.android.sync.BookNamesake)6 OrgzlyTest (com.orgzly.android.OrgzlyTest)4 Test (org.junit.Test)4 Book (com.orgzly.android.Book)3 Repo (com.orgzly.android.repos.Repo)1 VersionedRook (com.orgzly.android.repos.VersionedRook)1 IOException (java.io.IOException)1