More tests and some fixes
This commit is contained in:
parent
e68e058e6a
commit
98aff5cd1a
5 changed files with 118 additions and 9 deletions
|
@ -24,13 +24,15 @@ generic.local.1 = $prototype
|
|||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
tests = [
|
||||
"testEquality",
|
||||
"testSimpleMapping",
|
||||
"testSimpleCollection",
|
||||
"testObjectReference",
|
||||
|
@ -8,6 +9,19 @@ tests = [
|
|||
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 = {
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
tests = [
|
||||
"testSize",
|
||||
"testMaxSize",
|
||||
"testAddRemoveSmall",
|
||||
"testAddRemoveLarge",
|
||||
"testAddSmall",
|
||||
"testAddLarge",
|
||||
"testRemoveSmall",
|
||||
"testRemoveLarge",
|
||||
"testUpdateSmall",
|
||||
"testUpdateLarge",
|
||||
"testListSmall",
|
||||
"testListLarge",
|
||||
"testOrderLarge",
|
||||
|
@ -33,15 +37,56 @@ function testMaxSize() {
|
|||
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;
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
tests = [
|
||||
'testSize'
|
||||
'testSize',
|
||||
'testContent',
|
||||
'testGroupContent',
|
||||
'testRemove',
|
||||
'testAdd'
|
||||
];
|
||||
|
||||
var org;
|
||||
|
@ -38,6 +42,48 @@ function testSize() {
|
|||
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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue