Search in sources :

Example 1 with SyncUser

use of io.realm.SyncUser in project realm-java by realm.

the class SendOneCommit method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    Realm.init(getApplicationContext());
    SyncUser user = UserFactory.createDefaultUser(Constants.AUTH_URL);
    String realmUrl = Constants.SYNC_SERVER_URL;
    final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user, realmUrl).name(SendOneCommit.class.getSimpleName()).build();
    Realm.deleteRealm(syncConfig);
    Realm realm = Realm.getInstance(syncConfig);
    realm.beginTransaction();
    ProcessInfo processInfo = realm.createObject(ProcessInfo.class);
    processInfo.setName("Background_Process1");
    processInfo.setPid(android.os.Process.myPid());
    processInfo.setThreadId(Thread.currentThread().getId());
    realm.commitTransaction();
    //FIXME the close may not give a chance to the sync client to process/upload the changeset
    realm.close();
}
Also used : SyncUser(io.realm.SyncUser) ProcessInfo(io.realm.objectserver.model.ProcessInfo) Realm(io.realm.Realm) SyncConfiguration(io.realm.SyncConfiguration)

Example 2 with SyncUser

use of io.realm.SyncUser in project realm-java by realm.

the class SendsALot method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    Realm.init(getApplicationContext());
    SyncUser user = UserFactory.createDefaultUser(Constants.AUTH_URL);
    String realmUrl = Constants.SYNC_SERVER_URL_2;
    final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user, realmUrl).name(SendsALot.class.getSimpleName()).build();
    Realm.deleteRealm(syncConfig);
    Realm realm = Realm.getInstance(syncConfig);
    realm.beginTransaction();
    for (int i = 0; i < 100; i++) {
        TestObject testObject = realm.createObject(TestObject.class);
        testObject.setIntProp(i);
        testObject.setStringProp("property " + i);
    }
    realm.commitTransaction();
    //FIXME the close may not give a chance to the sync client to process/upload the changeset
    realm.close();
}
Also used : SyncUser(io.realm.SyncUser) TestObject(io.realm.objectserver.model.TestObject) Realm(io.realm.Realm) SyncConfiguration(io.realm.SyncConfiguration)

Example 3 with SyncUser

use of io.realm.SyncUser in project realm-java by realm.

the class ProcessCommitTests method expectSimpleCommit.

// 1. Open a sync Realm and listen to changes.
// A. Open the same sync Realm and add one object.
// 2. Get the notification, check if the change in A is received.
@Test
@RunTestInLooperThread
@RunTestWithRemoteService(remoteService = SimpleCommitRemoteService.class, onLooperThread = true)
public void expectSimpleCommit() {
    looperThread.runAfterTest(remoteService.afterRunnable);
    remoteService.createHandler(Looper.myLooper());
    final SyncUser user = UserFactory.getInstance().createDefaultUser(Constants.AUTH_URL);
    String realmUrl = Constants.SYNC_SERVER_URL;
    final SyncConfiguration syncConfig = user.createConfiguration(realmUrl).modules(new ProcessCommitTestsModule()).directory(looperThread.getRoot()).build();
    final Realm realm = Realm.getInstance(syncConfig);
    final RealmResults<ProcessInfo> all = realm.where(ProcessInfo.class).findAll();
    looperThread.keepStrongReference(all);
    all.addChangeListener(new RealmChangeListener<RealmResults<ProcessInfo>>() {

        @Override
        public void onChange(RealmResults<ProcessInfo> element) {
            assertEquals(1, all.size());
            assertEquals("Background_Process1", all.get(0).getName());
            realm.close();
            user.logOut();
            remoteService.triggerServiceStep(SimpleCommitRemoteService.stepB_closeRealmAndLogOut);
            looperThread.testComplete();
        }
    });
    remoteService.triggerServiceStep(SimpleCommitRemoteService.stepA_openRealmAndCreateOneObject);
}
Also used : SyncUser(io.realm.SyncUser) ProcessInfo(io.realm.objectserver.model.ProcessInfo) Realm(io.realm.Realm) SyncConfiguration(io.realm.SyncConfiguration) RealmResults(io.realm.RealmResults) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread) RunTestWithRemoteService(io.realm.rule.RunTestWithRemoteService) Test(org.junit.Test) StandardIntegrationTest(io.realm.StandardIntegrationTest)

