Package com.google.web.bindery.requestfactory.shared

Examples of com.google.web.bindery.requestfactory.shared.SimpleFooRequest


  }

  public void testPersistRelation() {
    delayTestFinish(DELAY_TEST_FINISH);

    SimpleFooRequest context = simpleFooRequest();
    SimpleFooProxy rayFoo = context.create(SimpleFooProxy.class);
    final Request<SimpleFooProxy> persistRay = context.persistAndReturnSelf().using(rayFoo);
    rayFoo = context.edit(rayFoo);
    rayFoo.setUserName("Ray");

    persistRay.fire(new Receiver<SimpleFooProxy>() {
      @Override
      public void onSuccess(SimpleFooProxy response) {
        final SimpleFooProxy persistedRay = checkSerialization(response);
        SimpleBarRequest context = simpleBarRequest();
        SimpleBarProxy amitBar = context.create(SimpleBarProxy.class);
        final Request<SimpleBarProxy> persistAmit = context.persistAndReturnSelf().using(amitBar);
        amitBar = context.edit(amitBar);
        amitBar.setUserName("Amit");

        persistAmit.fire(new Receiver<SimpleBarProxy>() {
          @Override
          public void onSuccess(SimpleBarProxy response) {
            response = checkSerialization(response);

            SimpleFooRequest context = simpleFooRequest();
            final Request<SimpleFooProxy> persistRelationship =
                context.persistAndReturnSelf().using(persistedRay).with("barField");
            SimpleFooProxy newRec = context.edit(persistedRay);
            newRec.setBarField(response);

            persistRelationship.fire(new Receiver<SimpleFooProxy>() {
              @Override
              public void onSuccess(SimpleFooProxy response) {
View Full Code Here


    final RuntimeException exception1 = new RuntimeException("first exception");
    final RuntimeException exception2 = new RuntimeException("second exception");
    final CountingReceiver count = new CountingReceiver();

    SimpleFooRequest context = req.simpleFooRequest();
    // 42 is the crash causing magic number for a runtime exception
    context.pleaseCrash(42).to(count);
    context.returnNullString().to(new ThrowingReceiver<String>(exception1));
    context.returnNullString().to(count);

    fireContextAndCatch(context, new ThrowingReceiver<Void>(exception2), new ExceptionVerifier() {
      @Override
      public void verify(Throwable e) {
        assertUmbrellaException(e, exception1, exception2);
View Full Code Here

    final RuntimeException exception1 = new RuntimeException("first exception");
    final RuntimeException exception2 = new RuntimeException("second exception");
    final CountingReceiver count = new CountingReceiver();

    SimpleFooRequest context = req.simpleFooRequest();
    context.returnNullString().to(count);
    // 42 is the crash causing magic number for a runtime exception
    context.pleaseCrash(42).to(new ThrowingReceiver<Void>(exception1));
    context.returnNullString().to(count);

    fireContextAndCatch(context, new ThrowingReceiver<Void>(exception2), new ExceptionVerifier() {
      @Override
      public void verify(Throwable e) {
        assertUmbrellaException(e, exception1, exception2);
View Full Code Here

    final RuntimeException exception1 = new RuntimeException("first exception");
    final RuntimeException exception2 = new RuntimeException("second exception");
    final CountingReceiver count = new CountingReceiver();

    SimpleFooRequest context = req.simpleFooRequest();
    SimpleFooProxy newFoo = context.create(SimpleFooProxy.class);

    context.returnNullString().to(count);
    context.persist().using(newFoo).to(new ThrowingReceiver<Void>(exception1));
    context.returnNullString().to(count);

    final SimpleFooProxy mutableFoo = context.edit(newFoo);
    // 42 is the crash causing magic number for a runtime exception
    mutableFoo.setPleaseCrash(42);

    fireContextAndCatch(context, new ThrowingReceiver<Void>(exception2), new ExceptionVerifier() {
      @Override
View Full Code Here

    final RuntimeException exception1 = new RuntimeException("first exception");
    final RuntimeException exception2 = new RuntimeException("second exception");
    final CountingReceiver count = new CountingReceiver();

    SimpleFooRequest context = req.simpleFooRequest();
    context.returnNullString().to(count);
    context.returnNullString().to(new ThrowingReceiver<String>(exception1));
    context.returnNullString().to(count);

    fireContextAndCatch(context, new ThrowingReceiver<Void>(exception2), new ExceptionVerifier() {
      @Override
      public void verify(Throwable e) {
        assertUmbrellaException(e, exception1, exception2);
View Full Code Here

    final RuntimeException exception1 = new RuntimeException("first exception");
    final RuntimeException exception2 = new RuntimeException("second exception");
    final CountingReceiver count = new CountingReceiver();

    SimpleFooRequest context = req.simpleFooRequest();
    SimpleFooProxy newFoo = context.create(SimpleFooProxy.class);
    newFoo.setUserName("a"); // too short

    context.returnNullString().to(count);
    context.persist().using(newFoo).to(new ThrowingReceiver<Void>(exception1));
    context.returnNullString().to(count);

    fireContextAndCatch(context, new ThrowingReceiver<Void>(exception2), new ExceptionVerifier() {
      @Override
      public void verify(Throwable e) {
        assertUmbrellaException(e, exception1, exception2);
View Full Code Here

    toReturn.initialize(new SimpleEventBus());
    return toReturn;
  }

  protected void finishTestAndReset() {
    SimpleFooRequest ctx = req.simpleFooRequest();
    ctx.reset();
    ctx.fire(new Receiver<Void>() {
      @Override
      public void onSuccess(Void response) {
        finishTest();
      }
    });
View Full Code Here

  /**
   * Basic functional test of the append method.
   */
  public void testAppend() {
    delayTestFinish(DELAY_TEST_FINISH);
    SimpleFooRequest fooCtx1 = req.simpleFooRequest();
    SimpleFooProxy foo1 = fooCtx1.create(SimpleFooProxy.class);
    SimpleBarRequest barCtx = fooCtx1.append(req.simpleBarRequest());
    SimpleFooRequest fooCtx2 = barCtx.append(req.simpleFooRequest());

    assertNotSame(fooCtx1, fooCtx2);
    assertSame(foo1, barCtx.edit(foo1));
    assertSame(foo1, fooCtx2.edit(foo1));

    SimpleBarProxy foo2 = barCtx.create(SimpleBarProxy.class);
    assertSame(foo2, fooCtx1.edit(foo2));
    assertSame(foo2, fooCtx2.edit(foo2));

    SimpleFooProxy foo3 = fooCtx2.create(SimpleFooProxy.class);
    assertSame(foo3, fooCtx1.edit(foo3));
    assertSame(foo3, barCtx.edit(foo3));

    try {
      // Throws exception because c3 has already accumulated some state
      req.simpleValueContext().append(fooCtx2);
      fail("Should have thrown IllegalStateException");
    } catch (IllegalStateException expected) {
    }

    try {
      // Throws exception because a different RequestFactory instance is used
      fooCtx2.append(createFactory().simpleFooRequest());
      fail("Should have thrown IllegalStateException");
    } catch (IllegalStateException expected) {
    }

    // Queue up two invocations, and test that both Receivers are called
    final boolean[] seen = {false, false};
    fooCtx1.add(1, 2).to(new Receiver<Integer>() {
      @Override
      public void onSuccess(Integer response) {
        seen[0] = true;
        assertEquals(3, response.intValue());
      }
    });
    barCtx.countSimpleBar().to(new Receiver<Long>() {
      @Override
      public void onSuccess(Long response) {
        seen[1] = true;
        assertEquals(2, response.longValue());
      }
    });

    // It doesn't matter which context instance is fired
    barCtx.fire(new Receiver<Void>() {
      @Override
      public void onSuccess(Void response) {
        assertTrue(seen[0]);
        assertTrue(seen[1]);
        finishTestAndReset();
      }
    });

    /*
     * Since the common State has been locked, calling any other
     * context-mutation methods should fail.
     */
    try {
      fooCtx1.fire();
      fail("Should have thrown exception");
    } catch (IllegalStateException expected) {
    }
    try {
      fooCtx2.fire();
      fail("Should have thrown exception");
    } catch (IllegalStateException expected) {
    }
    try {
      fooCtx2.create(SimpleFooProxy.class);
      fail("Should have thrown exception");
    } catch (IllegalStateException expected) {
    }
  }
View Full Code Here

TOP

Related Classes of com.google.web.bindery.requestfactory.shared.SimpleFooRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.