Search in sources :

Example 1 with SingleSignOnAccount

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;
    }
}
Also used : NextcloudAPI(com.nextcloud.android.sso.api.NextcloudAPI) Context(android.content.Context) NotesAPI(it.niedermann.owncloud.notes.persistence.sync.NotesAPI) NonNull(androidx.annotation.NonNull) NextcloudRetrofitApiBuilder(retrofit2.NextcloudRetrofitApiBuilder) Capabilities(it.niedermann.owncloud.notes.shared.model.Capabilities) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WorkerThread(androidx.annotation.WorkerThread) JsonSerializer(com.google.gson.JsonSerializer) CapabilitiesDeserializer(it.niedermann.owncloud.notes.persistence.sync.CapabilitiesDeserializer) GsonBuilder(com.google.gson.GsonBuilder) Retrofit(retrofit2.Retrofit) Nullable(androidx.annotation.Nullable) Calendar(java.util.Calendar) OcsAPI(it.niedermann.owncloud.notes.persistence.sync.OcsAPI) Gson(com.google.gson.Gson) Map(java.util.Map) JsonDeserializer(com.google.gson.JsonDeserializer) NextcloudAPI(com.nextcloud.android.sso.api.NextcloudAPI) SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) JsonPrimitive(com.google.gson.JsonPrimitive) ApiVersion(it.niedermann.owncloud.notes.shared.model.ApiVersion) Log(android.util.Log) GsonBuilder(com.google.gson.GsonBuilder) JsonPrimitive(com.google.gson.JsonPrimitive) Calendar(java.util.Calendar) CapabilitiesDeserializer(it.niedermann.owncloud.notes.persistence.sync.CapabilitiesDeserializer) JsonDeserializer(com.google.gson.JsonDeserializer)

Example 2 with SingleSignOnAccount

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", "");
}
Also used : SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) Before(org.junit.Before)

Example 3 with SingleSignOnAccount

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) {
        }
    };
}
Also used : SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) SyncResultStatus(it.niedermann.owncloud.notes.shared.model.SyncResultStatus) Before(org.junit.Before)

Example 4 with SingleSignOnAccount

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());
        }
    });
}
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 5 with SingleSignOnAccount

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()));
}
Also used : SingleSignOnAccount(com.nextcloud.android.sso.model.SingleSignOnAccount) Test(org.junit.Test)

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