Example 4 with SyncUser

use of io.realm.SyncUser in project realm-java by realm.

the class AuthTests method loginAsync_userNotExist.

@Test
@RunTestInLooperThread
public void loginAsync_userNotExist() {
    SyncCredentials credentials = SyncCredentials.usernamePassword("IWantToHackYou", "GeneralPassword", false);
    SyncUser.loginAsync(credentials, Constants.AUTH_URL, new SyncUser.Callback() {

        @Override
        public void onSuccess(SyncUser user) {
            fail();
        }

        @Override
        public void onError(ObjectServerError error) {
            assertEquals(ErrorCode.INVALID_CREDENTIALS, error.getErrorCode());
            looperThread.testComplete();
        }
    });
}
Also used : SyncUser(io.realm.SyncUser) SyncCredentials(io.realm.SyncCredentials) ObjectServerError(io.realm.ObjectServerError) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread) Test(org.junit.Test)

Example 5 with SyncUser

use of io.realm.SyncUser in project realm-java by realm.

the class AuthTests method loginAsync_errorHandlerThrows.

// The error handler throws an exception but it is ignored (but logged). That means, this test should not
// pass and not be stopped by an IllegalArgumentException.
@Test
@RunTestInLooperThread
public void loginAsync_errorHandlerThrows() {
    // set log level to info to make sure the IllegalArgumentException
    // thrown in the test is visible in Logcat
    final int defaultLevel = RealmLog.getLevel();
    RealmLog.setLevel(LogLevel.INFO);
    SyncCredentials credentials = SyncCredentials.usernamePassword("IWantToHackYou", "GeneralPassword", false);
    SyncUser.loginAsync(credentials, Constants.AUTH_URL, new SyncUser.Callback() {

        @Override
        public void onSuccess(SyncUser user) {
            fail();
        }

        @Override
        public void onError(ObjectServerError error) {
            assertEquals(ErrorCode.INVALID_CREDENTIALS, error.getErrorCode());
            throw new IllegalArgumentException("BOOM");
        }
    });
    looperThread.postRunnableDelayed(new Runnable() {

        @Override
        public void run() {
            RealmLog.setLevel(defaultLevel);
            looperThread.testComplete();
        }
    }, 1000);
}
Also used : SyncUser(io.realm.SyncUser) SyncCredentials(io.realm.SyncCredentials) ObjectServerError(io.realm.ObjectServerError) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread) Test(org.junit.Test)

Aggregations

SyncUser (io.realm.SyncUser)11 Realm (io.realm.Realm)8 SyncConfiguration (io.realm.SyncConfiguration)8 Test (org.junit.Test)7 ObjectServerError (io.realm.ObjectServerError)6 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)6 RealmResults (io.realm.RealmResults)4 SyncCredentials (io.realm.SyncCredentials)4 ClientResetHandler (io.realm.ClientResetHandler)3 SyncSession (io.realm.SyncSession)3 ProcessInfo (io.realm.objectserver.model.ProcessInfo)3 RealmChangeListener (io.realm.RealmChangeListener)2 StandardIntegrationTest (io.realm.StandardIntegrationTest)2 TestObject (io.realm.objectserver.model.TestObject)2 RunTestWithRemoteService (io.realm.rule.RunTestWithRemoteService)2 Ignore (org.junit.Ignore)2 ProgressDialog (android.app.ProgressDialog)1 Context (android.content.Context)1 Intent (android.content.Intent)1 SecureUserStore (io.realm.android.SecureUserStore)1