reidiculous-actionwebservice-client 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +320 -0
- data/MIT-LICENSE +21 -0
- data/README +381 -0
- data/Rakefile +180 -0
- data/TODO +32 -0
- data/lib/action_web_service.rb +71 -0
- data/lib/action_web_service/api.rb +297 -0
- data/lib/action_web_service/base.rb +38 -0
- data/lib/action_web_service/casting.rb +149 -0
- data/lib/action_web_service/client.rb +3 -0
- data/lib/action_web_service/client/base.rb +28 -0
- data/lib/action_web_service/client/soap_client.rb +113 -0
- data/lib/action_web_service/client/xmlrpc_client.rb +58 -0
- data/lib/action_web_service/container.rb +3 -0
- data/lib/action_web_service/container/action_controller_container.rb +93 -0
- data/lib/action_web_service/container/delegated_container.rb +86 -0
- data/lib/action_web_service/container/direct_container.rb +69 -0
- data/lib/action_web_service/dispatcher.rb +2 -0
- data/lib/action_web_service/dispatcher/abstract.rb +207 -0
- data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +379 -0
- data/lib/action_web_service/invocation.rb +202 -0
- data/lib/action_web_service/protocol.rb +4 -0
- data/lib/action_web_service/protocol/abstract.rb +115 -0
- data/lib/action_web_service/protocol/discovery.rb +37 -0
- data/lib/action_web_service/protocol/soap_protocol.rb +176 -0
- data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +242 -0
- data/lib/action_web_service/protocol/xmlrpc_protocol.rb +122 -0
- data/lib/action_web_service/scaffolding.rb +281 -0
- data/lib/action_web_service/soap/attachment.rb +107 -0
- data/lib/action_web_service/soap/baseData.rb +942 -0
- data/lib/action_web_service/soap/element.rb +258 -0
- data/lib/action_web_service/soap/encodingstyle/aspDotNetHandler.rb +213 -0
- data/lib/action_web_service/soap/encodingstyle/handler.rb +100 -0
- data/lib/action_web_service/soap/encodingstyle/literalHandler.rb +226 -0
- data/lib/action_web_service/soap/encodingstyle/soapHandler.rb +582 -0
- data/lib/action_web_service/soap/generator.rb +268 -0
- data/lib/action_web_service/soap/header/handler.rb +57 -0
- data/lib/action_web_service/soap/header/handlerset.rb +70 -0
- data/lib/action_web_service/soap/header/simplehandler.rb +44 -0
- data/lib/action_web_service/soap/httpconfigloader.rb +119 -0
- data/lib/action_web_service/soap/mapping.rb +10 -0
- data/lib/action_web_service/soap/mapping/factory.rb +355 -0
- data/lib/action_web_service/soap/mapping/mapping.rb +381 -0
- data/lib/action_web_service/soap/mapping/registry.rb +541 -0
- data/lib/action_web_service/soap/mapping/rubytypeFactory.rb +475 -0
- data/lib/action_web_service/soap/mapping/typeMap.rb +50 -0
- data/lib/action_web_service/soap/mapping/wsdlencodedregistry.rb +280 -0
- data/lib/action_web_service/soap/mapping/wsdlliteralregistry.rb +418 -0
- data/lib/action_web_service/soap/marshal.rb +59 -0
- data/lib/action_web_service/soap/mimemessage.rb +240 -0
- data/lib/action_web_service/soap/netHttpClient.rb +190 -0
- data/lib/action_web_service/soap/parser.rb +251 -0
- data/lib/action_web_service/soap/processor.rb +66 -0
- data/lib/action_web_service/soap/property.rb +333 -0
- data/lib/action_web_service/soap/rpc/cgistub.rb +206 -0
- data/lib/action_web_service/soap/rpc/driver.rb +254 -0
- data/lib/action_web_service/soap/rpc/element.rb +325 -0
- data/lib/action_web_service/soap/rpc/httpserver.rb +129 -0
- data/lib/action_web_service/soap/rpc/proxy.rb +497 -0
- data/lib/action_web_service/soap/rpc/router.rb +594 -0
- data/lib/action_web_service/soap/rpc/rpc.rb +25 -0
- data/lib/action_web_service/soap/rpc/soaplet.rb +162 -0
- data/lib/action_web_service/soap/rpc/standaloneServer.rb +43 -0
- data/lib/action_web_service/soap/soap.rb +140 -0
- data/lib/action_web_service/soap/streamHandler.rb +229 -0
- data/lib/action_web_service/soap/wsdlDriver.rb +575 -0
- data/lib/action_web_service/struct.rb +64 -0
- data/lib/action_web_service/support/class_inheritable_options.rb +28 -0
- data/lib/action_web_service/support/signature_types.rb +227 -0
- data/lib/action_web_service/test_invoke.rb +110 -0
- data/lib/action_web_service/version.rb +9 -0
- data/lib/action_web_service/wsdl/binding.rb +65 -0
- data/lib/action_web_service/wsdl/data.rb +64 -0
- data/lib/action_web_service/wsdl/definitions.rb +250 -0
- data/lib/action_web_service/wsdl/documentation.rb +32 -0
- data/lib/action_web_service/wsdl/import.rb +80 -0
- data/lib/action_web_service/wsdl/importer.rb +38 -0
- data/lib/action_web_service/wsdl/info.rb +39 -0
- data/lib/action_web_service/wsdl/message.rb +54 -0
- data/lib/action_web_service/wsdl/operation.rb +130 -0
- data/lib/action_web_service/wsdl/operationBinding.rb +108 -0
- data/lib/action_web_service/wsdl/param.rb +85 -0
- data/lib/action_web_service/wsdl/parser.rb +163 -0
- data/lib/action_web_service/wsdl/part.rb +52 -0
- data/lib/action_web_service/wsdl/port.rb +84 -0
- data/lib/action_web_service/wsdl/portType.rb +73 -0
- data/lib/action_web_service/wsdl/service.rb +61 -0
- data/lib/action_web_service/wsdl/soap/address.rb +40 -0
- data/lib/action_web_service/wsdl/soap/binding.rb +49 -0
- data/lib/action_web_service/wsdl/soap/body.rb +56 -0
- data/lib/action_web_service/wsdl/soap/cgiStubCreator.rb +76 -0
- data/lib/action_web_service/wsdl/soap/classDefCreator.rb +314 -0
- data/lib/action_web_service/wsdl/soap/classDefCreatorSupport.rb +126 -0
- data/lib/action_web_service/wsdl/soap/clientSkeltonCreator.rb +78 -0
- data/lib/action_web_service/wsdl/soap/complexType.rb +161 -0
- data/lib/action_web_service/wsdl/soap/data.rb +42 -0
- data/lib/action_web_service/wsdl/soap/definitions.rb +149 -0
- data/lib/action_web_service/wsdl/soap/driverCreator.rb +95 -0
- data/lib/action_web_service/wsdl/soap/element.rb +28 -0
- data/lib/action_web_service/wsdl/soap/fault.rb +56 -0
- data/lib/action_web_service/wsdl/soap/header.rb +86 -0
- data/lib/action_web_service/wsdl/soap/headerfault.rb +56 -0
- data/lib/action_web_service/wsdl/soap/mappingRegistryCreator.rb +92 -0
- data/lib/action_web_service/wsdl/soap/methodDefCreator.rb +228 -0
- data/lib/action_web_service/wsdl/soap/operation.rb +122 -0
- data/lib/action_web_service/wsdl/soap/servantSkeltonCreator.rb +67 -0
- data/lib/action_web_service/wsdl/soap/standaloneServerStubCreator.rb +85 -0
- data/lib/action_web_service/wsdl/soap/wsdl2ruby.rb +176 -0
- data/lib/action_web_service/wsdl/types.rb +43 -0
- data/lib/action_web_service/wsdl/wsdl.rb +23 -0
- data/lib/action_web_service/wsdl/xmlSchema/all.rb +69 -0
- data/lib/action_web_service/wsdl/xmlSchema/annotation.rb +34 -0
- data/lib/action_web_service/wsdl/xmlSchema/any.rb +56 -0
- data/lib/action_web_service/wsdl/xmlSchema/attribute.rb +127 -0
- data/lib/action_web_service/wsdl/xmlSchema/choice.rb +69 -0
- data/lib/action_web_service/wsdl/xmlSchema/complexContent.rb +92 -0
- data/lib/action_web_service/wsdl/xmlSchema/complexType.rb +139 -0
- data/lib/action_web_service/wsdl/xmlSchema/content.rb +96 -0
- data/lib/action_web_service/wsdl/xmlSchema/data.rb +80 -0
- data/lib/action_web_service/wsdl/xmlSchema/element.rb +154 -0
- data/lib/action_web_service/wsdl/xmlSchema/enumeration.rb +36 -0
- data/lib/action_web_service/wsdl/xmlSchema/import.rb +65 -0
- data/lib/action_web_service/wsdl/xmlSchema/importer.rb +87 -0
- data/lib/action_web_service/wsdl/xmlSchema/include.rb +54 -0
- data/lib/action_web_service/wsdl/xmlSchema/length.rb +35 -0
- data/lib/action_web_service/wsdl/xmlSchema/parser.rb +166 -0
- data/lib/action_web_service/wsdl/xmlSchema/pattern.rb +36 -0
- data/lib/action_web_service/wsdl/xmlSchema/schema.rb +143 -0
- data/lib/action_web_service/wsdl/xmlSchema/sequence.rb +69 -0
- data/lib/action_web_service/wsdl/xmlSchema/simpleContent.rb +65 -0
- data/lib/action_web_service/wsdl/xmlSchema/simpleExtension.rb +54 -0
- data/lib/action_web_service/wsdl/xmlSchema/simpleRestriction.rb +73 -0
- data/lib/action_web_service/wsdl/xmlSchema/simpleType.rb +73 -0
- data/lib/action_web_service/wsdl/xmlSchema/unique.rb +34 -0
- data/lib/action_web_service/wsdl/xmlSchema/xsd2ruby.rb +107 -0
- data/lib/action_web_service/xsd/charset.rb +187 -0
- data/lib/action_web_service/xsd/codegen.rb +12 -0
- data/lib/action_web_service/xsd/codegen/classdef.rb +203 -0
- data/lib/action_web_service/xsd/codegen/commentdef.rb +34 -0
- data/lib/action_web_service/xsd/codegen/gensupport.rb +166 -0
- data/lib/action_web_service/xsd/codegen/methoddef.rb +63 -0
- data/lib/action_web_service/xsd/codegen/moduledef.rb +191 -0
- data/lib/action_web_service/xsd/datatypes.rb +1269 -0
- data/lib/action_web_service/xsd/datatypes1999.rb +20 -0
- data/lib/action_web_service/xsd/iconvcharset.rb +33 -0
- data/lib/action_web_service/xsd/mapping.rb +42 -0
- data/lib/action_web_service/xsd/namedelements.rb +95 -0
- data/lib/action_web_service/xsd/ns.rb +140 -0
- data/lib/action_web_service/xsd/qname.rb +78 -0
- data/lib/action_web_service/xsd/xmlparser.rb +61 -0
- data/lib/action_web_service/xsd/xmlparser/parser.rb +96 -0
- data/lib/action_web_service/xsd/xmlparser/rexmlparser.rb +54 -0
- data/lib/action_web_service/xsd/xmlparser/xmlparser.rb +50 -0
- data/lib/action_web_service/xsd/xmlparser/xmlscanner.rb +147 -0
- data/lib/actionwebservice.rb +1 -0
- data/setup.rb +1379 -0
- data/test/abstract_client.rb +183 -0
- data/test/abstract_dispatcher.rb +548 -0
- data/test/abstract_unit.rb +45 -0
- data/test/api_test.rb +103 -0
- data/test/apis/auto_load_api.rb +3 -0
- data/test/apis/broken_auto_load_api.rb +2 -0
- data/test/base_test.rb +42 -0
- data/test/casting_test.rb +95 -0
- data/test/client_soap_test.rb +156 -0
- data/test/client_xmlrpc_test.rb +153 -0
- data/test/container_test.rb +73 -0
- data/test/dispatcher_action_controller_soap_test.rb +139 -0
- data/test/dispatcher_action_controller_xmlrpc_test.rb +59 -0
- data/test/fixtures/db_definitions/mysql.sql +8 -0
- data/test/fixtures/db_definitions/sqlite3.sql +8 -0
- data/test/fixtures/users.yml +12 -0
- data/test/gencov +3 -0
- data/test/invocation_test.rb +185 -0
- data/test/run +6 -0
- data/test/scaffolded_controller_test.rb +146 -0
- data/test/struct_test.rb +52 -0
- data/test/test_invoke_test.rb +112 -0
- metadata +265 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
$: << "#{File.dirname(__FILE__)}/../lib"
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
require 'rubygems'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'action_web_service'
|
6
|
+
require 'action_controller'
|
7
|
+
require 'action_controller/test_case'
|
8
|
+
require 'action_view'
|
9
|
+
require 'action_view/test_case'
|
10
|
+
require 'active_record'
|
11
|
+
require 'active_record/test_case'
|
12
|
+
|
13
|
+
# Show backtraces for deprecated behavior for quicker cleanup.
|
14
|
+
ActiveSupport::Deprecation.debug = true
|
15
|
+
|
16
|
+
|
17
|
+
ActiveRecord::Base.logger = ActionController::Base.logger = Logger.new("debug.log")
|
18
|
+
|
19
|
+
begin
|
20
|
+
require 'active_record'
|
21
|
+
require "active_record/test_case"
|
22
|
+
require "active_record/fixtures" unless Object.const_defined?(:Fixtures)
|
23
|
+
rescue LoadError => e
|
24
|
+
fail "\nFailed to load activerecord: #{e}"
|
25
|
+
end
|
26
|
+
|
27
|
+
ActiveRecord::Base.configurations = {
|
28
|
+
'mysql' => {
|
29
|
+
:adapter => "mysql",
|
30
|
+
:username => "root",
|
31
|
+
:encoding => "utf8",
|
32
|
+
:database => "actionwebservice_unittest"
|
33
|
+
},
|
34
|
+
'sqlite3' => {
|
35
|
+
:adapter => "sqlite3",
|
36
|
+
:database => "actionwebservice_unittest.db"
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
ActiveRecord::Base.establish_connection 'sqlite3'
|
41
|
+
|
42
|
+
class ActiveSupport::TestCase
|
43
|
+
include ActiveRecord::TestFixtures
|
44
|
+
self.fixture_path = "#{File.dirname(__FILE__)}/fixtures/"
|
45
|
+
end
|
data/test/api_test.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
#require File.dirname(__FILE__) + '/abstract_unit'
|
3
|
+
|
4
|
+
module APITest
|
5
|
+
class API < ActionWebService::API::Base
|
6
|
+
api_method :void
|
7
|
+
api_method :expects_and_returns, :expects_and_returns => [:string]
|
8
|
+
api_method :expects, :expects => [:int, :bool]
|
9
|
+
api_method :returns, :returns => [:int, [:string]]
|
10
|
+
api_method :named_signature, :expects => [{:appkey=>:int}, {:publish=>:bool}]
|
11
|
+
api_method :string_types, :expects => ['int', 'string', 'bool', 'base64']
|
12
|
+
api_method :class_types, :expects => [TrueClass, Bignum, String]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class TC_API < ActiveSupport::TestCase
|
17
|
+
API = APITest::API
|
18
|
+
|
19
|
+
def test_api_method_declaration
|
20
|
+
%w(
|
21
|
+
void
|
22
|
+
expects_and_returns
|
23
|
+
expects
|
24
|
+
returns
|
25
|
+
named_signature
|
26
|
+
string_types
|
27
|
+
class_types
|
28
|
+
).each do |name|
|
29
|
+
name = name.to_sym
|
30
|
+
public_name = API.public_api_method_name(name)
|
31
|
+
assert(API.has_api_method?(name))
|
32
|
+
assert(API.has_public_api_method?(public_name))
|
33
|
+
assert(API.api_method_name(public_name) == name)
|
34
|
+
assert(API.api_methods.has_key?(name))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_signature_canonicalization
|
39
|
+
assert_equal(nil, API.api_methods[:void].expects)
|
40
|
+
assert_equal(nil, API.api_methods[:void].returns)
|
41
|
+
assert_equal([String], API.api_methods[:expects_and_returns].expects.map{|x| x.type_class})
|
42
|
+
assert_equal([String], API.api_methods[:expects_and_returns].returns.map{|x| x.type_class})
|
43
|
+
assert_equal([Integer, TrueClass], API.api_methods[:expects].expects.map{|x| x.type_class})
|
44
|
+
assert_equal(nil, API.api_methods[:expects].returns)
|
45
|
+
assert_equal(nil, API.api_methods[:returns].expects)
|
46
|
+
assert_equal([Integer, [String]], API.api_methods[:returns].returns.map{|x| x.array?? [x.element_type.type_class] : x.type_class})
|
47
|
+
assert_equal([[:appkey, Integer], [:publish, TrueClass]], API.api_methods[:named_signature].expects.map{|x| [x.name, x.type_class]})
|
48
|
+
assert_equal(nil, API.api_methods[:named_signature].returns)
|
49
|
+
assert_equal([Integer, String, TrueClass, ActionWebService::Base64], API.api_methods[:string_types].expects.map{|x| x.type_class})
|
50
|
+
assert_equal(nil, API.api_methods[:string_types].returns)
|
51
|
+
assert_equal([TrueClass, Integer, String], API.api_methods[:class_types].expects.map{|x| x.type_class})
|
52
|
+
assert_equal(nil, API.api_methods[:class_types].returns)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_not_instantiable
|
56
|
+
assert_raises(NoMethodError) do
|
57
|
+
API.new
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_api_errors
|
62
|
+
assert_raises(ActionWebService::ActionWebServiceError) do
|
63
|
+
klass = Class.new(ActionWebService::API::Base) do
|
64
|
+
api_method :test, :expects => [ActiveRecord::Base]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
klass = Class.new(ActionWebService::API::Base) do
|
68
|
+
allow_active_record_expects true
|
69
|
+
api_method :test2, :expects => [ActiveRecord::Base]
|
70
|
+
end
|
71
|
+
assert_raises(ActionWebService::ActionWebServiceError) do
|
72
|
+
klass = Class.new(ActionWebService::API::Base) do
|
73
|
+
api_method :test, :invalid => [:int]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_parameter_names
|
79
|
+
method = API.api_methods[:named_signature]
|
80
|
+
assert_equal 0, method.expects_index_of(:appkey)
|
81
|
+
assert_equal 1, method.expects_index_of(:publish)
|
82
|
+
assert_equal 1, method.expects_index_of('publish')
|
83
|
+
assert_equal 0, method.expects_index_of('appkey')
|
84
|
+
assert_equal -1, method.expects_index_of('blah')
|
85
|
+
assert_equal -1, method.expects_index_of(:missing)
|
86
|
+
assert_equal -1, API.api_methods[:void].expects_index_of('test')
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_parameter_hash
|
90
|
+
method = API.api_methods[:named_signature]
|
91
|
+
hash = method.expects_to_hash([5, false])
|
92
|
+
assert_equal({:appkey => 5, :publish => false}, hash)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_api_methods_compat
|
96
|
+
sig = API.api_methods[:named_signature][:expects]
|
97
|
+
assert_equal [{:appkey=>Integer}, {:publish=>TrueClass}], sig
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_to_s
|
101
|
+
assert_equal 'void Expects(int param0, bool param1)', APITest::API.api_methods[:expects].to_s
|
102
|
+
end
|
103
|
+
end
|
data/test/base_test.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
module BaseTest
|
4
|
+
class API < ActionWebService::API::Base
|
5
|
+
api_method :add, :expects => [:int, :int], :returns => [:int]
|
6
|
+
api_method :void
|
7
|
+
end
|
8
|
+
|
9
|
+
class PristineAPI < ActionWebService::API::Base
|
10
|
+
inflect_names false
|
11
|
+
|
12
|
+
api_method :add
|
13
|
+
api_method :under_score
|
14
|
+
end
|
15
|
+
|
16
|
+
class Service < ActionWebService::Base
|
17
|
+
web_service_api API
|
18
|
+
|
19
|
+
def add(a, b)
|
20
|
+
end
|
21
|
+
|
22
|
+
def void
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class PristineService < ActionWebService::Base
|
27
|
+
web_service_api PristineAPI
|
28
|
+
|
29
|
+
def add
|
30
|
+
end
|
31
|
+
|
32
|
+
def under_score
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class TC_Base < ActiveSupport::TestCase
|
38
|
+
def test_options
|
39
|
+
assert(BaseTest::PristineService.web_service_api.inflect_names == false)
|
40
|
+
assert(BaseTest::Service.web_service_api.inflect_names == true)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
module CastingTest
|
4
|
+
class A < ActionWebService::Struct; end
|
5
|
+
class B < A; end
|
6
|
+
class API < ActionWebService::API::Base
|
7
|
+
api_method :int, :expects => [:int]
|
8
|
+
api_method :str, :expects => [:string]
|
9
|
+
api_method :base64, :expects => [:base64]
|
10
|
+
api_method :bool, :expects => [:bool]
|
11
|
+
api_method :float, :expects => [:float]
|
12
|
+
api_method :time, :expects => [:time]
|
13
|
+
api_method :datetime, :expects => [:datetime]
|
14
|
+
api_method :date, :expects => [:date]
|
15
|
+
|
16
|
+
api_method :int_array, :expects => [[:int]]
|
17
|
+
api_method :str_array, :expects => [[:string]]
|
18
|
+
api_method :bool_array, :expects => [[:bool]]
|
19
|
+
|
20
|
+
api_method :a, :expects => [A]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class TC_Casting < Test::Unit::TestCase
|
25
|
+
include CastingTest
|
26
|
+
|
27
|
+
def test_base_type_casting_valid
|
28
|
+
assert_equal 10000, cast_expects(:int, '10000')[0]
|
29
|
+
assert_equal '10000', cast_expects(:str, 10000)[0]
|
30
|
+
base64 = cast_expects(:base64, 10000)[0]
|
31
|
+
assert_equal '10000', base64
|
32
|
+
assert_instance_of ActionWebService::Base64, base64
|
33
|
+
[1, '1', 'true', 'y', 'yes'].each do |val|
|
34
|
+
assert_equal true, cast_expects(:bool, val)[0]
|
35
|
+
end
|
36
|
+
[0, '0', 'false', 'n', 'no'].each do |val|
|
37
|
+
assert_equal false, cast_expects(:bool, val)[0]
|
38
|
+
end
|
39
|
+
assert_equal 3.14159, cast_expects(:float, '3.14159')[0]
|
40
|
+
now = Time.at(Time.now.tv_sec)
|
41
|
+
casted = cast_expects(:time, now.to_s)[0]
|
42
|
+
assert_equal now, casted
|
43
|
+
now = DateTime.now
|
44
|
+
assert_equal now.to_s, cast_expects(:datetime, now.to_s)[0].to_s
|
45
|
+
today = Date.today
|
46
|
+
assert_equal today, cast_expects(:date, today.to_s)[0]
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_base_type_casting_invalid
|
50
|
+
assert_raises ArgumentError do
|
51
|
+
cast_expects(:int, 'this is not a number')
|
52
|
+
end
|
53
|
+
assert_raises ActionWebService::Casting::CastingError do
|
54
|
+
# neither true or false ;)
|
55
|
+
cast_expects(:bool, 'i always lie')
|
56
|
+
end
|
57
|
+
assert_raises ArgumentError do
|
58
|
+
cast_expects(:float, 'not a float')
|
59
|
+
end
|
60
|
+
# not sure why this test fails but too lazy to find out why :-(
|
61
|
+
# assert_raises ArgumentError do
|
62
|
+
# cast_expects(:time, '111111111111111111111111111111111')
|
63
|
+
# end
|
64
|
+
assert_raises ArgumentError do
|
65
|
+
cast_expects(:datetime, '-1')
|
66
|
+
end
|
67
|
+
assert_raises ArgumentError do
|
68
|
+
cast_expects(:date, '')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_array_type_casting
|
73
|
+
assert_equal [1, 2, 3213992, 4], cast_expects(:int_array, ['1', '2', '3213992', '4'])[0]
|
74
|
+
assert_equal ['one', 'two', '5.0', '200', nil, 'true'], cast_expects(:str_array, [:one, 'two', 5.0, 200, nil, true])[0]
|
75
|
+
assert_equal [true, nil, true, true, false], cast_expects(:bool_array, ['1', nil, 'y', true, 'false'])[0]
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_array_type_casting_failure
|
79
|
+
assert_raises ActionWebService::Casting::CastingError do
|
80
|
+
cast_expects(:bool_array, ['false', 'blahblah'])
|
81
|
+
end
|
82
|
+
assert_raises ArgumentError do
|
83
|
+
cast_expects(:int_array, ['1', '2.021', '4'])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_structured_type_casting_with_polymorphism
|
88
|
+
assert cast_expects(:a, B.new)[0].is_a?(B)
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def cast_expects(method_name, *args)
|
93
|
+
API.api_method_instance(method_name.to_sym).cast_expects([*args])
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'abstract_client'
|
3
|
+
|
4
|
+
|
5
|
+
module ClientSoapTest
|
6
|
+
PORT = 8998
|
7
|
+
|
8
|
+
class SoapClientLet < ClientTest::AbstractClientLet
|
9
|
+
def do_POST(req, res)
|
10
|
+
test_request = ActionController::TestRequest.new
|
11
|
+
test_request.request_parameters['action'] = req.path.gsub(/^\//, '').split(/\//)[1]
|
12
|
+
test_request.env['REQUEST_METHOD'] = "POST"
|
13
|
+
test_request.env['HTTP_CONTENTTYPE'] = 'text/xml'
|
14
|
+
test_request.env['HTTP_SOAPACTION'] = req.header['soapaction'][0]
|
15
|
+
test_request.env['RAW_POST_DATA'] = req.body
|
16
|
+
response = ActionController::TestResponse.new
|
17
|
+
@controller.process(test_request, response)
|
18
|
+
res.header['content-type'] = 'text/xml'
|
19
|
+
res.body = response.body
|
20
|
+
rescue Exception => e
|
21
|
+
$stderr.puts e.message
|
22
|
+
$stderr.puts e.backtrace.join("\n")
|
23
|
+
ensure
|
24
|
+
ActiveRecord::Base.clear_active_connections!
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class ClientContainer < ActionController::Base
|
29
|
+
web_client_api :client, :soap, "http://localhost:#{PORT}/client/api", :api => ClientTest::API
|
30
|
+
web_client_api :invalid, :null, "", :api => true
|
31
|
+
|
32
|
+
def get_client
|
33
|
+
client
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_invalid
|
37
|
+
invalid
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class SoapServer < ClientTest::AbstractServer
|
42
|
+
def create_clientlet(controller)
|
43
|
+
SoapClientLet.new(controller)
|
44
|
+
end
|
45
|
+
|
46
|
+
def server_port
|
47
|
+
PORT
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class TC_ClientSoap < ActiveSupport::TestCase
|
53
|
+
include ClientTest
|
54
|
+
include ClientSoapTest
|
55
|
+
|
56
|
+
fixtures :users
|
57
|
+
|
58
|
+
def setup
|
59
|
+
@server = SoapServer.instance
|
60
|
+
@container = @server.container
|
61
|
+
@client = ActionWebService::Client::Soap.new(API, "http://localhost:#{@server.server_port}/client/api")
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_void
|
65
|
+
assert(@container.value_void.nil?)
|
66
|
+
@client.void
|
67
|
+
assert(!@container.value_void.nil?)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_normal
|
71
|
+
assert(@container.value_normal.nil?)
|
72
|
+
assert_equal(5, @client.normal(5, 6))
|
73
|
+
assert_equal([5, 6], @container.value_normal)
|
74
|
+
assert_equal(5, @client.normal("7", "8"))
|
75
|
+
assert_equal([7, 8], @container.value_normal)
|
76
|
+
assert_equal(5, @client.normal(true, false))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_array_return
|
80
|
+
assert(@container.value_array_return.nil?)
|
81
|
+
new_person = Person.new
|
82
|
+
new_person.firstnames = ["one", "two"]
|
83
|
+
new_person.lastname = "last"
|
84
|
+
assert_equal([new_person], @client.array_return)
|
85
|
+
assert_equal([new_person], @container.value_array_return)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_struct_pass
|
89
|
+
assert(@container.value_struct_pass.nil?)
|
90
|
+
new_person = Person.new
|
91
|
+
new_person.firstnames = ["one", "two"]
|
92
|
+
new_person.lastname = "last"
|
93
|
+
assert_equal(true, @client.struct_pass([new_person]))
|
94
|
+
assert_equal([[new_person]], @container.value_struct_pass)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_nil_struct_return
|
98
|
+
assert_nil @client.nil_struct_return
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_inner_nil
|
102
|
+
outer = @client.inner_nil
|
103
|
+
assert_equal 'outer', outer.name
|
104
|
+
assert_nil outer.inner
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_client_container
|
108
|
+
assert_equal(50, ClientContainer.new.get_client.client_container)
|
109
|
+
assert(ClientContainer.new.get_invalid.nil?)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_named_parameters
|
113
|
+
assert(@container.value_named_parameters.nil?)
|
114
|
+
assert(@client.named_parameters("key", 5).nil?)
|
115
|
+
assert_equal(["key", 5], @container.value_named_parameters)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_capitalized_method_name
|
119
|
+
@container.value_normal = nil
|
120
|
+
assert_equal(5, @client.Normal(5, 6))
|
121
|
+
assert_equal([5, 6], @container.value_normal)
|
122
|
+
@container.value_normal = nil
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_model_return
|
126
|
+
user = @client.user_return
|
127
|
+
assert_equal 1, user.id
|
128
|
+
assert_equal 'Kent', user.name
|
129
|
+
assert user.active?
|
130
|
+
assert_kind_of Date, user.created_on
|
131
|
+
assert_equal Date.today, user.created_on
|
132
|
+
assert_equal BigDecimal('12.2'), user.balance
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_with_model
|
136
|
+
with_model = @client.with_model_return
|
137
|
+
assert_equal 'Kent', with_model.user.name
|
138
|
+
assert_equal 2, with_model.users.size
|
139
|
+
with_model.users.each do |user|
|
140
|
+
assert_kind_of User, user
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_scoped_model_return
|
145
|
+
scoped_model = @client.scoped_model_return
|
146
|
+
assert_kind_of Accounting::User, scoped_model
|
147
|
+
assert_equal 'Kent', scoped_model.name
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_multi_dim_return
|
151
|
+
md_struct = @client.multi_dim_return
|
152
|
+
assert_kind_of Array, md_struct.pref
|
153
|
+
assert_equal 2, md_struct.pref.size
|
154
|
+
assert_kind_of Array, md_struct.pref[0]
|
155
|
+
end
|
156
|
+
end
|