use of com.nextcloud.android.sso.model.SingleSignOnAccount in project nextcloud-notes by stefan-niedermann.
the class ApiProvider method getNextcloudAPI.
private synchronized NextcloudAPI getNextcloudAPI(@NonNull Context context, @NonNull SingleSignOnAccount ssoAccount) {
if (API_CACHE.containsKey(ssoAccount.name)) {
return API_CACHE.get(ssoAccount.name);
} else {
Log.v(TAG, "NextcloudRequest account: " + ssoAccount.name);
final var nextcloudAPI = new NextcloudAPI(context.getApplicationContext(), ssoAccount, new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeHierarchyAdapter(Calendar.class, (JsonSerializer<Calendar>) (src, typeOfSrc, ctx) -> new JsonPrimitive(src.getTimeInMillis() / 1_000)).registerTypeHierarchyAdapter(Calendar.class, (JsonDeserializer<Calendar>) (src, typeOfSrc, ctx) -> {
final var calendar = Calendar.getInstance();
calendar.setTimeInMillis(src.getAsLong() * 1_000);
return calendar;
}).registerTypeAdapter(Capabilities.class, new CapabilitiesDeserializer()).create(), (e) -> {
invalidateAPICache(ssoAccount);
e.printStackTrace();
});
API_CACHE.put(ssoAccount.name, nextcloudAPI);
return nextcloudAPI;
}
}
use of com.nextcloud.android.sso.model.SingleSignOnAccount in project nextcloud-notes by stefan-niedermann.
the class ApiProviderTest method setup.
@Before
public void setup() {
apiProvider = ApiProvider.getInstance();
ssoAccount = new SingleSignOnAccount("one", "eins", "1", "example.com", "");
secondSsoAccount = new SingleSignOnAccount("two", "zwei", "2", "example.org", "");
}
use of com.nextcloud.android.sso.model.SingleSignOnAccount in project nextcloud-notes by stefan-niedermann.
the class NotesServerSyncTaskTest method setup.
@Before
public void setup() throws NextcloudFilesAppAccountNotFoundException, IOException {
when(apiProvider.getNotesAPI(any(), any(), any())).thenReturn(notesAPI);
NotesTestingUtil.mockSingleSignOn(new SingleSignOnAccount(account.getAccountName(), account.getUserName(), "", account.getUrl(), ""));
this.task = new NotesServerSyncTask(mock(Context.class), repo, account, false, apiProvider) {
@Override
void onPreExecute() {
}
@Override
void onPostExecute(SyncResultStatus status) {
}
};
}
use of com.nextcloud.android.sso.model.SingleSignOnAccount 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 com.nextcloud.android.sso.model.SingleSignOnAccount in project nextcloud-notes by stefan-niedermann.
the class NotesRepositoryTest method testDeleteAccount.
@Test
public void testDeleteAccount() throws IOException {
NotesTestingUtil.mockSingleSignOn(new SingleSignOnAccount(account.getAccountName(), account.getUserName(), "1337", account.getUrl(), ""));
assertNotNull(repo.getAccountById(account.getId()));
repo.deleteAccount(account);
assertNull(repo.getAccountById(account.getId()));
}
Aggregations