s2container 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Apache_Software_License_2.0.txt +202 -0
- data/ChangeLog +1 -0
- data/ChangeLog.ja +64 -0
- data/README +9 -0
- data/Rakefile +51 -0
- data/example/example01/example.rb +13 -0
- data/example/example01/run.rb +20 -0
- data/example/example02/example.rb +30 -0
- data/example/example02/run.rb +8 -0
- data/example/example03/example.rb +8 -0
- data/example/example03/run.rb +12 -0
- data/example/example04/example.rb +9 -0
- data/example/example04/run.rb +15 -0
- data/example/example05/example.rb +9 -0
- data/example/example05/run.rb +21 -0
- data/example/example06/example.rb +9 -0
- data/example/example06/run.rb +8 -0
- data/example/example07/example.rb +8 -0
- data/example/example07/run.rb +15 -0
- data/example/example08/example.rb +9 -0
- data/example/example08/run.rb +19 -0
- data/example/example09/example.rb +7 -0
- data/example/example09/run.rb +11 -0
- data/example/example10/example.rb +9 -0
- data/example/example10/run.rb +10 -0
- data/example/example11/example.rb +18 -0
- data/example/example11/run.rb +10 -0
- data/example/example12/example.rb +9 -0
- data/example/example12/run.rb +8 -0
- data/example/example13/example.rb +18 -0
- data/example/example13/example.sql +4 -0
- data/example/example13/run.rb +22 -0
- data/example/example13/sample.db +0 -0
- data/example/example14/example.db +0 -0
- data/example/example14/example.rb +57 -0
- data/example/example14/example.sql +50 -0
- data/example/example14/run1.rb +23 -0
- data/example/example14/run2.rb +28 -0
- data/example/example14/run3.rb +25 -0
- data/example/example14/run4.rb +23 -0
- data/example/example14/run5.rb +35 -0
- data/example/example15/example.rb +20 -0
- data/example/example15/run.rb +28 -0
- data/example/example16/example.rb +15 -0
- data/example/example16/run.rb +24 -0
- data/example/quickstart/quickstart1/quickstart.rb +10 -0
- data/example/quickstart/quickstart2/quickstart.rb +9 -0
- data/example/quickstart/quickstart3/quickstart.rb +9 -0
- data/example/quickstart/quickstart4/quickstart.rb +14 -0
- data/example/quickstart/quickstart5/quickstart.rb +21 -0
- data/example/quickstart/quickstart6/quickstart.rb +28 -0
- data/example/quickstart/quickstart7/quickstart.rb +18 -0
- data/lib/s2container.rb +25 -0
- data/lib/seasar/aop/aspect.rb +30 -0
- data/lib/seasar/aop/interceptor/trace-interceptor.rb +48 -0
- data/lib/seasar/aop/method-invocation.rb +57 -0
- data/lib/seasar/aop/pointcut.rb +53 -0
- data/lib/seasar/aop/s2aop-factory.rb +125 -0
- data/lib/seasar/aop.rb +29 -0
- data/lib/seasar/beans/abstract-property-desc.rb +59 -0
- data/lib/seasar/beans/attribute-accessor-desc.rb +60 -0
- data/lib/seasar/beans/bean-desc-factory.rb +68 -0
- data/lib/seasar/beans/bean-desc.rb +232 -0
- data/lib/seasar/beans/instance-variable-desc.rb +58 -0
- data/lib/seasar/beans.rb +29 -0
- data/lib/seasar/container/arg-def.rb +51 -0
- data/lib/seasar/container/aspect-def.rb +60 -0
- data/lib/seasar/container/aspect-info-def.rb +94 -0
- data/lib/seasar/container/assembler/abstract-assembler.rb +68 -0
- data/lib/seasar/container/assembler/auto-property-assembler.rb +57 -0
- data/lib/seasar/container/assembler/autobinding-auto-def.rb +55 -0
- data/lib/seasar/container/assembler/autobinding-def-factory.rb +57 -0
- data/lib/seasar/container/assembler/autobinding-none-def.rb +53 -0
- data/lib/seasar/container/assembler/manual-constructor-assembler.rb +67 -0
- data/lib/seasar/container/assembler/manual-property-assembler.rb +68 -0
- data/lib/seasar/container/autobinding-def.rb +36 -0
- data/lib/seasar/container/component-def.rb +229 -0
- data/lib/seasar/container/component-info-def.rb +117 -0
- data/lib/seasar/container/deployer/abstract-component-deployer.rb +47 -0
- data/lib/seasar/container/deployer/instance-def-factory.rb +56 -0
- data/lib/seasar/container/deployer/instance-outer-def.rb +44 -0
- data/lib/seasar/container/deployer/instance-prototype-def.rb +44 -0
- data/lib/seasar/container/deployer/instance-singleton-def.rb +42 -0
- data/lib/seasar/container/deployer/outer-component-deployer.rb +47 -0
- data/lib/seasar/container/deployer/prototype-component-deployer.rb +51 -0
- data/lib/seasar/container/deployer/singleton-component-deployer.rb +54 -0
- data/lib/seasar/container/exception/component-notfound-runtime-exception.rb +44 -0
- data/lib/seasar/container/exception/cyclic-reference-runtime-exception.rb +43 -0
- data/lib/seasar/container/exception/illegal-autobinding-def-runtime-exception.rb +43 -0
- data/lib/seasar/container/exception/illegal-instance-def-runtime-exception.rb +44 -0
- data/lib/seasar/container/exception/toomany-registration-runtime-exception.rb +46 -0
- data/lib/seasar/container/instance-def.rb +37 -0
- data/lib/seasar/container/outer-component-def.rb +34 -0
- data/lib/seasar/container/property-def.rb +43 -0
- data/lib/seasar/container/s2application-context.rb +447 -0
- data/lib/seasar/container/s2container-component-def.rb +41 -0
- data/lib/seasar/container/s2container.rb +308 -0
- data/lib/seasar/container/simple-component-def.rb +45 -0
- data/lib/seasar/container/toomany-registration-component-def.rb +69 -0
- data/lib/seasar/container.rb +143 -0
- data/lib/seasar/dbi/dbi-interceptor.rb +97 -0
- data/lib/seasar/dbi/paginate.rb +215 -0
- data/lib/seasar/dbi.rb +26 -0
- data/lib/seasar/exception/notyet-implemented-exception.rb +25 -0
- data/lib/seasar/exception/property-notfound-runtime-exception.rb +48 -0
- data/lib/seasar/exception/s2runtime-exception.rb +35 -0
- data/lib/seasar/exception/unsupported-operation-exception.rb +25 -0
- data/lib/seasar/exception.rb +27 -0
- data/lib/seasar/log/s2logger.rb +75 -0
- data/lib/seasar/log.rb +38 -0
- data/lib/seasar/util/class-util.rb +116 -0
- data/lib/seasar/util.rb +24 -0
- data/setup.rb +1585 -0
- data/test/seasar/aop/test_pointcut.rb +25 -0
- data/test/seasar/aop/test_s2aop_factory.rb +90 -0
- data/test/seasar/beans/test_bean-desc.rb +179 -0
- data/test/seasar/container/assembler/test_auto_property_assembler.rb +87 -0
- data/test/seasar/container/assembler/test_autobinding_def_factory.rb +22 -0
- data/test/seasar/container/assembler/test_manual_property_assembler.rb +59 -0
- data/test/seasar/container/assembler/test_manula_constructor_assembler.rb +59 -0
- data/test/seasar/container/assembler/test_proc_constructor_assembler.rb +61 -0
- data/test/seasar/container/deployer/test_instance_def_factory.rb +24 -0
- data/test/seasar/container/deployer/test_prototype-deployer.rb +25 -0
- data/test/seasar/container/deployer/test_singleton-component-deployer.rb +24 -0
- data/test/seasar/container/s2app_load_sample.rb +6 -0
- data/test/seasar/container/test_arg-def.rb +34 -0
- data/test/seasar/container/test_aspect-info-def.rb +85 -0
- data/test/seasar/container/test_component-def.rb +91 -0
- data/test/seasar/container/test_component-info-def.rb +88 -0
- data/test/seasar/container/test_s2application-context.rb +290 -0
- data/test/seasar/container/test_s2container.rb +268 -0
- data/test/seasar/dbi/test_paginate.rb +265 -0
- data/test/seasar/test_log.rb +20 -0
- data/test/seasar/test_util.rb +46 -0
- data/test/test-suite.rb +7 -0
- metadata +211 -0
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'seasar/container/s2application-context'
|
2
|
+
|
3
|
+
module Seasar
|
4
|
+
module Container
|
5
|
+
class TC_AspectInfoDef < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_match_regexp
|
13
|
+
cd = ComponentDef.new(A, 'abc')
|
14
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => /ab/, :pointcut => nil)
|
15
|
+
assert(info.applicable?(cd))
|
16
|
+
|
17
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => /A/, :pointcut => nil)
|
18
|
+
assert(info.applicable?(cd))
|
19
|
+
|
20
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => /cde/, :pointcut => nil)
|
21
|
+
assert(!info.applicable?(cd))
|
22
|
+
|
23
|
+
cd = ComponentDef.new(A)
|
24
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => /ab/, :pointcut => nil)
|
25
|
+
assert(!info.applicable?(cd))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_match_class
|
29
|
+
cd = ComponentDef.new(A)
|
30
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => A, :pointcut => nil)
|
31
|
+
assert(info.applicable?(cd))
|
32
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => B, :pointcut => nil)
|
33
|
+
assert(!info.applicable?(cd))
|
34
|
+
|
35
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => A, :pointcut => nil)
|
36
|
+
cd = ComponentDef.new(B)
|
37
|
+
assert(!info.applicable?(cd))
|
38
|
+
cd = ComponentDef.new(A)
|
39
|
+
assert(info.applicable?(cd))
|
40
|
+
cd = ComponentDef.new(C)
|
41
|
+
assert(!info.applicable?(cd))
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_match_module
|
45
|
+
cd = ComponentDef.new(D::A)
|
46
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => D, :pointcut => nil)
|
47
|
+
assert(info.applicable?(cd))
|
48
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => A, :pointcut => nil)
|
49
|
+
assert(!info.applicable?(cd))
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_match_string
|
53
|
+
cd = ComponentDef.new(A, 'abc')
|
54
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => 'abc', :pointcut => nil)
|
55
|
+
assert(info.applicable?(cd))
|
56
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => 'c', :pointcut => nil)
|
57
|
+
assert(!info.applicable?(cd))
|
58
|
+
|
59
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => A, :pointcut => nil)
|
60
|
+
assert(info.applicable?(cd))
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_match_symbol
|
64
|
+
cd = ComponentDef.new(A, :abc)
|
65
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => :abc, :pointcut => nil)
|
66
|
+
assert(info.applicable?(cd))
|
67
|
+
info = AspectInfoDef.new(:interceptor => 'trace', :pattern => :c, :pointcut => nil)
|
68
|
+
assert(!info.applicable?(cd))
|
69
|
+
end
|
70
|
+
|
71
|
+
class A
|
72
|
+
end
|
73
|
+
|
74
|
+
class B < A
|
75
|
+
end
|
76
|
+
|
77
|
+
class C
|
78
|
+
end
|
79
|
+
|
80
|
+
module D
|
81
|
+
class A; end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'seasar/container/component-def'
|
2
|
+
|
3
|
+
module Seasar
|
4
|
+
module Container
|
5
|
+
class TC_ComponentDef < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_instantiate
|
13
|
+
cd = Seasar::Container::ComponentDef.new(A, "a")
|
14
|
+
assert_equal(A, cd.component_class)
|
15
|
+
assert_equal("a", cd.component_name)
|
16
|
+
|
17
|
+
cd = Seasar::Container::ComponentDef.new(A)
|
18
|
+
assert_equal(A, cd.component_class)
|
19
|
+
assert_equal(:a, cd.component_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_get_component_deployer
|
23
|
+
cd = Seasar::Container::ComponentDef.new(A, "a")
|
24
|
+
assert_equal(Seasar::Container::Deployer::SingletonComponentDeployer,
|
25
|
+
cd.get_component_deployer.class)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_get_concreate_class
|
29
|
+
cd = Seasar::Container::ComponentDef.new(A, "a")
|
30
|
+
assert_equal(A, cd.get_concreate_class)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_get_component_deployer
|
34
|
+
begin
|
35
|
+
cd = Seasar::Container::ComponentDef.new(A, :a)
|
36
|
+
rescue => e
|
37
|
+
assert(e.instance_of?(TypeError))
|
38
|
+
assert_equal("component name must be String or nil.", e.message)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_onetime_proc
|
43
|
+
cd = Seasar::Container::ComponentDef.new(B, "b")
|
44
|
+
cd.onetime_proc = lambda {
|
45
|
+
b = B.new
|
46
|
+
b.name = "abc"
|
47
|
+
b
|
48
|
+
}
|
49
|
+
assert(cd.component.instance_of?(B))
|
50
|
+
assert_equal("abc", cd.component.name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_proc_block
|
54
|
+
cd = Seasar::Container::ComponentDef.new(Proc, "b") {
|
55
|
+
next A.new
|
56
|
+
}
|
57
|
+
component = cd.get_component
|
58
|
+
assert(component.instance_of?(Proc))
|
59
|
+
assert(component.call.instance_of?(A))
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_constructor_block
|
63
|
+
cd = Seasar::Container::ComponentDef.new(B, "b") {
|
64
|
+
next B.new
|
65
|
+
}
|
66
|
+
component = cd.get_component
|
67
|
+
assert(component.instance_of?(B))
|
68
|
+
|
69
|
+
cd = Seasar::Container::ComponentDef.new(B, "b") {
|
70
|
+
next A.new
|
71
|
+
}
|
72
|
+
begin
|
73
|
+
component = cd.get_component
|
74
|
+
rescue TypeError => e
|
75
|
+
assert(e.message.match(/^invalid instance found./))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class A
|
80
|
+
end
|
81
|
+
|
82
|
+
class B
|
83
|
+
def initialize
|
84
|
+
@name = "xyz"
|
85
|
+
end
|
86
|
+
attr_accessor :name
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'seasar/container/s2application-context'
|
2
|
+
|
3
|
+
module Seasar
|
4
|
+
module Container
|
5
|
+
class TC_ComponentInfoDef < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_accessor
|
13
|
+
info = ComponentInfoDef.new(:class => A, :name => "abc")
|
14
|
+
assert_equal("abc", info["@component_name"])
|
15
|
+
assert_equal("abc", info[:@component_name])
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_match_regexp
|
19
|
+
info = ComponentInfoDef.new(:class => A, :name => "abc")
|
20
|
+
assert(info.match(/ab/))
|
21
|
+
assert(!info.match(/bcd/))
|
22
|
+
assert(info.match(/A/))
|
23
|
+
assert(info.match(/Seasar/))
|
24
|
+
assert(!info.match(/seasar/))
|
25
|
+
|
26
|
+
info = ComponentInfoDef.new(:class => A)
|
27
|
+
assert(!info.match(/abc/))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_match_class
|
31
|
+
info = ComponentInfoDef.new(:class => A, :name => "abc")
|
32
|
+
assert(info.match(A))
|
33
|
+
assert(!info.match(B))
|
34
|
+
assert(!info.match(C))
|
35
|
+
|
36
|
+
info = ComponentInfoDef.new(:class => B, :name => "abc")
|
37
|
+
assert(!info.match(A))
|
38
|
+
assert(info.match(B))
|
39
|
+
assert(!info.match(C))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_match_module
|
43
|
+
info = ComponentInfoDef.new(:class => D::A, :name => "abc")
|
44
|
+
assert(info.match(D))
|
45
|
+
assert(!info.match(A))
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_match_string
|
49
|
+
info = ComponentInfoDef.new(:class => A, :name => "abc")
|
50
|
+
assert(info.match("abc"))
|
51
|
+
assert(!info.match("bcd"))
|
52
|
+
|
53
|
+
info = ComponentInfoDef.new(:class => A)
|
54
|
+
assert(!info.match("abc"))
|
55
|
+
assert(info.match(A))
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_match_symbol
|
59
|
+
info = ComponentInfoDef.new(:class => A, :name => :abc)
|
60
|
+
assert(info.match(:abc))
|
61
|
+
assert(!info.match(:bcd))
|
62
|
+
|
63
|
+
info = ComponentInfoDef.new(:class => A)
|
64
|
+
assert(!info.match(:abc))
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_auto_namespace
|
68
|
+
ComponentInfoDef.auto_namespace = true
|
69
|
+
info = ComponentInfoDef.new(:class => A)
|
70
|
+
assert('Seasar::Container::TC_ComponentInfoDef', info.namespace)
|
71
|
+
ComponentInfoDef.auto_namespace = false
|
72
|
+
end
|
73
|
+
|
74
|
+
class A
|
75
|
+
end
|
76
|
+
|
77
|
+
class B < A
|
78
|
+
end
|
79
|
+
|
80
|
+
class C
|
81
|
+
end
|
82
|
+
|
83
|
+
module D
|
84
|
+
class A; end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,290 @@
|
|
1
|
+
require 'seasar/container/s2application-context'
|
2
|
+
|
3
|
+
module Seasar
|
4
|
+
module Container
|
5
|
+
class TC_S2ApplicationContext < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_get
|
13
|
+
s2app.init
|
14
|
+
assert_equal(A, s2app.get(A).class)
|
15
|
+
assert_equal(A, s2app.get('a').class)
|
16
|
+
assert_equal(A, s2app.get('foo.a2', 'foo').class)
|
17
|
+
assert_equal(A, s2app.get('foo.bar.a3', 'foo').class)
|
18
|
+
assert_equal(A, s2app.get('a3', 'foo.bar').class)
|
19
|
+
assert_equal(A, s2app.get('a4', 'foo.bar.huga').class)
|
20
|
+
assert_equal(s2app.get('foo.bar.huga'), s2app.get('foo.bar.huga'))
|
21
|
+
|
22
|
+
s2app.init
|
23
|
+
assert_equal(A, s2app[A].class)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_get_by_symbol
|
27
|
+
s2app.init
|
28
|
+
assert_equal(J, s2app[J].class)
|
29
|
+
assert_equal(J, s2app[:j].class)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_di
|
33
|
+
s2app.init
|
34
|
+
s2app.register_aspect(:pattern => /b/, :interceptor => Seasar::Aop::Interceptor::TraceInterceptor.new)
|
35
|
+
s2app.get(C).b.foo
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_aspect
|
39
|
+
s2app.register_aspect(:pattern => /b/, :interceptor => Seasar::Aop::Interceptor::TraceInterceptor.new)
|
40
|
+
s2app.get('b').foo
|
41
|
+
|
42
|
+
s2app.init
|
43
|
+
s2app.aspect(:pattern => /b/) {|invocation|
|
44
|
+
puts "before : foo"
|
45
|
+
invocation.proceed
|
46
|
+
puts "after : foo"
|
47
|
+
}
|
48
|
+
s2app.get('b').foo
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_singleton
|
52
|
+
s2app.init
|
53
|
+
assert(s2app.get(C) == s2app.get(C))
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_prototype
|
57
|
+
s2app.init
|
58
|
+
assert(s2app.get(D) != s2app.get(D))
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_di_none
|
62
|
+
s2app.init
|
63
|
+
assert_equal(s2app.get(E).b, B)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_zzznamespaced_component
|
67
|
+
s2app.init
|
68
|
+
assert_equal(F, s2app.get(F).class)
|
69
|
+
assert_equal(F, s2app.get(F, 'namespace_f').class)
|
70
|
+
assert_equal(F, s2app.get('namespace_f.f').class)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_proc_component
|
74
|
+
s2app.init
|
75
|
+
g = s2app[G]
|
76
|
+
assert_equal(G, g.class)
|
77
|
+
assert_equal(10, g.val)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_onetime_proc
|
81
|
+
s2app.init
|
82
|
+
g = s2app.get(G) {
|
83
|
+
G.new(20)
|
84
|
+
}
|
85
|
+
assert_equal(G, g.class)
|
86
|
+
assert_equal(20, g.val)
|
87
|
+
g = s2app[G]
|
88
|
+
assert_equal(G, g.class)
|
89
|
+
assert_equal(10, g.val)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_include
|
93
|
+
s2app.init
|
94
|
+
s2app.include(H)
|
95
|
+
container = s2app.create
|
96
|
+
assert(container.has_component_def(H))
|
97
|
+
assert(!container.has_component_def(B))
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_exclude
|
101
|
+
s2app.init
|
102
|
+
s2app.include('hi')
|
103
|
+
container = s2app.create
|
104
|
+
assert(container.has_component_def(H))
|
105
|
+
assert(container.has_component_def(I))
|
106
|
+
|
107
|
+
s2app.init
|
108
|
+
s2app.exclude(I)
|
109
|
+
container = s2app.create
|
110
|
+
assert(container.has_component_def(H))
|
111
|
+
assert(!container.has_component_def(I))
|
112
|
+
|
113
|
+
s2app.init
|
114
|
+
s2app.include('hi')
|
115
|
+
s2app.exclude(I)
|
116
|
+
container = s2app.create
|
117
|
+
assert(container.has_component_def(H))
|
118
|
+
assert(!container.has_component_def(I))
|
119
|
+
assert(!container.has_component_def(B))
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_s2comp
|
123
|
+
begin
|
124
|
+
s2comp
|
125
|
+
rescue => e
|
126
|
+
assert(e.instance_of?(TypeError))
|
127
|
+
assert_equal("class not specified.", e.message)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_aspect_error
|
132
|
+
begin
|
133
|
+
s2app.aspect({})
|
134
|
+
rescue => e
|
135
|
+
assert(e.instance_of?(ArgumentError))
|
136
|
+
assert_equal("interceptor not specified.", e.message)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_select_by_include
|
141
|
+
s2app.init
|
142
|
+
s2app.include(J)
|
143
|
+
s2app.include(J)
|
144
|
+
s2app.include(J)
|
145
|
+
s2app.include(I)
|
146
|
+
s2app.include(I)
|
147
|
+
s2app.include(I)
|
148
|
+
infos = s2app.select_component_info_by_include(s2app.component_infos)
|
149
|
+
assert_equal(2, infos.size)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_selectors
|
153
|
+
s2app.init
|
154
|
+
s2app.select {|infos|
|
155
|
+
infos.select {|info| info.component_class == H}
|
156
|
+
}
|
157
|
+
s2app.select {|infos|
|
158
|
+
assert_equal(2, infos.size)
|
159
|
+
infos.select {|info| info.component_name == "h"}
|
160
|
+
}
|
161
|
+
container = s2app.create {|infos|
|
162
|
+
assert_equal(1, infos.size)
|
163
|
+
next infos
|
164
|
+
}
|
165
|
+
|
166
|
+
assert(container.has_component_def(H))
|
167
|
+
assert(!container.has_component_def(B))
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_di_accessor
|
171
|
+
s2app.init
|
172
|
+
assert(s2app.get(K).l.is_a?(L))
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_select_component_info_by_namespace
|
176
|
+
infos = []
|
177
|
+
infos << ComponentInfoDef.new(:namespace => 'a.b.c')
|
178
|
+
infos << ComponentInfoDef.new(:namespace => 'a.b.d')
|
179
|
+
infos << ComponentInfoDef.new(:namespace => 'a.e.f')
|
180
|
+
infos << ComponentInfoDef.new(:namespace => 'x.y.z')
|
181
|
+
assert(2, s2app.select_component_info_by_namespace(infos, %w[a.b]).size)
|
182
|
+
assert(1, s2app.select_component_info_by_namespace(infos, %w[a.e]).size)
|
183
|
+
assert(3, s2app.select_component_info_by_namespace(infos, %w[a]).size)
|
184
|
+
assert(3, s2app.select_component_info_by_namespace(infos, %w[a.b a.e]).size)
|
185
|
+
assert(2, s2app.select_component_info_by_namespace(infos, %w[a.e x.y]).size)
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_create_singleton
|
189
|
+
s2app.init
|
190
|
+
c1 = s2app.create_singleton(%w[a.b a.c])
|
191
|
+
c2 = s2app.create_singleton(%w[a.c a.b])
|
192
|
+
assert(c1 == c2)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_snapshot
|
196
|
+
s2app.init
|
197
|
+
assert(!s2app.snapshot?)
|
198
|
+
app = s2app.snapshot
|
199
|
+
assert(app.snapshot?)
|
200
|
+
assert_equal(s2app.component_infos, app.component_infos)
|
201
|
+
assert_equal(s2app.aspect_infos, app.aspect_infos)
|
202
|
+
assert_raise(RuntimeError) {app.register('test')}
|
203
|
+
assert_raise(RuntimeError) {app.register_aspect('test')}
|
204
|
+
end
|
205
|
+
|
206
|
+
=begin
|
207
|
+
def test_z_reload
|
208
|
+
s2app.init(:force => true)
|
209
|
+
load File.join(File.dirname(__FILE__), 's2app_load_sample.rb')
|
210
|
+
assert_equal(2, s2app.component_infos.size)
|
211
|
+
load File.join(File.dirname(__FILE__), 's2app_load_sample.rb')
|
212
|
+
assert_equal(2, s2app.component_infos.size)
|
213
|
+
exit
|
214
|
+
end
|
215
|
+
=end
|
216
|
+
class A
|
217
|
+
s2component :name => 'a'
|
218
|
+
s2component :name => 'a2', :namespace => 'foo'
|
219
|
+
s2component :name => 'a3', :namespace => 'foo.bar'
|
220
|
+
s2component :name => 'a4', :namespace => 'foo.bar.huga'
|
221
|
+
def foo
|
222
|
+
puts "foo called."
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
class B
|
227
|
+
s2comp :name => 'b'
|
228
|
+
def foo
|
229
|
+
puts "foo called."
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
class C
|
234
|
+
s2component
|
235
|
+
def initialize
|
236
|
+
@b = B
|
237
|
+
end
|
238
|
+
attr_accessor :b
|
239
|
+
end
|
240
|
+
|
241
|
+
class D
|
242
|
+
s2component :instance => :prototype
|
243
|
+
end
|
244
|
+
|
245
|
+
class E
|
246
|
+
s2component :autobinding => :none
|
247
|
+
def initialize
|
248
|
+
@b = B
|
249
|
+
end
|
250
|
+
attr_accessor :b
|
251
|
+
end
|
252
|
+
|
253
|
+
class F
|
254
|
+
s2component :name => 'f', :namespace => 'namespace_f'
|
255
|
+
end
|
256
|
+
|
257
|
+
class G
|
258
|
+
s2component(:instance => :prototype) {
|
259
|
+
G.new(10)
|
260
|
+
}
|
261
|
+
def initialize(val)
|
262
|
+
@val = val
|
263
|
+
end
|
264
|
+
attr_accessor :val
|
265
|
+
end
|
266
|
+
|
267
|
+
class H
|
268
|
+
s2component :name => 'h'
|
269
|
+
s2component :name => 'hi'
|
270
|
+
end
|
271
|
+
|
272
|
+
class I
|
273
|
+
s2component :name => 'hi'
|
274
|
+
end
|
275
|
+
|
276
|
+
class J
|
277
|
+
s2component :name => :j
|
278
|
+
end
|
279
|
+
|
280
|
+
class K
|
281
|
+
s2component
|
282
|
+
attr_accessor :l
|
283
|
+
end
|
284
|
+
|
285
|
+
class L
|
286
|
+
s2component :name => :l
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|