1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221 |
2x
2x
2x
2x
2x
2x
2x
2x
2x
2x
2x
18x
18x
2x
2x
2x
2x
2x
2x
2x
2x
| /*!
GPII Settings Transformer Tests
Copyright 2012 OCAD University
Copyright 2013 Raising the Floor
Licensed under the New BSD license. You may not use this file except in
compliance with this License.
The research leading to these results has received funding from the European Union's
Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016.
You may obtain a copy of the License at
https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
var fluid = fluid || require("infusion"),
jqUnit = fluid.registerNamespace("jqUnit"),
gpii = fluid.registerNamespace("gpii");
(function () {
"use strict";
fluid.registerNamespace("gpii.tests.ontologyHandlerUtilities");
var full = {
simple: {
a: {
b: 1,
c: 2
}
},
medium: {
a: {
a1: {
a11: 14
},
a2: {
a21: [ "a", "b" ]
}
}
},
complex: {
a: 12,
b: {},
c: {
c1: [
{ hello: "world" }
]
}
}
};
var testFixtures = [
{
description: "Very simple non-nested removal of single key",
full: full.simple,
remove: {
a: {
b: 3
}
},
expected: {
a: {
c: 2
}
}
}, {
description: "simple value filtering",
full: full.medium,
remove: {
a: {
a1: {
a11: 12
}
}
},
expected: {
a: {
a2: {
a21: [ "a", "b" ]
}
}
}
}, {
description: "Higher hierarchy filtering",
full: full.medium,
remove: {
a: 13
},
expected: {}
}, {
description: "Filtering simple array value",
full: full.medium,
remove: {
a: {
a2: {
a21: [ "a" ]
}
}
},
expected: {
a: {
a1: {
a11: 14
}
}
}
}, {
description: "filtering complementary objects",
full: full.medium,
remove: {
b: 12
},
expected: full.medium
}, {
description: "removing multiple keys",
full: full.complex,
remove: {
a: 15,
c: 18
},
expected: {
b: {}
}
}, {
description: "Removing all keys",
full: full.complex,
remove: {
a: {
a1: "hello"
},
b: "stupid",
c: "cat"
},
expected: {}
}, {
description: "empty object passed as 'full' parameter",
full: {},
remove: {
a: 15
},
expected: {}
}, {
description: "empty object passed as 'remove' parameter",
full: {
a: 15
},
remove: {},
expected: {
a: 15
}
}
];
gpii.tests.ontologyHandlerUtilities.applicationTransformTests = [
{
name: "ISOtoFlat",
input: {
"applications": {
"org.alsa-project": {
"id": "org.alsa-project",
"parameters": {
"volume": 14,
"pitch": 100
}
}
}
},
rules: {
"": {
"transform": {
"type": "gpii.ontologyHandler.transforms.applicationISOToFlat",
"inputPath": "applications",
"outputPath": ""
}
}
},
expected: {
"http://registry.gpii.net/applications/org.alsa-project": {
"volume": 14,
"pitch": 100
}
},
invertedRules: {
transform: [
{
"type": "gpii.ontologyHandler.transforms.applicationFlatToISO",
"inputPath": "",
"outputPath": "applications"
}
]
}
}
];
gpii.tests.ontologyHandlerUtilities.runTests = function () {
jqUnit.test("ontologyServer.filter", function () {
fluid.each(testFixtures, function (test) {
var result = gpii.ontologyHandler.utils.filterPrefs(test.full, test.remove);
jqUnit.assertDeepEq(test.description, test.expected, result);
});
});
jqUnit.test("Testing Application Transformats; applicationFlatToISO and applicationISOToFlat",
function () {
fluid.each(gpii.tests.ontologyHandlerUtilities.applicationTransformTests, function (test) {
var transformed = fluid.model.transform(test.input, test.rules);
jqUnit.assertDeepEq(test.name, test.expected, transformed);
var inverseRules = fluid.model.transform.invertConfiguration(test.rules);
jqUnit.assertDeepEq("Rules inversion for " + test.name, test.invertedRules, inverseRules);
var doubleTransformed = fluid.model.transform(transformed, inverseRules);
jqUnit.assertDeepEq(test.name, test.input, doubleTransformed);
});
}
);
};
})();
|