forked from opensourceBIM/bimvie.ws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.html
425 lines (407 loc) · 16.4 KB
/
testing.html
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<div class="testing">
<button class="btn btn-default testAllSequentiallyButton">Test all sequentially</button>
<button class="btn btn-default testAllConcurrentlyButton">Test all concurrently</button>
<button class="btn btn-default lazyProjectStructure">Create lazy project structure</button>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Run</th>
<th>Results</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<script>
function Testing() {
var othis = this;
var tests = [];
this.show = function(){};
this.close = function(){};
this.testAllConcurrently = function(){
for (var i=0; i<tests.length; i++) {
var test = tests[i];
var resultTd = $(".testing tr[testid=\"" + i + "\"] td.result");
resultTd.html("");
othis.runTest(i, test, resultTd);
}
};
this.testSingleSequentially = function(testid, callback){
var test = tests[testid];
var resultTd = $(".testing tr[testid=\"" + testid + "\"] td.result");
othis.runTest(testid, test, resultTd, function(){
if (testid < tests.length) {
othis.testSingleSequentially(testid + 1, callback);
}
});
};
this.testAllSequentially = function(){
for (var i=0; i<tests.length; i++) {
var resultTd = $(".testing tr[testid=\"" + i + "\"] td.result");
resultTd.html("");
}
othis.testSingleSequentially(0);
};
this.runTest = function(testid, test, resultTd, callback) {
resultTd.html("RUNNING").addClass("running").removeClass("error").removeClass("success");
test(function(code, result){
if (code == "ERROR") {
resultTd.addClass("error").removeClass("success").removeClass("running");
resultTd.html("ERROR");
} else if (code == "SUCCESS") {
resultTd.addClass("success").removeClass("running").removeClass("error");
resultTd.html("SUCCESS");
}
if (result != null) {
resultTd.html(result);
}
if (callback != null) {
callback();
}
});
};
this.addTest = function(name, description, test){
var testid = tests.push(test) - 1;
var tr = $("<tr class=\"testtr\" testid=\"" + testid + "\">");
tr.append("<td>" + name + "</td>");
tr.append("<td>" + description + "</td>");
tr.append("<td><button class=\"btn btn-default\">Run</button></td>");
tr.append("<td class=\"result\"></td>");
$(".testing table tbody").append(tr);
tr.find("button").click(function(){
othis.runTest(0, test, $(this).parents("tr").find(".result"));
});
};
$(".testing .testAllSequentiallyButton").click(othis.testAllSequentially);
$(".testing .testAllConcurrentlyButton").click(othis.testAllConcurrently);
this.addTest("Test 1", "Create furnishing + GUID", function(doneCallback){
Global.bimServerApi.call("ServiceInterface", "addProject", {projectName: "Test 1 - " + Math.random()}, function(project){
Global.bimServerApi.createModel(project.oid, function(model){
model.create("IfcFurnishingElement", {}, function(furnishingElement){
furnishingElement.setGlobalId("blablabla");
});
}).done(function(model){
model.commit("initial revision", function(roid){
// Now we will test and see if the objects are really there
Global.bimServerApi.getModel(project.oid, roid, false, project.schema, function(model){
var first = true;
model.getAllOfType("IfcFurnishingElement", true, function(furnishingElement){
if (first) {
first = false;
furnishingElement.getGlobalId(function(guid){
if (guid == null) {
doneCallback("ERROR", "No GUID");
} else if (guid == "blablabla") {
doneCallback("SUCCESS");
} else {
doneCallback("ERROR", "Not the right GUID value (" + guid + ")");
}
});
} else {
doneCallback("ERROR", "Multiple IfcFurnishingElement");
}
});
});
});
});
});
});
this.addTest("Test 2", "Create 10 walls, delete 1", function(doneCallback){
Global.bimServerApi.call("ServiceInterface", "addProject", {projectName: "Test 2 - " + Math.random()}, function(project){
// Stage 1: create 10 walls
Global.bimServerApi.createModel(project.oid, function(model){
for (var i=1; i<=10; i++) {
(function(i){
model.create("IfcWall", {}, function(wall){
wall.setName("wall " + i);
wall.setGlobalId("wall" + i); // yes not using real GUID, this is just for testing
});
})(i);
}
}).done(function(model){
model.commit("initial revision with 10 walls", function(roid){
// Stage 2: count the walls and remove the 6th
Global.bimServerApi.getModel(project.oid, roid, project.schema, false, function(model){
model.count("IfcWall", true, function(count){
if (count == 10) {
model.getByGuid("wall6", function(wall6){
wall6.remove();
});
} else {
doneCallback("ERROR", count + " walls found, should be 10");
}
});
}).done(function(model){
model.commit("removing the 6th wall", function(roid){
// Stage 3: count again
Global.bimServerApi.getModel(project.oid, roid, project.schema, false, function(model){
model.count("IfcWall", true, function(count){
if (count == 9) {
doneCallback("SUCCESS");
} else {
doneCallback("ERROR", "Found " + count + " walls, should be 9");
}
});
});
});
});
});
});
});
});
this.addTest("Test 3", "Create a few objects and find it back by name", function(doneCallback){
Global.bimServerApi.call("ServiceInterface", "addProject", {projectName: "Test 3 - " + Math.random()}, function(project){
// Stage 1: create 10 windows
Global.bimServerApi.createModel(project.oid, function(model){
for (var i=1; i<=10; i++) {
(function(i){
model.create("IfcWindow", {}, function(window){
window.setName("window" + i);
window.setGlobalId("window" + i); // yes not using real GUID, this is just for testing
});
})(i);
}
}).done(function(model){
model.commit("10 windows", function(roid){
// Stage 2: count the walls and remove the 6th
Global.bimServerApi.getModel(project.oid, roid, project.schema, false, function(model){
model.getByName("window7", function(window7){
if (window7 == null) {
doneCallback("ERROR", "Window not found");
} else if (window7.getGlobalId() == "window7") {
doneCallback("SUCCESS");
} else {
doneCallback("ERROR", "Wrong GUID (" + window7.getGlobalId() + ")");
}
});
});
});
});
});
});
this.addTest("Test 4", "Unset attribute", function(doneCallback){
Global.bimServerApi.call("ServiceInterface", "addProject", {projectName: "Test 4 - " + Math.random()}, function(project){
// Stage 1: create 1 window
Global.bimServerApi.createModel(project.oid, function(model){
model.create("IfcWindow", {}, function(window){
window.setName("window");
window.setGlobalId("window"); // yes not using real GUID, this is just for testing
});
}).done(function(model){
model.commit("1 window", function(roid){
Global.bimServerApi.getModel(project.oid, roid, project.schema, false, function(model){
model.getByName("window", function(window){
window.setName(null);
});
}).done(function(model){
model.commit("name unset", function(roid){
Global.bimServerApi.getModel(project.oid, roid, project.schema, false, function(model){
model.getByGuid("window", function(window){
if (window.getName() == null) {
doneCallback("SUCCESS");
} else if (window.getName() == "window") {
doneCallback("ERROR", "Window name unchanged");
} else {
doneCallback("ERROR", "Unknown error");
}
});
});
});
});
});
});
});
});
this.addTest("Test 5", "Unset reference", function(doneCallback){
Global.bimServerApi.call("ServiceInterface", "addProject", {projectName: "Test 5 - " + Math.random()}, function(project){
// Stage 1: create 1 window
Global.bimServerApi.createModel(project.oid, function(model){
model.create("IfcWindow", {}, function(window){
window.setName("window");
window.setGlobalId("window");
model.create("IfcOwnerHistory", {}, function(ownerHistory){
window.setOwnerHistory(ownerHistory);
});
});
}).done(function(model){
model.commit("1 window + ownerhistory", function(roid){
Global.bimServerApi.getModel(project.oid, roid, project.schema, false, function(model){
model.getByName("window", function(window){
console.log(window);
window.getOwnerHistory(function(ownerHistory){
if (ownerHistory == null) {
doneCallback("ERROR", "OwnerHistory already not set");
} else {
window.setOwnerHistory(null);
}
});
});
}).done(function(model){
model.commit("unsetting owner history of window", function(roid){
Global.bimServerApi.getModel(project.oid, roid, project.schema, false, function(model){
model.getByGuid("window", function(window){
if (window.getOwnerHistory() == null) {
doneCallback("SUCCESS");
} else {
doneCallback("ERROR", "OwnerHistory still present");
}
});
});
});
});
});
});
});
});
this.addTest("Test 6", "Setting and reading enum and integer values", function(doneCallback){
Global.bimServerApi.call("ServiceInterface", "addProject", {projectName: "Test 6 - " + Math.random()}, function(project){
var ownerHistoryOid = -1;
var timestamp = -1;
Global.bimServerApi.createModel(project.oid, function(model){
model.create("IfcOwnerHistory", {}, function(ownerHistory){
ownerHistory.setState("READWRITELOCKED");
timestamp = Math.floor(new Date().getTime() / 1000);
ownerHistory.setCreationDate(timestamp);
ownerHistoryOid = ownerHistory.__oid;
});
}).done(function(model){
model.commit("ownerhistory with state and creation date", function(roid){
Global.bimServerApi.getModel(project.oid, roid, false, project.schema, function(model){
model.get(ownerHistoryOid, function(ownerHistory){
if (ownerHistory.getState() == "READWRITELOCKED" && ownerHistory.getCreationDate() == timestamp) {
doneCallback("SUCCESS");
} else {
doneCallback("ERROR", "Mismatch");
}
});
});
});
});
});
});
this.addTest("Test 7", "Settings and reading boolean values", function(doneCallback){
Global.bimServerApi.call("ServiceInterface", "addProject", {projectName: "Test 7 - " + Math.random()}, function(project){
var ifcRectangularTrimmedSurfaceOid = -1;
Global.bimServerApi.createModel(project.oid, function(model){
model.create("IfcRectangularTrimmedSurface", {}, function(ifcRectangularTrimmedSurface){
ifcRectangularTrimmedSurface.setUsense(true);
ifcRectangularTrimmedSurface.setVsense(false);
ifcRectangularTrimmedSurfaceOid = ifcRectangularTrimmedSurface.__oid;
});
}).done(function(model){
model.commit("IfcRectangularTrimmedSurface with booleans", function(roid){
Global.bimServerApi.getModel(project.oid, roid, project.schema, false, function(model){
model.get(ifcRectangularTrimmedSurfaceOid, function(ifcRectangularTrimmedSurface){
if (ifcRectangularTrimmedSurface.getUsense() == true && ifcRectangularTrimmedSurface.getVsense() == false) {
doneCallback("SUCCESS");
} else {
doneCallback("ERROR", "Mismatch");
}
});
});
});
});
});
});
this.addTest("Test 8", "Primitive lists", function(doneCallback){
Global.bimServerApi.call("ServiceInterface", "addProject", {projectName: "Test 8 - " + Math.random()}, function(project){
var oid;
Global.bimServerApi.createModel(project.oid, function(model){
model.create("IfcCartesianPoint", {}, function(ifcCartesianPoint){
ifcCartesianPoint.setCoordinates([0.1, 0.2, 0.3]);
oid = ifcCartesianPoint.__oid;
});
}).done(function(model){
model.commit("IfcCartesianPoint with values", function(roid){
Global.bimServerApi.getModel(project.oid, roid, project.schema, false, function(model){
model.get(oid, function(ifcCartesianPoint){
console.log(ifcCartesianPoint.getCoordinates());
if (ifcCartesianPoint.getCoordinates()[0] == 0.1 && ifcCartesianPoint.getCoordinates()[1] == 0.2 && ifcCartesianPoint.getCoordinates()[2] == 0.3) {
doneCallback("SUCCESS");
} else {
doneCallback("ERROR", "Mismatch");
}
});
});
});
});
});
});
this.addTest("Test 9", "Checkin from URL", function(doneCallback){
Global.bimServerApi.call("ServiceInterface", "addProject", {projectName: "Test 9 - " + Math.random()}, function(project){
Global.bimServerApi.call("ServiceInterface", "getSuggestedDeserializerForExtension", {extension: "ifc"}, function(deserializer){
Global.bimServerApi.call("ServiceInterface", "checkinFromUrl", {
poid: project.oid,
comment: "New revision from url",
deserializerOid: deserializer.oid,
fileName: "AC11-Institute-Var-2-IFC.ifc",
url: "http://archive.opensourcebim.org/BIMserver/IFC-example-files/AC11-Institute-Var-2-IFC.ifc",
merge: false,
sync: true
}, function(checkinId){
Global.bimServerApi.call("ServiceInterface", "getProjectByPoid", {poid: project.oid}, function(project){
Global.bimServerApi.getModel(project.oid, project.lastRevisionId, project.schema, false, function(model){
model.size(function(size){
if (size == 49664) {
doneCallback("SUCCESS");
} else {
doneCallback("ERROR", "Size is not correct " + size + "/" + 49664);
}
});
});
});
});
});
});
});
this.addTest("Test 10", "Checkin from URL and load", function(doneCallback){
Global.bimServerApi.call("ServiceInterface", "addProject", {projectName: "Test 10 - " + Math.random()}, function(project){
Global.bimServerApi.call("ServiceInterface", "getSuggestedDeserializerForExtension", {extension: "ifc"}, function(deserializer){
Global.bimServerApi.call("ServiceInterface", "checkinFromUrl", {
poid: project.oid,
comment: "New revision from url",
deserializerOid: deserializer.oid,
fileName: "AC11-Institute-Var-2-IFC.ifc",
url: "http://archive.opensourcebim.org/BIMserver/IFC-example-files/AC11-Institute-Var-2-IFC.ifc",
merge: false,
sync: true
}, function(checkinId){
Global.bimServerApi.call("ServiceInterface", "getProjectByPoid", {poid: project.oid}, function(project){
Global.bimServerApi.getModel(project.oid, project.lastRevisionId, project.schema, false, function(model){
model.load(false, function(){
doneCallback("SUCCESS");
});
});
});
});
});
});
});
$(".lazyProjectStructure").click(function(){
Global.bimServerApi.call("ServiceInterface", "addProject", {projectName: "Gebouw"}, function(building){
Global.bimServerApi.call("ServiceInterface", "addProjectAsSubProject", {projectName: "Architekt", parentPoid: building.oid}, function(architekt){
Global.bimServerApi.call("ServiceInterface", "addProjectAsSubProject", {projectName: "Dakkap", parentPoid: architekt.oid}, function(dakkap){
});
Global.bimServerApi.call("ServiceInterface", "addProjectAsSubProject", {projectName: "Dakkappellen", parentPoid: architekt.oid}, function(dakkappellen){
});
Global.bimServerApi.call("ServiceInterface", "addProjectAsSubProject", {projectName: "Deurbellen", parentPoid: architekt.oid}, function(deurbellen){
});
Global.bimServerApi.call("ServiceInterface", "addProjectAsSubProject", {projectName: "Kalkzandsteen", parentPoid: architekt.oid}, function(kalkzandsteen){
});
Global.bimServerApi.call("ServiceInterface", "addProjectAsSubProject", {projectName: "Plafonds", parentPoid: architekt.oid}, function(plafonds){
});
Global.bimServerApi.call("ServiceInterface", "addProjectAsSubProject", {projectName: "Reclame", parentPoid: architekt.oid}, function(reclame){
});
Global.bimServerApi.call("ServiceInterface", "addProjectAsSubProject", {projectName: "Tegelwerk", parentPoid: architekt.oid}, function(tegelwerk){
});
Global.bimServerApi.call("ServiceInterface", "addProjectAsSubProject", {projectName: "Trapleuningen", parentPoid: architekt.oid}, function(trapleuningen){
});
Global.bimServerApi.call("ServiceInterface", "addProjectAsSubProject", {projectName: "Trappen", parentPoid: architekt.oid}, function(trappen){
});
});
});
});
}
</script>