Merge pull request #632 from ahocevar/wps-client
WPS Client. r=@bartvde,@tschaub
This commit is contained in:
108
tests/WPSClient.html
Normal file
108
tests/WPSClient.html
Normal file
@@ -0,0 +1,108 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="OLLoader.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var client;
|
||||
|
||||
function test_initialize(t) {
|
||||
t.plan(3);
|
||||
|
||||
client = new OpenLayers.WPSClient({
|
||||
servers: {
|
||||
local: "/geoserver/wps"
|
||||
}
|
||||
});
|
||||
|
||||
t.ok(client instanceof OpenLayers.WPSClient, 'creates an instance');
|
||||
t.ok(client.events, 'has an events 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_describeProcess(t) {
|
||||
t.plan(6);
|
||||
var log = {request: [], event: []};
|
||||
var originalGET = OpenLayers.Request.GET;
|
||||
OpenLayers.Request.GET = function(cfg) {
|
||||
log.request.push(cfg);
|
||||
}
|
||||
function describe(evt) {
|
||||
log.event.push(evt);
|
||||
}
|
||||
client.events.register('describeprocess', this, describe);
|
||||
|
||||
process = client.getProcess('local', 'gs:splitPolygon');
|
||||
t.eq(client.servers.local.processDescription['gs:splitPolyon'], null, 'describeProcess pending');
|
||||
process.describe();
|
||||
t.eq(log.request.length, 1, 'describeProcess request only sent once');
|
||||
log.request[0].success.call(client, {
|
||||
responseText: '<?xml version="1.0" encoding="UTF-8"?><wps:ProcessDescriptions xmlns:wps="http://www.opengis.net/wps/1.0.0"></wps:ProcessDescriptions>'
|
||||
});
|
||||
t.eq(log.event[0].type, 'describeprocess', 'describeprocess event triggered');
|
||||
t.ok(client.servers.local.processDescription['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;
|
||||
client.events.unregister('describeprocess', this, describe);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
function test_destroy(t) {
|
||||
t.plan(2);
|
||||
client = new OpenLayers.WPSClient({
|
||||
servers: {
|
||||
local: "/geoserver/wps"
|
||||
},
|
||||
lazy: true
|
||||
});
|
||||
client.destroy();
|
||||
t.eq(client.events, null, "Events nullified");
|
||||
t.eq(client.servers, null, "Servers nullified");
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
188
tests/WPSProcess.html
Normal file
188
tests/WPSProcess.html
Normal file
@@ -0,0 +1,188 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="OLLoader.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var wkt = new OpenLayers.Format.WKT();
|
||||
var process;
|
||||
var client = new OpenLayers.WPSClient({
|
||||
servers: {
|
||||
local: 'geoserver/wps'
|
||||
}
|
||||
});
|
||||
client.servers.local.processDescription = {
|
||||
'JTS:intersection': '<?xml version="1.0" encoding="UTF-8"?>' +
|
||||
'<wps:ProcessDescriptions xml:lang="en" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink"><ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true"><ows:Identifier>JTS:intersection</ows:Identifier><ows:Title>Returns the intersectoin between a and b (eventually an empty collection if there is no intersection)</ows:Title><ows:Abstract>Returns the intersectoin between a and b (eventually an empty collection if there is no intersection)</ows:Abstract><DataInputs><Input maxOccurs="1" minOccurs="1"><ows:Identifier>a</ows:Identifier><ows:Title>a</ows:Title><ows:Abstract>[undescribed]</ows:Abstract><ComplexData><Default><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format><Format><MimeType>text/xml; subtype=gml/2.1.2</MimeType></Format><Format><MimeType>application/wkt</MimeType></Format><Format><MimeType>application/gml-3.1.1</MimeType></Format><Format><MimeType>application/gml-2.1.2</MimeType></Format></Supported></ComplexData></Input><Input maxOccurs="1" minOccurs="1"><ows:Identifier>b</ows:Identifier><ows:Title>b</ows:Title><ows:Abstract>[undescribed]</ows:Abstract><ComplexData><Default><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format><Format><MimeType>text/xml; subtype=gml/2.1.2</MimeType></Format><Format><MimeType>application/wkt</MimeType></Format><Format><MimeType>application/gml-3.1.1</MimeType></Format><Format><MimeType>application/gml-2.1.2</MimeType></Format></Supported></ComplexData></Input></DataInputs><ProcessOutputs><Output><ows:Identifier>result</ows:Identifier><ows:Title>Process result</ows:Title><ComplexOutput><Default><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format><Format><MimeType>text/xml; subtype=gml/2.1.2</MimeType></Format><Format><MimeType>application/wkt</MimeType></Format><Format><MimeType>application/gml-3.1.1</MimeType></Format><Format><MimeType>application/gml-2.1.2</MimeType></Format></Supported></ComplexOutput></Output></ProcessOutputs></ProcessDescription></wps:ProcessDescriptions>'
|
||||
};
|
||||
|
||||
function test_initialize(t) {
|
||||
t.plan(1);
|
||||
process = new OpenLayers.WPSProcess();
|
||||
t.ok(process instanceof OpenLayers.WPSProcess, 'creates an instance');
|
||||
}
|
||||
|
||||
function test_describe(t) {
|
||||
t.plan(2);
|
||||
process = client.getProcess('local', 'JTS:intersection');
|
||||
var log = [];
|
||||
process.describe({
|
||||
callback: function(description) { log.push(description); }
|
||||
});
|
||||
t.delay_call(0.1, function() {
|
||||
t.eq(log.length, 1, 'callback called');
|
||||
t.eq(log[0].identifier, 'JTS:intersection', 'callback called with correct description');
|
||||
});
|
||||
}
|
||||
|
||||
function test_execute(t) {
|
||||
t.plan(7);
|
||||
|
||||
var log = [];
|
||||
var originalPOST = OpenLayers.Request.POST;
|
||||
OpenLayers.Request.POST = function(cfg) {
|
||||
log.push(cfg);
|
||||
cfg.success.call(cfg.scope, {responseText: ''});
|
||||
}
|
||||
|
||||
process = new OpenLayers.WPSProcess({
|
||||
client: client,
|
||||
server: 'local',
|
||||
identifier: 'gs:splitPolygon'
|
||||
});
|
||||
process.description = {
|
||||
dataInputs: [{
|
||||
identifier: 'line',
|
||||
complexData: {
|
||||
supported: {
|
||||
formats: {'application/wkt': true}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
identifier: 'polygon',
|
||||
complexData: {
|
||||
supported: {
|
||||
formats: {'application/wkt': true}
|
||||
}
|
||||
}
|
||||
}],
|
||||
processOutputs: [{
|
||||
identifier: 'foo',
|
||||
complexOutput: {
|
||||
supported: {
|
||||
formats: {'application/wkt': true}
|
||||
}
|
||||
}
|
||||
}]
|
||||
};
|
||||
var line = 'LINESTRING(117 22,112 18,118 13,115 8)';
|
||||
var polygon = 'POLYGON((110 20,120 20,120 10,110 10,110 20),(112 17,118 18,118 16,112 15,112 17))';
|
||||
var output = [];
|
||||
function success(result) {
|
||||
output.push(result);
|
||||
}
|
||||
// configured with output identifier
|
||||
process.execute({
|
||||
inputs: {
|
||||
line: wkt.read(line),
|
||||
polygon: wkt.read(polygon)
|
||||
},
|
||||
output: 'foo',
|
||||
success: success
|
||||
});
|
||||
// configured without output identifier
|
||||
process.execute({
|
||||
inputs: {
|
||||
line: wkt.read(line),
|
||||
polygon: wkt.read(polygon)
|
||||
},
|
||||
success: success
|
||||
});
|
||||
|
||||
t.delay_call(0.1, function() {
|
||||
t.eq(log.length, 2, 'Two execute requests 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, 'foo', 'correct identifier for responseForm');
|
||||
t.eq(process.description.responseForm.rawDataOutput.mimeType, 'application/wkt', 'correct format for responseForm');
|
||||
t.ok('foo' in output[0], 'process result contains output with correct identifier when configured with output');
|
||||
t.ok('result' in output[1], 'process result contains output with correct identifier when configured without output');
|
||||
|
||||
OpenLayers.Request.POST = originalPOST;
|
||||
});
|
||||
}
|
||||
|
||||
function test_chainProcess(t) {
|
||||
t.plan(5);
|
||||
|
||||
var originalGET = OpenLayers.Request.GET;
|
||||
OpenLayers.Request.GET = function(cfg) {
|
||||
window.setTimeout(function() {
|
||||
cfg.success.call(cfg.scope, {
|
||||
responseText: '<?xml version="1.0" encoding="UTF-8"?>' +
|
||||
'<wps:ProcessDescriptions xml:lang="en" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink"><ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true"><ows:Identifier>JTS:buffer</ows:Identifier><ows:Title>Buffers a geometry using a certain distance</ows:Title><ows:Abstract>Buffers a geometry using a certain distance</ows:Abstract><DataInputs><Input maxOccurs="1" minOccurs="1"><ows:Identifier>geom</ows:Identifier><ows:Title>geom</ows:Title><ows:Abstract>The geometry to be buffered</ows:Abstract><ComplexData><Default><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format><Format><MimeType>text/xml; subtype=gml/2.1.2</MimeType></Format><Format><MimeType>application/wkt</MimeType></Format><Format><MimeType>application/gml-3.1.1</MimeType></Format><Format><MimeType>application/gml-2.1.2</MimeType></Format></Supported></ComplexData></Input><Input maxOccurs="1" minOccurs="1"><ows:Identifier>distance</ows:Identifier><ows:Title>distance</ows:Title><ows:Abstract>The distance (same unit of measure as the geometry)</ows:Abstract><LiteralData><ows:DataType>xs:double</ows:DataType><ows:AnyValue/></LiteralData></Input><Input maxOccurs="1" minOccurs="0"><ows:Identifier>quadrantSegments</ows:Identifier><ows:Title>quadrantSegments</ows:Title><ows:Abstract>Number of quadrant segments. Use > 0 for round joins, 0 for flat joins, < 0 for mitred joins</ows:Abstract><LiteralData><ows:DataType>xs:int</ows:DataType><ows:AnyValue/></LiteralData></Input><Input maxOccurs="1" minOccurs="0"><ows:Identifier>capStyle</ows:Identifier><ows:Title>capStyle</ows:Title><ows:Abstract>The buffer cap style, round, flat, square</ows:Abstract><LiteralData><ows:AllowedValues><ows:Value>Round</ows:Value><ows:Value>Flat</ows:Value><ows:Value>Square</ows:Value></ows:AllowedValues></LiteralData></Input></DataInputs><ProcessOutputs><Output><ows:Identifier>result</ows:Identifier><ows:Title>result</ows:Title><ComplexOutput><Default><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format><Format><MimeType>text/xml; subtype=gml/2.1.2</MimeType></Format><Format><MimeType>application/wkt</MimeType></Format><Format><MimeType>application/gml-3.1.1</MimeType></Format><Format><MimeType>application/gml-2.1.2</MimeType></Format></Supported></ComplexOutput></Output></ProcessOutputs></ProcessDescription></wps:ProcessDescriptions>'
|
||||
});
|
||||
}, 100);
|
||||
}
|
||||
var originalPOST = OpenLayers.Request.POST;
|
||||
OpenLayers.Request.POST = function(cfg) {
|
||||
cfg.success.call(cfg.scope, {responseText: ''});
|
||||
};
|
||||
|
||||
var intersect = client.getProcess('local', 'JTS:intersection');
|
||||
intersect.configure({
|
||||
inputs: {
|
||||
a: wkt.read(
|
||||
'LINESTRING(117 22,112 18,118 13,115 8)'
|
||||
),
|
||||
b: wkt.read(
|
||||
'POLYGON((110 20,120 20,120 10,110 10,110 20),(112 17,118 18,118 16,112 15,112 17))'
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
// one buffer process to make sure chaining works
|
||||
var buffer1 = client.getProcess('local', 'JTS:buffer');
|
||||
// another buffer process to make sure that things work asynchronously
|
||||
var buffer2 = client.getProcess('local', 'JTS:buffer');
|
||||
var log = [];
|
||||
buffer1.chainProcess = buffer2.chainProcess = function() {
|
||||
log.push(this.executeCallbacks.length);
|
||||
OpenLayers.WPSProcess.prototype.chainProcess.apply(this, arguments);
|
||||
};
|
||||
var done1 = done2 = false;
|
||||
buffer1.execute({
|
||||
inputs: {
|
||||
geom: intersect.output(),
|
||||
distance: 1
|
||||
},
|
||||
success: function(outputs) {
|
||||
done1 = true;
|
||||
}
|
||||
});
|
||||
buffer2.execute({
|
||||
inputs: {
|
||||
geom: intersect.output(),
|
||||
distance: 2
|
||||
},
|
||||
success: function(outputs) {
|
||||
done2 = true;
|
||||
}
|
||||
});
|
||||
|
||||
t.delay_call(0.5, function() {
|
||||
t.eq(log.length, 2, 'chainProcess called once for each process');
|
||||
t.eq(log[0], 1, 'executeCallback queued to wait for 1 chained process');
|
||||
t.eq(log[1], 1, 'executeCallback queued to wait for 1 chained process');
|
||||
t.eq(done1, true, 'execute for buffer1 process successfully completed');
|
||||
t.eq(done2, true, 'execute for buffer2 process successfully completed');
|
||||
|
||||
OpenLayers.Request.GET = originalGET;
|
||||
OpenLayers.Request.POST = originalPOST;
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -232,6 +232,8 @@
|
||||
<li>Kinetic.html</li>
|
||||
<li>Util.html</li>
|
||||
<li>Util/vendorPrefix.html</li>
|
||||
<li>WPSClient.html</li>
|
||||
<li>WPSProcess.html</li>
|
||||
<li>deprecated/Ajax.html</li>
|
||||
<li>deprecated/Util.html</li>
|
||||
<li>deprecated/BaseTypes/Class.html</li>
|
||||
@@ -249,4 +251,4 @@
|
||||
<li>deprecated/Renderer/SVG2.html</li>
|
||||
<li>deprecated/Layer/Yahoo.html</li>
|
||||
<li>deprecated/Tile/WFS.html</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user