r9926 - in apps/modules/trunk/test: code code/Organisation tests

[email protected] Fri, 18 Sep 2009 21:09:52 +0200 (CEST)
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20090918190952.EFB573D0E3@mia>
Author: hannes
Date: 2009-09-18 21:09:52 +0200 (Fri, 18 Sep 2009)
New Revision: 9926

Modified:
   apps/modules/trunk/test/code/Organisation/type.properties
   apps/modules/trunk/test/code/app.properties
   apps/modules/trunk/test/tests/HopObjectBasicMapping.js
   apps/modules/trunk/test/tests/HopObjectCollection.js
   apps/modules/trunk/test/tests/HopObjectGeneric.js
Log:
More tests and some fixes

Details at http://dev.helma.org/trac/helma/changeset/9926

Modified: apps/modules/trunk/test/code/Organisation/type.properties
===================================================================
--- apps/modules/trunk/test/code/Organisation/type.properties	2009-09-18 15:01:48 UTC (rev 9925)
+++ apps/modules/trunk/test/code/Organisation/type.properties	2009-09-18 19:09:52 UTC (rev 9926)
@@ -24,13 +24,15 @@
 generic.foreign.1 = person_generic_prototype
 generic.local.2 = $id
 generic.foreign.2 = person_generic_id
+generic.order = person_name
 
 groupedGeneric = collection(Person)
 groupedGeneric.local.1 = $prototype
 groupedGeneric.foreign.1 = person_generic_prototype
 groupedGeneric.local.2 = $id
 groupedGeneric.foreign.2 = person_generic_id
-groupredGeneric.group = person_name
+groupedGeneric.group = person_name
+groupedGeneric.group.order = person_name
 
 name = org_name
 country = org_country

Modified: apps/modules/trunk/test/code/app.properties
===================================================================
--- apps/modules/trunk/test/code/app.properties	2009-09-18 15:01:48 UTC (rev 9925)
+++ apps/modules/trunk/test/code/app.properties	2009-09-18 19:09:52 UTC (rev 9926)
@@ -1 +1,3 @@
 baseUri = http://localhost:8080/test/
+# hard-code cache size to default value to make sure there's some cache rotation
+cacheSize = 500

Modified: apps/modules/trunk/test/tests/HopObjectBasicMapping.js
===================================================================
--- apps/modules/trunk/test/tests/HopObjectBasicMapping.js	2009-09-18 15:01:48 UTC (rev 9925)
+++ apps/modules/trunk/test/tests/HopObjectBasicMapping.js	2009-09-18 19:09:52 UTC (rev 9926)
@@ -1,4 +1,5 @@
 tests = [
+   "testEquality",
    "testSimpleMapping",
    "testSimpleCollection",
    "testObjectReference",
@@ -8,6 +9,19 @@
 function setup() {
 }
 
+function testEquality() {
+    var person = new Person();
+    root.persons.add(person);
+    res.commit();
+    var id = person._id;
+    app.clearCache();
+    var person2 = root.persons.get(id);
+    assertNotNull(person2);
+    assertTrue(person !== person2);
+    assertTrue(person._id === person2._id);
+    assertTrue(person == person2);
+}
+
 function testSimpleMapping() {
 
    var data = {

Modified: apps/modules/trunk/test/tests/HopObjectCollection.js
===================================================================
--- apps/modules/trunk/test/tests/HopObjectCollection.js	2009-09-18 15:01:48 UTC (rev 9925)
+++ apps/modules/trunk/test/tests/HopObjectCollection.js	2009-09-18 19:09:52 UTC (rev 9926)
@@ -1,8 +1,12 @@
 tests = [
     "testSize",
     "testMaxSize",
-    "testAddRemoveSmall",
-    "testAddRemoveLarge",
+    "testAddSmall",
+    "testAddLarge",
+    "testRemoveSmall",
+    "testRemoveLarge",
+    "testUpdateSmall",
+    "testUpdateLarge",
     "testListSmall",
     "testListLarge",
     "testOrderLarge",
@@ -33,17 +37,58 @@
     assertEqual(150, ikea.persons.indexOf(person));
 }
 
-function testAddRemoveSmall(org) {
-    testAddRemove(helma, small);
+function testAddSmall() {
+    testAdd(helma, small);
 }
 
-function testAddRemoveLarge(org) {
-    testAddRemove(ikea, large);
+function testAddLarge() {
+    testAdd(ikea, large);
 }
 
-function testAddRemove(org, size) {
+// test directly adding to a collection
+function testAdd(org, size) {
     var person = new Person();
     person.name = "TestPerson";
+    org.persons.add(person);
+    assertEqual(org.persons.size(), size + 1);
+    assertEqual(org.persons.indexOf(person), size);
+    assertEqual(org.persons.contains(person), size);
+    assertEqual(person.href(), org.persons.href() + "TestPerson/");
+    // make sure the add has set the back-reference on the person object.
+    // note that === comparison will return false if the
+    // collection size exceeds the cache size.
+    assertTrue(person.organisation == org);
+}
+
+function testRemoveSmall() {
+    testRemove(helma, small);
+}
+
+function testRemoveLarge() {
+    testRemove(ikea, large);
+}
+
+// test directly removing from a collection
+function testRemove(org, size) {
+    var person = org.persons.get(org.persons.size() - 1);
+    person.remove();
+    assertEqual(org.persons.size(), size);
+    assertEqual(org.persons.indexOf(person), -1);
+    assertEqual(org.persons.contains(person), -1);
+}
+
+function testUpdateSmall() {
+    testUpdate(helma, small);
+}
+
+function testUpdateLarge() {
+    testUpdate(ikea, large);
+}
+
+// test indirectly adding to and removing form a collection
+function testUpdate(org, size) {
+    var person = new Person();
+    person.name = "TestPerson";
     person.organisation = org;
     person.persist();
     res.commit();

Modified: apps/modules/trunk/test/tests/HopObjectGeneric.js
===================================================================
--- apps/modules/trunk/test/tests/HopObjectGeneric.js	2009-09-18 15:01:48 UTC (rev 9925)
+++ apps/modules/trunk/test/tests/HopObjectGeneric.js	2009-09-18 19:09:52 UTC (rev 9926)
@@ -1,5 +1,9 @@
 tests = [
-    'testSize'
+    'testSize',
+    'testContent',
+    'testGroupContent',
+    'testRemove',
+    'testAdd'
 ];
 
 var org;
@@ -38,6 +42,48 @@
     assertEqual(org.generic.size(), size);
 }
 
+function testContent() {
+    var list = org.generic.list();
+    assertEqual(list.length, size);
+    for (var i = 0; i < list.length; i++) {
+        assertEqual(list[i].name, "GenericPerson " + i.format("00"));
+    }
+}
+
+function testGroupContent() {
+    var list = org.groupedGeneric.list();
+    assertEqual(list.length, size);
+    for (var i = 0; i < list.length; i++) {
+        assertEqual(list[i].groupname, "GenericPerson " + i.format("00"));
+        assertEqual(list[i].size(), 1);
+        assertEqual(list[i].get(0).name, "GenericPerson " + i.format("00"));
+    }
+}
+
+function testRemove() {
+    var person = org.generic.get(size/2);
+    org.generic.removeChild(person);
+    assertEqual(org.generic.size(), size - 1);
+    res.rollback();
+    // note: removeChild does not remove the node, nor does it
+    // unset the constraints between parent and child, so after a rollback
+    // the object is back in place. While this behaviour is disputable,
+    // until this is so we test for it.
+    assertEqual(org.generic.size(), size);
+}
+
+function testAdd() {
+    var person = new Person();
+    org.generic.add(person);
+    assertEqual(org.generic.size(), size + 1);
+    assertEqual(org.groupedGeneric.size(), size);
+    res.commit();
+    // note: even after commit the grouped collection must not grow
+    // since we added a person without a name
+    assertEqual(org.generic.size(), size + 1);
+    assertEqual(org.groupedGeneric.size(), size);
+}
+
 function cleanup() {
     var persons = org.generic.list();
     for each (var person in persons) {