Skip to content
This repository
Browse code

first pass of web service scaffolding. add ability to quickly generat…

…e an

action pack request for a protocol, add missing log_error when we fail to parse
protocol messages. add RDoc for scaffolding and functional testing.


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1037 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit b94bd32f3116b469b48400382dbc964bf17994d1 1 parent 715715a
Leon Breedt authored March 29, 2005

Showing 19 changed files with 451 additions and 28 deletions. Show diff stats Hide diff stats

  1. 4  actionwebservice/CHANGELOG
  2. 45  actionwebservice/README
  3. 6  actionwebservice/TODO
  4. 2  actionwebservice/lib/action_web_service.rb
  5. 21  actionwebservice/lib/action_web_service/api/base.rb
  6. 1  actionwebservice/lib/action_web_service/dispatcher/action_controller_dispatcher.rb
  7. 54  actionwebservice/lib/action_web_service/protocol/abstract.rb
  8. 8  actionwebservice/lib/action_web_service/protocol/soap_protocol.rb
  9. 2  actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb
  10. 181  actionwebservice/lib/action_web_service/scaffolding.rb
  11. 65  actionwebservice/lib/action_web_service/templates/scaffolds/layout.rhtml
  12. 6  actionwebservice/lib/action_web_service/templates/scaffolds/methods.rhtml
  13. 20  actionwebservice/lib/action_web_service/templates/scaffolds/parameters.rhtml
  14. 26  actionwebservice/lib/action_web_service/templates/scaffolds/result.rhtml
  15. 3  actionwebservice/lib/action_web_service/vendor/ws/encoding/xmlrpc_encoding.rb
  16. 10  actionwebservice/test/abstract_dispatcher.rb
  17. 4  actionwebservice/test/api_test.rb
  18. 11  actionwebservice/test/dispatcher_action_controller_soap_test.rb
  19. 10  actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb
4  actionwebservice/CHANGELOG
... ...
@@ -1,7 +1,11 @@
1 1
 *0.7.0* (Unreleased)
2 2
 
  3
+* Add scaffolding via ActionController::Base.web_service_scaffold for quick testing using a web browser
  4
+
3 5
 * Generalize casting code to be used by both SOAP and XML-RPC (previously, it was only XML-RPC)
4 6
 
  7
+* Include backtraces in 500 error responses for failed request parsing, and remove "rescue nil" statements obscuring real errors for XML-RPC
  8
+
5 9
 
6 10
 *0.6.2* (27th March, 2005)
7 11
 
45  actionwebservice/README
@@ -197,6 +197,51 @@ For this example, a remote call for a method with a name like
197 197
 method on the <tt>:mt</tt> service.
198 198
 
199 199
 
  200
+== Testing your APIs
  201
+
  202
+
  203
+=== Functional testing
  204
+
  205
+You can perform testing of your APIs by creating a functional test for the
  206
+controller dispatching the API, and calling #invoke in the test case to
  207
+perform the invocation.
  208
+
  209
+Example:
  210
+
  211
+  class PersonApiControllerTest < Test::Unit::TestCase
  212
+    def setup
  213
+      @controller = PersonController.new
  214
+      @request    = ActionController::TestRequest.new
  215
+      @response   = ActionController::TestResponse.new
  216
+    end
  217
+
  218
+    def test_add
  219
+      result = invoke :remove, 1
  220
+      assert_equal true, result
  221
+    end
  222
+  end
  223
+
  224
+This example invokes the API method <tt>test</tt>, defined on 
  225
+the PersonController, and returns the result.
  226
+
  227
+
  228
+=== Scaffolding
  229
+
  230
+You can also test your APIs with a web browser by attaching scaffolding
  231
+to the controller.
  232
+
  233
+Example:
  234
+
  235
+  class PersonController
  236
+    web_service_scaffold :invocation
  237
+  end
  238
+
  239
+This creates an action named <tt>invocation</tt> on the PersonController.
  240
+
  241
+Navigating to this action lets you select the method to invoke, supply the parameters,
  242
+and view the result of the invocation.
  243
+
  244
+
200 245
 == Using the client support
201 246
 
202 247
 Action Web Service includes client classes that can use the same API
6  actionwebservice/TODO
... ...
@@ -1,6 +1,10 @@
1 1
 = 0.7.0
2 2
   - WS Dynamic Scaffolding
3  
-  - WS Scaffolding Generators
  3
+    * add protocol selection ability
  4
+    * test with XML-RPC (namespaced method name support)
  5
+    * support structured types as input parameters with the input field helper
  6
+
  7
+  - update manual for scaffolding and functional testing
4 8
 
5 9
 = 0.8.0
6 10
   - Consumption of WSDL services
2  actionwebservice/lib/action_web_service.rb
@@ -46,6 +46,7 @@
46 46
 require 'action_web_service/protocol'
47 47
 require 'action_web_service/struct'
48 48
 require 'action_web_service/dispatcher'
  49
+require 'action_web_service/scaffolding'
49 50
 
50 51
 ActionWebService::Base.class_eval do
51 52
   include ActionWebService::Container::Direct
@@ -61,4 +62,5 @@
61 62
   include ActionWebService::Container::ActionController
62 63
   include ActionWebService::Dispatcher
63 64
   include ActionWebService::Dispatcher::ActionController
  65
+  include ActionWebService::Scaffolding
64 66
 end
21  actionwebservice/lib/action_web_service/api/base.rb
@@ -284,10 +284,31 @@ def cast_returns(marshaler, return_value)
284 284
         marshaler.cast_inbound_recursive(return_value, @returns[0])
285 285
       end
286 286
 
  287
+      # String representation of this method
  288
+      def to_s
  289
+        fqn = ""
  290
+        fqn << (@returns ? (friendly_param(@returns[0], nil) + " ") : "void ")
  291
+        fqn << "#{@public_name}("
  292
+        if @expects
  293
+          i = 0
  294
+          fqn << @expects.map{ |p| friendly_param(p, i+= 1) }.join(", ")
  295
+        end
  296
+        fqn << ")"
  297
+        fqn
  298
+      end
  299
+
287 300
       private
288 301
         def response_name(encoder)
289 302
           encoder.is_a?(WS::Encoding::SoapRpcEncoding) ? (@public_name + "Response") : @public_name
290 303
         end
  304
+
  305
+        def friendly_param(spec, i)
  306
+          name = param_name(spec, i)
  307
+          type = param_type(spec)
  308
+          spec = spec.values.first if spec.is_a?(Hash)
  309
+          type = spec.is_a?(Array) ? (type.to_s + "[]") : type.to_s
  310
+          i ? (type + " " + name) : type
  311
+        end
291 312
     end
292 313
   end
293 314
 end
1  actionwebservice/lib/action_web_service/dispatcher/action_controller_dispatcher.rb
@@ -63,6 +63,7 @@ def dispatch_web_service_request
63 63
               end
64 64
             else
65 65
               exception ||= DispatcherError.new("Malformed SOAP or XML-RPC protocol message")
  66
+              log_error(exception) unless logger.nil?
66 67
               send_web_service_error_response(request, exception)
67 68
             end
68 69
           rescue Exception => e
54  actionwebservice/lib/action_web_service/protocol/abstract.rb
@@ -7,10 +7,64 @@ class AbstractProtocol
7 7
       attr :marshaler
8 8
       attr :encoder
9 9
 
  10
+      def unmarshal_request(ap_request)
  11
+      end
  12
+
10 13
       def marshal_response(method, return_value)
11 14
         body = method.encode_rpc_response(marshaler, encoder, return_value)
12 15
         Response.new(body, 'text/xml')
13 16
       end
  17
+
  18
+      def protocol_client(api, protocol_name, endpoint_uri, options)
  19
+      end
  20
+
  21
+      def create_action_pack_request(service_name, public_method_name, raw_body, options={})
  22
+        klass = options[:request_class] || SimpleActionPackRequest
  23
+        request = klass.new
  24
+        request.request_parameters['action'] = service_name.to_s
  25
+        request.env['RAW_POST_DATA'] = raw_body
  26
+        request.env['REQUEST_METHOD'] = 'POST'
  27
+        request.env['HTTP_CONTENT_TYPE'] = 'text/xml'
  28
+        request
  29
+      end
  30
+    end
  31
+
  32
+    class SimpleActionPackRequest < ActionController::AbstractRequest
  33
+      def initialize
  34
+        @env = {}
  35
+        @qparams = {}
  36
+        @rparams = {}
  37
+        @cookies = {}
  38
+        reset_session
  39
+      end
  40
+
  41
+      def query_parameters
  42
+        @qparams
  43
+      end
  44
+
  45
+      def request_parameters
  46
+        @rparams
  47
+      end
  48
+
  49
+      def env
  50
+        @env
  51
+      end
  52
+
  53
+      def host
  54
+        ''
  55
+      end
  56
+
  57
+      def cookies
  58
+        @cookies
  59
+      end
  60
+
  61
+      def session
  62
+        @session
  63
+      end
  64
+
  65
+      def reset_session
  66
+        @session = {}
  67
+      end
14 68
     end
15 69
 
16 70
     class Request # :nodoc:
8  actionwebservice/lib/action_web_service/protocol/soap_protocol.rb
@@ -20,11 +20,17 @@ def unmarshal_request(ap_request)
20 20
           Request.new(self, method_name, params, service_name)
21 21
         end
22 22
 
23  
-        def protocol_client(api, protocol_name, endpoint_uri, options)
  23
+        def protocol_client(api, protocol_name, endpoint_uri, options={})
24 24
           return nil unless protocol_name == :soap
25 25
           ActionWebService::Client::Soap.new(api, endpoint_uri, options)
26 26
         end
27 27
 
  28
+        def create_action_pack_request(service_name, public_method_name, raw_body, options={})
  29
+          request = super
  30
+          request.env['HTTP_SOAPACTION'] = '/soap/%s/%s' % [service_name, public_method_name]
  31
+          request
  32
+        end
  33
+
28 34
         private
29 35
           def has_valid_soap_action?(request)
30 36
             return nil unless request.method == :post
2  actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb
@@ -18,7 +18,7 @@ def unmarshal_request(ap_request)
18 18
           Request.new(self, method_name, params, service_name)
19 19
         end
20 20
 
21  
-        def protocol_client(api, protocol_name, endpoint_uri, options)
  21
+        def protocol_client(api, protocol_name, endpoint_uri, options={})
22 22
           return nil unless protocol_name == :xmlrpc
23 23
           ActionWebService::Client::XmlRpc.new(api, endpoint_uri, options)
24 24
         end
181  actionwebservice/lib/action_web_service/scaffolding.rb
... ...
@@ -0,0 +1,181 @@
  1
+require 'ostruct'
  2
+require 'uri'
  3
+
  4
+module ActionWebService
  5
+  module Scaffolding # :nodoc:
  6
+    def self.append_features(base)
  7
+      super
  8
+      base.extend(ClassMethods)
  9
+    end
  10
+
  11
+    # Web service invocation scaffolding provides a way to quickly invoke web service methods in a controller. The
  12
+    # generated scaffold actions have default views to let you enter the method parameters and view the
  13
+    # results.
  14
+    #
  15
+    # Example:
  16
+    #
  17
+    #   class ApiController < ActionController
  18
+    #     web_service_scaffold :invoke
  19
+    #   end
  20
+    #
  21
+    # This example generates an +invoke+ action in the +ApiController+ that you can navigate to from
  22
+    # your browser, select the API method, enter its parameters, and perform the invocation.
  23
+    #
  24
+    # If you want to customize the default views, create the following views in "app/views":
  25
+    #
  26
+    # * <tt>action_name/methods.rhtml</tt>
  27
+    # * <tt>action_name/parameters.rhtml</tt>
  28
+    # * <tt>action_name/result.rhtml</tt>
  29
+    # * <tt>action_name/layout.rhtml</tt>
  30
+    #
  31
+    # Where <tt>action_name</tt> is the name of the action you gave to ClassMethods#web_service_scaffold.
  32
+    #
  33
+    # You can use the default views in <tt>RAILS_DIR/lib/action_web_service/templates/scaffolds</tt> as
  34
+    # a guide.
  35
+    module ClassMethods
  36
+      # Generates web service invocation scaffolding for the current controller. The given action name
  37
