Revision: 8707
Author: amitman...@google.com
Date: Thu Sep 2 10:56:13 2010
Log: Added tests for constraint violations.
Patch by: amitmanjhi
Review by: robertvawter,fabbott
http://code.google.com/p/google-web-toolkit/source/detail?r=8707
Modified:
/trunk/user/build.xml
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
/trunk/user/test/com/google/gwt/requestfactory/server/SimpleFoo.java
=======================================
--- /trunk/user/build.xml Fri Aug 20 07:59:07 2010
+++ /trunk/user/build.xml Thu Sep 2 10:56:13 2010
@@ -61,6 +61,10 @@
<pathelement location="${gwt.tools.lib}/objectweb/asm-3.1.jar"/>
<pathelement
location="${gwt.tools.lib}/javax/validation/validation-api-1.0.0.GA.jar" />
<pathelement
location="${gwt.tools.lib}/javax/validation/validation-api-1.0.0.GA-sources.jar"
/>
+ <pathelement location="${gwt.tools.lib}/apache/log4j/log4j-1.2.16.jar"
/>
+ <pathelement
location="${gwt.tools.lib}/hibernate/validator/hibernate-validator-4.1.0.Final.jar"
/>
+ <pathelement
location="${gwt.tools.lib}/slf4j/slf4j-api/slf4j-api-1.6.1.jar" />
+ <pathelement
location="${gwt.tools.lib}/slf4j/slf4j-log4j12/slf4j-log4j12-1.6.1.jar" />
<pathelement
location="${gwt.tools}/redist/json/r2_20080312/json-1.5.jar" />
<pathelement location="${gwt.dev.jar}" />
</path>
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
Wed Aug 25 17:41:41 2010
+++
/trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
Thu Sep 2 10:56:13 2010
@@ -26,6 +26,7 @@
import com.google.gwt.requestfactory.shared.SimpleRequestFactory;
import com.google.gwt.requestfactory.shared.SyncResult;
+import java.util.Map;
import java.util.Set;
/**
@@ -33,6 +34,53 @@
*/
public class RequestFactoryTest extends GWTTestCase {
+ public void testViolationPresent() {
+ final SimpleRequestFactory req =
GWT.create(SimpleRequestFactory.class);
+ HandlerManager hm = new HandlerManager(null);
+ req.init(hm);
+ delayTestFinish(5000);
+
+ SimpleFooRecord newFoo = (SimpleFooRecord)
req.create(SimpleFooRecord.class);
+ final RequestObject<Void> fooReq =
req.simpleFooRequest().persist(newFoo);
+
+ newFoo = fooReq.edit(newFoo);
+ newFoo.setUserName("A"); // will cause constraint violation
+
+ fooReq.fire(new Receiver<Void>() {
+ public void onSuccess(Void ignore, Set<SyncResult> syncResults) {
+ assertEquals(1, syncResults.size());
+ SyncResult syncResult = syncResults.iterator().next();
+ assertTrue(syncResult.hasViolations());
+ Map<String, String> violations = syncResult.getViolations();
+ assertEquals(1, violations.size());
+ assertEquals("size must be between 3 and 30",
violations.get("userName"));
+ finishTest();
+ }
+ });
+ }
+
+ public void testViolationAbsent() {
+ final SimpleRequestFactory req =
GWT.create(SimpleRequestFactory.class);
+ HandlerManager hm = new HandlerManager(null);
+ req.init(hm);
+ delayTestFinish(5000);
+
+ SimpleFooRecord newFoo = (SimpleFooRecord)
req.create(SimpleFooRecord.class);
+ final RequestObject<Void> fooReq =
req.simpleFooRequest().persist(newFoo);
+
+ newFoo = fooReq.edit(newFoo);
+ newFoo.setUserName("Amit"); // will not cause violation.
+
+ fooReq.fire(new Receiver<Void>() {
+ public void onSuccess(Void ignore, Set<SyncResult> syncResults) {
+ assertEquals(1, syncResults.size());
+ SyncResult syncResult = syncResults.iterator().next();
+ assertFalse(syncResult.hasViolations());
+ finishTest();
+ }
+ });
+ }
+
/*
* TODO: all these tests should check the final values. It will be easy
when
* we have better persistence than the singleton pattern.
@@ -138,7 +186,8 @@
new Receiver<SimpleFooRecord>() {
public void onSuccess(SimpleFooRecord finalFooRecord,
Set<SyncResult> syncResults) {
- // newFoo hasn't been persisted, so userName is
the old value.
+ // newFoo hasn't been persisted, so userName is
the old
+ // value.
assertEquals("GWT", finalFooRecord.getUserName());
finishTest();
}
@@ -204,7 +253,7 @@
});
}
- public void testPersistRecursiveRelation() {
+ public void testPersistRecursiveRelation() {
final SimpleRequestFactory req =
GWT.create(SimpleRequestFactory.class);
HandlerManager hm = new HandlerManager(null);
req.init(hm);
@@ -324,12 +373,12 @@
public void onSuccess(SimpleFooRecord response,
Set<SyncResult> syncResult) {
SimpleBarRecord bar = req.create(SimpleBarRecord.class);
- RequestObject<String> helloReq =
req.simpleFooRequest().hello(response, bar);
+ RequestObject<String> helloReq = req.simpleFooRequest().hello(
+ response, bar);
bar = helloReq.edit(bar);
bar.setUserName("BAR");
helloReq.fire(new Receiver<String>() {
- public void onSuccess(String response,
- Set<SyncResult> syncResults) {
+ public void onSuccess(String response, Set<SyncResult>
syncResults) {
assertEquals("Greetings BAR from GWT", response);
finishTest();
}
@@ -339,8 +388,8 @@
}
/*
- * tests that (a) any method can have a side effect that is handled
correctly. (b)
- * instance methods are handled correctly.
+ * tests that (a) any method can have a side effect that is handled
correctly.
+ * (b) instance methods are handled correctly.
*/
public void testMethodWithSideEffects() {
final SimpleRequestFactory req =
GWT.create(SimpleRequestFactory.class);
@@ -367,7 +416,8 @@
assertNull(syncResultArray[0].getFutureId());
Record record = syncResultArray[0].getRecord();
assertEquals(new Long(999L), record.getId());
- // confirm that the instance method did have the desired
sideEffect.
+ // confirm that the instance method did have the desired
+ // sideEffect.
req.simpleFooRequest().findSimpleFooById(999L).fire(
new Receiver<SimpleFooRecord>() {
public void onSuccess(SimpleFooRecord finalFoo,
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/server/SimpleFoo.java
Wed Aug 25 20:23:14 2010
+++ /trunk/user/test/com/google/gwt/requestfactory/server/SimpleFoo.java
Thu Sep 2 10:56:13 2010
@@ -24,6 +24,8 @@
import java.util.Date;
import java.util.List;
+import javax.validation.constraints.Size;
+
/**
* Domain object for SimpleFooRequest.
*/
@@ -68,6 +70,7 @@
Integer version = 1;
+ @Size(min = 3, max = 30)
private String userName;
private String password;
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors