diff options
Diffstat (limited to 'app/src/test/java')
6 files changed, 219 insertions, 167 deletions
diff --git a/app/src/test/java/it/niedermann/owncloud/notes/persistence/AccountDaoTest.java b/app/src/test/java/it/niedermann/owncloud/notes/persistence/AccountDaoTest.java index 1949dbad..7e8d49ea 100644 --- a/app/src/test/java/it/niedermann/owncloud/notes/persistence/AccountDaoTest.java +++ b/app/src/test/java/it/niedermann/owncloud/notes/persistence/AccountDaoTest.java @@ -1,6 +1,5 @@ package it.niedermann.owncloud.notes.persistence; -import android.database.sqlite.SQLiteConstraintException; import android.os.Build; import androidx.annotation.NonNull; @@ -18,22 +17,11 @@ import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -import java.util.Calendar; -import java.util.List; - import it.niedermann.owncloud.notes.persistence.entity.Account; -import it.niedermann.owncloud.notes.persistence.entity.CategoryWithNotesCount; -import it.niedermann.owncloud.notes.persistence.entity.Note; import it.niedermann.owncloud.notes.shared.model.Capabilities; -import static it.niedermann.owncloud.notes.shared.model.DBStatus.LOCAL_DELETED; -import static it.niedermann.owncloud.notes.shared.model.DBStatus.LOCAL_EDITED; -import static it.niedermann.owncloud.notes.shared.model.DBStatus.VOID; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; @RunWith(RobolectricTestRunner.class) @Config(sdk = {Build.VERSION_CODES.P}) @@ -66,4 +54,25 @@ public class AccountDaoTest { assertEquals("彼得", createdAccount.getUserName()); assertEquals("彼得@äöüß.example.com", createdAccount.getAccountName()); } + + @Test + public void updateApiVersionFromNull() throws NextcloudHttpRequestFailedException { + final Account account = db.getAccountDao().getAccountById(db.getAccountDao().insert(new Account("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", new Capabilities("{ocs: {}}", null)))); + assertNull(account.getApiVersion()); + + assertEquals(0, db.getAccountDao().updateApiVersion(account.getId(), null)); + assertEquals(1, db.getAccountDao().updateApiVersion(account.getId(), "[0.2]")); + assertEquals(0, db.getAccountDao().updateApiVersion(account.getId(), "[0.2]")); + } + + @Test + public void updateApiVersionFromExisting() throws NextcloudHttpRequestFailedException { + final Account account = db.getAccountDao().getAccountById(db.getAccountDao().insert(new Account("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", new Capabilities("{ocs: {data: {capabilities: {notes: {api_version: '[0.2]'}}}}}", null)))); + assertEquals("[0.2]", account.getApiVersion()); + + assertEquals(0, db.getAccountDao().updateApiVersion(account.getId(), "[0.2]")); + assertEquals(1, db.getAccountDao().updateApiVersion(account.getId(), "[0.2, 1.0]")); + assertEquals(1, db.getAccountDao().updateApiVersion(account.getId(), null)); + } + }
\ No newline at end of file diff --git a/app/src/test/java/it/niedermann/owncloud/notes/persistence/NotesDaoTest.java b/app/src/test/java/it/niedermann/owncloud/notes/persistence/NotesDaoTest.java index c59186c0..17df5122 100644 --- a/app/src/test/java/it/niedermann/owncloud/notes/persistence/NotesDaoTest.java +++ b/app/src/test/java/it/niedermann/owncloud/notes/persistence/NotesDaoTest.java @@ -53,7 +53,7 @@ public class NotesDaoTest { .inMemoryDatabaseBuilder(ApplicationProvider.getApplicationContext(), NotesDatabase.class) .allowMainThreadQueries() .build(); - db.addAccount("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", new Capabilities("{ocs: {}}", null)); + db.getAccountDao().insert(new Account("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", new Capabilities("{ocs: {}}", null))); account = db.getAccountDao().getAccountByName("彼得@äöüß.example.com"); } @@ -410,7 +410,7 @@ public class NotesDaoTest { } private Account setupSecondAccount() throws NextcloudHttpRequestFailedException { - db.addAccount("https://example.org", "test", "test@example.org", new Capabilities("{ocs: {}}", null)); + db.getAccountDao().insert(new Account("https://example.org", "test", "test@example.org", new Capabilities("{ocs: {}}", null))); return db.getAccountDao().getAccountByName("test@example.org"); } diff --git a/app/src/test/java/it/niedermann/owncloud/notes/persistence/NotesDatabaseTest.java b/app/src/test/java/it/niedermann/owncloud/notes/persistence/NotesDatabaseTest.java deleted file mode 100644 index 04536d32..00000000 --- a/app/src/test/java/it/niedermann/owncloud/notes/persistence/NotesDatabaseTest.java +++ /dev/null @@ -1,149 +0,0 @@ -package it.niedermann.owncloud.notes.persistence; - -import android.content.Context; -import android.os.Build; - -import androidx.annotation.NonNull; -import androidx.arch.core.executor.testing.InstantTaskExecutorRule; -import androidx.room.Room; -import androidx.test.core.app.ApplicationProvider; - -import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.annotation.Config; - -import java.util.Arrays; -import java.util.Calendar; -import java.util.Map; - -import it.niedermann.owncloud.notes.persistence.entity.Account; -import it.niedermann.owncloud.notes.persistence.entity.Note; -import it.niedermann.owncloud.notes.shared.model.Capabilities; - -import static it.niedermann.owncloud.notes.persistence.NotesDatabaseTestUtil.getOrAwaitValue; -import static it.niedermann.owncloud.notes.shared.model.DBStatus.LOCAL_DELETED; -import static it.niedermann.owncloud.notes.shared.model.DBStatus.LOCAL_EDITED; -import static it.niedermann.owncloud.notes.shared.model.DBStatus.VOID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; - -@RunWith(RobolectricTestRunner.class) -@Config(sdk = {Build.VERSION_CODES.P}) -public class NotesDatabaseTest { - - @Rule - public InstantTaskExecutorRule instantTaskExecutorRule = new InstantTaskExecutorRule(); - - @NonNull - private Context context; - private NotesDatabase db = null; - private Account account = null; - private Account secondAccount = null; - - @Before - public void setupDB() throws NextcloudHttpRequestFailedException { - context = ApplicationProvider.getApplicationContext(); - db = Room - .inMemoryDatabaseBuilder(ApplicationProvider.getApplicationContext(), NotesDatabase.class) - .allowMainThreadQueries() - .build(); - - db.addAccount("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", new Capabilities("{\"ocs\":{\"meta\":{\"status\":\"ok\",\"statuscode\":200,\"message\":\"OK\"},\"data\":{\"version\":{\"major\":18,\"minor\":0,\"micro\":4,\"string\":\"18.0.4\",\"edition\":\"\",\"extendedSupport\":false},\"capabilities\":{\"core\":{\"pollinterval\":60,\"webdav-root\":\"remote.php\\/webdav\"},\"bruteforce\":{\"delay\":0},\"files\":{\"bigfilechunking\":true,\"blacklisted_files\":[\".htaccess\"],\"directEditing\":{\"url\":\"https:\\/\\/efss.qloud.my\\/ocs\\/v2.php\\/apps\\/files\\/api\\/v1\\/directEditing\",\"etag\":\"ed2b141af2a39b0e42666952ba60988d\"},\"versioning\":true,\"undelete\":true},\"activity\":{\"apiv2\":[\"filters\",\"filters-api\",\"previews\",\"rich-strings\"]},\"ocm\":{\"enabled\":true,\"apiVersion\":\"1.0-proposal1\",\"endPoint\":\"https:\\/\\/efss.qloud.my\\/index.php\\/ocm\",\"resourceTypes\":[{\"name\":\"file\",\"shareTypes\":[\"user\",\"group\"],\"protocols\":{\"webdav\":\"\\/public.php\\/webdav\\/\"}}]},\"deck\":{\"version\":\"0.8.2\"},\"richdocuments\":{\"mimetypes\":[\"application\\/vnd.oasis.opendocument.text\",\"application\\/vnd.oasis.opendocument.spreadsheet\",\"application\\/vnd.oasis.opendocument.graphics\",\"application\\/vnd.oasis.opendocument.presentation\",\"application\\/vnd.lotus-wordpro\",\"application\\/vnd.visio\",\"application\\/vnd.wordperfect\",\"application\\/msonenote\",\"application\\/msword\",\"application\\/rtf\",\"text\\/rtf\",\"application\\/vnd.openxmlformats-officedocument.wordprocessingml.document\",\"application\\/vnd.openxmlformats-officedocument.wordprocessingml.template\",\"application\\/vnd.ms-word.document.macroEnabled.12\",\"application\\/vnd.ms-word.template.macroEnabled.12\",\"application\\/vnd.ms-excel\",\"application\\/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\"application\\/vnd.openxmlformats-officedocument.spreadsheetml.template\",\"application\\/vnd.ms-excel.sheet.macroEnabled.12\",\"application\\/vnd.ms-excel.template.macroEnabled.12\",\"application\\/vnd.ms-excel.addin.macroEnabled.12\",\"application\\/vnd.ms-excel.sheet.binary.macroEnabled.12\",\"application\\/vnd.ms-powerpoint\",\"application\\/vnd.openxmlformats-officedocument.presentationml.presentation\",\"application\\/vnd.openxmlformats-officedocument.presentationml.template\",\"application\\/vnd.openxmlformats-officedocument.presentationml.slideshow\",\"application\\/vnd.ms-powerpoint.addin.macroEnabled.12\",\"application\\/vnd.ms-powerpoint.presentation.macroEnabled.12\",\"application\\/vnd.ms-powerpoint.template.macroEnabled.12\",\"application\\/vnd.ms-powerpoint.slideshow.macroEnabled.12\",\"text\\/csv\"],\"mimetypesNoDefaultOpen\":[\"image\\/svg+xml\",\"application\\/pdf\",\"text\\/plain\",\"text\\/spreadsheet\"],\"collabora\":[],\"direct_editing\":false,\"templates\":false,\"productName\":\"\\u5728\\u7ebf\\u534f\\u4f5c\"},\"dav\":{\"chunking\":\"1.0\"},\"files_sharing\":{\"api_enabled\":true,\"public\":{\"enabled\":true,\"password\":{\"enforced\":true,\"askForOptionalPassword\":false},\"expire_date\":{\"enabled\":true,\"days\":\"7\",\"enforced\":false},\"multiple_links\":true,\"expire_date_internal\":{\"enabled\":false},\"send_mail\":false,\"upload\":true,\"upload_files_drop\":true},\"resharing\":true,\"user\":{\"send_mail\":false,\"expire_date\":{\"enabled\":true}},\"group_sharing\":true,\"group\":{\"enabled\":true,\"expire_date\":{\"enabled\":true}},\"default_permissions\":31,\"federation\":{\"outgoing\":false,\"incoming\":false,\"expire_date\":{\"enabled\":true}},\"sharee\":{\"query_lookup_default\":false},\"sharebymail\":{\"enabled\":true,\"upload_files_drop\":{\"enabled\":true},\"password\":{\"enabled\":true},\"expire_date\":{\"enabled\":true}}},\"external\":{\"v1\":[\"sites\",\"device\",\"groups\",\"redirect\"]},\"notifications\":{\"ocs-endpoints\":[\"list\",\"get\",\"delete\",\"delete-all\",\"icons\",\"rich-strings\",\"action-web\"],\"push\":[\"devices\",\"object-data\",\"delete\"],\"admin-notifications\":[\"ocs\",\"cli\"]},\"password_policy\":{\"minLength\":8,\"enforceNonCommonPassword\":true,\"enforceNumericCharacters\":false,\"enforceSpecialCharacters\":false,\"enforceUpperLowerCase\":false,\"api\":{\"generate\":\"https:\\/\\/efss.qloud.my\\/ocs\\/v2.php\\/apps\\/password_policy\\/api\\/v1\\/generate\",\"validate\":\"https:\\/\\/efss.qloud.my\\/ocs\\/v2.php\\/apps\\/password_policy\\/api\\/v1\\/validate\"}},\"theming\":{\"name\":\"QloudData\",\"url\":\"https:\\/\\/www.qloud.my\\/qloud-data\\/\",\"slogan\":\"Powered by NextCloud\",\"color\":\"#1E4164\",\"color-text\":\"#ffffff\",\"color-element\":\"#1E4164\",\"logo\":\"https:\\/\\/efss.qloud.my\\/index.php\\/apps\\/theming\\/image\\/logo?useSvg=1&v=47\",\"background\":\"https:\\/\\/efss.qloud.my\\/core\\/img\\/background.png?v=47\",\"background-plain\":false,\"background-default\":true,\"logoheader\":\"https:\\/\\/efss.qloud.my\\/index.php\\/apps\\/theming\\/image\\/logo?useSvg=1&v=47\",\"favicon\":\"https:\\/\\/efss.qloud.my\\/index.php\\/apps\\/theming\\/image\\/logo?useSvg=1&v=47\"},\"registration\":{\"enabled\":true,\"apiRoot\":\"\\/ocs\\/v2.php\\/apps\\/registration\\/api\\/v1\\/\",\"apiLevel\":\"v1\"}}}}}", null)); - account = db.getAccountDao().getAccountByName("彼得@äöüß.example.com"); - - db.addAccount("https://example.org", "test", "test@example.org", new Capabilities("{ocs: {}}", null)); - secondAccount = db.getAccountDao().getAccountByName("test@example.org"); - - Arrays.stream(new Note[]{ - new Note(1, 1001L, Calendar.getInstance(), "美好的一天", "C", "Movies", false, null, VOID, account.getId(), "", 0), - new Note(2, null, Calendar.getInstance(), "T", "C", "Movies", false, null, LOCAL_EDITED, account.getId(), "", 0), - new Note(3, 1003L, Calendar.getInstance(), "美好的一天", "C", "Movies", false, null, LOCAL_EDITED, account.getId(), "", 0), - new Note(4, null, Calendar.getInstance(), "T", "C", "Music", false, null, VOID, account.getId(), "", 0), - new Note(5, 1005L, Calendar.getInstance(), "美好的一天", "C", " 兄弟,这真是美好的一天。", false, null, LOCAL_EDITED, account.getId(), "", 0), - new Note(6, 1006L, Calendar.getInstance(), "美好的一天", "C", " 兄弟,这真是美好的一天。", false, null, LOCAL_DELETED, account.getId(), "", 0), - new Note(7, null, Calendar.getInstance(), "T", "C", "Music", true, null, LOCAL_EDITED, secondAccount.getId(), "", 0), - new Note(8, 1008L, Calendar.getInstance(), "美好的一天", "C", "ToDo", true, null, LOCAL_EDITED, secondAccount.getId(), "", 0), - new Note(9, 1009L, Calendar.getInstance(), "美好的一天", "C", "ToDo", true, null, LOCAL_DELETED, secondAccount.getId(), "", 0) - }).forEach(note -> db.getNoteDao().addNote(note)); - } - - @After - public void closeDb() { - db.close(); - } - - @Test - public void testGetIdMap() { - final Map<Long, Long> idMapOfFirstAccount = db.getIdMap(account.getId()); - assertEquals(3, idMapOfFirstAccount.size()); - assertEquals(Long.valueOf(1L), idMapOfFirstAccount.get(1001L)); - assertEquals(Long.valueOf(3L), idMapOfFirstAccount.get(1003L)); - assertEquals(Long.valueOf(5L), idMapOfFirstAccount.get(1005L)); - - final Map<Long, Long> idMapOfSecondAccount = db.getIdMap(secondAccount.getId()); - assertEquals(1, idMapOfSecondAccount.size()); - assertEquals(Long.valueOf(8L), idMapOfSecondAccount.get(1008L)); - } - - @Test - public void testAddAccount() throws NextcloudHttpRequestFailedException, InterruptedException { - final Account createdAccount = getOrAwaitValue(db.addAccount("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", new Capabilities("{ocs: {}}", null))); - assertEquals("https://äöüß.example.com", createdAccount.getUrl()); - assertEquals("彼得", createdAccount.getUserName()); - assertEquals("彼得@äöüß.example.com", createdAccount.getAccountName()); - } - - @Test - public void testAddNote() { - final Note localNote = new Note(null, Calendar.getInstance(), "Fancy Title", "MyContent", "Samples", false, "123"); - localNote.setId(99); - final Note createdNoteFromLocal = db.addNote(account.getId(), localNote); - assertEquals(LOCAL_EDITED, createdNoteFromLocal.getStatus()); - assertEquals("MyContent", createdNoteFromLocal.getExcerpt()); - - final Note createdNoteFromRemote = db.addNote(account.getId(), new Note(null, Calendar.getInstance(), "Fancy Title", "MyContent", "Samples", false, "123")); - assertEquals(VOID, createdNoteFromRemote.getStatus()); - assertEquals("MyContent", createdNoteFromRemote.getExcerpt()); - } - - @Test - public void updateApiVersion() { - assertThrows(IllegalArgumentException.class, () -> db.updateApiVersion(account.getId(), "")); - assertThrows(IllegalArgumentException.class, () -> db.updateApiVersion(account.getId(), "asdf")); - assertThrows(IllegalArgumentException.class, () -> db.updateApiVersion(account.getId(), "{}")); - - db.updateApiVersion(account.getId(), null); - assertNull(db.getAccountDao().getAccountById(account.getId()).getApiVersion()); - db.updateApiVersion(account.getId(), "[]"); - assertNull(db.getAccountDao().getAccountById(account.getId()).getApiVersion()); - - db.updateApiVersion(account.getId(), "[1.0]"); - assertEquals("[1.0]", db.getAccountDao().getAccountById(account.getId()).getApiVersion()); - db.updateApiVersion(account.getId(), "[0.2, 1.0]"); - assertEquals("[0.2, 1.0]", db.getAccountDao().getAccountById(account.getId()).getApiVersion()); - - // TODO is this really indented? - db.updateApiVersion(account.getId(), "[0.2, abc]"); - assertEquals("[0.2, abc]", db.getAccountDao().getAccountById(account.getId()).getApiVersion()); - } - - @Test - @Ignore("Need to find a way to stub deleteAndSync method") - public void moveNoteToAnotherAccount() throws InterruptedException { - final Note noteToMove = db.getNoteDao().getNoteById(1); - assertEquals(3, db.getNoteDao().getLocalModifiedNotes(secondAccount.getId()).size()); - final Note movedNote = getOrAwaitValue(db.moveNoteToAnotherAccount(secondAccount, noteToMove)); - assertEquals(4, db.getNoteDao().getLocalModifiedNotes(secondAccount.getId()).size()); - assertEquals(LOCAL_EDITED, movedNote.getStatus()); - // TODO assert deleteAndSync has been called - } -}
\ No newline at end of file diff --git a/app/src/test/java/it/niedermann/owncloud/notes/persistence/NotesRepositoryTest.java b/app/src/test/java/it/niedermann/owncloud/notes/persistence/NotesRepositoryTest.java new file mode 100644 index 00000000..11c58dde --- /dev/null +++ b/app/src/test/java/it/niedermann/owncloud/notes/persistence/NotesRepositoryTest.java @@ -0,0 +1,187 @@ +package it.niedermann.owncloud.notes.persistence; + +import android.content.Context; +import android.os.Build; + +import androidx.annotation.NonNull; +import androidx.arch.core.executor.testing.InstantTaskExecutorRule; +import androidx.room.Room; +import androidx.test.core.app.ApplicationProvider; + +import com.google.common.util.concurrent.MoreExecutors; +import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Map; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; + +import it.niedermann.owncloud.notes.persistence.entity.Account; +import it.niedermann.owncloud.notes.persistence.entity.Note; +import it.niedermann.owncloud.notes.shared.model.Capabilities; +import it.niedermann.owncloud.notes.shared.model.IResponseCallback; + +import static it.niedermann.owncloud.notes.persistence.NotesDatabaseTestUtil.getOrAwaitValue; +import static it.niedermann.owncloud.notes.shared.model.DBStatus.LOCAL_DELETED; +import static it.niedermann.owncloud.notes.shared.model.DBStatus.LOCAL_EDITED; +import static it.niedermann.owncloud.notes.shared.model.DBStatus.VOID; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.fail; + +@RunWith(RobolectricTestRunner.class) +@Config(sdk = {Build.VERSION_CODES.P}) +public class NotesRepositoryTest { + + @Rule + public InstantTaskExecutorRule instantTaskExecutorRule = new InstantTaskExecutorRule(); + + private NotesRepository repo = null; + private Account account = null; + private Account secondAccount = null; + private NotesDatabase db; + + @Before + public void setupDB() throws NextcloudHttpRequestFailedException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { + final Context context = ApplicationProvider.getApplicationContext(); + db = Room + .inMemoryDatabaseBuilder(ApplicationProvider.getApplicationContext(), NotesDatabase.class) + .allowMainThreadQueries() + .build(); + + final Constructor<NotesRepository> constructor = NotesRepository.class.getDeclaredConstructor(Context.class, NotesDatabase.class, ExecutorService.class); + constructor.setAccessible(true); + repo = constructor.newInstance(context, db, MoreExecutors.newDirectExecutorService()); + + repo.addAccount("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", new Capabilities("{\"ocs\":{\"meta\":{\"status\":\"ok\",\"statuscode\":200,\"message\":\"OK\"},\"data\":{\"version\":{\"major\":18,\"minor\":0,\"micro\":4,\"string\":\"18.0.4\",\"edition\":\"\",\"extendedSupport\":false},\"capabilities\":{\"core\":{\"pollinterval\":60,\"webdav-root\":\"remote.php\\/webdav\"},\"bruteforce\":{\"delay\":0},\"files\":{\"bigfilechunking\":true,\"blacklisted_files\":[\".htaccess\"],\"directEditing\":{\"url\":\"https:\\/\\/efss.qloud.my\\/ocs\\/v2.php\\/apps\\/files\\/api\\/v1\\/directEditing\",\"etag\":\"ed2b141af2a39b0e42666952ba60988d\"},\"versioning\":true,\"undelete\":true},\"activity\":{\"apiv2\":[\"filters\",\"filters-api\",\"previews\",\"rich-strings\"]},\"ocm\":{\"enabled\":true,\"apiVersion\":\"1.0-proposal1\",\"endPoint\":\"https:\\/\\/efss.qloud.my\\/index.php\\/ocm\",\"resourceTypes\":[{\"name\":\"file\",\"shareTypes\":[\"user\",\"group\"],\"protocols\":{\"webdav\":\"\\/public.php\\/webdav\\/\"}}]},\"deck\":{\"version\":\"0.8.2\"},\"richdocuments\":{\"mimetypes\":[\"application\\/vnd.oasis.opendocument.text\",\"application\\/vnd.oasis.opendocument.spreadsheet\",\"application\\/vnd.oasis.opendocument.graphics\",\"application\\/vnd.oasis.opendocument.presentation\",\"application\\/vnd.lotus-wordpro\",\"application\\/vnd.visio\",\"application\\/vnd.wordperfect\",\"application\\/msonenote\",\"application\\/msword\",\"application\\/rtf\",\"text\\/rtf\",\"application\\/vnd.openxmlformats-officedocument.wordprocessingml.document\",\"application\\/vnd.openxmlformats-officedocument.wordprocessingml.template\",\"application\\/vnd.ms-word.document.macroEnabled.12\",\"application\\/vnd.ms-word.template.macroEnabled.12\",\"application\\/vnd.ms-excel\",\"application\\/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\"application\\/vnd.openxmlformats-officedocument.spreadsheetml.template\",\"application\\/vnd.ms-excel.sheet.macroEnabled.12\",\"application\\/vnd.ms-excel.template.macroEnabled.12\",\"application\\/vnd.ms-excel.addin.macroEnabled.12\",\"application\\/vnd.ms-excel.sheet.binary.macroEnabled.12\",\"application\\/vnd.ms-powerpoint\",\"application\\/vnd.openxmlformats-officedocument.presentationml.presentation\",\"application\\/vnd.openxmlformats-officedocument.presentationml.template\",\"application\\/vnd.openxmlformats-officedocument.presentationml.slideshow\",\"application\\/vnd.ms-powerpoint.addin.macroEnabled.12\",\"application\\/vnd.ms-powerpoint.presentation.macroEnabled.12\",\"application\\/vnd.ms-powerpoint.template.macroEnabled.12\",\"application\\/vnd.ms-powerpoint.slideshow.macroEnabled.12\",\"text\\/csv\"],\"mimetypesNoDefaultOpen\":[\"image\\/svg+xml\",\"application\\/pdf\",\"text\\/plain\",\"text\\/spreadsheet\"],\"collabora\":[],\"direct_editing\":false,\"templates\":false,\"productName\":\"\\u5728\\u7ebf\\u534f\\u4f5c\"},\"dav\":{\"chunking\":\"1.0\"},\"files_sharing\":{\"api_enabled\":true,\"public\":{\"enabled\":true,\"password\":{\"enforced\":true,\"askForOptionalPassword\":false},\"expire_date\":{\"enabled\":true,\"days\":\"7\",\"enforced\":false},\"multiple_links\":true,\"expire_date_internal\":{\"enabled\":false},\"send_mail\":false,\"upload\":true,\"upload_files_drop\":true},\"resharing\":true,\"user\":{\"send_mail\":false,\"expire_date\":{\"enabled\":true}},\"group_sharing\":true,\"group\":{\"enabled\":true,\"expire_date\":{\"enabled\":true}},\"default_permissions\":31,\"federation\":{\"outgoing\":false,\"incoming\":false,\"expire_date\":{\"enabled\":true}},\"sharee\":{\"query_lookup_default\":false},\"sharebymail\":{\"enabled\":true,\"upload_files_drop\":{\"enabled\":true},\"password\":{\"enabled\":true},\"expire_date\":{\"enabled\":true}}},\"external\":{\"v1\":[\"sites\",\"device\",\"groups\",\"redirect\"]},\"notifications\":{\"ocs-endpoints\":[\"list\",\"get\",\"delete\",\"delete-all\",\"icons\",\"rich-strings\",\"action-web\"],\"push\":[\"devices\",\"object-data\",\"delete\"],\"admin-notifications\":[\"ocs\",\"cli\"]},\"password_policy\":{\"minLength\":8,\"enforceNonCommonPassword\":true,\"enforceNumericCharacters\":false,\"enforceSpecialCharacters\":false,\"enforceUpperLowerCase\":false,\"api\":{\"generate\":\"https:\\/\\/efss.qloud.my\\/ocs\\/v2.php\\/apps\\/password_policy\\/api\\/v1\\/generate\",\"validate\":\"https:\\/\\/efss.qloud.my\\/ocs\\/v2.php\\/apps\\/password_policy\\/api\\/v1\\/validate\"}},\"theming\":{\"name\":\"QloudData\",\"url\":\"https:\\/\\/www.qloud.my\\/qloud-data\\/\",\"slogan\":\"Powered by NextCloud\",\"color\":\"#1E4164\",\"color-text\":\"#ffffff\",\"color-element\":\"#1E4164\",\"logo\":\"https:\\/\\/efss.qloud.my\\/index.php\\/apps\\/theming\\/image\\/logo?useSvg=1&v=47\",\"background\":\"https:\\/\\/efss.qloud.my\\/core\\/img\\/background.png?v=47\",\"background-plain\":false,\"background-default\":true,\"logoheader\":\"https:\\/\\/efss.qloud.my\\/index.php\\/apps\\/theming\\/image\\/logo?useSvg=1&v=47\",\"favicon\":\"https:\\/\\/efss.qloud.my\\/index.php\\/apps\\/theming\\/image\\/logo?useSvg=1&v=47\"},\"registration\":{\"enabled\":true,\"apiRoot\":\"\\/ocs\\/v2.php\\/apps\\/registration\\/api\\/v1\\/\",\"apiLevel\":\"v1\"}}}}}", null), new IResponseCallback<Account>() { + @Override + public void onSuccess(Account result) { + + } + + @Override + public void onError(@NonNull Throwable t) { + fail(); + } + }); + account = repo.getAccountByName("彼得@äöüß.example.com"); + + repo.addAccount("https://example.org", "test", "test@example.org", new Capabilities("{ocs: {}}", null), new IResponseCallback<Account>() { + @Override + public void onSuccess(Account result) { + + } + + @Override + public void onError(@NonNull Throwable t) { + fail(); + } + }); + secondAccount = repo.getAccountByName("test@example.org"); + + Arrays.stream(new Note[]{ + new Note(1, 1001L, Calendar.getInstance(), "美好的一天", "C", "Movies", false, null, VOID, account.getId(), "", 0), + new Note(2, null, Calendar.getInstance(), "T", "C", "Movies", false, null, LOCAL_EDITED, account.getId(), "", 0), + new Note(3, 1003L, Calendar.getInstance(), "美好的一天", "C", "Movies", false, null, LOCAL_EDITED, account.getId(), "", 0), + new Note(4, null, Calendar.getInstance(), "T", "C", "Music", false, null, VOID, account.getId(), "", 0), + new Note(5, 1005L, Calendar.getInstance(), "美好的一天", "C", " 兄弟,这真是美好的一天。", false, null, LOCAL_EDITED, account.getId(), "", 0), + new Note(6, 1006L, Calendar.getInstance(), "美好的一天", "C", " 兄弟,这真是美好的一天。", false, null, LOCAL_DELETED, account.getId(), "", 0), + new Note(7, null, Calendar.getInstance(), "T", "C", "Music", true, null, LOCAL_EDITED, secondAccount.getId(), "", 0), + new Note(8, 1008L, Calendar.getInstance(), "美好的一天", "C", "ToDo", true, null, LOCAL_EDITED, secondAccount.getId(), "", 0), + new Note(9, 1009L, Calendar.getInstance(), "美好的一天", "C", "ToDo", true, null, LOCAL_DELETED, secondAccount.getId(), "", 0) + }).forEach(note -> db.getNoteDao().addNote(note)); + } + + @After + public void closeDb() { + db.close(); + } + + @Test + public void testGetIdMap() { + final Map<Long, Long> idMapOfFirstAccount = repo.getIdMap(account.getId()); + assertEquals(3, idMapOfFirstAccount.size()); + assertEquals(Long.valueOf(1L), idMapOfFirstAccount.get(1001L)); + assertEquals(Long.valueOf(3L), idMapOfFirstAccount.get(1003L)); + assertEquals(Long.valueOf(5L), idMapOfFirstAccount.get(1005L)); + + final Map<Long, Long> idMapOfSecondAccount = repo.getIdMap(secondAccount.getId()); + assertEquals(1, idMapOfSecondAccount.size()); + assertEquals(Long.valueOf(8L), idMapOfSecondAccount.get(1008L)); + } + + @Test + public void testAddAccount() throws NextcloudHttpRequestFailedException, InterruptedException { + repo.addAccount("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", new Capabilities("{ocs: {}}", null), new IResponseCallback<Account>() { + @Override + public void onSuccess(Account createdAccount) { + assertEquals("https://äöüß.example.com", createdAccount.getUrl()); + assertEquals("彼得", createdAccount.getUserName()); + assertEquals("彼得@äöüß.example.com", createdAccount.getAccountName()); + } + + @Override + public void onError(@NonNull Throwable t) { + fail(); + } + }); + } + + @Test + public void testAddNote() { + final Note localNote = new Note(null, Calendar.getInstance(), "Fancy Title", "MyContent", "Samples", false, "123"); + localNote.setId(99); + final Note createdNoteFromLocal = repo.addNote(account.getId(), localNote); + assertEquals(LOCAL_EDITED, createdNoteFromLocal.getStatus()); + assertEquals("MyContent", createdNoteFromLocal.getExcerpt()); + + final Note createdNoteFromRemote = repo.addNote(account.getId(), new Note(null, Calendar.getInstance(), "Fancy Title", "MyContent", "Samples", false, "123")); + assertEquals(VOID, createdNoteFromRemote.getStatus()); + assertEquals("MyContent", createdNoteFromRemote.getExcerpt()); + } + + @Test + public void updateApiVersion() { + assertThrows(IllegalArgumentException.class, () -> repo.updateApiVersion(account.getId(), "")); + assertThrows(IllegalArgumentException.class, () -> repo.updateApiVersion(account.getId(), "asdf")); + assertThrows(IllegalArgumentException.class, () -> repo.updateApiVersion(account.getId(), "{}")); + + repo.updateApiVersion(account.getId(), null); + assertNull(repo.getAccountById(account.getId()).getApiVersion()); + repo.updateApiVersion(account.getId(), "[]"); + assertNull(repo.getAccountById(account.getId()).getApiVersion()); + + repo.updateApiVersion(account.getId(), "[1.0]"); + assertEquals("[1.0]", repo.getAccountById(account.getId()).getApiVersion()); + repo.updateApiVersion(account.getId(), "[0.2, 1.0]"); + assertEquals("[0.2, 1.0]", repo.getAccountById(account.getId()).getApiVersion()); + + // TODO is this really indented? + repo.updateApiVersion(account.getId(), "[0.2, abc]"); + assertEquals("[0.2, abc]", repo.getAccountById(account.getId()).getApiVersion()); + } + + @Test + @Ignore("Need to find a way to stub deleteAndSync method") + public void moveNoteToAnotherAccount() throws InterruptedException { + final Note noteToMove = repo.getNoteById(1); + assertEquals(3, repo.getLocalModifiedNotes(secondAccount.getId()).size()); + final Note movedNote = getOrAwaitValue(repo.moveNoteToAnotherAccount(secondAccount, noteToMove)); + assertEquals(4, repo.getLocalModifiedNotes(secondAccount.getId()).size()); + assertEquals(LOCAL_EDITED, movedNote.getStatus()); + // TODO assert deleteAndSync has been called + } +}
\ No newline at end of file diff --git a/app/src/test/java/it/niedermann/owncloud/notes/shared/model/CapabilitiesTest.java b/app/src/test/java/it/niedermann/owncloud/notes/shared/model/CapabilitiesTest.java index 6415bb39..5a30bd2a 100644 --- a/app/src/test/java/it/niedermann/owncloud/notes/shared/model/CapabilitiesTest.java +++ b/app/src/test/java/it/niedermann/owncloud/notes/shared/model/CapabilitiesTest.java @@ -48,8 +48,8 @@ public class CapabilitiesTest { final Capabilities capabilities = new Capabilities(response, null); assertNull(capabilities.getETag()); assertNull(capabilities.getApiVersion()); - assertEquals(Integer.valueOf(Color.parseColor("#1E4164")), capabilities.getColor()); - assertEquals(Integer.valueOf(Color.parseColor("#ffffff")), capabilities.getTextColor()); + assertEquals(Color.parseColor("#1E4164"), capabilities.getColor()); + assertEquals(Color.parseColor("#ffffff"), capabilities.getTextColor()); } @Test @@ -86,8 +86,8 @@ public class CapabilitiesTest { final Capabilities capabilities = new Capabilities(response, null); assertNull(capabilities.getETag()); assertEquals("1.0", capabilities.getApiVersion()); - assertEquals(Integer.valueOf(Color.parseColor("#1E4164")), capabilities.getColor()); - assertEquals(Integer.valueOf(Color.parseColor("#ffffff")), capabilities.getTextColor()); + assertEquals(Color.parseColor("#1E4164"), capabilities.getColor()); + assertEquals(Color.parseColor("#ffffff"), capabilities.getTextColor()); } @Test diff --git a/app/src/test/java/it/niedermann/owncloud/notes/shared/util/NoteUtilTest.java b/app/src/test/java/it/niedermann/owncloud/notes/shared/util/NoteUtilTest.java index a0e1f9c0..7a264fdd 100644 --- a/app/src/test/java/it/niedermann/owncloud/notes/shared/util/NoteUtilTest.java +++ b/app/src/test/java/it/niedermann/owncloud/notes/shared/util/NoteUtilTest.java @@ -9,6 +9,8 @@ import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; +import it.niedermann.android.markdown.MarkdownUtil; + /** * Tests the NoteUtil * Created by stefan on 06.10.15. @@ -42,6 +44,9 @@ public class NoteUtilTest extends TestCase { assertEquals("Test", NoteUtil.generateNoteTitle("Test\nFoo")); assertEquals("Test", NoteUtil.generateNoteTitle("\nTest")); assertEquals("Test", NoteUtil.generateNoteTitle("\n\nTest")); + + // https://github.com/stefan-niedermann/nextcloud-notes/issues/1104 + assertEquals("2021-03-24 - Example title", MarkdownUtil.removeMarkdown("2021-03-24 - Example title")); } @Test |