+      # can then be used as the entry point for invoking API methods from a web browser.
  38
+      def web_service_scaffold(action_name)
  39
+        add_template_helper(Helpers)
  40
+        module_eval <<-END, __FILE__, __LINE__
  41
+          def #{action_name}
  42
+            if @request.method == :get
  43
+              setup_#{action_name}_assigns
  44
+              render_#{action_name}_scaffold 'methods'
  45
+            end
  46
+          end
  47
+
  48
+          def #{action_name}_method_params
  49
+            if @request.method == :get
  50
+              setup_#{action_name}_assigns
  51
+              render_#{action_name}_scaffold 'parameters'
  52
+            end
  53
+          end
  54
+
  55
+          def #{action_name}_submit
  56
+            if @request.method == :post
  57
+              setup_#{action_name}_assigns
  58
+              protocol_name = @params['protocol'] ? @params['protocol'].to_sym : :soap
  59
+              case protocol_name
  60
+              when :soap
  61
+                protocol = Protocol::Soap::SoapProtocol.new
  62
+              when :xmlrpc
  63
+                protocol = Protocol::XmlRpc::XmlRpcProtocol.new
  64
+              end
  65
+              @method_request_xml = @scaffold_method.encode_rpc_call(protocol.marshaler, protocol.encoder, @params['method_params'].dup)
  66
+              cgi = @request.cgi
  67
+              @request = protocol.create_action_pack_request(@scaffold_service.name, @scaffold_method.public_name, @method_request_xml)
  68
+              dispatch_web_service_request
  69
+              @method_response_xml = @response.body
  70
+              @method_return_value = protocol.marshaler.unmarshal(protocol.encoder.decode_rpc_response(@method_response_xml)[1]).value
  71
+              add_instance_variables_to_assigns
  72
+              @response = ::ActionController::CgiResponse.new(cgi)
  73
+              @performed_render = false
  74
+              render_#{action_name}_scaffold 'result'
  75
+            end
  76
+          end
  77
+
  78
+          private
  79
+            def setup_#{action_name}_assigns
  80
+              @scaffold_class = self.class
  81
+              @scaffold_action_name = "#{action_name}"
  82
+              @scaffold_container = WebServiceModel::Container.new(self)
  83
+              if @params['service'] && @params['method']
  84
+                @scaffold_service = @scaffold_container.services.find{ |x| x.name == @params['service'] }
  85
+                @scaffold_method = @scaffold_service.api_methods[@params['method']]
  86
+              end
  87
+              add_instance_variables_to_assigns
  88
+            end
  89
+
  90
+            def render_#{action_name}_scaffold(action)
  91
+              customized_template = "\#{self.class.controller_path}/#{action_name}/\#{action}"
  92
+              default_template = scaffold_path(action)
  93
+              @content_for_layout = template_exists?(customized_template) ? @template.render_file(customized_template) : @template.render_file(default_template, false)
  94
+              self.active_layout ? render_file(self.active_layout, "200 OK", true) : render_file(scaffold_path("layout"))
  95
+            end
  96
+
  97
+            def scaffold_path(template_name)
  98
+              File.dirname(__FILE__) + "/templates/scaffolds/" + template_name + ".rhtml"
  99
+            end
  100
+        END
  101
+      end
  102
+    end
  103
+
  104
+    module Helpers # :nodoc:
  105
+      def method_parameter_input_fields(method, param_spec, i)
  106
+        klass = method.param_class(param_spec)
  107
+        unless WS::BaseTypes.base_type?(klass)
  108
+          name = method.param_name(param_spec, i)
  109
+          raise "Parameter #{name}: Structured/array types not supported in scaffolding input fields yet"
  110
+        end
  111
+        type_name = method.param_type(param_spec)
  112
+        field_name = "method_params[]"
  113
+        case type_name
  114
+        when :int
  115
+          text_field_tag field_name
  116
+        when :string
  117
+          text_field_tag field_name
  118
+        when :bool
  119
+          radio_button_tag field_name, "True"
  120
+          radio_button_tag field_name, "False"
  121
+        when :float
  122
+          text_field_tag field_name
  123
+        when :time
  124
+          select_datetime Time.now, 'name' => field_name
  125
