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));
}
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());
}
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());
}
});
}
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());
}
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]"));
}
Aggregations