aboutsummaryrefslogtreecommitdiffstats
path: root/actionservice/test/protocol_registry_test.rb
blob: 8e2b9659a6fc9833194cffd9829c77aae4aeda96 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require File.dirname(__FILE__) + '/abstract_unit'


module Foo
  include ActionService::Protocol

  def self.append_features(base)
    super
    base.register_protocol(BodyOnly, FooMinimalProtocol)
    base.register_protocol(HeaderAndBody, FooMinimalProtocolTwo)
    base.register_protocol(HeaderAndBody, FooMinimalProtocolTwo)
    base.register_protocol(HeaderAndBody, FooFullProtocol)
  end

  class FooFullProtocol < AbstractProtocol
    def self.create_protocol_request(klass, request)
      protocol = FooFullProtocol.new klass
      ActionService::Protocol::ProtocolRequest.new(protocol, '', '', '', '')
    end
  end

  class FooMinimalProtocol < AbstractProtocol
    def self.create_protocol_request(klass, request)
      protocol = FooMinimalProtocol.new klass
      ActionService::Protocol::ProtocolRequest.new(protocol, '', '', '', '')
    end
  end

  class FooMinimalProtocolTwo < AbstractProtocol
  end
end

class ProtocolRegistry
  include ActionService::Protocol::Registry
  include Foo

  def all_protocols
    header_and_body_protocols + body_only_protocols
  end

  def protocol_request
    probe_request_protocol(nil)
  end
end


class TC_ProtocolRegistry < Test::Unit::TestCase
  def test_registration
    registry = ProtocolRegistry.new
    assert(registry.all_protocols.length == 4)
    assert(registry.protocol_request.protocol.is_a?(Foo::FooFullProtocol))
  end
end