Loading app/src/androidTest/java/it/niedermann/owncloud/notes/persistence/NotesDatabaseTest.java +62 −34 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package it.niedermann.owncloud.notes.persistence; import it.niedermann.owncloud.notes.model.CloudNote; import it.niedermann.owncloud.notes.model.DBNote; import it.niedermann.owncloud.notes.model.DBStatus; import it.niedermann.owncloud.notes.model.LocalAccount; import it.niedermann.owncloud.notes.model.NavigationAdapter; import it.niedermann.owncloud.notes.persistence.NotesDatabase; Loading Loading @@ -354,14 +355,28 @@ public class NotesDatabaseTest { @Test public void test_10_multiDeleteNote() { // List<NavigationAdapter.NavigationItem> cat = db.getCategories(account.getId()); // for (NavigationAdapter.NavigationItem categoryItem : cat) { // Log.i("12bTest_test_getCategories_Item", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon)); // } long thisAccountID = account.getId(); List<DBNote> notes = db.getNotes(thisAccountID); int added_size = notes.size(); // int counter = 0; Log.i("Test_10_multiDeleteNote_All_Before_Deletion", "Size: " + added_size); for (DBNote e : notes) { Log.i("Test_10_multiDeleteNote_All_Before_Deletion", e.toString()); db.deleteNote(e.getId(), e.getStatus()); // cat = db.getCategories(account.getId()); // Log.i("12aTest_test_getCategories_Item", "counter: " + ++counter); // for (NavigationAdapter.NavigationItem categoryItem : cat) { // Log.i("12aTest_test_getCategories_Item", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon)); // } } // Check if the note is deleted successfully Loading @@ -374,6 +389,7 @@ public class NotesDatabaseTest { @Test public void test_11_Chinese() { long accountID = account.getId(); CloudNote cloudNote = new CloudNote(1, Calendar.getInstance(), "美好的一天", getCurDate() + " 兄弟,这真是美好的一天。", Loading Loading @@ -451,6 +467,7 @@ public class NotesDatabaseTest { @Test public void test_12_getCategoryIdByTitle() { try { Method method = NotesDatabase.class.getDeclaredMethod("getCategoryIdByTitle", long.class, Loading Loading @@ -490,6 +507,7 @@ public class NotesDatabaseTest { @Test public void test_13_getTitleByCategoryId() { try { Method method_title_by_id = NotesDatabase.class.getDeclaredMethod("getTitleByCategoryId", long.class, int.class); method_title_by_id.setAccessible(true); Loading @@ -500,17 +518,23 @@ public class NotesDatabaseTest { int catId = (int) method_id_by_title.invoke(db, account.getId(), "Diary", true); String catTitle = (String) method_title_by_id.invoke(db, account.getId(), catId); Log.i("test_13_getTitleByCategoryId", "ID: " + catId + " Tile: " + catTitle); assertEquals("Diary", catTitle); } catch (Exception e) { fail(Arrays.toString(e.getStackTrace())); Log.e("Test_13_getTitleByCategoryId", Arrays.toString(e.getStackTrace())); } } @Test public void test_14_getCategoryIdsByTitle() { try { // long noteID = db.addNote(account.getId(), new CloudNote(1, Calendar.getInstance(), // "woc", getCurDate() + " woc nmd testing", // true, "aha", null)); Method method_ids_by_title = NotesDatabase.class.getDeclaredMethod("getCategoryIdsByTitle", long.class, String.class); method_ids_by_title.setAccessible(true); Loading @@ -518,6 +542,8 @@ public class NotesDatabaseTest { Method method_id_by_title = NotesDatabase.class.getDeclaredMethod("getCategoryIdByTitle", long.class, String.class, boolean.class); method_id_by_title.setAccessible(true); List<NavigationAdapter.NavigationItem> categories = db.getCategories(account.getId()); Log.i("Test_14_getCategoryIdsByTitle", "size: " + categories.size()); // Log.i("Test_14_getCategoryIdsByTitle", "item: "+ categories.get(0).label); String pattern = "Dia"; List<Integer> matchList = new ArrayList<>(); for (NavigationAdapter.NavigationItem categoryItem : categories) { Loading @@ -539,6 +565,8 @@ public class NotesDatabaseTest { Log.i("Test_14_getCategoryIdsByTitle", matchList.toString()); Log.i("Test_14_getCategoryIdsByTitle", testList.toString()); assertEquals(matchList.toString(), testList.toString()); // db.deleteNote(noteID, DBStatus.VOID); } catch (Exception e) { fail(Arrays.toString(e.getStackTrace())); Log.e("Test_14_getCategoryIdsByTitle", Arrays.toString(e.getStackTrace())); Loading app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +2 −0 Original line number Diff line number Diff line Loading @@ -387,6 +387,8 @@ public class NotesDatabase extends AbstractNotesDatabase { String category_accountId = String.format("%s.%s", table_category, key_account_id); // Weird problem: If I use ? instead of concat directly, there is no result in the join table // TODO: Find a way to use ? instead of concat. // TODO: a bug here // when no notes and have cat, inner join will not return this cat String rawQuery = "SELECT " + category_title + ", COUNT(*) FROM " + table_category + " INNER JOIN " + table_notes + " ON " + category_id + " = " + note_title + " WHERE " + category_accountId + " = " + accountId + " GROUP BY " + category_id; Loading Loading
app/src/androidTest/java/it/niedermann/owncloud/notes/persistence/NotesDatabaseTest.java +62 −34 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package it.niedermann.owncloud.notes.persistence; import it.niedermann.owncloud.notes.model.CloudNote; import it.niedermann.owncloud.notes.model.DBNote; import it.niedermann.owncloud.notes.model.DBStatus; import it.niedermann.owncloud.notes.model.LocalAccount; import it.niedermann.owncloud.notes.model.NavigationAdapter; import it.niedermann.owncloud.notes.persistence.NotesDatabase; Loading Loading @@ -354,14 +355,28 @@ public class NotesDatabaseTest { @Test public void test_10_multiDeleteNote() { // List<NavigationAdapter.NavigationItem> cat = db.getCategories(account.getId()); // for (NavigationAdapter.NavigationItem categoryItem : cat) { // Log.i("12bTest_test_getCategories_Item", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon)); // } long thisAccountID = account.getId(); List<DBNote> notes = db.getNotes(thisAccountID); int added_size = notes.size(); // int counter = 0; Log.i("Test_10_multiDeleteNote_All_Before_Deletion", "Size: " + added_size); for (DBNote e : notes) { Log.i("Test_10_multiDeleteNote_All_Before_Deletion", e.toString()); db.deleteNote(e.getId(), e.getStatus()); // cat = db.getCategories(account.getId()); // Log.i("12aTest_test_getCategories_Item", "counter: " + ++counter); // for (NavigationAdapter.NavigationItem categoryItem : cat) { // Log.i("12aTest_test_getCategories_Item", String.format("%s | %s | %d | %d", categoryItem.id, categoryItem.label, categoryItem.count, categoryItem.icon)); // } } // Check if the note is deleted successfully Loading @@ -374,6 +389,7 @@ public class NotesDatabaseTest { @Test public void test_11_Chinese() { long accountID = account.getId(); CloudNote cloudNote = new CloudNote(1, Calendar.getInstance(), "美好的一天", getCurDate() + " 兄弟,这真是美好的一天。", Loading Loading @@ -451,6 +467,7 @@ public class NotesDatabaseTest { @Test public void test_12_getCategoryIdByTitle() { try { Method method = NotesDatabase.class.getDeclaredMethod("getCategoryIdByTitle", long.class, Loading Loading @@ -490,6 +507,7 @@ public class NotesDatabaseTest { @Test public void test_13_getTitleByCategoryId() { try { Method method_title_by_id = NotesDatabase.class.getDeclaredMethod("getTitleByCategoryId", long.class, int.class); method_title_by_id.setAccessible(true); Loading @@ -500,17 +518,23 @@ public class NotesDatabaseTest { int catId = (int) method_id_by_title.invoke(db, account.getId(), "Diary", true); String catTitle = (String) method_title_by_id.invoke(db, account.getId(), catId); Log.i("test_13_getTitleByCategoryId", "ID: " + catId + " Tile: " + catTitle); assertEquals("Diary", catTitle); } catch (Exception e) { fail(Arrays.toString(e.getStackTrace())); Log.e("Test_13_getTitleByCategoryId", Arrays.toString(e.getStackTrace())); } } @Test public void test_14_getCategoryIdsByTitle() { try { // long noteID = db.addNote(account.getId(), new CloudNote(1, Calendar.getInstance(), // "woc", getCurDate() + " woc nmd testing", // true, "aha", null)); Method method_ids_by_title = NotesDatabase.class.getDeclaredMethod("getCategoryIdsByTitle", long.class, String.class); method_ids_by_title.setAccessible(true); Loading @@ -518,6 +542,8 @@ public class NotesDatabaseTest { Method method_id_by_title = NotesDatabase.class.getDeclaredMethod("getCategoryIdByTitle", long.class, String.class, boolean.class); method_id_by_title.setAccessible(true); List<NavigationAdapter.NavigationItem> categories = db.getCategories(account.getId()); Log.i("Test_14_getCategoryIdsByTitle", "size: " + categories.size()); // Log.i("Test_14_getCategoryIdsByTitle", "item: "+ categories.get(0).label); String pattern = "Dia"; List<Integer> matchList = new ArrayList<>(); for (NavigationAdapter.NavigationItem categoryItem : categories) { Loading @@ -539,6 +565,8 @@ public class NotesDatabaseTest { Log.i("Test_14_getCategoryIdsByTitle", matchList.toString()); Log.i("Test_14_getCategoryIdsByTitle", testList.toString()); assertEquals(matchList.toString(), testList.toString()); // db.deleteNote(noteID, DBStatus.VOID); } catch (Exception e) { fail(Arrays.toString(e.getStackTrace())); Log.e("Test_14_getCategoryIdsByTitle", Arrays.toString(e.getStackTrace())); Loading
app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java +2 −0 Original line number Diff line number Diff line Loading @@ -387,6 +387,8 @@ public class NotesDatabase extends AbstractNotesDatabase { String category_accountId = String.format("%s.%s", table_category, key_account_id); // Weird problem: If I use ? instead of concat directly, there is no result in the join table // TODO: Find a way to use ? instead of concat. // TODO: a bug here // when no notes and have cat, inner join will not return this cat String rawQuery = "SELECT " + category_title + ", COUNT(*) FROM " + table_category + " INNER JOIN " + table_notes + " ON " + category_id + " = " + note_title + " WHERE " + category_accountId + " = " + accountId + " GROUP BY " + category_id; Loading