Reviewers: amitmanjhi,
Description:
Adds test that events can be registered and that they fire correctly.
This is a followup to ROO-1434 that implements a TODO to test the
events.
Please review this at http://gwt-code-reviews.appspot.com/878803/show
Affected files:
M user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
Index:
user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
===================================================================
--- user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
(revision 8854)
+++ user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
(working copy)
@@ -17,6 +17,7 @@
import com.google.gwt.requestfactory.client.impl.ProxyImpl;
import com.google.gwt.requestfactory.shared.EntityProxy;
+import com.google.gwt.requestfactory.shared.EntityProxyChange;
import com.google.gwt.requestfactory.shared.EntityProxyId;
import com.google.gwt.requestfactory.shared.Receiver;
import com.google.gwt.requestfactory.shared.Request;
@@ -102,6 +103,26 @@
request.fire(this);
}
}
+
+ // Class for counting events
+ private class SimpleFooEventHandler implements
EntityProxyChange.Handler<SimpleFooProxy> {
+ public int acquireEventCount = 0;
+ public int createEventCount = 0;
+ public int deleteEventCount = 0;
+ public int totalEventCount = 0;
+ public int updateEventCount = 0;
+
+ public void onProxyChange(EntityProxyChange<SimpleFooProxy> event) {
+ totalEventCount++;
+ switch (event.getWriteOperation()) {
+ case ACQUIRE: acquireEventCount++; break;
+ case CREATE: createEventCount++; break;
+ case DELETE: deleteEventCount++; break;
+ case UPDATE: updateEventCount++; break;
+ default: break;
+ }
+ }
+ }
public <T extends EntityProxy> void assertContains(Collection<T> col,
T value) {
@@ -135,6 +156,9 @@
public void testDummyCreate() {
delayTestFinish(5000);
+
+ final SimpleFooEventHandler handler = new SimpleFooEventHandler();
+ EntityProxyChange.registerForProxyType(req.getEventBus(),
SimpleFooProxy.class, handler);
final SimpleFooProxy foo = req.create(SimpleFooProxy.class);
Object futureId = foo.getId();
@@ -149,6 +173,9 @@
Object futureId = foo.getId();
assertEquals(futureId, foo.getId());
assertTrue(((ProxyImpl) foo).isFuture());
+ assertEquals(1, handler.acquireEventCount);
+ assertEquals(1, handler.createEventCount);
+ assertEquals(2, handler.totalEventCount);
checkStableIdEquals(foo, returned);
finishTestAndReset();
@@ -326,6 +353,8 @@
*/
public void testMethodWithSideEffects() {
delayTestFinish(5000);
+ final SimpleFooEventHandler handler = new SimpleFooEventHandler();
+ EntityProxyChange.registerForProxyType(req.getEventBus(),
SimpleFooProxy.class, handler);
req.simpleFooRequest().findSimpleFooById(999L).fire(
new Receiver<SimpleFooProxy>() {
@@ -340,8 +369,7 @@
public void onSuccess(Long response) {
assertCannotFire(mutateRequest);
assertEquals(new Long(1L), response);
- // TODO: listen to create events also
-
+
// confirm that the instance method did have the desired
// sideEffect.
req.simpleFooRequest().findSimpleFooById(999L).fire(
@@ -349,6 +377,9 @@
@Override
public void onSuccess(SimpleFooProxy finalFoo) {
assertEquals("Ray", finalFoo.getUserName());
+ assertEquals(1, handler.acquireEventCount);
+ assertEquals(2, handler.updateEventCount);
+ assertEquals(3, handler.totalEventCount);
finishTestAndReset();
}
});
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors