Permalink
Browse files

Support update operation in model

  • Loading branch information...
greenlaw110 committed Mar 20, 2012
1 parent 9ec477b commit e7ef95468b894e2e836759a51cc69998a7578e21
View
@@ -1,9 +1,10 @@
# History
+# 1.2.5b - process keywords in MorphiaPlugin.MorphiaModelLoader.fetch(), simulate google search
# 1.2.5a - Synchronize to class when get long ID
# - trim value when processing where statement in Factory.fetch
# 1.2.5 - mavenize project
# 1.2.4d - Add BlobGsonAdapter and ModelFactoryGsonAdapter utilities
-self: play -> morphia 1.2.5a
+self: play -> morphia 1.2.5b
require:
- play 1.2
@@ -1,6 +1,6 @@
h1. PlayMorphia module Documentation
-Welcome to PlayMorphia module documentation. This documentation is intended for the *1.2.4a release* and may significantly differ from previous module version's documentation.
+Welcome to PlayMorphia module documentation. This documentation is intended for the *1.2.5b release* and may significantly differ from previous module version's documentation.
Check the "version history":history.
View
@@ -30,7 +30,7 @@ under the License.
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.greenlaw110.play-morphia</groupId>
<artifactId>play-morphia</artifactId>
- <version>1.2.5b</version>
+ <version>1.2.6</version>
<packaging>jar</packaging>
<name>Play! Morphia Module</name>
@@ -0,0 +1,59 @@
+import java.util.Set;
+
+import models.Account;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import play.Logger;
+import play.test.UnitTest;
+
+import javax.security.auth.login.AccountException;
+
+
+public class UpdateOperationsTest extends UnitTest {
+
+ @Before
+ public void setup() {
+ Account.deleteAll();
+ new Account("abc", "abc@1.com", "au", "it", 29, 77).save();
+ new Account("xyz", "xyz@1.com", "au", "it", 32, 89).save();
+ }
+
+ @Test
+ public void testUpdateFirst() {
+ Account acc0 = Account.o().inc("age").updateFirst(Account.q().filter("region", "au"));
+ Account acc = Account.q().filter("login", "abc").get();
+ assertEquals(acc0, acc);
+ assertEquals(30, acc.age);
+ acc = Account.q().filter("login", "xyz").get();
+ assertEquals(32, acc.age);
+ }
+
+ @Test
+ public void testUpdateAll() {
+ Account.o().inc("age").update(Account.q().filter("region", "au"));
+ Account acc = Account.q().filter("login", "abc").get();
+ assertEquals(30, acc.age);
+ acc = Account.q().filter("login", "xyz").get();
+ assertEquals(33, acc.age);
+ }
+
+ @Test
+ public void testUpdateNull() {
+ Account acc = Account.o().inc("age").updateFirst(Account.q().filter("region", "cn"));
+ assertNull(acc);
+ }
+
+ public void testUpdateSet() {
+ Account.o().set("byAgeAndRegion", 100, "cn").updateAll();
+ Account acc = Account.q().filter("login", "abc").get();
+ assertEquals(100, acc.age);
+ assertEquals("cn", acc.region);
+ acc = Account.q().filter("login", "xyz").get();
+ assertEquals(100, acc.age);
+ assertEquals("cn", acc.region);
+ }
+
+}
Oops, something went wrong.

0 comments on commit e7ef954

Please sign in to comment.