Search in sources :

Example 6 with SingleSignOnAccount

use of com.nextcloud.android.sso.model.SingleSignOnAccount in project nextcloud-notes by stefan-niedermann.

the class NotesRepositoryTest method testSyncErrorsLiveData.

@Test
public void testSyncErrorsLiveData() throws InterruptedException, IOException {
    NotesTestingUtil.mockSingleSignOn(new SingleSignOnAccount(account.getAccountName(), account.getUserName(), "1337", account.getUrl(), ""));
    assertThrows("The very first time, this LiveData should never have been set", RuntimeException.class, () -> NotesTestingUtil.getOrAwaitValue(repo.getSyncErrors()));
    repo.scheduleSync(account, true);
    assertEquals("In our scenario, we expect 4 failed note syncs to be handled.", 4, getOrAwaitValue(repo.getSyncErrors()).size());
}
Also used : SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) Test(org.junit.Test)

Example 7 with SingleSignOnAccount

use of com.nextcloud.android.sso.model.SingleSignOnAccount in project nextcloud-notes by stefan-niedermann.

the class NotesRepositoryTest method testSyncStatusLiveData.

@Test
public void testSyncStatusLiveData() throws InterruptedException, IOException {
    NotesTestingUtil.mockSingleSignOn(new SingleSignOnAccount(account.getAccountName(), account.getUserName(), "1337", account.getUrl(), ""));
    assertFalse(NotesTestingUtil.getOrAwaitValue(repo.getSyncStatus()));
    repo.addCallbackPull(account, () -> {
        try {
            assertTrue(NotesTestingUtil.getOrAwaitValue(repo.getSyncStatus()));
        } catch (InterruptedException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    });
    repo.scheduleSync(account, false);
    assertFalse(NotesTestingUtil.getOrAwaitValue(repo.getSyncStatus()));
}
Also used : SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) Test(org.junit.Test)

Example 8 with SingleSignOnAccount

use of com.nextcloud.android.sso.model.SingleSignOnAccount 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)

Aggregations

SingleSignOnAccount (com.nextcloud.android.sso.model.SingleSignOnAccount)8 Test (org.junit.Test)4 Capabilities (it.niedermann.owncloud.notes.shared.model.Capabilities)3 Before (org.junit.Before)3 Account (it.niedermann.owncloud.notes.persistence.entity.Account)2 Context (android.content.Context)1 Log (android.util.Log)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 WorkerThread (androidx.annotation.WorkerThread)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonDeserializer (com.google.gson.JsonDeserializer)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 JsonSerializer (com.google.gson.JsonSerializer)1 NextcloudAPI (com.nextcloud.android.sso.api.NextcloudAPI)1 Note (it.niedermann.owncloud.notes.persistence.entity.Note)1 CapabilitiesDeserializer (it.niedermann.owncloud.notes.persistence.sync.CapabilitiesDeserializer)1 NotesAPI (it.niedermann.owncloud.notes.persistence.sync.NotesAPI)1 OcsAPI (it.niedermann.owncloud.notes.persistence.sync.OcsAPI)1