Add test for generic collections
This commit is contained in:
parent
f96e053417
commit
9490b2e48c
4 changed files with 72 additions and 1 deletions
|
@ -19,6 +19,19 @@ range.order = person_name
|
|||
range.offset = 100
|
||||
range.maxsize = 100
|
||||
|
||||
generic = collection(Person)
|
||||
generic.local.1 = $prototype
|
||||
generic.foreign.1 = person_generic_prototype
|
||||
generic.local.2 = $id
|
||||
generic.foreign.2 = person_generic_id
|
||||
|
||||
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
|
||||
|
||||
name = org_name
|
||||
country = org_country
|
||||
|
||||
|
|
|
@ -12,3 +12,6 @@ dateOfBirth = person_dateofbirth
|
|||
organisation = object(Organisation)
|
||||
organisation.local = person_org_id
|
||||
organisation.foreign = org_id
|
||||
|
||||
genericPrototype = person_generic_prototype
|
||||
genericId = person_generic_id
|
|
@ -1,15 +1,20 @@
|
|||
|
||||
CREATE DATABASE helmaTest;
|
||||
CREATE DATABASE IF NOT EXISTS helmaTest;
|
||||
USE helmaTest;
|
||||
|
||||
GRANT ALL ON helmaTest.* TO helma@localhost IDENTIFIED BY 'secret';
|
||||
|
||||
DROP TABLE IF EXISTS tb_person;
|
||||
DROP TABLE IF EXISTS tb_organisation;
|
||||
|
||||
CREATE TABLE tb_person (
|
||||
person_id MEDIUMINT(10) NOT NULL,
|
||||
person_name TINYTEXT,
|
||||
person_height TINYINT unsigned,
|
||||
person_dateofbirth DATETIME,
|
||||
person_org_id MEDIUMINT(10) unsigned,
|
||||
person_generic_prototype VARCHAR(30),
|
||||
person_generic_id MEDIUMINT(10) unsigned,
|
||||
PRIMARY KEY (person_id)
|
||||
);
|
||||
|
||||
|
|
50
test/tests/HopObjectGeneric.js
Normal file
50
test/tests/HopObjectGeneric.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
tests = [
|
||||
'testSize'
|
||||
];
|
||||
|
||||
var org;
|
||||
var size = 16;
|
||||
|
||||
function setup() {
|
||||
org = new Organisation();
|
||||
org.name = "GenericOrg";
|
||||
var i = 0, person;
|
||||
|
||||
function addPerson(collection) {
|
||||
person = new Person();
|
||||
person.name = "GenericPerson " + i.format("00");
|
||||
collection.add(person);
|
||||
i++;
|
||||
}
|
||||
|
||||
// add first half to both collections of transient parent ...
|
||||
while (i < 4)
|
||||
addPerson(org.generic);
|
||||
while (i < 8)
|
||||
addPerson(org.groupedGeneric);
|
||||
root.organisations.add(org);
|
||||
// ... second half to both collections of persistent parent.
|
||||
while (i < 12)
|
||||
addPerson(org.generic);
|
||||
while (i < size)
|
||||
addPerson(org.groupedGeneric);
|
||||
|
||||
res.commit();
|
||||
}
|
||||
|
||||
function testSize() {
|
||||
assertEqual(org.generic.size(), size);
|
||||
org.invalidate();
|
||||
assertEqual(org.generic.size(), size);
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
var persons = org.generic.list();
|
||||
for each (var person in persons) {
|
||||
if (person.groupname)
|
||||
person.get(0).remove();
|
||||
else
|
||||
person.remove();
|
||||
}
|
||||
org.remove();
|
||||
}
|
Loading…
Add table
Reference in a new issue