Search in sources :

Example 16 with GetSchema

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

Example 17 with GetSchema

use of org.activityinfo.legacy.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.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 18 with GetSchema

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

Example 19 with GetSchema

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

the class MockRemoteCommandService method execute.

@Override
public void execute(String authToken, String locale, List<Command> cmds, AsyncCallback<List<CommandResult>> callback) {
    List<CommandResult> results = new ArrayList<CommandResult>();
    for (Command cmd : cmds) {
        Integer count = commandCounts.get(cmd.getClass());
        commandCounts.put(cmd.getClass(), count == null ? 1 : count + 1);
        if (schema != null && cmd instanceof GetSchema) {
            results.add(schema);
        } else {
            results.add(mockExecute(cmd));
        }
    }
    callback.onSuccess(results);
}
Also used : Command(org.activityinfo.legacy.shared.command.Command) ArrayList(java.util.ArrayList) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) CommandResult(org.activityinfo.legacy.shared.command.result.CommandResult)

Example 20 with GetSchema

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

the class DbListPresenterTest method commandShouldBePreparedProperly.

@Test
public void commandShouldBePreparedProperly() {
    Capture<CreateEntity> cmd = new Capture<CreateEntity>();
    expectDispatch(new GetSchema(), schema);
    captureDispatch(cmd);
    replay(dispatcher);
    UserDatabaseDTO newDb = new UserDatabaseDTO();
    newDb.setCountry(new CountryDTO(31, "Haiti"));
    newDb.setName("My Db");
    createPresenter();
    presenter.save(newDb, niceFormDialogMock());
    assertTrue("command was dispatched", cmd.hasCaptured());
    assertThat((Integer) cmd.getValue().getProperties().get("countryId"), is(equalTo(31)));
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) CountryDTO(org.activityinfo.legacy.shared.model.CountryDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) Capture(org.easymock.Capture) Test(org.junit.Test)

Aggregations

GetSchema (org.activityinfo.legacy.shared.command.GetSchema)42 Test (org.junit.Test)27 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)22 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)11 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)9 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)7 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)6 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)4 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)4 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)4 CloneDatabase (org.activityinfo.legacy.shared.command.CloneDatabase)3 OnDataSet (org.activityinfo.server.database.OnDataSet)3 Delete (org.activityinfo.legacy.shared.command.Delete)2 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)2 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)2 CacheResult (org.activityinfo.ui.client.dispatch.remote.cache.CacheResult)2 NullCallback (com.bedatadriven.rebar.async.NullCallback)1 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)1 TreeStore (com.extjs.gxt.ui.client.store.TreeStore)1