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

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


   * trying to invoke a method on the deleted entity using a stale EntityProxy
   * reference on the client.
   */
  public void testUseOfDeletedEntity() {
    delayTestFinish(DELAY_TEST_FINISH);
    SimpleBarRequest context = simpleBarRequest();
    SimpleBarProxy willDelete = context.create(SimpleBarProxy.class);
    willDelete.setUserName("A");

    // Persist the newly-created object
    context.persistAndReturnSelf().using(willDelete).fire(new Receiver<SimpleBarProxy>() {
      @Override
      public void onSuccess(SimpleBarProxy response) {
        response = checkSerialization(response);
        assertEquals("A", response.getUserName());
        // Mark the object as deleted
        SimpleBarRequest context = simpleBarRequest();
        response = context.edit(response);
        response.setFindFails(true);
        response.setUserName("B");
        context.persistAndReturnSelf().using(response).fire(new Receiver<SimpleBarProxy>() {

          @Override
          public void onSuccess(SimpleBarProxy response) {
            response = checkSerialization(response);
            // The last-known state should be returned
            assertNotNull(response);
            assertEquals("B", response.getUserName());

            SimpleBarRequest context = simpleBarRequest();
            // Ensure attempts to mutate deleted objects don't blow up
            response = context.edit(response);
            response.setUserName("C");

            // Attempting to use the now-deleted object should fail
            context.persistAndReturnSelf().using(response).fire(new Receiver<SimpleBarProxy>() {
              @Override
              public void onFailure(ServerFailure error) {
                assertTrue(error.getMessage().contains(
                    "The requested entity is not available on" + " the server"));
                finishTestAndReset();
View Full Code Here


   */
  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();
View Full Code Here

TOP

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

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.