PDA

View Full Version : GWTTestCase and GXT Loader.



mtarantini
17 Jun 2010, 1:29 AM
Hi,

i'm trying to setup some GWTTestCase in my project, and i'm confront to strange problem.

I have 2 test case, one where I use an AsyncService directly, the other where I do the same but on a top layer (with the loader / rpcproxy system).



@Test
public void testGetAllApplicationsAsync()
{
delayTestFinish(timeoutMillis);
AuthServiceAsync service = AuthService.Util.getInstance();
service.getAllApplications(new AsyncCallback<List<BValue>>()
{

/**
* @see com.google.gwt.user.client.rpc.AsyncCallback#onFailure(java.lang.Throwable)
*/
@Override
public void onFailure(Throwable arg0)
{
}

public void onSuccess(java.util.List<BValue> arg0)
{
finishTest();
};
});
}


@Test
public void testGetAllApplications()
{
delayTestFinish(timeoutMillis);
ListStore<BValue> appStore = manageClient.getAllApplications();
appStore.getLoader().addLoadListener(new LoadListener()
{

/**
* @see com.extjs.gxt.ui.client.event.LoadListener#loaderLoad(com.extjs.gxt.ui.client.data.LoadEvent)
*/
@Override
public void loaderLoad(LoadEvent le)
{
System.out.println("before");
finishTest();
System.out.println("after");
}

/**
* @see com.extjs.gxt.ui.client.event.LoadListener#loaderLoadException(com.extjs.gxt.ui.client.data.LoadEvent)
*/
@Override
public void loaderLoadException(LoadEvent le)
{
fail("testGetAllApplications");
}
});}Here the code for the manageClient.getAllApplications();


public ListStore<BValue> getAllApplications()
{
RpcProxy<List<BValue>> proxy = new RpcProxy<List<BValue>>()
{

protected void load(Object loadConfig, AsyncCallback<List<BValue>> callback)
{
authService.getAllApplications(callback);
}
};

BaseListLoader<ListLoadResult<BValue>> loader = new BaseListLoader<ListLoadResult<BValue>>(proxy, new ModelReader());

ListStore<BValue> bv = new ListStore<BValue>(loader);
bv.setSortDir(SortDir.ASC);
bv.setSortField("name");

loader.load();
return bv;
}
The problem I have, is that the 1st test is done correctly, but not the 2nd, the service is done, i'm coming in the loaderload event, I see both of the log and...that is, the test block after that and don't go to the next test.

Maybe I'm doing something wrong, I hope that you can help me.

Thx,

mtarantini
17 Jun 2010, 1:37 AM
In fact I understand why this not gonna work,

in the BaseLoader, the onSuccess is call, but it will fire the Load event, the finishTest i call is not on the onSuccess method but in a Listner..

I need a way to inject get the AsyncCallback from

protected void loadData(final Object config) {
AsyncCallback<D> callback = new AsyncCallback<D>() {
public void onFailure(Throwable caught) {
onLoadFailure(config, caught);
}

public void onSuccess(D result) {
onLoadSuccess(config, result);
}
};
if (proxy == null) {
loadData(config, callback);
return;
}
proxy.load(reader, config, callback);
}

in order to complete the test...