Adding unit tests.
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="OLLoader.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
var client;
|
||||||
|
|
||||||
|
function test_initialize(t) {
|
||||||
|
t.plan(2);
|
||||||
|
|
||||||
|
client = new OpenLayers.WPSClient({
|
||||||
|
servers: {
|
||||||
|
local: "/geoserver/wps"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
t.ok(client instanceof OpenLayers.WPSClient, 'creates an instance');
|
||||||
|
t.eq(client.servers.local.url, '/geoserver/wps', 'servers stored on instance');
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_getProcess(t) {
|
||||||
|
t.plan(4);
|
||||||
|
|
||||||
|
client = new OpenLayers.WPSClient({
|
||||||
|
servers: {
|
||||||
|
local: "/geoserver/wps"
|
||||||
|
},
|
||||||
|
lazy: true
|
||||||
|
});
|
||||||
|
|
||||||
|
var process = client.getProcess('local', 'gs:splitPolygon');
|
||||||
|
t.ok(process instanceof OpenLayers.WPSProcess, 'creates a process');
|
||||||
|
t.ok(process.client === client, 'process knows about client');
|
||||||
|
t.eq(process.server, 'local', 'process created with correct server');
|
||||||
|
t.eq(process.identifier, 'gs:splitPolygon', 'process created with correct identifier');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_execute(t) {
|
||||||
|
t.plan(1);
|
||||||
|
|
||||||
|
client = new OpenLayers.WPSClient({
|
||||||
|
servers: {
|
||||||
|
local: "/geoserver/wps"
|
||||||
|
},
|
||||||
|
lazy: true
|
||||||
|
});
|
||||||
|
var log = [];
|
||||||
|
client.getProcess = function() {
|
||||||
|
return {
|
||||||
|
execute: function(options) {
|
||||||
|
log.push(options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
client.execute({inputs: 'a', success: 'b', scope: 'c'});
|
||||||
|
t.eq(log[0], {inputs: 'a', success: 'b', scope: 'c'}, "process executed with correct options");
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="OLLoader.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
var process;
|
||||||
|
var client = new OpenLayers.WPSClient({
|
||||||
|
servers: {
|
||||||
|
local: 'geoserver/wps'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function test_initialize(t) {
|
||||||
|
t.plan(2);
|
||||||
|
|
||||||
|
process = new OpenLayers.WPSProcess();
|
||||||
|
|
||||||
|
t.ok(process instanceof OpenLayers.WPSProcess, 'creates an instance');
|
||||||
|
t.ok(process.events, 'has an events instance');
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_describe(t) {
|
||||||
|
t.plan(6);
|
||||||
|
var log = {request: [], event: []};
|
||||||
|
var originalGET = OpenLayers.Request.GET;
|
||||||
|
OpenLayers.Request.GET = function(cfg) {
|
||||||
|
log.request.push(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
process = client.getProcess('local', 'gs:splitPolygon');
|
||||||
|
process.events.register('describeprocess', this, function(evt) {
|
||||||
|
log.event.push(evt);
|
||||||
|
});
|
||||||
|
t.eq(client.servers.local.describeProcessResponse['gs:splitPolyon'], null, 'describeProcess pending');
|
||||||
|
process.describe();
|
||||||
|
t.eq(log.request.length, 1, 'describeProcess request only sent once');
|
||||||
|
log.request[0].success.call(process, {
|
||||||
|
responseText: '<wps:ProcessDescriptions></wps:ProcessDescriptions>'
|
||||||
|
});
|
||||||
|
t.eq(log.event[0].type, 'describeprocess', 'describeprocess event triggered');
|
||||||
|
t.ok(client.servers.local.describeProcessResponse['gs:splitPolygon'], 'We have a process description!');
|
||||||
|
process.describe();
|
||||||
|
t.eq(log.request.length, 1, 'describeProcess request only sent once');
|
||||||
|
t.eq(log.event.length, 1, 'describeprocess event only triggered once');
|
||||||
|
|
||||||
|
OpenLayers.Request.GET = originalGET;
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_execute(t) {
|
||||||
|
t.plan(5);
|
||||||
|
|
||||||
|
var log = [];
|
||||||
|
var originalPOST = OpenLayers.Request.POST;
|
||||||
|
OpenLayers.Request.POST = function(cfg) {
|
||||||
|
log.push(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
process = client.getProcess('local', 'gs:splitPolygon');
|
||||||
|
process.description = {
|
||||||
|
dataInputs: [{
|
||||||
|
identifier: 'line',
|
||||||
|
complexData: {
|
||||||
|
supported: {
|
||||||
|
formats: {'application/wkt': true}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
identifier: 'polygon',
|
||||||
|
complexData: {
|
||||||
|
supported: {
|
||||||
|
formats: {'application/wkt': true}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
processOutputs: [{
|
||||||
|
identifier: 'result',
|
||||||
|
complexOutput: {
|
||||||
|
supported: {
|
||||||
|
formats: {'application/wkt': true}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
var line = 'LINESTRING(117 22,112 18,118 13,115 8)';
|
||||||
|
process.execute({
|
||||||
|
inputs: {
|
||||||
|
line: new OpenLayers.Format.WKT().read(line),
|
||||||
|
polygon: new OpenLayers.Format.WKT().read(
|
||||||
|
'POLYGON((110 20,120 20,120 10,110 10,110 20),(112 17,118 18,118 16,112 15,112 17))'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
t.eq(log.length, 1, 'execute request sent');
|
||||||
|
t.eq(process.description.dataInputs[0].data.complexData.value, line, 'data for first input correct');
|
||||||
|
t.eq(process.description.dataInputs[0].data.complexData.mimeType, 'application/wkt', 'format for first input correct');
|
||||||
|
t.eq(process.description.responseForm.rawDataOutput.identifier, 'result', 'correct identifier for responseForm');
|
||||||
|
t.eq(process.description.responseForm.rawDataOutput.mimeType, 'application/wkt', 'correct format for responseForm');
|
||||||
|
|
||||||
|
OpenLayers.Request.POST = originalPOST;
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -232,6 +232,8 @@
|
|||||||
<li>Kinetic.html</li>
|
<li>Kinetic.html</li>
|
||||||
<li>Util.html</li>
|
<li>Util.html</li>
|
||||||
<li>Util/vendorPrefix.html</li>
|
<li>Util/vendorPrefix.html</li>
|
||||||
|
<li>WPSClient.html</li>
|
||||||
|
<li>WPSProcess.html</li>
|
||||||
<li>deprecated/Ajax.html</li>
|
<li>deprecated/Ajax.html</li>
|
||||||
<li>deprecated/Util.html</li>
|
<li>deprecated/Util.html</li>
|
||||||
<li>deprecated/BaseTypes/Class.html</li>
|
<li>deprecated/BaseTypes/Class.html</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user