ogc 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ogc.rb +3 -5
- data/lib/ogc/abstract_base.rb +94 -0
- data/lib/ogc/core_ext.rb +1 -0
- data/lib/ogc/core_ext/string.rb +9 -0
- data/lib/ogc/errors.rb +8 -0
- data/lib/ogc/{exceptions → errors}/exception_report.rb +3 -3
- data/lib/ogc/errors/ogc_error.rb +5 -0
- data/lib/ogc/errors/request_error.rb +7 -0
- data/lib/ogc/{exceptions/request_failed_exception.rb → errors/service_error.rb} +4 -2
- data/lib/ogc/version.rb +1 -1
- data/lib/ogc/web_feature_service/base.rb +4 -89
- data/lib/ogc/web_feature_service/get_capabilities.rb +2 -0
- data/lib/ogc/web_feature_service/get_feature.rb +3 -0
- data/lib/ogc/web_processing_service.rb +16 -0
- data/lib/ogc/web_processing_service/base.rb +9 -0
- data/lib/ogc/web_processing_service/execute.rb +16 -0
- data/test/ogc/abstract_base_test.rb +137 -0
- data/test/ogc/{clean_xml_test.rb → core_ext/string_test.rb} +1 -2
- data/test/ogc/{exceptions → errors}/exception_report_test.rb +3 -5
- data/test/ogc/{exceptions/ogc_exception_test.rb → errors/ogc_error_test.rb} +3 -3
- data/test/ogc/errors/request_error_test.rb +11 -0
- data/test/ogc/{exceptions/request_failed_exception_test.rb → errors/service_error_test.rb} +5 -5
- data/test/ogc/errors_test.rb +9 -0
- data/test/ogc/web_feature_service/base_test.rb +3 -136
- data/test/ogc/web_feature_service/get_capabilities_test.rb +1 -3
- data/test/ogc/web_feature_service/get_feature_test.rb +1 -3
- data/test/ogc/web_processing_service/base_test.rb +12 -0
- data/test/ogc/web_processing_service/execute_test.rb +36 -0
- data/test/test_helper.rb +0 -2
- data/test/xml/wps/execute_response.xml +35 -0
- metadata +22 -15
- data/lib/ogc/clean_xml.rb +0 -13
- data/lib/ogc/exceptions.rb +0 -8
- data/lib/ogc/exceptions/ogc_exception.rb +0 -5
- data/lib/ogc/exceptions/request_error_exception.rb +0 -7
- data/lib/ogc/query.rb +0 -11
- data/test/ogc/exceptions/request_error_exception_test.rb +0 -11
- data/test/ogc/exceptions_test.rb +0 -9
- data/test/ogc/query_test.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f7d9616808aaf51444ddebc1e4c74708406ad59
|
4
|
+
data.tar.gz: ab9d14e38cc52bd883037b0d1c58261aa44ccf13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d7c8c41ea813e3800008bdc2f9d4714c754d11793b16abed18a3960d7c1ce18812733187b7d1f45672228b6669d2a17350ee687a01d32cbbe10a3a6d2484fbb
|
7
|
+
data.tar.gz: eafd33772ebafa0658d1d2efe0a3d42ff17c47f0657ddde86981feac530c30a9b1187462a0c8d300f89ad6c12d516c86116b3e0767cf3fec9f9693d0459a09a9
|
data/lib/ogc.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
module Ogc; end
|
2
2
|
|
3
|
-
|
4
|
-
require 'ogc/
|
5
|
-
require 'ogc/query'
|
6
|
-
|
7
|
-
require 'ogc/exceptions'
|
3
|
+
require 'ogc/core_ext'
|
4
|
+
require 'ogc/errors'
|
8
5
|
require 'ogc/version'
|
9
6
|
require 'ogc/web_feature_service'
|
7
|
+
require 'ogc/web_processing_service'
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'ogc/errors'
|
2
|
+
|
3
|
+
require 'active_support/core_ext/class/attribute'
|
4
|
+
require 'active_support/core_ext/hash/keys'
|
5
|
+
require 'active_support/core_ext/object/blank'
|
6
|
+
require 'active_support/core_ext/object/to_query'
|
7
|
+
require 'active_support/core_ext/string/inflections'
|
8
|
+
require 'nokogiri'
|
9
|
+
|
10
|
+
module Ogc
|
11
|
+
class AbstractBase
|
12
|
+
include Errors
|
13
|
+
|
14
|
+
attr_reader :params, :response, :url
|
15
|
+
|
16
|
+
class_attribute :default_params
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def request_name
|
20
|
+
@request_name ||= to_s.demodulize
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(url, params = nil)
|
25
|
+
@url = url
|
26
|
+
@params = params.is_a?(Hash) ? params.stringify_keys : {}
|
27
|
+
@params.merge!(default_params) if default_params.is_a?(Hash)
|
28
|
+
end
|
29
|
+
|
30
|
+
def get(extra_params, &block)
|
31
|
+
params = extra_params ? extra_params.merge(@params) : @params
|
32
|
+
fetch(:get, params, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def post(body, &block)
|
36
|
+
fetch(:post, body.respond_to?(:to_xml) ? body.to_xml : body, &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def http
|
40
|
+
@http ||= Net::HTTP.new(uri.host, uri.port)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def fetch(type, content, &block)
|
46
|
+
request = request(type, content)
|
47
|
+
block.call(request) if block
|
48
|
+
handle_response(request)
|
49
|
+
end
|
50
|
+
|
51
|
+
def handle_response(request)
|
52
|
+
case (response = http.request(request))
|
53
|
+
when Net::HTTPSuccess
|
54
|
+
@response = Nokogiri::XML(response.body.clean_xml!).tap do |xml|
|
55
|
+
# rubocop:disable Style/RaiseArgs
|
56
|
+
raise ExceptionReport.new(xml) if ExceptionReport.exception?(xml)
|
57
|
+
# rubocop:enable Style/RaiseArgs
|
58
|
+
end
|
59
|
+
else
|
60
|
+
# rubocop:disable Style/RaiseArgs
|
61
|
+
raise ServiceError.new(response)
|
62
|
+
# rubocop:enable Style/RaiseArgs
|
63
|
+
end
|
64
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
65
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
66
|
+
Net::ProtocolError
|
67
|
+
raise RequestError
|
68
|
+
end
|
69
|
+
|
70
|
+
def request(type, content)
|
71
|
+
case type
|
72
|
+
when :get then Net::HTTP::Get.new(uri_with_params(content))
|
73
|
+
when :post
|
74
|
+
Net::HTTP::Post.new(uri_without_params).tap do |req|
|
75
|
+
req.body = content
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def uri_with_params(extra_params)
|
81
|
+
return uri_without_params if extra_params.blank?
|
82
|
+
|
83
|
+
uri_without_params.dup.tap do |uri|
|
84
|
+
www_form = Hash[URI.decode_www_form(uri.query.to_s)]
|
85
|
+
uri.query = www_form.merge!(extra_params).to_query
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def uri_without_params
|
90
|
+
@uri ||= URI(@url)
|
91
|
+
end
|
92
|
+
alias_method :uri, :uri_without_params
|
93
|
+
end
|
94
|
+
end
|
data/lib/ogc/core_ext.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ogc/core_ext/string'
|
data/lib/ogc/errors.rb
ADDED
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'ogc/
|
1
|
+
require 'ogc/errors/ogc_error'
|
2
2
|
|
3
3
|
module Ogc
|
4
|
-
module
|
5
|
-
class ExceptionReport <
|
4
|
+
module Errors
|
5
|
+
class ExceptionReport < OgcError
|
6
6
|
ROOTS = %w( ServiceExceptionReport ExceptionReport ).freeze
|
7
7
|
|
8
8
|
attr_reader :report
|
data/lib/ogc/version.rb
CHANGED
@@ -1,96 +1,11 @@
|
|
1
|
-
require 'ogc/
|
1
|
+
require 'ogc/abstract_base'
|
2
2
|
|
3
|
-
require 'active_support/core_ext/
|
4
|
-
require 'active_support/core_ext/object/blank'
|
5
|
-
require 'active_support/core_ext/object/to_query'
|
6
|
-
require 'active_support/core_ext/string/inflections'
|
7
|
-
require 'nokogiri'
|
3
|
+
require 'active_support/core_ext/module/introspection'
|
8
4
|
|
9
5
|
module Ogc
|
10
6
|
module WebFeatureService
|
11
|
-
class Base
|
12
|
-
|
13
|
-
|
14
|
-
using CleanXML
|
15
|
-
using Query
|
16
|
-
|
17
|
-
attr_reader :params, :response, :url
|
18
|
-
|
19
|
-
DEFAULT_PARAMS = { 'service' => 'wfs' }.freeze
|
20
|
-
|
21
|
-
class << self
|
22
|
-
def request_name
|
23
|
-
@request_name ||= to_s.demodulize
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def initialize(url, params = nil)
|
28
|
-
@url = url
|
29
|
-
@params = (params ? params.stringify_keys : {}).merge!(DEFAULT_PARAMS)
|
30
|
-
end
|
31
|
-
|
32
|
-
def get(extra_params, &block)
|
33
|
-
params = extra_params ? extra_params.merge(@params) : @params
|
34
|
-
fetch(:get, params, &block)
|
35
|
-
end
|
36
|
-
|
37
|
-
def post(body, &block)
|
38
|
-
fetch(:post, body.respond_to?(:to_xml) ? body.to_xml : body, &block)
|
39
|
-
end
|
40
|
-
|
41
|
-
def http
|
42
|
-
@http ||= Net::HTTP.new(uri.host, uri.port)
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def fetch(type, content, &block)
|
48
|
-
request = request(type, content)
|
49
|
-
block.call(request) if block
|
50
|
-
handle_response(request)
|
51
|
-
end
|
52
|
-
|
53
|
-
def handle_response(request)
|
54
|
-
case (response = http.request(request))
|
55
|
-
when Net::HTTPSuccess
|
56
|
-
@response = Nokogiri::XML(response.body.clean_xml!).tap do |xml|
|
57
|
-
# rubocop:disable Style/RaiseArgs
|
58
|
-
raise ExceptionReport.new(xml) if ExceptionReport.exception?(xml)
|
59
|
-
# rubocop:enable Style/RaiseArgs
|
60
|
-
end
|
61
|
-
else
|
62
|
-
# rubocop:disable Style/RaiseArgs
|
63
|
-
raise RequestFailedException.new(response)
|
64
|
-
# rubocop:enable Style/RaiseArgs
|
65
|
-
end
|
66
|
-
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
67
|
-
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
68
|
-
Net::ProtocolError
|
69
|
-
raise RequestErrorException
|
70
|
-
end
|
71
|
-
|
72
|
-
def request(type, content)
|
73
|
-
case type
|
74
|
-
when :get then Net::HTTP::Get.new(uri_with_params(content))
|
75
|
-
when :post
|
76
|
-
Net::HTTP::Post.new(uri_without_params).tap do |req|
|
77
|
-
req.body = content
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def uri_with_params(extra_params)
|
83
|
-
return uri_without_params if extra_params.blank?
|
84
|
-
|
85
|
-
uri_without_params.dup.tap do |uri|
|
86
|
-
uri.query = Hash.from_query(uri.query).merge!(extra_params).to_query
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def uri_without_params
|
91
|
-
@uri ||= URI(@url)
|
92
|
-
end
|
93
|
-
alias_method :uri, :uri_without_params
|
7
|
+
class Base < AbstractBase
|
8
|
+
self.default_params = { 'service' => 'wfs' }.freeze
|
94
9
|
end
|
95
10
|
end
|
96
11
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'ogc/web_processing_service/base'
|
2
|
+
require 'ogc/web_processing_service/execute'
|
3
|
+
|
4
|
+
require 'active_support/core_ext/string/inflections'
|
5
|
+
|
6
|
+
module Ogc
|
7
|
+
module WebProcessingService
|
8
|
+
SUPPORTED_METHODS = %i( execute ).freeze
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def execute(*args)
|
12
|
+
Execute.new(*args)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'ogc/web_processing_service/base'
|
2
|
+
|
3
|
+
module Ogc
|
4
|
+
module WebProcessingService
|
5
|
+
class Execute < Base
|
6
|
+
def get(type_name, extra_params = {}, &block)
|
7
|
+
params = {
|
8
|
+
'request' => self.class.request_name,
|
9
|
+
'identifier' => type_name
|
10
|
+
}.merge!(extra_params)
|
11
|
+
|
12
|
+
super(params, &block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Ogc
|
4
|
+
class AbstractBaseTest < TestCase
|
5
|
+
include Errors
|
6
|
+
|
7
|
+
URL = 'http://localhost/wfs'
|
8
|
+
PARAMS = { 'version' => '1.0.0', 'key' => 'ABCDE' }
|
9
|
+
|
10
|
+
# Fake exception
|
11
|
+
CalledBlockException = Class.new(StandardError)
|
12
|
+
|
13
|
+
setup do
|
14
|
+
@base = AbstractBase.new(URL, PARAMS)
|
15
|
+
|
16
|
+
# XML files
|
17
|
+
@request = read_file('wfs/get_capabilities_request')
|
18
|
+
@response = read_file('wfs/get_capabilities_response')
|
19
|
+
@exception = read_file('wfs/exception_report')
|
20
|
+
|
21
|
+
query = PARAMS.merge(request: :hello).to_query
|
22
|
+
|
23
|
+
# Get method returns xml response:
|
24
|
+
stub_request(:get, "#{URL}?#{query}").to_return(body: @response)
|
25
|
+
|
26
|
+
# Get method returns xml exception:
|
27
|
+
stub_request(:get, "#{URL}?ex=xml&#{query}")
|
28
|
+
.to_return(body: @exception)
|
29
|
+
|
30
|
+
# Get method returns Timeout exception:
|
31
|
+
stub_request(:get, "#{URL}?ex=timeout&#{query}")
|
32
|
+
.to_raise(Timeout::Error)
|
33
|
+
|
34
|
+
# Get method returns NotFound return:
|
35
|
+
stub_request(:get, "#{URL}?ex=notFound&#{query}")
|
36
|
+
.to_return(status: [404, 'Not Found'])
|
37
|
+
|
38
|
+
# Post method returns xml response:
|
39
|
+
stub_request(:post, "#{URL}").with(body: @request)
|
40
|
+
.to_return(body: @response)
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'request_name class method returns the name of the class' do
|
44
|
+
assert_equal 'AbstractBase', AbstractBase.request_name
|
45
|
+
assert_same AbstractBase.request_name, AbstractBase.request_name
|
46
|
+
|
47
|
+
FakeService = Class.new(AbstractBase)
|
48
|
+
assert_equal 'FakeService', FakeService.request_name
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'constructor takes an url and some params as arguments' do
|
52
|
+
assert_equal URL, @base.url
|
53
|
+
refute_same PARAMS, @base.params
|
54
|
+
assert_equal PARAMS, @base.params
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'constructor stringifies the keys of params' do
|
58
|
+
base = AbstractBase.new(URL, PARAMS.symbolize_keys)
|
59
|
+
assert_equal PARAMS, base.params
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'http method exposes the http object' do
|
63
|
+
assert_instance_of Net::HTTP, @base.http
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'get method returns xml response' do
|
67
|
+
xml = Nokogiri::XML(@response.clean_xml!).to_xml
|
68
|
+
assert_equal xml, @base.get(request: 'hello').to_xml
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'get method takes a block to overload the request' do
|
72
|
+
assert_raises CalledBlockException do
|
73
|
+
@base.get(request: 'hello') do |_|
|
74
|
+
raise CalledBlockException
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'get method takes a block which exposes the request' do
|
80
|
+
@base.get(request: :hello) do |request|
|
81
|
+
assert_instance_of Net::HTTP::Get, request
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
test 'post method returns xml response' do
|
86
|
+
xml = Nokogiri::XML(@response.clean_xml!).to_xml
|
87
|
+
assert_equal xml, @base.post(@request).to_xml
|
88
|
+
end
|
89
|
+
|
90
|
+
test 'post method takes a block to overload the request' do
|
91
|
+
assert_raises CalledBlockException do
|
92
|
+
@base.post(@request) do |_|
|
93
|
+
raise CalledBlockException
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'post method takes a block which exposes the request' do
|
99
|
+
@base.post(@request) do |request|
|
100
|
+
assert_instance_of Net::HTTP::Post, request
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
test 'exception is raised if WFS returns exception' do
|
105
|
+
assert_raises ExceptionReport do
|
106
|
+
@base.get(request: :hello, ex: :xml)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
test 'exception is raised if Timeout is raised' do
|
111
|
+
assert_raises RequestError do
|
112
|
+
@base.get(request: :hello, ex: :timeout)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
test 'exception raised has a cause' do
|
117
|
+
begin
|
118
|
+
@base.get(request: :hello, ex: :timeout)
|
119
|
+
assert false # In case where the exception is not raised.
|
120
|
+
rescue RequestError => ex
|
121
|
+
assert_instance_of Timeout::Error, ex.cause
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
test 'request error raises ServiceError exception' do
|
126
|
+
assert_raises ServiceError do
|
127
|
+
@base.get(request: :hello, ex: :notFound)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
test 'response is cached' do
|
132
|
+
assert_nil @base.response
|
133
|
+
@base.get(request: 'hello')
|
134
|
+
refute_nil @base.response
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
module Ogc
|
4
|
-
module
|
4
|
+
module Errors
|
5
5
|
class ExceptionReportTest < TestCase
|
6
|
-
using CleanXML
|
7
|
-
|
8
6
|
setup do
|
9
7
|
@xml_100 = read_xml('wfs/service_exception_report')
|
10
8
|
@report_100 = ExceptionReport.new(@xml_100)
|
@@ -15,8 +13,8 @@ module Ogc
|
|
15
13
|
@xml_fake = read_xml('wfs/fake_report')
|
16
14
|
end
|
17
15
|
|
18
|
-
test 'class inherits from
|
19
|
-
assert ExceptionReport <
|
16
|
+
test 'class inherits from OgcError' do
|
17
|
+
assert ExceptionReport < OgcError
|
20
18
|
end
|
21
19
|
|
22
20
|
test 'ROOTS constant is a frozen array of string' do
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
module Ogc
|
4
|
-
module
|
5
|
-
class
|
4
|
+
module Errors
|
5
|
+
class OgcErrorTest < TestCase
|
6
6
|
test 'class inherits from StandardError' do
|
7
|
-
assert
|
7
|
+
assert OgcError < StandardError
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -2,20 +2,20 @@ require 'test_helper'
|
|
2
2
|
require 'minitest/mock'
|
3
3
|
|
4
4
|
module Ogc
|
5
|
-
module
|
6
|
-
class
|
5
|
+
module Errors
|
6
|
+
class ServiceErrorTest < TestCase
|
7
7
|
setup do
|
8
8
|
@mock = Minitest::Mock.new
|
9
9
|
@mock.expect :code, 666
|
10
10
|
@mock.expect :message, 'Hello Wolrd'
|
11
11
|
end
|
12
12
|
|
13
|
-
test 'class inherits from
|
14
|
-
assert
|
13
|
+
test 'class inherits from OgcError' do
|
14
|
+
assert ServiceError < OgcError
|
15
15
|
end
|
16
16
|
|
17
17
|
test 'constructor takes a HTTP error' do
|
18
|
-
ex =
|
18
|
+
ex = ServiceError.new(@mock)
|
19
19
|
assert 666, ex.code
|
20
20
|
assert 'Hello World', ex.message
|
21
21
|
@mock.verify
|
@@ -3,142 +3,9 @@ require 'test_helper'
|
|
3
3
|
module Ogc
|
4
4
|
module WebFeatureService
|
5
5
|
class BaseTest < TestCase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
URL = 'http://localhost/wfs'
|
10
|
-
PARAMS = { 'version' => '1.0.0', 'key' => 'ABCDE' }
|
11
|
-
FULL_PARAMS = PARAMS.merge(Base::DEFAULT_PARAMS)
|
12
|
-
|
13
|
-
# Fake exception
|
14
|
-
CalledBlockException = Class.new(StandardError)
|
15
|
-
|
16
|
-
setup do
|
17
|
-
@base = Base.new(URL, PARAMS)
|
18
|
-
|
19
|
-
# XML files
|
20
|
-
@request = read_file('wfs/get_capabilities_request')
|
21
|
-
@response = read_file('wfs/get_capabilities_response')
|
22
|
-
@exception = read_file('wfs/exception_report')
|
23
|
-
|
24
|
-
query = FULL_PARAMS.merge(request: :hello).to_query
|
25
|
-
|
26
|
-
# Get method returns xml response:
|
27
|
-
stub_request(:get, "#{URL}?#{query}").to_return(body: @response)
|
28
|
-
|
29
|
-
# Get method returns xml exception:
|
30
|
-
stub_request(:get, "#{URL}?ex=xml&#{query}")
|
31
|
-
.to_return(body: @exception)
|
32
|
-
|
33
|
-
# Get method returns Timeout exception:
|
34
|
-
stub_request(:get, "#{URL}?ex=timeout&#{query}")
|
35
|
-
.to_raise(Timeout::Error)
|
36
|
-
|
37
|
-
# Get method returns NotFound return:
|
38
|
-
stub_request(:get, "#{URL}?ex=notFound&#{query}")
|
39
|
-
.to_return(status: [404, 'Not Found'])
|
40
|
-
|
41
|
-
# Post method returns xml response:
|
42
|
-
stub_request(:post, "#{URL}").with(body: @request)
|
43
|
-
.to_return(body: @response)
|
44
|
-
end
|
45
|
-
|
46
|
-
test 'DEFAULT_PARAMS constant is frozen' do
|
47
|
-
assert Base::DEFAULT_PARAMS.frozen?
|
48
|
-
end
|
49
|
-
|
50
|
-
test 'request_name class method returns the name of the class' do
|
51
|
-
assert_equal 'Base', Base.request_name
|
52
|
-
assert_same Base.request_name, Base.request_name
|
53
|
-
|
54
|
-
FakeService = Class.new(Base)
|
55
|
-
assert_equal 'FakeService', FakeService.request_name
|
56
|
-
end
|
57
|
-
|
58
|
-
test 'constructor takes an url and some params as arguments' do
|
59
|
-
assert_equal URL, @base.url
|
60
|
-
refute_same PARAMS, @base.params
|
61
|
-
assert_equal FULL_PARAMS, @base.params
|
62
|
-
end
|
63
|
-
|
64
|
-
test 'constructor stringifies the keys of params' do
|
65
|
-
base = Base.new(URL, PARAMS.symbolize_keys)
|
66
|
-
assert_equal FULL_PARAMS, base.params
|
67
|
-
end
|
68
|
-
|
69
|
-
test 'http method exposes the http object' do
|
70
|
-
assert_instance_of Net::HTTP, @base.http
|
71
|
-
end
|
72
|
-
|
73
|
-
test 'get method returns xml response' do
|
74
|
-
xml = Nokogiri::XML(@response.clean_xml!).to_xml
|
75
|
-
assert_equal xml, @base.get(request: 'hello').to_xml
|
76
|
-
end
|
77
|
-
|
78
|
-
test 'get method takes a block to overload the request' do
|
79
|
-
assert_raises CalledBlockException do
|
80
|
-
@base.get(request: 'hello') do |_|
|
81
|
-
raise CalledBlockException
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
test 'get method takes a block which exposes the request' do
|
87
|
-
@base.get(request: :hello) do |request|
|
88
|
-
assert_instance_of Net::HTTP::Get, request
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
test 'post method returns xml response' do
|
93
|
-
xml = Nokogiri::XML(@response.clean_xml!).to_xml
|
94
|
-
assert_equal xml, @base.post(@request).to_xml
|
95
|
-
end
|
96
|
-
|
97
|
-
test 'post method takes a block to overload the request' do
|
98
|
-
assert_raises CalledBlockException do
|
99
|
-
@base.post(@request) do |_|
|
100
|
-
raise CalledBlockException
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
test 'post method takes a block which exposes the request' do
|
106
|
-
@base.post(@request) do |request|
|
107
|
-
assert_instance_of Net::HTTP::Post, request
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
test 'exception is raised if WFS returns exception' do
|
112
|
-
assert_raises ExceptionReport do
|
113
|
-
@base.get(request: :hello, ex: :xml)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
test 'exception is raised if Timeout is raised' do
|
118
|
-
assert_raises RequestErrorException do
|
119
|
-
@base.get(request: :hello, ex: :timeout)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
test 'exception raised has a cause' do
|
124
|
-
begin
|
125
|
-
@base.get(request: :hello, ex: :timeout)
|
126
|
-
assert false # In case where the exception is not raised.
|
127
|
-
rescue RequestErrorException => ex
|
128
|
-
assert_instance_of Timeout::Error, ex.cause
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
test 'request error raises RequestFailedException exception' do
|
133
|
-
assert_raises RequestFailedException do
|
134
|
-
@base.get(request: :hello, ex: :notFound)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
test 'response is cached' do
|
139
|
-
assert_nil @base.response
|
140
|
-
@base.get(request: 'hello')
|
141
|
-
refute_nil @base.response
|
6
|
+
test 'default_params class attribute is frozen' do
|
7
|
+
assert_instance_of Hash, Base.default_params
|
8
|
+
assert Base.default_params.frozen?
|
142
9
|
end
|
143
10
|
end
|
144
11
|
end
|
@@ -3,11 +3,9 @@ require 'test_helper'
|
|
3
3
|
module Ogc
|
4
4
|
module WebFeatureService
|
5
5
|
class GetCapabilitiesTest < TestCase
|
6
|
-
using CleanXML
|
7
|
-
|
8
6
|
URL = 'http://localhost/wfs'
|
9
7
|
PARAMS = { 'version' => '1.0.0', 'key' => 'ABCDE' }
|
10
|
-
FULL_PARAMS = PARAMS.merge(Base
|
8
|
+
FULL_PARAMS = PARAMS.merge(Base.default_params)
|
11
9
|
|
12
10
|
setup do
|
13
11
|
@base = GetCapabilities.new(URL, PARAMS)
|
@@ -3,15 +3,13 @@ require 'test_helper'
|
|
3
3
|
module Ogc
|
4
4
|
module WebFeatureService
|
5
5
|
class GetFeatureTest < TestCase
|
6
|
-
using CleanXML
|
7
|
-
|
8
6
|
URL = 'http://localhost/wfs'
|
9
7
|
PARAMS = {
|
10
8
|
'version' => '1.0.0',
|
11
9
|
'key' => 'ABCDE',
|
12
10
|
'typeName' => 'HYDROGRAPHY'
|
13
11
|
}
|
14
|
-
FULL_PARAMS = PARAMS.merge(Base
|
12
|
+
FULL_PARAMS = PARAMS.merge(Base.default_params)
|
15
13
|
|
16
14
|
setup do
|
17
15
|
@base = GetFeature.new(URL, PARAMS)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Ogc
|
4
|
+
module WebProcessingService
|
5
|
+
class BaseTest < TestCase
|
6
|
+
test 'default_params class attribute is frozen' do
|
7
|
+
assert_instance_of Hash, Base.default_params
|
8
|
+
assert Base.default_params.frozen?
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Ogc
|
4
|
+
module WebProcessingService
|
5
|
+
class ExecuteTest < TestCase
|
6
|
+
URL = 'http://localhost/wfs'
|
7
|
+
PARAMS = {
|
8
|
+
'version' => '1.0.0',
|
9
|
+
'key' => 'ABCDE',
|
10
|
+
'identifier' => 'HYDROGRAPHY'
|
11
|
+
}
|
12
|
+
FULL_PARAMS = PARAMS.merge(Base.default_params)
|
13
|
+
|
14
|
+
setup do
|
15
|
+
@base = Execute.new(URL, PARAMS)
|
16
|
+
|
17
|
+
# XML files
|
18
|
+
@response = read_file('wps/execute_response')
|
19
|
+
|
20
|
+
query = FULL_PARAMS.merge(request: Execute.request_name).to_query
|
21
|
+
|
22
|
+
# Get method returns xml response:
|
23
|
+
stub_request(:get, "#{URL}?#{query}").to_return(body: @response)
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'class inherits from Base' do
|
27
|
+
assert Execute < Base
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'get method returns xml response' do
|
31
|
+
xml = Nokogiri::XML(@response.clean_xml!).to_xml
|
32
|
+
assert_equal xml, @base.get(:HYDROGRAPHY).to_xml
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
<wps:ExecuteResponse xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xmlns:cub="http://data.bordeaux-metropole.fr" service="WPS" version="1.0.0" xml:lang="fr" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecuteResponse_response.xsd" serviceInstance="http://data.bordeaux-metropole.fr/wps?key=27Y2TBGE91&service=WPS&version=1.0.0&request=getcapabilities">
|
2
|
+
<wps:Process wps:processVersion="1.0.0">
|
3
|
+
<ows:Identifier>SV_HORAI_A</ows:Identifier>
|
4
|
+
<ows:Title>Horaire de bus</ows:Title>
|
5
|
+
<ows:Abstract>Retourne les horaires sur SAEIV Bus - Tram</ows:Abstract>
|
6
|
+
</wps:Process>
|
7
|
+
<wps:Status creationTime="2015-12-01T14:26:26+01:00">
|
8
|
+
<wps:ProcessSucceeded>Traitement terminé</wps:ProcessSucceeded>
|
9
|
+
</wps:Status>
|
10
|
+
<wps:ProcessOutputs>
|
11
|
+
<wps:Output>
|
12
|
+
<ows:Identifier>result</ows:Identifier>
|
13
|
+
<ows:Title>Tous les objets de la couche</ows:Title>
|
14
|
+
<ows:Abstract>Tous les objets de la couche</ows:Abstract>
|
15
|
+
<wps:Data>
|
16
|
+
<wps:ComplexData mimeType="text/xml">
|
17
|
+
<gml:featureMember>
|
18
|
+
<cub:SV_HORAI_A>
|
19
|
+
<cub:GID>267436295</cub:GID>
|
20
|
+
<cub:HOR_THEO>2015-12-01T08:18:57</cub:HOR_THEO>
|
21
|
+
<cub:HOR_APP>2015-12-01T08:18:57</cub:HOR_APP>
|
22
|
+
<cub:HOR_REAL/>
|
23
|
+
<cub:ETAT>REALISE</cub:ETAT>
|
24
|
+
<cub:TYPE>REGULIER</cub:TYPE>
|
25
|
+
<cub:CDATE>2015-12-01T08:40:09</cub:CDATE>
|
26
|
+
<cub:MDATE>2015-12-01T08:40:09</cub:MDATE>
|
27
|
+
<cub:RS_SV_ARRET_P>592</cub:RS_SV_ARRET_P>
|
28
|
+
<cub:RS_SV_COURS_A>258470616</cub:RS_SV_COURS_A>
|
29
|
+
</cub:SV_HORAI_A>
|
30
|
+
</gml:featureMember>
|
31
|
+
</wps:ComplexData>
|
32
|
+
</wps:Data>
|
33
|
+
</wps:Output>
|
34
|
+
</wps:ProcessOutputs>
|
35
|
+
</wps:ExecuteResponse>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ogc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoffrey Roguelon
|
@@ -170,31 +170,37 @@ files:
|
|
170
170
|
- bin/guard
|
171
171
|
- bin/setup
|
172
172
|
- lib/ogc.rb
|
173
|
-
- lib/ogc/
|
174
|
-
- lib/ogc/
|
175
|
-
- lib/ogc/
|
176
|
-
- lib/ogc/
|
177
|
-
- lib/ogc/
|
178
|
-
- lib/ogc/
|
179
|
-
- lib/ogc/
|
173
|
+
- lib/ogc/abstract_base.rb
|
174
|
+
- lib/ogc/core_ext.rb
|
175
|
+
- lib/ogc/core_ext/string.rb
|
176
|
+
- lib/ogc/errors.rb
|
177
|
+
- lib/ogc/errors/exception_report.rb
|
178
|
+
- lib/ogc/errors/ogc_error.rb
|
179
|
+
- lib/ogc/errors/request_error.rb
|
180
|
+
- lib/ogc/errors/service_error.rb
|
180
181
|
- lib/ogc/version.rb
|
181
182
|
- lib/ogc/web_feature_service.rb
|
182
183
|
- lib/ogc/web_feature_service/base.rb
|
183
184
|
- lib/ogc/web_feature_service/get_capabilities.rb
|
184
185
|
- lib/ogc/web_feature_service/get_feature.rb
|
186
|
+
- lib/ogc/web_processing_service.rb
|
187
|
+
- lib/ogc/web_processing_service/base.rb
|
188
|
+
- lib/ogc/web_processing_service/execute.rb
|
185
189
|
- ogc.gemspec
|
186
|
-
- test/ogc/
|
187
|
-
- test/ogc/
|
188
|
-
- test/ogc/
|
189
|
-
- test/ogc/
|
190
|
-
- test/ogc/
|
191
|
-
- test/ogc/
|
192
|
-
- test/ogc/
|
190
|
+
- test/ogc/abstract_base_test.rb
|
191
|
+
- test/ogc/core_ext/string_test.rb
|
192
|
+
- test/ogc/errors/exception_report_test.rb
|
193
|
+
- test/ogc/errors/ogc_error_test.rb
|
194
|
+
- test/ogc/errors/request_error_test.rb
|
195
|
+
- test/ogc/errors/service_error_test.rb
|
196
|
+
- test/ogc/errors_test.rb
|
193
197
|
- test/ogc/version_test.rb
|
194
198
|
- test/ogc/web_feature_service/base_test.rb
|
195
199
|
- test/ogc/web_feature_service/get_capabilities_test.rb
|
196
200
|
- test/ogc/web_feature_service/get_feature_test.rb
|
197
201
|
- test/ogc/web_feature_service_test.rb
|
202
|
+
- test/ogc/web_processing_service/base_test.rb
|
203
|
+
- test/ogc/web_processing_service/execute_test.rb
|
198
204
|
- test/ogc_test.rb
|
199
205
|
- test/test_helper.rb
|
200
206
|
- test/xml/wfs/exception_report.xml
|
@@ -203,6 +209,7 @@ files:
|
|
203
209
|
- test/xml/wfs/get_capabilities_response.xml
|
204
210
|
- test/xml/wfs/get_feature_response.xml
|
205
211
|
- test/xml/wfs/service_exception_report.xml
|
212
|
+
- test/xml/wps/execute_response.xml
|
206
213
|
homepage: https://github.com/GRoguelon/ogc
|
207
214
|
licenses:
|
208
215
|
- MIT
|
data/lib/ogc/clean_xml.rb
DELETED
data/lib/ogc/exceptions.rb
DELETED
data/lib/ogc/query.rb
DELETED
data/test/ogc/exceptions_test.rb
DELETED
data/test/ogc/query_test.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'active_support/core_ext/object/to_query'
|
3
|
-
|
4
|
-
module Ogc
|
5
|
-
class QueryTest < TestCase
|
6
|
-
using Query
|
7
|
-
|
8
|
-
setup do
|
9
|
-
@hash = {
|
10
|
-
'service' => 'wfs',
|
11
|
-
'srsname' => 'epsg:4326',
|
12
|
-
'version' => '1.0.0'
|
13
|
-
}
|
14
|
-
@query = @hash.to_query
|
15
|
-
end
|
16
|
-
|
17
|
-
test 'query method converts a query to hash' do
|
18
|
-
assert_equal @hash, Hash.from_query(@query)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|