Search in sources :

Example 11 with GetSchema

use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method commandExceptionsShouldBeCalledBackWithFailure.

@Test
public void commandExceptionsShouldBeCalledBackWithFailure() {
    expectRemoteCall(new GetSchema());
    // remote call succeeded,
    andCallbackWihSuccess(new CommandException());
    // command failed
    replay(service);
    AsyncCallback callback = makeCallbackThatExpectsFailure();
    dispatcher.execute(new GetSchema(), callback);
    processPendingCommands();
    verify(service, callback);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CommandException(org.activityinfo.shared.exception.CommandException) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 12 with GetSchema

use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method successiveCommandsServedByProxyAreCorrectlyHandleded.

@Test
public void successiveCommandsServedByProxyAreCorrectlyHandleded() {
    GetSchema command = new GetSchema();
    expect(proxy.maybeExecute(eq(command))).andReturn(new CacheResult(new SchemaDTO())).anyTimes();
    replay(proxy);
    // no calls should be made to the remote service
    replay(service);
    final AsyncCallback callback2 = makeCallbackThatExpectsNonNullSuccess();
    proxyManager.registerProxy(GetSchema.class, proxy);
    dispatcher.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

        @Override
        public void onFailure(Throwable arg0) {
            throw new AssertionError();
        }

        @Override
        public void onSuccess(SchemaDTO arg0) {
            dispatcher.execute(new GetSchema(), callback2);
        }
    });
    processPendingCommands();
    processPendingCommands();
    verify(proxy, service, callback2);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CacheResult(org.activityinfo.client.dispatch.remote.cache.CacheResult) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Test(org.junit.Test)

Example 13 with GetSchema

use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method mergedCommandsShouldEachReceiveACallback.

@Test
public void mergedCommandsShouldEachReceiveACallback() {
    expectRemoteCall(new GetSchema());
    andCallbackWihSuccess(new SchemaDTO());
    replay(service);
    AsyncCallback callback1 = makeCallbackThatExpectsNonNullSuccess();
    AsyncCallback callback2 = makeCallbackThatExpectsNonNullSuccess();
    // simulate successive dispatches of the same command from different
    // components of the application
    dispatcher.execute(new GetSchema(), callback1);
    dispatcher.execute(new GetSchema(), callback2);
    processPendingCommands();
    // verify that only one command was sent
    verify(callback1);
    verify(callback2);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Test(org.junit.Test)

Example 14 with GetSchema

use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method duplicateCommandsShouldBeMergedWithPendingRequests.

@Test
public void duplicateCommandsShouldBeMergedWithPendingRequests() {
    expectRemoteCall(new GetSchema());
    replay(service);
    // simulate successive dispatches of the same command from different
    // components of the application
    dispatcher.execute(new GetSchema(), makeNullCallback());
    dispatcher.execute(new GetSchema(), makeNullCallback());
    processPendingCommands();
    // verify that only one command was sent
    verify(service);
}
Also used : GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 15 with GetSchema

use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method exceptionsThrownByCallbacksDoNotDistubOthers.

/**
 * The RemoteDispatcher will group and bundle commands together-- we need to
 * make sure that different components remain isolated from failures within
 * other components.
 */
@Test
public void exceptionsThrownByCallbacksDoNotDistubOthers() {
    expectRemoteCall(new GetSchema());
    andCallbackWihSuccess(new SchemaDTO());
    replay(service);
    // Here we set up one component that will call request a command
    // but something will go wrong when the command return (successfully)
    // the error is unrelated to the remote command -- it just happens to be
    // there.
    dispatcher.execute(new GetSchema(), null, new AsyncCallback<SchemaDTO>() {

        @Override
        public void onFailure(Throwable caught) {
        }

        @Override
        public void onSuccess(SchemaDTO result) {
            throw new RuntimeException();
        }
    });
    // the second command independently requests the same command,
    // we need to make sure we receive a result
    AsyncCallback secondCallback = makeCallbackThatExpectsNonNullSuccess();
    dispatcher.execute(new GetSchema(), null, secondCallback);
    processPendingCommands();
    verify(secondCallback);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Test(org.junit.Test)

Aggregations

GetSchema (org.activityinfo.shared.command.GetSchema)65 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)56 Test (org.junit.Test)42 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)15 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)10 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)9 CreateResult (org.activityinfo.shared.command.result.CreateResult)8 CreateEntity (org.activityinfo.shared.command.CreateEntity)5 Filter (org.activityinfo.shared.command.Filter)5 HashMap (java.util.HashMap)4 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)4 Delete (org.activityinfo.shared.command.Delete)4 UpdateEntity (org.activityinfo.shared.command.UpdateEntity)4 OnDataSet (org.activityinfo.server.database.OnDataSet)3 BatchCommand (org.activityinfo.shared.command.BatchCommand)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2