Search in sources :

Example 6 with StringOnly

use of io.realm.entities.StringOnly in project realm-java by realm.

the class SyncConfigurationTests method initialData.

/* FIXME: deleteRealmOnLogout is not supported by now
    @Test
    public void deleteOnLogout() {
        User user = createTestUser();
        String url = "realm://objectserver.realm.io/default";

        SyncConfiguration config = new SyncConfiguration.Builder(user, url)
                .deleteRealmOnLogout()
                .build();
        assertTrue(config.shouldDeleteRealmOnLogout());
    }
    */
@Test
public void initialData() {
    SyncUser user = createTestUser();
    String url = "realm://objectserver.realm.io/default";
    SyncConfiguration config = configFactory.createSyncConfigurationBuilder(user, url).schema(StringOnly.class).initialData(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            StringOnly stringOnly = realm.createObject(StringOnly.class);
            stringOnly.setChars("TEST 42");
        }
    }).build();
    assertNotNull(config.getInitialDataTransaction());
    // open the first time - initialData must be triggered
    Realm realm1 = Realm.getInstance(config);
    RealmResults<StringOnly> results = realm1.where(StringOnly.class).findAll();
    assertEquals(1, results.size());
    assertEquals("TEST 42", results.first().getChars());
    realm1.close();
    // open the second time - initialData must not be triggered
    Realm realm2 = Realm.getInstance(config);
    assertEquals(1, realm2.where(StringOnly.class).count());
    realm2.close();
}
Also used : StringOnly(io.realm.entities.StringOnly) Test(org.junit.Test)

Example 7 with StringOnly

use of io.realm.entities.StringOnly in project realm-java by realm.

the class RealmTests method unicodeStrings.

// This test is slow. Move it to another testsuite that runs once a day on Jenkins.
// The test writes and reads random Strings.
// @Test TODO AndroidJUnit4 runner doesn't seem to respect the @Ignore annotation?
@Ignore
public void unicodeStrings() {
    List<String> chars_array = getCharacterArray();
    // Change seed value for new random values.
    long seed = 20;
    Random random = new Random(seed);
    int random_value = 0;
    String test_char = "";
    String test_char_old = "";
    for (int i = 0; i < 1000; i++) {
        random_value = random.nextInt(25);
        for (int j = 0; j < random_value; j++) {
            test_char = test_char_old + chars_array.get(random.nextInt(27261));
            test_char_old = test_char;
        }
        realm.beginTransaction();
        StringOnly stringOnly = realm.createObject(StringOnly.class);
        stringOnly.setChars(test_char);
        realm.commitTransaction();
        realm.where(StringOnly.class).findFirst().getChars();
        realm.beginTransaction();
        realm.delete(StringOnly.class);
        realm.commitTransaction();
    }
}
Also used : StringOnly(io.realm.entities.StringOnly) Random(java.util.Random) PrimaryKeyRequiredAsString(io.realm.entities.PrimaryKeyRequiredAsString) PrimaryKeyAsString(io.realm.entities.PrimaryKeyAsString) Ignore(org.junit.Ignore)

Aggregations

StringOnly (io.realm.entities.StringOnly)7 Test (org.junit.Test)5 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)2 UiThreadTest (android.support.test.annotation.UiThreadTest)1 PrimaryKeyRequiredAsString (io.realm.entities.PrimaryKeyRequiredAsString)1 Table (io.realm.internal.Table)1 RunInLooperThread (io.realm.rule.RunInLooperThread)1 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Ignore (org.junit.Ignore)1