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