Search in sources :

Example 6 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO 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.legacy.shared.command.GetSchema) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) Test(org.junit.Test)

Example 7 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method commandsUnsuccessfullyExecutedThroughProxiesShouldBeSentToServer.

@Test
public void commandsUnsuccessfullyExecutedThroughProxiesShouldBeSentToServer() {
    GetSchema command = new GetSchema();
    expect(proxy.maybeExecute(eq(command))).andReturn(CacheResult.couldNotExecute());
    replay(proxy);
    expectRemoteCall(command);
    andCallbackWihSuccess(new SchemaDTO());
    replay(service);
    AsyncCallback callback = makeCallbackThatExpectsNonNullSuccess();
    proxyManager.registerProxy(GetSchema.class, proxy);
    dispatcher.execute(new GetSchema(), callback);
    processPendingCommands();
    verify(proxy, service, callback);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) Test(org.junit.Test)

Example 8 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method commandsSuccessfullyExecutedThroughProxiesShouldNotBeSentToServer.

@Test
public void commandsSuccessfullyExecutedThroughProxiesShouldNotBeSentToServer() {
    GetSchema command = new GetSchema();
    expect(proxy.maybeExecute(eq(command))).andReturn(new CacheResult(new SchemaDTO()));
    replay(proxy);
    // no calls should be made to the remote service
    replay(service);
    AsyncCallback callback = makeCallbackThatExpectsNonNullSuccess();
    proxyManager.registerProxy(GetSchema.class, proxy);
    dispatcher.execute(new GetSchema(), callback);
    processPendingCommands();
    verify(proxy, service, callback);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CacheResult(org.activityinfo.ui.client.dispatch.remote.cache.CacheResult) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) Test(org.junit.Test)

Example 9 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO 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.legacy.shared.command.GetSchema) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) Test(org.junit.Test)

Example 10 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO 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.ui.client.dispatch.remote.cache.CacheResult) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) Test(org.junit.Test)

Aggregations

SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)29 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)22 Test (org.junit.Test)19 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)9 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)7 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)4 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)4 OnDataSet (org.activityinfo.server.database.OnDataSet)4 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)3 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)3 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)3 Function (com.google.common.base.Function)2 Delete (org.activityinfo.legacy.shared.command.Delete)2 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)2 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)2 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)2 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)2 User (org.activityinfo.server.database.hibernate.entity.User)2 CacheResult (org.activityinfo.ui.client.dispatch.remote.cache.CacheResult)2 Before (org.junit.Before)2