コード例 #1
0
 @Override
 protected void setUp() throws InterruptedException {
   RealmConfiguration realmConfig = new RealmConfiguration.Builder(getContext()).build();
   Realm.deleteRealm(realmConfig);
   testRealm = Realm.getInstance(realmConfig);
   populateTestRealm();
 }
コード例 #2
0
  protected void setUp() throws Exception {
    super.setUp();
    Realm.deleteRealmFile(getContext());
    testRealm = Realm.getInstance(getContext());

    testRealm.beginTransaction();
    for (int i = 0; i < TEST_DATA_SIZE; ++i) {
      AllTypes allTypes = testRealm.createObject(AllTypes.class);
      allTypes.setColumnString("test data " + i);
    }
    testRealm.commitTransaction();
  }
コード例 #3
0
ファイル: RealmConfig.java プロジェクト: winsx/Payara
  public static void createRealms(String defaultRealm, List<AuthRealm> realms, String configName) {
    assert (realms != null);

    String goodRealm = null; // need at least one good realm

    for (AuthRealm aRealm : realms) {
      String realmName = aRealm.getName();
      String realmClass = aRealm.getClassname();
      assert (realmName != null);
      assert (realmClass != null);

      try {
        List<Property> realmProps = aRealm.getProperty();
        /*V3 Commented ElementProperty[] realmProps =
        aRealm.getElementProperty();*/
        Properties props = new Properties();
        for (Property realmProp : realmProps) {
          props.setProperty(realmProp.getName(), realmProp.getValue());
        }
        Realm.instantiate(realmName, realmClass, props, configName);
        if (logger.isLoggable(Level.FINE)) {
          logger.fine("Configured realm: " + realmName);
        }

        if (goodRealm == null) {
          goodRealm = realmName;
        }
      } catch (Exception e) {
        logger.log(Level.WARNING, SecurityLoggerInfo.realmConfigDisabledError, realmName);
        logger.log(Level.WARNING, SecurityLoggerInfo.securityExceptionError, e);
      }
    }

    // done loading all realms, check that there is at least one
    // in place and that default is installed, or change default
    // to the first one loaded (arbitrarily).

    if (goodRealm == null) {
      logger.severe(SecurityLoggerInfo.noRealmsError);

    } else {
      try {
        Realm.getInstance(defaultRealm);
      } catch (Exception e) {
        defaultRealm = goodRealm;
      }
      Realm.setDefaultRealm(defaultRealm);
      if (logger.isLoggable(Level.FINE)) {
        logger.fine("Default realm is set to: " + defaultRealm);
      }
    }
  }
コード例 #4
0
  public void testContainsDoesNotContainAnItem() {
    RealmConfiguration realmConfig =
        TestHelper.createConfiguration(getContext(), "contains_test.realm");
    Realm.deleteRealm(realmConfig);
    Realm testRealmTwo = Realm.getInstance(realmConfig);
    try {

      testRealmTwo.beginTransaction();
      testRealmTwo.allObjects(AllTypes.class).clear();
      testRealmTwo.allObjects(NonLatinFieldNames.class).clear();

      for (int i = 0; i < TEST_DATA_SIZE; ++i) {
        AllTypes allTypes = testRealmTwo.createObject(AllTypes.class);
        allTypes.setColumnBoolean((i % 2) == 0);
        allTypes.setColumnBinary(new byte[] {1, 2, 3});
        allTypes.setColumnDate(new Date(YEAR_MILLIS * (i - TEST_DATA_SIZE / 2)));
        allTypes.setColumnDouble(3.1415 + i);
        allTypes.setColumnFloat(1.234567f + i);
        allTypes.setColumnString("test data " + i);
        allTypes.setColumnLong(i);
        Dog d = testRealmTwo.createObject(Dog.class);
        d.setName("Foo " + i);
        allTypes.setColumnRealmObject(d);
        allTypes.getColumnRealmList().add(d);
        NonLatinFieldNames nonLatinFieldNames = testRealmTwo.createObject(NonLatinFieldNames.class);
        nonLatinFieldNames.set델타(i);
        nonLatinFieldNames.setΔέλτα(i);
      }
      testRealmTwo.commitTransaction();

      final AllTypes item = testRealmTwo.where(AllTypes.class).findFirst();

      assertFalse(
          "Should not be able to find one object in another Realm via RealmResults#contains",
          testRealm.where(AllTypes.class).findAll().contains(item));

    } finally {
      if (testRealmTwo != null && !testRealmTwo.isClosed()) {
        testRealmTwo.close();
      }
    }
  }