示例#1
0
  public void testQueryEvents() {

    EventRegistry registry = EventRegistryFactory.forObjectContainer(db());

    EventRecorder recorder = new EventRecorder(fileSession().lock());

    registry.queryStarted().addListener(recorder);
    registry.queryFinished().addListener(recorder);

    Assert.areEqual(0, recorder.size());

    Query q = db().query();
    q.execute();

    Assert.areEqual(2, recorder.size());
    EventRecord e1 = recorder.get(0);
    Assert.areSame(registry.queryStarted(), e1.e);
    Assert.areSame(q, ((QueryEventArgs) e1.args).query());

    EventRecord e2 = recorder.get(1);
    Assert.areSame(registry.queryFinished(), e2.e);
    Assert.areSame(q, ((QueryEventArgs) e2.args).query());

    recorder.clear();

    registry.queryStarted().removeListener(recorder);
    registry.queryFinished().removeListener(recorder);

    db().query().execute();

    Assert.areEqual(0, recorder.size());
  }
 @Override
 protected void db4oSetupAfterStore() throws Exception {
   EventRegistryFactory.forObjectContainer(db())
       .updated()
       .addListener(
           new EventListener4<ObjectInfoEventArgs>() {
             @Override
             public void onEvent(Event4<ObjectInfoEventArgs> e, ObjectInfoEventArgs args) {
               if (doThrow) {
                 if (args.info().getObject().getClass().equals(Item.class)) {
                   throw new RuntimeException();
                 }
               }
             }
           });
 }
示例#3
0
 public void testForObjectContainerReturnsSameInstance() {
   Assert.areSame(
       EventRegistryFactory.forObjectContainer(db()),
       EventRegistryFactory.forObjectContainer(db()));
 }