+        when :date
  126
+          select_date Date.today, 'name' => field_name
  127
+        end
  128
+      end
  129
+
  130
+      def service_method_list(service)
  131
+        action = @scaffold_action_name + '_method_params'
  132
+        methods = service.api_methods_full.map do |desc, name|
  133
+          content_tag("li", link_to(desc, :action => action, :service => service.name, :method => name))
  134
+        end
  135
+        content_tag("ul", methods.join("\n"))
  136
+      end
  137
+    end
  138
+
  139
+    module WebServiceModel # :nodoc:
  140
+      class Container # :nodoc:
  141
+        attr :services
  142
+
  143
+        def initialize(real_container)
  144
+          @real_container = real_container
  145
+          @services = []
  146
+          if @real_container.class.web_service_dispatching_mode == :direct
  147
+            @services << Service.new(@real_container.controller_name, @real_container)
  148
+          else
  149
+            @real_container.class.web_services.each do |name|
  150
+              @services << Service.new(name, @real_container.instance_eval{ web_service_object(name) })
  151
+            end
  152
+          end
  153
+        end
  154
+      end
  155
+
  156
+      class Service # :nodoc:
  157
+        attr :name
  158
+        attr :object
  159
+        attr :api
  160
+        attr :api_methods
  161
+        attr :api_methods_full
  162
+
  163
+        def initialize(name, real_service)
  164
+          @name = name.to_s
  165
+          @object = real_service
  166
+          @api = @object.class.web_service_api
  167
+          @api_methods = {}
  168
+          @api_methods_full = []
  169
+          @api.api_methods.each do |name, method|
  170
+            @api_methods[method.public_name.to_s] = method
  171
+            @api_methods_full << [method.to_s, method.public_name.to_s]
  172
+          end
  173
+        end
  174
+
  175
+        def to_s
  176
+          self.name.camelize
  177
+        end
  178
+      end
  179
+    end
  180
+  end
  181
+end
65  actionwebservice/lib/action_web_service/templates/scaffolds/layout.rhtml
... ...
@@ -0,0 +1,65 @@
  1
+<html>
  2
+<head>
  3
+  <title><%= @scaffold_class.wsdl_service_name %> Web Service</title>
  4
+  <style>
  5
+    body { background-color: #fff; color: #333; }
  6
+
  7
+    body, p, ol, ul, td {
  8
+      font-family: verdana, arial, helvetica, sans-serif;
  9
+      font-size:   13px;
  10
+      line-height: 18px;
  11
+    }
  12
+
  13
+    pre {
  14
+      background-color: #eee;
  15
+      padding: 10px;
  16
+      font-size: 11px;
  17
+    }
  18
+
  19
+    a { color: #000; }
  20
+    a:visited { color: #666; }
  21
+    a:hover { color: #fff; background-color:#000; }
  22
+
  23
+    .fieldWithErrors {
  24
+      padding: 2px;
  25
+      background-color: red;
  26
+      display: table;
  27
+    }
  28
+
  29
+    #ErrorExplanation {
  30
+      width: 400px;
  31
+    	border: 2px solid #red;
  32
+    	padding: 7px;
  33
+    	padding-bottom: 12px;
  34
+    	margin-bottom: 20px;
  35
+    	background-color: #f0f0f0;
  36
+    }
  37
+
  38
+    #ErrorExplanation h2 {
  39
+    	text-align: left;
  40
+    	font-weight: bold;
  41
+    	padding: 5px 5px 5px 15px;
  42
+    	font-size: 12px;
  43
+    	margin: -7px;
  44
+    	background-color: #c00;
  45
+    	color: #fff;
  46
+    }
  47
+
  48
+    #ErrorExplanation p {
  49
+    	color: #333;
  50
+    	margin-bottom: 0;
  51
+    	padding: 5px;
  52
+    }
  53
+
  54
+    #ErrorExplanation ul li {
  55
+    	font-size: 12px;
  56
+    	list-style: square;
  57
+    }
  58
+  </style>
  59
+</head>
  60
+<body>
  61
+
  62
+<%= @content_for_layout %>
  63
+
  64
+</body>
  65
