diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-18 23:43:09 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-18 23:43:09 +0000 |
commit | 7a67d0f617db7d2962b6c3b80466e21570b244bf (patch) | |
tree | 56fa640e31f4f7f22d34a246bc1b197706a07e3a /actionwebservice/test/abstract_soap.rb | |
parent | fdecb6843ba8c5b0f718225f343017e11fa7f711 (diff) | |
download | rails-7a67d0f617db7d2962b6c3b80466e21570b244bf.tar.gz rails-7a67d0f617db7d2962b6c3b80466e21570b244bf.tar.bz2 rails-7a67d0f617db7d2962b6c3b80466e21570b244bf.zip |
Renamed Action Service to Action Web Service
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@669 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionwebservice/test/abstract_soap.rb')
-rw-r--r-- | actionwebservice/test/abstract_soap.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/actionwebservice/test/abstract_soap.rb b/actionwebservice/test/abstract_soap.rb new file mode 100644 index 0000000000..7454be9bdf --- /dev/null +++ b/actionwebservice/test/abstract_soap.rb @@ -0,0 +1,58 @@ +require File.dirname(__FILE__) + '/abstract_unit' +require 'soap/rpc/element' + +class SoapTestError < StandardError +end + +class AbstractSoapTest < Test::Unit::TestCase + def default_test + end + + protected + def service_name + raise NotImplementedError + end + + def do_soap_call(public_method_name, *args) + mapper = @container.class.soap_mapper + param_def = [] + i = 1 + args.each do |arg| + mapping = mapper.lookup(arg.class) + param_def << ["in", "param#{i}", mapping.registry_mapping] + i += 1 + end + qname = XSD::QName.new('urn:ActionService', public_method_name) + request = SOAP::RPC::SOAPMethodRequest.new(qname, param_def) + soap_args = [] + i = 1 + args.each do |arg| + soap_args << ["param#{i}", SOAP::Mapping.obj2soap(arg)] + i += 1 + end + request.set_param(soap_args) + header = SOAP::SOAPHeader.new + body = SOAP::SOAPBody.new(request) + envelope = SOAP::SOAPEnvelope.new(header, body) + raw_request = SOAP::Processor.marshal(envelope) + test_request = ActionController::TestRequest.new + test_request.request_parameters['action'] = service_name + test_request.env['REQUEST_METHOD'] = "POST" + test_request.env['HTTP_CONTENTTYPE'] = 'text/xml' + test_request.env['HTTP_SOAPACTION'] = "/soap/#{service_name}/#{public_method_name}" + test_request.env['RAW_POST_DATA'] = raw_request + test_response = ActionController::TestResponse.new + response = yield test_request, test_response + raw_body = response.respond_to?(:body) ? response.body : response.raw_body + envelope = SOAP::Processor.unmarshal(raw_body) + if envelope + if envelope.body.response + SOAP::Mapping.soap2obj(envelope.body.response) + else + nil + end + else + raise(SoapTestError, "empty/invalid body from server") + end + end +end |