Search in sources :

Example 1 with Capabilities

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

the class CapabilitiesClientTest method testGetCapabilities.

@Test
public void testGetCapabilities() throws Throwable {
    // noinspection unchecked
    final ParsedResponse<OcsResponse<Capabilities>> responseMock = mock(ParsedResponse.class);
    final OcsResponse<Capabilities> mockOcs = new OcsResponse<>();
    mockOcs.ocs = new OcsResponse.OcsWrapper<>();
    mockOcs.ocs.data = new Capabilities();
    mockOcs.ocs.data.setApiVersion("[1.0]");
    when(responseMock.getResponse()).thenReturn(mockOcs);
    when(responseMock.getHeaders()).thenReturn(Map.of("ETag", "1234"));
    when(ocsAPI.getCapabilities(any())).thenReturn(Observable.just(responseMock));
    final var capabilities = CapabilitiesClient.getCapabilities(ApplicationProvider.getApplicationContext(), ssoAccount, null, apiProvider);
    assertEquals("[1.0]", capabilities.getApiVersion());
    assertEquals("ETag should be read correctly from response but wasn't.", "1234", capabilities.getETag());
    when(ocsAPI.getCapabilities(any())).thenReturn(Observable.error(new RuntimeException()));
    assertThrows(RuntimeException.class, () -> CapabilitiesClient.getCapabilities(ApplicationProvider.getApplicationContext(), ssoAccount, null, apiProvider));
    when(ocsAPI.getCapabilities(any())).thenReturn(Observable.error(new RuntimeException(new NetworkErrorException())));
    assertThrows("Should unwrap exception cause if possible", NetworkErrorException.class, () -> CapabilitiesClient.getCapabilities(ApplicationProvider.getApplicationContext(), ssoAccount, null, apiProvider));
}
Also used : NetworkErrorException(android.accounts.NetworkErrorException) Capabilities(it.niedermann.owncloud.notes.shared.model.Capabilities) OcsResponse(it.niedermann.owncloud.notes.shared.model.OcsResponse) Test(org.junit.Test)

Example 2 with Capabilities

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

the class NotesRepositoryTest 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());
    repo.updateDisplayName(account.getId(), "");
    assertEquals("Should properly update the displayName, even if it is blank", "", db.getAccountDao().getAccountById(account.getId()).getDisplayName());
    repo.updateDisplayName(account.getId(), "Foo Bar");
    assertEquals("Foo Bar", db.getAccountDao().getAccountById(account.getId()).getDisplayName());
    repo.updateDisplayName(account.getId(), null);
    assertEquals("Should read userName in favor of displayName if displayName is NULL", "彼得", db.getAccountDao().getAccountById(account.getId()).getDisplayName());
}
Also used : SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) Account(it.niedermann.owncloud.notes.persistence.entity.Account) Capabilities(it.niedermann.owncloud.notes.shared.model.Capabilities) Test(org.junit.Test)

Example 3 with Capabilities

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

the class NotesRepositoryTest method testAddAccount.

@Test
public void testAddAccount() throws IOException {
    NotesTestingUtil.mockSingleSignOn(new SingleSignOnAccount("彼得@äöüß.example.com", "彼得", "1337", "https://äöüß.example.com", ""));
    repo.addAccount("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", new Capabilities(), "", new IResponseCallback<>() {

        @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(t.getMessage());
        }
    });
}
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) Test(org.junit.Test)

Example 4 with Capabilities

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

the class AccountDaoTest method insertAccount.

@Test
public void insertAccount() {
    final long createdId = db.getAccountDao().insert(new Account("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", null, new Capabilities()));
    final var createdAccount = db.getAccountDao().getAccountById(createdId);
    assertEquals("https://äöüß.example.com", createdAccount.getUrl());
    assertEquals("彼得", createdAccount.getUserName());
    assertEquals("彼得@äöüß.example.com", createdAccount.getAccountName());
}
Also used : Account(it.niedermann.owncloud.notes.persistence.entity.Account) Capabilities(it.niedermann.owncloud.notes.shared.model.Capabilities) Test(org.junit.Test)

Example 5 with Capabilities

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

the class AccountDaoTest method updateApiVersionFromNull.

@Test
public void updateApiVersionFromNull() {
    final var account = db.getAccountDao().getAccountById(db.getAccountDao().insert(new Account("https://äöüß.example.com", "彼得", "彼得@äöüß.example.com", null, new Capabilities())));
    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]"));
}
Also used : Account(it.niedermann.owncloud.notes.persistence.entity.Account) Capabilities(it.niedermann.owncloud.notes.shared.model.Capabilities) Test(org.junit.Test)

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