Search in sources :

Example 11 with SchemaDTO

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

Example 12 with SchemaDTO

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

Example 13 with SchemaDTO

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

Example 14 with SchemaDTO

use of org.activityinfo.shared.dto.SchemaDTO in project activityinfo by bedatadriven.

the class SchemaCacheTest method testSchemaCache.

@Test
public void testSchemaCache() {
    CacheManager proxyMgr = new CacheManager(new MockEventBus());
    new SchemaCache(proxyMgr);
    SchemaDTO schema = DTOs.pear();
    proxyMgr.notifyListenersOfSuccess(new GetSchema(), schema);
    CacheResult<SchemaDTO> proxyResult = proxyMgr.execute(new GetSchema());
    Assert.assertTrue("could execute locally", proxyResult.isCouldExecute());
    Assert.assertEquals("PEAR", proxyResult.getResult().getDatabaseById(1).getName());
}
Also used : MockEventBus(org.activityinfo.client.MockEventBus) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 15 with SchemaDTO

use of org.activityinfo.shared.dto.SchemaDTO in project activityinfo by bedatadriven.

the class DesignTest method testSaveOnNavigateAway.

@Test
public void testSaveOnNavigateAway() {
    // Dummy Data
    SchemaDTO schema = DTOs.pear();
    // Collaborator
    MockEventBus eventBus = new MockEventBus();
    // Collaborator
    DispatcherStub service = new DispatcherStub();
    service.setResult(GetSchema.class, schema);
    service.setResult(UpdateEntity.class, new VoidResult());
    // Collaborator
    DesignPresenter.View view = createNiceMock(DesignPresenter.View.class);
    replay(view);
    // Collaborator
    UIConstants constants = createNiceMock(UIConstants.class);
    replay(constants);
    DesignPresenter designer = new DesignPresenter(eventBus, service, new StateManagerStub(), view, constants);
    designer.go(schema.getDatabaseById(1));
    // Verify that following a change to the record, a save call
    // triggers an update command
    ActivityDTO activity = (ActivityDTO) ((TreeStore) designer.getStore()).getRootItems().get(0);
    Record record = designer.getStore().getRecord(activity);
    record.set("name", "New Name");
    designer.requestToNavigateAway(new DataEntryPlace(), new NavigationCallback() {

        @Override
        public void onDecided(boolean allowed) {
        }
    });
    UpdateEntity cmd = service.getLastExecuted(UpdateEntity.class);
    Assert.assertTrue(cmd.getChanges().containsKey("name"));
    Assert.assertEquals("New Name", cmd.getChanges().get("name"));
}
Also used : VoidResult(org.activityinfo.shared.command.result.VoidResult) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) TreeStore(com.extjs.gxt.ui.client.store.TreeStore) DataEntryPlace(org.activityinfo.client.page.entry.place.DataEntryPlace) MockEventBus(org.activityinfo.client.MockEventBus) NavigationCallback(org.activityinfo.client.page.NavigationCallback) Record(com.extjs.gxt.ui.client.store.Record) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) Test(org.junit.Test)

Aggregations

SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)66 GetSchema (org.activityinfo.shared.command.GetSchema)56 Test (org.junit.Test)41 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)20 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)10 CreateResult (org.activityinfo.shared.command.result.CreateResult)9 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)8 MockEventBus (org.activityinfo.client.MockEventBus)6 HashMap (java.util.HashMap)5 DispatcherStub (org.activityinfo.client.dispatch.DispatcherStub)5 UIConstants (org.activityinfo.client.i18n.UIConstants)5 StateManagerStub (org.activityinfo.client.mock.StateManagerStub)5 OnDataSet (org.activityinfo.server.database.OnDataSet)5 Delete (org.activityinfo.shared.command.Delete)5 Filter (org.activityinfo.shared.command.Filter)5 UpdateEntity (org.activityinfo.shared.command.UpdateEntity)5 AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)5 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)4 CreateEntity (org.activityinfo.shared.command.CreateEntity)4 VoidResult (org.activityinfo.shared.command.result.VoidResult)4