Search in sources :

Example 6 with Capabilities

use of it.niedermann.owncloud.notes.shared.model.Capabilities in project nextcloud-notes by stefan-niedermann.

the class AccountDaoTest method updateDisplayName.

@Test
public void updateDisplayName() {
    final var account = db.getAccountDao().getAccountById(db.getAccountDao().insert(new Account("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", null, new Capabilities())));
    assertEquals("Should read userName in favor of displayName if displayName is NULL", "彼得", account.getDisplayName());
    db.getAccountDao().updateDisplayName(account.getId(), "");
    assertEquals("Should properly update the displayName, even if it is blank", "", db.getAccountDao().getAccountById(account.getId()).getDisplayName());
    db.getAccountDao().updateDisplayName(account.getId(), "Foo Bar");
    assertEquals("Foo Bar", db.getAccountDao().getAccountById(account.getId()).getDisplayName());
    db.getAccountDao().updateDisplayName(account.getId(), null);
    assertEquals("Should read userName in favor of displayName if displayName is NULL", "彼得", db.getAccountDao().getAccountById(account.getId()).getDisplayName());
}
Also used : Account(it.niedermann.owncloud.notes.persistence.entity.Account) Capabilities(it.niedermann.owncloud.notes.shared.model.Capabilities) Test(org.junit.Test)

Example 7 with Capabilities

use of it.niedermann.owncloud.notes.shared.model.Capabilities in project nextcloud-notes by stefan-niedermann.

the class NotesRepositoryTest method setupDB.

@Before
public void setupDB() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, IOException {
    final var context = ApplicationProvider.getApplicationContext();
    db = Room.inMemoryDatabaseBuilder(ApplicationProvider.getApplicationContext(), NotesDatabase.class).allowMainThreadQueries().build();
    final var constructor = NotesRepository.class.getDeclaredConstructor(Context.class, NotesDatabase.class, ExecutorService.class, ExecutorService.class, ExecutorService.class, ApiProvider.class);
    constructor.setAccessible(true);
    final var executor = MoreExecutors.newDirectExecutorService();
    final var apiProviderSpy = mock(ApiProvider.class);
    final var notesApiSpy = mock(NotesAPI.class);
    repo = constructor.newInstance(context, db, executor, executor, executor, apiProviderSpy);
    doReturn(notesApiSpy).when(apiProviderSpy).getNotesAPI(any(), any(), any());
    when(notesApiSpy.getNotesIDs()).thenReturn(Observable.just(Collections.emptyList()));
    when(notesApiSpy.getNote(anyLong())).thenReturn(Observable.just(ParsedResponse.of(new Note())));
    NotesTestingUtil.mockSingleSignOn(new SingleSignOnAccount("彼得@äöüß.example.com", "彼得", "1337", "https://äöüß.example.com", ""));
    repo.addAccount("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", new Capabilities(), null, new IResponseCallback<>() {

        @Override
        public void onSuccess(Account result) {
        }

        @Override
        public void onError(@NonNull Throwable t) {
            fail(t.getMessage());
        }
    });
    account = repo.getAccountByName("彼得@äöüß.example.com");
    NotesTestingUtil.mockSingleSignOn(new SingleSignOnAccount("test@example.org", "test", "1337", "https://example.org", ""));
    repo.addAccount("https://example.org", "test", "test@example.org", new Capabilities(), "Herbert", new IResponseCallback<>() {

        @Override
        public void onSuccess(Account result) {
        }

        @Override
        public void onError(@NonNull Throwable t) {
            fail(t.getMessage());
        }
    });
    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));
}
Also used : SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) Account(it.niedermann.owncloud.notes.persistence.entity.Account) Capabilities(it.niedermann.owncloud.notes.shared.model.Capabilities) Note(it.niedermann.owncloud.notes.persistence.entity.Note) Before(org.junit.Before)

Example 8 with Capabilities

use of it.niedermann.owncloud.notes.shared.model.Capabilities in project nextcloud-notes by stefan-niedermann.

the class NotesDaoTest method setupDB.

@Before
public void setupDB() {
    db = Room.inMemoryDatabaseBuilder(ApplicationProvider.getApplicationContext(), NotesDatabase.class).allowMainThreadQueries().build();
    db.getAccountDao().insert(new Account("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", null, new Capabilities()));
    account = db.getAccountDao().getAccountByName("彼得@äöüß.example.com");
}
Also used : Account(it.niedermann.owncloud.notes.persistence.entity.Account) Capabilities(it.niedermann.owncloud.notes.shared.model.Capabilities) Before(org.junit.Before)

Aggregations

Capabilities (it.niedermann.owncloud.notes.shared.model.Capabilities)8 Account (it.niedermann.owncloud.notes.persistence.entity.Account)7 Test (org.junit.Test)6 SingleSignOnAccount (com.nextcloud.android.sso.model.SingleSignOnAccount)3 Before (org.junit.Before)2 NetworkErrorException (android.accounts.NetworkErrorException)1 Note (it.niedermann.owncloud.notes.persistence.entity.Note)1 OcsResponse (it.niedermann.owncloud.notes.shared.model.OcsResponse)1