+</html>
6  actionwebservice/lib/action_web_service/templates/scaffolds/methods.rhtml
... ...
@@ -0,0 +1,6 @@
  1
+<% @scaffold_container.services.each do |service| %>
  2
+
  3
+  <h4>API Methods for <%= service %></h4>
  4
+  <%= service_method_list(service) %>
  5
+
  6
+<% end %>
20  actionwebservice/lib/action_web_service/templates/scaffolds/parameters.rhtml
... ...
@@ -0,0 +1,20 @@
  1
+<h4>Method Parameters for <em><%= @scaffold_service %>#<%= @scaffold_method.public_name %></em></h4>
  2
+
  3
+<%= form_tag :action => @scaffold_action_name + '_submit'  %>
  4
+<%= hidden_field_tag "service", @scaffold_service.name %>
  5
+<%= hidden_field_tag "method", @scaffold_method.public_name %>
  6
+
  7
+<% i = 0 %>
  8
+<% @scaffold_method.expects.each do |spec| %>
  9
+  <p>
  10
+  <label for="method_params[]"><%= @scaffold_method.param_name(spec, i).camelize %></label><br />
  11
+  <%= method_parameter_input_fields(@scaffold_method, spec, i) %>
  12
+  </p>
  13
+  <% i += 1 %>
  14
+<% end %>
  15
+
  16
+<%= submit_tag "Invoke" %>
  17
+
  18
+<p>
  19
+<%= link_to "Back", :action => @scaffold_action_name %>
  20
+</p>
26  actionwebservice/lib/action_web_service/templates/scaffolds/result.rhtml
... ...
@@ -0,0 +1,26 @@
  1
+<h4>Method Invocation Result for <em><%= @scaffold_service %>#<%= @scaffold_method.public_name %></em></h4>
  2
+
  3
+<p>
  4
+<strong>Return Value:</strong><br />
  5
+<pre>
  6
+<%= h @method_return_value.inspect %>
  7
+</pre>
  8
+</p>
  9
+
  10
+<p>
  11
+<strong>Request XML:</strong><br />
  12
+<pre>
  13
+<%= h @method_request_xml %>
  14
+</pre>
  15
+</p>
  16
+
  17
+<p>
  18
+<strong>Response XML:</strong><br />
  19
+<pre>
  20
+<%= h @method_response_xml %>
  21
+</pre>
  22
+</p>
  23
+
  24
+<p>
  25
+<%= link_to "Back", :action => @scaffold_action_name + '_method_params', :method => @scaffold_method.public_name, :service => @scaffold_service.name %>
  26
+</p>
3  actionwebservice/lib/action_web_service/vendor/ws/encoding/xmlrpc_encoding.rb
@@ -2,9 +2,6 @@
2 2
 
3 3
 module WS
4 4
   module Encoding
5  
-    class XmlRpcError < WSError
6  
-    end
7  
-
8 5
     class XmlRpcEncoding < AbstractEncoding
9 6
       def encode_rpc_call(method_name, params)
10 7
         XMLRPC::Marshal.dump_call(method_name, *params)
10  actionwebservice/test/abstract_dispatcher.rb
@@ -301,7 +301,8 @@ def test_garbage_request
301 301
     [@direct_controller, @delegated_controller].each do |controller|
302 302
       controller.class.web_service_exception_reporting = true
303 303
       send_garbage_request = lambda do
304  
-        request = create_ap_request(controller, 'invalid request body', 'xxx')
  304
+        service_name = service_name(controller)
  305
+        request = @protocol.create_action_pack_request(service_name, 'broken, method, name!', 'broken request body', :request_class => ActionController::TestRequest)
305 306
         response = ActionController::TestResponse.new
306 307
         controller.process(request, response)
307 308
         # puts response.body
@@ -378,22 +379,25 @@ def do_method_call(container, public_method_name, *params)
378 379
       mode = container.web_service_dispatching_mode
379 380
       case mode
380 381
       when :direct
  382
+        service_name = service_name(container)
381 383
         api = container.class.web_service_api
382 384
       when :delegated
383  
-        api = container.web_service_object(service_name(container)).class.web_service_api
  385
+        service_name = service_name(container)
  386
