s2container 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/Apache_Software_License_2.0.txt +202 -0
  2. data/ChangeLog +1 -0
  3. data/ChangeLog.ja +64 -0
  4. data/README +9 -0
  5. data/Rakefile +51 -0
  6. data/example/example01/example.rb +13 -0
  7. data/example/example01/run.rb +20 -0
  8. data/example/example02/example.rb +30 -0
  9. data/example/example02/run.rb +8 -0
  10. data/example/example03/example.rb +8 -0
  11. data/example/example03/run.rb +12 -0
  12. data/example/example04/example.rb +9 -0
  13. data/example/example04/run.rb +15 -0
  14. data/example/example05/example.rb +9 -0
  15. data/example/example05/run.rb +21 -0
  16. data/example/example06/example.rb +9 -0
  17. data/example/example06/run.rb +8 -0
  18. data/example/example07/example.rb +8 -0
  19. data/example/example07/run.rb +15 -0
  20. data/example/example08/example.rb +9 -0
  21. data/example/example08/run.rb +19 -0
  22. data/example/example09/example.rb +7 -0
  23. data/example/example09/run.rb +11 -0
  24. data/example/example10/example.rb +9 -0
  25. data/example/example10/run.rb +10 -0
  26. data/example/example11/example.rb +18 -0
  27. data/example/example11/run.rb +10 -0
  28. data/example/example12/example.rb +9 -0
  29. data/example/example12/run.rb +8 -0
  30. data/example/example13/example.rb +18 -0
  31. data/example/example13/example.sql +4 -0
  32. data/example/example13/run.rb +22 -0
  33. data/example/example13/sample.db +0 -0
  34. data/example/example14/example.db +0 -0
  35. data/example/example14/example.rb +57 -0
  36. data/example/example14/example.sql +50 -0
  37. data/example/example14/run1.rb +23 -0
  38. data/example/example14/run2.rb +28 -0
  39. data/example/example14/run3.rb +25 -0
  40. data/example/example14/run4.rb +23 -0
  41. data/example/example14/run5.rb +35 -0
  42. data/example/example15/example.rb +20 -0
  43. data/example/example15/run.rb +28 -0
  44. data/example/example16/example.rb +15 -0
  45. data/example/example16/run.rb +24 -0
  46. data/example/quickstart/quickstart1/quickstart.rb +10 -0
  47. data/example/quickstart/quickstart2/quickstart.rb +9 -0
  48. data/example/quickstart/quickstart3/quickstart.rb +9 -0
  49. data/example/quickstart/quickstart4/quickstart.rb +14 -0
  50. data/example/quickstart/quickstart5/quickstart.rb +21 -0
  51. data/example/quickstart/quickstart6/quickstart.rb +28 -0
  52. data/example/quickstart/quickstart7/quickstart.rb +18 -0
  53. data/lib/s2container.rb +25 -0
  54. data/lib/seasar/aop/aspect.rb +30 -0
  55. data/lib/seasar/aop/interceptor/trace-interceptor.rb +48 -0
  56. data/lib/seasar/aop/method-invocation.rb +57 -0
  57. data/lib/seasar/aop/pointcut.rb +53 -0
  58. data/lib/seasar/aop/s2aop-factory.rb +125 -0
  59. data/lib/seasar/aop.rb +29 -0
  60. data/lib/seasar/beans/abstract-property-desc.rb +59 -0
  61. data/lib/seasar/beans/attribute-accessor-desc.rb +60 -0
  62. data/lib/seasar/beans/bean-desc-factory.rb +68 -0
  63. data/lib/seasar/beans/bean-desc.rb +232 -0
  64. data/lib/seasar/beans/instance-variable-desc.rb +58 -0
  65. data/lib/seasar/beans.rb +29 -0
  66. data/lib/seasar/container/arg-def.rb +51 -0
  67. data/lib/seasar/container/aspect-def.rb +60 -0
  68. data/lib/seasar/container/aspect-info-def.rb +94 -0
  69. data/lib/seasar/container/assembler/abstract-assembler.rb +68 -0
  70. data/lib/seasar/container/assembler/auto-property-assembler.rb +57 -0
  71. data/lib/seasar/container/assembler/autobinding-auto-def.rb +55 -0
  72. data/lib/seasar/container/assembler/autobinding-def-factory.rb +57 -0
  73. data/lib/seasar/container/assembler/autobinding-none-def.rb +53 -0
  74. data/lib/seasar/container/assembler/manual-constructor-assembler.rb +67 -0
  75. data/lib/seasar/container/assembler/manual-property-assembler.rb +68 -0
  76. data/lib/seasar/container/autobinding-def.rb +36 -0
  77. data/lib/seasar/container/component-def.rb +229 -0
  78. data/lib/seasar/container/component-info-def.rb +117 -0
  79. data/lib/seasar/container/deployer/abstract-component-deployer.rb +47 -0
  80. data/lib/seasar/container/deployer/instance-def-factory.rb +56 -0
  81. data/lib/seasar/container/deployer/instance-outer-def.rb +44 -0
  82. data/lib/seasar/container/deployer/instance-prototype-def.rb +44 -0
  83. data/lib/seasar/container/deployer/instance-singleton-def.rb +42 -0
  84. data/lib/seasar/container/deployer/outer-component-deployer.rb +47 -0
  85. data/lib/seasar/container/deployer/prototype-component-deployer.rb +51 -0
  86. data/lib/seasar/container/deployer/singleton-component-deployer.rb +54 -0
  87. data/lib/seasar/container/exception/component-notfound-runtime-exception.rb +44 -0
  88. data/lib/seasar/container/exception/cyclic-reference-runtime-exception.rb +43 -0
  89. data/lib/seasar/container/exception/illegal-autobinding-def-runtime-exception.rb +43 -0
  90. data/lib/seasar/container/exception/illegal-instance-def-runtime-exception.rb +44 -0
  91. data/lib/seasar/container/exception/toomany-registration-runtime-exception.rb +46 -0
  92. data/lib/seasar/container/instance-def.rb +37 -0
  93. data/lib/seasar/container/outer-component-def.rb +34 -0
  94. data/lib/seasar/container/property-def.rb +43 -0
  95. data/lib/seasar/container/s2application-context.rb +447 -0
  96. data/lib/seasar/container/s2container-component-def.rb +41 -0
  97. data/lib/seasar/container/s2container.rb +308 -0
  98. data/lib/seasar/container/simple-component-def.rb +45 -0
  99. data/lib/seasar/container/toomany-registration-component-def.rb +69 -0
  100. data/lib/seasar/container.rb +143 -0
  101. data/lib/seasar/dbi/dbi-interceptor.rb +97 -0
  102. data/lib/seasar/dbi/paginate.rb +215 -0
  103. data/lib/seasar/dbi.rb +26 -0
  104. data/lib/seasar/exception/notyet-implemented-exception.rb +25 -0
  105. data/lib/seasar/exception/property-notfound-runtime-exception.rb +48 -0
  106. data/lib/seasar/exception/s2runtime-exception.rb +35 -0
  107. data/lib/seasar/exception/unsupported-operation-exception.rb +25 -0
  108. data/lib/seasar/exception.rb +27 -0
  109. data/lib/seasar/log/s2logger.rb +75 -0
  110. data/lib/seasar/log.rb +38 -0
  111. data/lib/seasar/util/class-util.rb +116 -0
  112. data/lib/seasar/util.rb +24 -0
  113. data/setup.rb +1585 -0
  114. data/test/seasar/aop/test_pointcut.rb +25 -0
  115. data/test/seasar/aop/test_s2aop_factory.rb +90 -0
  116. data/test/seasar/beans/test_bean-desc.rb +179 -0
  117. data/test/seasar/container/assembler/test_auto_property_assembler.rb +87 -0
  118. data/test/seasar/container/assembler/test_autobinding_def_factory.rb +22 -0
  119. data/test/seasar/container/assembler/test_manual_property_assembler.rb +59 -0
  120. data/test/seasar/container/assembler/test_manula_constructor_assembler.rb +59 -0
  121. data/test/seasar/container/assembler/test_proc_constructor_assembler.rb +61 -0
  122. data/test/seasar/container/deployer/test_instance_def_factory.rb +24 -0
  123. data/test/seasar/container/deployer/test_prototype-deployer.rb +25 -0
  124. data/test/seasar/container/deployer/test_singleton-component-deployer.rb +24 -0
  125. data/test/seasar/container/s2app_load_sample.rb +6 -0
  126. data/test/seasar/container/test_arg-def.rb +34 -0
  127. data/test/seasar/container/test_aspect-info-def.rb +85 -0
  128. data/test/seasar/container/test_component-def.rb +91 -0
  129. data/test/seasar/container/test_component-info-def.rb +88 -0
  130. data/test/seasar/container/test_s2application-context.rb +290 -0
  131. data/test/seasar/container/test_s2container.rb +268 -0
  132. data/test/seasar/dbi/test_paginate.rb +265 -0
  133. data/test/seasar/test_log.rb +20 -0
  134. data/test/seasar/test_util.rb +46 -0
  135. data/test/test-suite.rb +7 -0
  136. metadata +211 -0
@@ -0,0 +1,25 @@
1
+ module Seasar
2
+ module Aop
3
+ class TC_Pointcut < Test::Unit::TestCase
4
+ def setup
5
+ end
6
+
7
+ def teardown
8
+ end
9
+
10
+ def test_applicable?
11
+ pointcut = Seasar::Aop::Pointcut.new("foo")
12
+ assert(pointcut.applicable?("foo"))
13
+ assert(!pointcut.applicable?("bar"))
14
+
15
+ pointcut = Seasar::Aop::Pointcut.new(:foo)
16
+ assert(pointcut.applicable?("foo"))
17
+ assert(!pointcut.applicable?("bar"))
18
+
19
+ pointcut = Seasar::Aop::Pointcut.new(/foo/)
20
+ assert(pointcut.applicable?("foo"))
21
+ assert(!pointcut.applicable?("bar"))
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,90 @@
1
+ module Seasar
2
+ module Aop
3
+ class TC_S2AopFactory < Test::Unit::TestCase
4
+ def setup
5
+ end
6
+
7
+ def teardown
8
+ end
9
+
10
+ def test_interceptor
11
+ aspect_def = Seasar::Container::AspectDef.new(/^bar$/, Seasar::Aop::Interceptor::TraceInterceptor.new)
12
+ aspects = [aspect_def.aspect]
13
+ enhanced_class = S2AopFactory.create(A, aspects)
14
+ a = enhanced_class.new
15
+ a.bar(100, "abc")
16
+ end
17
+
18
+ def test_procedure_arg
19
+ aspect_def = Seasar::Container::AspectDef.new(/^hoge$/) {|invocation|
20
+ result = invocation.proceed
21
+ next result * 10
22
+ }
23
+ aspects = [aspect_def.aspect]
24
+ aa = S2AopFactory.create(A, aspects)
25
+ a = aa.new
26
+ val = a.hoge(10) {|i|
27
+ next i * 10
28
+ }
29
+ assert_equal(100000, val)
30
+ end
31
+
32
+ def test_result
33
+ aspect_def = Seasar::Container::AspectDef.new(/^huga$/) {|invocation|
34
+ puts "before #{invocation.method.name}"
35
+ result = invocation.proceed
36
+ puts "after #{invocation.method.name} result #{result}"
37
+ next result * 10
38
+ }
39
+ aspects = [aspect_def.aspect]
40
+ aa = S2AopFactory.create(A, aspects)
41
+ a = aa.new
42
+ assert_equal(100, a.huga(1))
43
+ end
44
+
45
+ def test_aspects
46
+ aspect_def1 = Seasar::Container::AspectDef.new('huga', Seasar::Aop::Interceptor::TraceInterceptor.new)
47
+ aspect_def2 = Seasar::Container::AspectDef.new(:huga) {|invocation|
48
+ result = invocation.proceed
49
+ result * 10
50
+ }
51
+ aspect_def3 = Seasar::Container::AspectDef.new(/^huga$/) {|invocation|
52
+ result = invocation.proceed
53
+ result * 10
54
+ }
55
+ aspects = [aspect_def1.aspect, aspect_def2.aspect, aspect_def3.aspect]
56
+ aa = S2AopFactory.create(A, aspects)
57
+ a = aa.new
58
+ assert_equal(1000, a.huga(1))
59
+ end
60
+
61
+ def test_parent
62
+ aspect_def = Seasar::Container::AspectDef.new(:huga) {|invocation|
63
+ result = invocation.proceed
64
+ result * 10
65
+ }
66
+ enhanced_class = S2AopFactory.create(B, [aspect_def.aspect])
67
+ b = enhanced_class.new
68
+ assert_equal(100, b.huga(1))
69
+ end
70
+
71
+ class A
72
+ def bar(i, s)
73
+ return "xyz"
74
+ end
75
+
76
+ def hoge(s)
77
+ result = yield 100
78
+ return s * result
79
+ end
80
+
81
+ def huga(i)
82
+ return i * 10
83
+ end
84
+ end
85
+
86
+ class B < A
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,179 @@
1
+ module Seasar
2
+ module Beans
3
+ class TC_BeanDesc < Test::Unit::TestCase
4
+ def setup
5
+ end
6
+
7
+ def teardown
8
+ end
9
+
10
+ def test_bean_desc_factory
11
+ assert_equal(BeanDescFactory.get_bean_desc(A.new), BeanDescFactory.get_bean_desc(A.new))
12
+ begin
13
+ BeanDescFactory.get_bean_desc(A.new).get_property_desc("aaa")
14
+ rescue => e
15
+ assert(e.instance_of?(Seasar::Exception::PropertyNotFoundRuntimeException))
16
+ assert_equal("class : Seasar::Beans::TC_BeanDesc::A, attribute : aaa", e.message)
17
+ end
18
+
19
+ begin
20
+ BeanDescFactory.get_bean_desc(A.new).get_typehint_property_desc("aaa")
21
+ rescue => e
22
+ assert(e.instance_of?(Seasar::Exception::PropertyNotFoundRuntimeException))
23
+ assert_equal("class : Seasar::Beans::TC_BeanDesc::A, attribute : aaa", e.message)
24
+ end
25
+ end
26
+
27
+ def test_has_property
28
+ desc = BeanDescFactory.get_bean_desc(A.new)
29
+ assert(desc.has_property_desc(:@name))
30
+ assert(desc.has_typehint_property_desc(:@name))
31
+ assert(!desc.get_typehint_property_desc(:@name).array_acceptable)
32
+ assert_equal(desc.get_typehint_property_desc(:@name).typehint, :name)
33
+
34
+ assert(desc.has_property_desc(:@b))
35
+ assert(desc.has_typehint_property_desc(:@b))
36
+ assert(!desc.get_typehint_property_desc(:@b).array_acceptable)
37
+ assert_equal(desc.get_typehint_property_desc(:@b).typehint, B)
38
+
39
+ assert(desc.has_property_desc(:@c))
40
+ assert(!desc.has_typehint_property_desc(:@c))
41
+ assert(!desc.has_property_desc(:@d))
42
+ assert(!desc.has_typehint_property_desc(:@d))
43
+
44
+ assert(desc.has_property_desc(:@z))
45
+ assert(desc.has_typehint_property_desc(:@z))
46
+ assert(!desc.get_typehint_property_desc(:@z).array_acceptable)
47
+ assert_equal(desc.get_typehint_property_desc(:@z).typehint, :z)
48
+ end
49
+
50
+ def test_array_property
51
+ desc = BeanDescFactory.get_bean_desc(C.new)
52
+ assert(desc.has_property_desc(:@a))
53
+ assert(desc.has_typehint_property_desc(:@a))
54
+ assert(desc.get_typehint_property_desc(:@a).array_acceptable )
55
+ assert_equal(desc.get_typehint_property_desc(:@a).typehint, "a")
56
+
57
+ assert(desc.has_property_desc(:@b))
58
+ assert(desc.get_property_desc(:@b).array_acceptable )
59
+ assert(desc.has_typehint_property_desc(:@b))
60
+ assert(desc.get_typehint_property_desc(:@b).array_acceptable )
61
+ assert_equal(desc.get_typehint_property_desc(:@b).typehint, :b)
62
+ end
63
+
64
+ def test_has_property_array
65
+ desc = BeanDescFactory.get_bean_desc(D.new)
66
+ assert_equal(desc.get_typehint_property_desc(:@a).typehint, "a")
67
+ assert_equal(desc.get_typehint_property_desc(:@a).array_acceptable, false)
68
+ assert_equal(desc.get_typehint_property_desc(:@a2).typehint, "a2")
69
+ assert_equal(desc.get_typehint_property_desc(:@a2).array_acceptable, true)
70
+
71
+ assert_equal(desc.get_typehint_property_desc(:@b).typehint, :b)
72
+ assert_equal(desc.get_typehint_property_desc(:@b).array_acceptable, false)
73
+ assert_equal(desc.get_typehint_property_desc(:@b2).typehint, "b2")
74
+ assert_equal(desc.get_typehint_property_desc(:@b2).array_acceptable, true)
75
+ end
76
+
77
+ def test_has_property_hash
78
+ desc = BeanDescFactory.get_bean_desc(E.new)
79
+ assert_equal(desc.get_typehint_property_desc(:@a).typehint, "a")
80
+ assert_equal(desc.get_typehint_property_desc(:@a).array_acceptable, false)
81
+ assert_equal(desc.get_typehint_property_desc(:@a2).typehint, "a2")
82
+ assert_equal(desc.get_typehint_property_desc(:@a2).array_acceptable, true)
83
+
84
+ assert_equal(desc.get_typehint_property_desc(:@b).typehint, :b)
85
+ assert_equal(desc.get_typehint_property_desc(:@b).array_acceptable, false)
86
+ assert_equal(desc.get_typehint_property_desc(:@b2).typehint, "b2")
87
+ assert_equal(desc.get_typehint_property_desc(:@b2).array_acceptable, true)
88
+ end
89
+
90
+ def test_has_property_error
91
+ begin
92
+ desc = BeanDescFactory.get_bean_desc(F.new)
93
+ assert(false)
94
+ rescue ArgumentError => e
95
+ assert_equal(%Q[invalid value ["a", "b", "c"] for :DI. property [@a] of class [Seasar::Beans::TC_BeanDesc::F].], e.message)
96
+ end
97
+ end
98
+
99
+ def test_s2di
100
+ desc = BeanDescFactory.get_bean_desc(G.new)
101
+ assert(desc.has_typehint_property_desc(:@a))
102
+ assert_equal(desc.get_typehint_property_desc(:@a).typehint, :g)
103
+ assert(desc.has_typehint_property_desc(:@b))
104
+ assert_equal(desc.get_typehint_property_desc(:@b).typehint, "b")
105
+ end
106
+
107
+ def test_accessor
108
+ h = H.new
109
+ desc = BeanDescFactory.get_bean_desc(h)
110
+ assert(desc.has_typehint_property_desc(:@a))
111
+ assert_equal(desc.get_typehint_property_desc(:@a).typehint, :a)
112
+ assert(desc.has_typehint_property_desc(:@b))
113
+ assert(desc.has_typehint_property_desc(:@c))
114
+ assert(!desc.has_typehint_property_desc(:@d))
115
+ assert(!desc.has_typehint_property_desc(:@e))
116
+ assert(!desc.has_typehint_property_desc(:@f))
117
+ assert(!desc.has_typehint_property_desc(:@g))
118
+ prop = desc.get_typehint_property_desc(:@a)
119
+ prop.set_value(h, 1000)
120
+ assert_equal(1000, prop.get_value(h))
121
+ end
122
+
123
+ class A
124
+ def initialize
125
+ @name = nil
126
+ @b = B
127
+ @c = "not type hint property"
128
+ @z = :z
129
+ end
130
+ end
131
+
132
+ class B; end
133
+
134
+ class C
135
+ def initialize
136
+ @a = "di a[]"
137
+ @b = "di []"
138
+ end
139
+ end
140
+
141
+ class D
142
+ def initialize
143
+ @a = :di, "a"
144
+ @a2 = :di, "a2[]"
145
+ @b = "di", :b
146
+ @b2 = "di", "b2[]"
147
+ end
148
+ end
149
+
150
+ class E
151
+ def initialize
152
+ @a = {:di => "a"}
153
+ @a2 = {:di => "a2[]"}
154
+ @b = {"di" => :b}
155
+ @b2 = {"di" => "b2[]"}
156
+ end
157
+ end
158
+
159
+ class F
160
+ def initialize
161
+ @a = :di, %w[a b c]
162
+ end
163
+ end
164
+
165
+ class G
166
+ def initialize
167
+ @a = s2di :g
168
+ @b = s2di "b"
169
+ end
170
+ end
171
+
172
+ class H
173
+ attr_accessor :a, :b, :c
174
+ attr_reader :d, :e
175
+ attr_writer :f, :g
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,87 @@
1
+ module Seasar
2
+ module Container
3
+ module Assembler
4
+ class TC_AutoPropertyAssembler < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_assemble
12
+ container = S2Container.new
13
+ cd = Seasar::Container::ComponentDef.new(A, 'a')
14
+ container.register(cd)
15
+ cd = Seasar::Container::ComponentDef.new(B, :b)
16
+ container.register(cd)
17
+ cd = Seasar::Container::ComponentDef.new(E, 'b')
18
+ container.register(cd)
19
+ a = container.get_component('a')
20
+ assert(a.is_a?(A))
21
+ assert(a.b.instance_of?(B))
22
+ assert(a.c.instance_of?(B))
23
+ assert(a.d.is_a?(E))
24
+ assert_equal('b', a.e)
25
+ assert_equal(Array, a.f.class)
26
+ assert(a.g.instance_of?(B))
27
+ assert(a.h.is_a?(E))
28
+ end
29
+
30
+ def test_component_not_found
31
+ container = S2Container.new
32
+ cd = Seasar::Container::ComponentDef.new(C)
33
+ container.register(cd)
34
+ assert_equal(C, container.get_component(C).class)
35
+ end
36
+
37
+ def test_too_many_to_array
38
+ container = S2Container.new
39
+ cd = Seasar::Container::ComponentDef.new(D)
40
+ container.register(cd)
41
+ cd = Seasar::Container::ComponentDef.new(B, 'b')
42
+ container.register(cd)
43
+ cd = Seasar::Container::ComponentDef.new(B, 'b')
44
+ container.register(cd)
45
+ bs = container.get_component(D).bs
46
+ assert_equal(Array, bs.class)
47
+ assert_equal(2, bs.size)
48
+ end
49
+
50
+ class A
51
+ def initialize
52
+ @b = nil
53
+ @c = B
54
+ @d = 'di b'
55
+ @e = 'b'
56
+ @f = []
57
+ @g = :di, :b
58
+ @h = {:di => "b"}
59
+ end
60
+ attr_reader :b, :c, :d, :e, :f, :g, :h
61
+ end
62
+
63
+ class B
64
+ end
65
+
66
+ class C
67
+ def initialize
68
+ @b = B
69
+ end
70
+ end
71
+
72
+ class D
73
+ def initialize
74
+ @b = "di b[]"
75
+ end
76
+
77
+ def bs
78
+ return @b
79
+ end
80
+ end
81
+
82
+ class E
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,22 @@
1
+ module Seasar
2
+ module Container
3
+ module Assembler
4
+ class TC_AutoBindingDefFactory < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_get_autobinding_def
12
+ begin
13
+ AutoBindingDefFactory.get_autobinding_def(:abc)
14
+ rescue => e
15
+ assert(e.instance_of?(Seasar::Container::Exception::IllegalAutoBindingDefRuntimeException))
16
+ assert_equal("autobinding name is abc", e.message)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,59 @@
1
+ module Seasar
2
+ module Container
3
+ module Assembler
4
+ class TC_ManualPropertyAssembler < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_inject_val
12
+ container = S2Container.new
13
+ cd = Seasar::Container::ComponentDef.new(A, 'a')
14
+ cd.add_property_def(Seasar::Container::PropertyDef.new('val', 100))
15
+ container.register(cd)
16
+ a = container.get_component('a')
17
+ assert_equal(A, a.class)
18
+ assert_equal(100, a.val)
19
+ end
20
+
21
+ def test_inject_component
22
+ container = S2Container.new
23
+ cd = Seasar::Container::ComponentDef.new(B, 'b')
24
+ container.register(cd)
25
+
26
+ cd = Seasar::Container::ComponentDef.new(C, 'c')
27
+ cd.add_property_def(Seasar::Container::PropertyDef.new('val', 100))
28
+ property_def = Seasar::Container::PropertyDef.new(:@b)
29
+ property_def.child_component_def = container.get_component_def('b')
30
+ cd.add_property_def(property_def)
31
+ container.register(cd)
32
+
33
+ c = container.get_component('c')
34
+ assert_equal(C, c.class)
35
+ assert_equal(100, c.val)
36
+ assert(c.b.is_a?(B))
37
+ end
38
+
39
+ class A
40
+ def initialize
41
+ @val = nil
42
+ end
43
+ attr_reader :val
44
+ end
45
+
46
+ class B
47
+ end
48
+
49
+ class C
50
+ def initialize
51
+ @val = nil
52
+ @b = nil
53
+ end
54
+ attr_reader :val, :b
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,59 @@
1
+ module Seasar
2
+ module Container
3
+ module Assembler
4
+ class TC_ManualConstructorAssembler < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_inject_val
12
+ container = S2Container.new
13
+ cd = Seasar::Container::ComponentDef.new(A, 'a')
14
+ cd.add_arg_def(Seasar::Container::ArgDef.new(100))
15
+ container.register(cd)
16
+ a = container.get_component('a')
17
+ assert_equal(A, a.class)
18
+ assert_equal(100, a.val)
19
+ end
20
+
21
+ def test_inject_component
22
+ container = S2Container.new
23
+ cd = Seasar::Container::ComponentDef.new(B, 'b')
24
+ container.register(cd)
25
+
26
+ cd = Seasar::Container::ComponentDef.new(C, 'c')
27
+ cd.add_arg_def(Seasar::Container::ArgDef.new(100))
28
+ arg_def = Seasar::Container::ArgDef.new
29
+ arg_def.child_component_def = container.get_component_def('b')
30
+ cd.add_arg_def(arg_def)
31
+ container.register(cd)
32
+
33
+ c = container.get_component('c')
34
+ assert_equal(C, c.class)
35
+ assert_equal(100, c.val)
36
+ assert_equal(B, c.b.class)
37
+ end
38
+
39
+ class A
40
+ def initialize(val)
41
+ @val = val
42
+ end
43
+ attr_reader :val
44
+ end
45
+
46
+ class B
47
+ end
48
+
49
+ class C
50
+ def initialize(val, b)
51
+ @val = val
52
+ @b = b
53
+ end
54
+ attr_reader :val, :b
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,61 @@
1
+ module Seasar
2
+ module Container
3
+ module Assembler
4
+ class TC_ProcConstructorAssembler < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_proc_component
12
+ container = S2Container.new
13
+ cd = Seasar::Container::ComponentDef.new(A, 'a') {
14
+ A.new
15
+ }
16
+ container.register(cd)
17
+ a = container.get_component('a')
18
+ assert_equal(A, a.class)
19
+ end
20
+
21
+ def test_class_error
22
+ container = S2Container.new
23
+ cd = Seasar::Container::ComponentDef.new(B, 'a') {
24
+ A.new
25
+ }
26
+ container.register(cd)
27
+ begin
28
+ a = container.get_component('a')
29
+ rescue => e
30
+ puts e.message
31
+ end
32
+ end
33
+
34
+ def test_proc_args
35
+ container = S2Container.new
36
+ cd = Seasar::Container::ComponentDef.new(C, 'c') {|val1, val2|
37
+ C.new(val1, val2)
38
+ }
39
+ cd.add_arg_def(Seasar::Container::ArgDef.new(100))
40
+ cd.add_arg_def(Seasar::Container::ArgDef.new(200))
41
+ container.register(cd)
42
+ c = container.get_component(C)
43
+ assert_equal(300, c.value)
44
+ end
45
+
46
+ class A
47
+ end
48
+
49
+ class B
50
+ end
51
+
52
+ class C
53
+ def initialize(val1, val2)
54
+ @value = val1 + val2
55
+ end
56
+ attr_accessor :value
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,24 @@
1
+ module Seasar
2
+ module Container
3
+ module Deployer
4
+ class TC_InstanceDefFactory < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_deploy
12
+ begin
13
+ InstanceDefFactory.get_instance_def(:abc)
14
+ rescue => e
15
+ assert(e.instance_of?(Seasar::Container::Exception::IllegalInstanceDefRuntimeException))
16
+ assert_equal("instanceDef name is abc", e.message)
17
+ end
18
+ end
19
+ class A
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ module Seasar
2
+ module Container
3
+ module Deployer
4
+ class TC_PrototypeComponentDeployer < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_deploy
12
+ cd = Seasar::Container::ComponentDef.new(A, "a")
13
+ deployer = PrototypeComponentDeployer.new(cd)
14
+ a = deployer.deploy
15
+ assert_equal(A, a.class)
16
+ a1 = deployer.deploy
17
+ assert(a != a1)
18
+ end
19
+
20
+ class A
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ module Seasar
2
+ module Container
3
+ module Deployer
4
+ class TC_SingletonComponentDeployer < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_deploy
12
+ cd = Seasar::Container::ComponentDef.new(A, "a")
13
+ deployer = SingletonComponentDeployer.new(cd)
14
+ a = deployer.deploy
15
+ assert_equal(A, a.class)
16
+ a1 = deployer.deploy
17
+ assert_equal(a, a1)
18
+ end
19
+ class A
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ class A
2
+ s2component :name => 'a'
3
+ end
4
+
5
+ class B; end
6
+ s2component :class => B, :name => 'b'
@@ -0,0 +1,34 @@
1
+ module Seasar
2
+ module Container
3
+ class TC_ArgDef < Test::Unit::TestCase
4
+ def setup
5
+ end
6
+
7
+ def teardown
8
+ end
9
+
10
+ def test_instantiate
11
+ cd = Seasar::Container::ComponentDef.new(A, "a")
12
+ arg_def = ArgDef.new(100)
13
+ assert_equal(100, arg_def.value)
14
+
15
+ arg_def.expression = "200"
16
+ assert_equal(200, arg_def.value)
17
+
18
+ arg_def.child_component_def = cd
19
+ assert(arg_def.value.is_a?(A))
20
+ end
21
+
22
+ class A
23
+ end
24
+
25
+ class B
26
+ def initialize
27
+ @name = "xyz"
28
+ end
29
+ attr_accessor :name
30
+ end
31
+
32
+ end
33
+ end
34
+ end