+        api = container.web_service_object(service_name).class.web_service_api
384 387
       when :layered
385 388
         service_name = nil
386 389
         if public_method_name =~ /^([^\.]+)\.(.*)$/
387 390
           service_name = $1
388 391
         end
389 392
         api = container.web_service_object(service_name.to_sym).class.web_service_api
  393
+        service_name = self.service_name(container)
390 394
       end
391 395
       method = api.public_api_method_instance(public_method_name)
392 396
       method ||= api.dummy_public_api_method_instance(public_method_name)
393 397
       # we turn off strict so we can test our own handling of incorrectly typed parameters
394 398
       body = method.encode_rpc_call(@marshaler, @encoder, params.dup, :strict => false)
395 399
       # puts body
396  
-      ap_request = create_ap_request(container, body, public_method_name, *params)
  400
+      ap_request = protocol.create_action_pack_request(service_name, public_method_name, body, :request_class => ActionController::TestRequest)
397 401
       ap_response = ActionController::TestResponse.new
398 402
       container.process(ap_request, ap_response)
399 403
       # puts ap_response.body
4  actionwebservice/test/api_test.rb
@@ -73,4 +73,8 @@ def test_api_errors
73 73
       end
74 74
     end
75 75
   end
  76
+
  77
+  def test_to_s
  78
+    assert_equal 'void Expects(int p1, bool p2)', APITest::API.api_methods[:expects].to_s
  79
+  end
76 80
 end
11  actionwebservice/test/dispatcher_action_controller_soap_test.rb
@@ -28,6 +28,7 @@ def setup
28 28
     @direct_controller = DirectController.new
29 29
     @delegated_controller = DelegatedController.new
30 30
     @virtual_controller = VirtualController.new
  31
+    @protocol = ActionWebService::Protocol::Soap::SoapProtocol.new
31 32
   end
32 33
 
33 34
   def test_wsdl_generation
@@ -70,16 +71,6 @@ def is_exception?(obj)
70 71
       obj.detail.cause.is_a?(Exception)
71 72
     end
72 73
 
73  
-    def create_ap_request(container, body, public_method_name, *args)
74  
-      test_request = ActionController::TestRequest.new
75  
-      test_request.request_parameters['action'] = service_name(container)
76  
-      test_request.env['REQUEST_METHOD'] = "POST"
77  
-      test_request.env['HTTP_CONTENT_TYPE'] = 'text/xml'
78  
-      test_request.env['HTTP_SOAPACTION'] = "/soap/#{service_name(container)}/#{public_method_name}"
79  
-      test_request.env['RAW_POST_DATA'] = body
80  
-      test_request
81  
-    end
82  
-
83 74
     def service_name(container)
84 75
       container.is_a?(DelegatedController) ? 'test_service' : 'api'
85 76
     end
10  actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb
@@ -5,6 +5,7 @@ class TC_DispatcherActionControllerXmlRpc < Test::Unit::TestCase
5 5
   include DispatcherCommonTests
6 6
 
7 7
   def setup
  8
+    @protocol = ActionWebService::Protocol::XmlRpc::XmlRpcProtocol.new
8 9
     @encoder = WS::Encoding::XmlRpcEncoding.new
9 10
     @marshaler = WS::Marshaling::XmlRpcMarshaler.new
10 11
     @direct_controller = DirectController.new
@@ -29,15 +30,6 @@ def is_exception?(obj)
29 30
       obj.is_a?(XMLRPC::FaultException)
30 31
     end
31 32
 
32  
-    def create_ap_request(container, body, public_method_name, *args)
33  
-      test_request = ActionController::TestRequest.new
34  
-      test_request.request_parameters['action'] = service_name(container)
35  
-      test_request.env['REQUEST_METHOD'] = "POST"
36  
-      test_request.env['HTTP_CONTENT_TYPE'] = 'text/xml'
37  
-      test_request.env['RAW_POST_DATA'] = body
38  
-      test_request
39  
-    end
40  
-
41 33
     def service_name(container)
42 34
       container.is_a?(DelegatedController) ? 'test_service' : 'api'
43 35
     end

0 notes on commit b94bd32

Please sign in to comment.
Something went wrong with that request. Please try again.