copland 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/README +88 -0
- data/doc/manual-html/chapter-1.html +454 -0
- data/doc/manual-html/chapter-10.html +399 -0
- data/doc/manual-html/chapter-11.html +600 -0
- data/doc/manual-html/chapter-12.html +406 -0
- data/doc/manual-html/chapter-2.html +382 -0
- data/doc/manual-html/chapter-3.html +424 -0
- data/doc/manual-html/chapter-4.html +432 -0
- data/doc/manual-html/chapter-5.html +381 -0
- data/doc/manual-html/chapter-6.html +364 -0
- data/doc/manual-html/chapter-7.html +434 -0
- data/doc/manual-html/chapter-8.html +373 -0
- data/doc/manual-html/chapter-9.html +324 -0
- data/doc/manual-html/copland.png +0 -0
- data/doc/manual-html/index.html +331 -0
- data/doc/manual-html/manual.css +179 -0
- data/doc/manual-html/tutorial-1.html +407 -0
- data/doc/manual-html/tutorial-2.html +451 -0
- data/doc/manual-html/tutorial-3.html +484 -0
- data/doc/manual-html/tutorial-4.html +446 -0
- data/doc/manual-html/tutorial-5.html +520 -0
- data/doc/manual/chapter.erb +18 -0
- data/doc/manual/example.erb +18 -0
- data/doc/manual/img/copland.png +0 -0
- data/doc/manual/index.erb +30 -0
- data/doc/manual/manual.css +179 -0
- data/doc/manual/manual.rb +239 -0
- data/doc/manual/manual.yml +2643 -0
- data/doc/manual/page.erb +102 -0
- data/doc/manual/tutorial.erb +30 -0
- data/doc/packages/copland.html +764 -0
- data/doc/packages/copland.lib.html +439 -0
- data/doc/packages/copland.remote.html +2096 -0
- data/doc/packages/copland.webrick.html +925 -0
- data/doc/packages/index.html +49 -0
- data/doc/packages/packrat.css +125 -0
- data/examples/calc/calc.rb +47 -0
- data/examples/calc/package.yml +35 -0
- data/examples/calc/services.rb +74 -0
- data/examples/solitaire-cipher/README +11 -0
- data/examples/solitaire-cipher/Rakefile +57 -0
- data/examples/solitaire-cipher/bin/main.rb +14 -0
- data/examples/solitaire-cipher/lib/cipher.rb +230 -0
- data/examples/solitaire-cipher/lib/cli.rb +24 -0
- data/examples/solitaire-cipher/lib/package.yml +106 -0
- data/examples/solitaire-cipher/test/tc_deck.rb +30 -0
- data/examples/solitaire-cipher/test/tc_key-stream.rb +19 -0
- data/examples/solitaire-cipher/test/tc_keying-algorithms.rb +31 -0
- data/examples/solitaire-cipher/test/tc_solitaire-cipher.rb +66 -0
- data/examples/solitaire-cipher/test/tc_unkeyed-algorithm.rb +17 -0
- data/examples/solitaire-cipher/test/tests.rb +2 -0
- data/lib/copland.rb +56 -0
- data/lib/copland/class-factory.rb +95 -0
- data/lib/copland/configuration-point.rb +38 -0
- data/lib/copland/configuration-point/common.rb +203 -0
- data/lib/copland/configuration-point/errors.rb +44 -0
- data/lib/copland/configuration-point/list.rb +59 -0
- data/lib/copland/configuration-point/map.rb +59 -0
- data/lib/copland/configuration/errors.rb +43 -0
- data/lib/copland/configuration/loader.rb +113 -0
- data/lib/copland/configuration/yaml/configuration-point.rb +87 -0
- data/lib/copland/configuration/yaml/implementor.rb +134 -0
- data/lib/copland/configuration/yaml/interceptor.rb +63 -0
- data/lib/copland/configuration/yaml/listener.rb +56 -0
- data/lib/copland/configuration/yaml/loader.rb +122 -0
- data/lib/copland/configuration/yaml/package.rb +125 -0
- data/lib/copland/configuration/yaml/parser.rb +71 -0
- data/lib/copland/configuration/yaml/schema.rb +165 -0
- data/lib/copland/configuration/yaml/service-point.rb +116 -0
- data/lib/copland/configuration/yaml/utils.rb +82 -0
- data/lib/copland/default-schema-processor.rb +144 -0
- data/lib/copland/errors.rb +82 -0
- data/lib/copland/event-producer.rb +95 -0
- data/lib/copland/impl/builder-factory.rb +112 -0
- data/lib/copland/impl/copland-config.yml +1 -0
- data/lib/copland/impl/include-exclude.rb +140 -0
- data/lib/copland/impl/logging-interceptor.rb +106 -0
- data/lib/copland/impl/package.yml +217 -0
- data/lib/copland/impl/startup.rb +116 -0
- data/lib/copland/impl/symbol-source-manager.rb +131 -0
- data/lib/copland/impl/symbol-source.rb +63 -0
- data/lib/copland/instantiator.rb +38 -0
- data/lib/copland/instantiator/abstract.rb +91 -0
- data/lib/copland/instantiator/complex.rb +96 -0
- data/lib/copland/instantiator/identity.rb +58 -0
- data/lib/copland/instantiator/simple.rb +68 -0
- data/lib/copland/interceptor-chain.rb +166 -0
- data/lib/copland/interceptor.rb +139 -0
- data/lib/copland/log-factory.rb +206 -0
- data/lib/copland/models.rb +39 -0
- data/lib/copland/models/abstract.rb +78 -0
- data/lib/copland/models/prototype-deferred.rb +58 -0
- data/lib/copland/models/prototype.rb +58 -0
- data/lib/copland/models/proxy.rb +100 -0
- data/lib/copland/models/singleton-deferred.rb +59 -0
- data/lib/copland/models/singleton.rb +77 -0
- data/lib/copland/models/threaded.rb +65 -0
- data/lib/copland/ordering.rb +123 -0
- data/lib/copland/package.rb +246 -0
- data/lib/copland/registry.rb +368 -0
- data/lib/copland/schema.rb +206 -0
- data/lib/copland/service-point.rb +282 -0
- data/lib/copland/utils.rb +221 -0
- data/lib/copland/version.rb +47 -0
- data/test/conf-test/list-bad-key.yml +30 -0
- data/test/conf-test/list-bad-missing.yml +28 -0
- data/test/conf-test/list-bad-type.yml +28 -0
- data/test/conf-test/list-good.yml +29 -0
- data/test/conf-test/map-bad-key.yml +25 -0
- data/test/conf-test/map-bad-missing.yml +24 -0
- data/test/conf-test/map-bad-type.yml +23 -0
- data/test/conf-test/map-good.yml +25 -0
- data/test/configuration-point/package.yml +52 -0
- data/test/configuration/yaml/config/copland-config.yml +2 -0
- data/test/configuration/yaml/config/module.yml +2 -0
- data/test/configuration/yaml/config/subdir/copland-config.yml +2 -0
- data/test/configuration/yaml/config/subdir/package.yml +4 -0
- data/test/configuration/yaml/defaults/package.yml +5 -0
- data/test/configuration/yaml/defaults/subdir/package.yml +4 -0
- data/test/configuration/yaml/tc_config-loader.rb +86 -0
- data/test/configuration/yaml/tc_configuration-point-processor.rb +134 -0
- data/test/configuration/yaml/tc_implementor-processor.rb +104 -0
- data/test/configuration/yaml/tc_interceptor-processor.rb +85 -0
- data/test/configuration/yaml/tc_listener-processor.rb +69 -0
- data/test/configuration/yaml/tc_loader.rb +74 -0
- data/test/configuration/yaml/tc_package-processor.rb +120 -0
- data/test/configuration/yaml/tc_parser.rb +94 -0
- data/test/configuration/yaml/tc_schema-parser.rb +160 -0
- data/test/configuration/yaml/tc_service-point-processor.rb +104 -0
- data/test/configuration/yaml/tc_type-validator.rb +90 -0
- data/test/custom-logger.yml +3 -0
- data/test/impl/logging/package.yml +44 -0
- data/test/impl/logging/services.rb +84 -0
- data/test/impl/startup/package.yml +46 -0
- data/test/impl/startup/services.rb +47 -0
- data/test/impl/symbols/package.yml +24 -0
- data/test/impl/symbols/services.rb +38 -0
- data/test/impl/tc_builder-factory.rb +173 -0
- data/test/impl/tc_logging-interceptor.rb +148 -0
- data/test/impl/tc_startup.rb +59 -0
- data/test/impl/tc_symbol-sources.rb +61 -0
- data/test/logger.yml +6 -0
- data/test/mock.rb +201 -0
- data/test/schema/bad-package.yml +65 -0
- data/test/schema/package.yml +102 -0
- data/test/schema/services.rb +5 -0
- data/test/services/package.yml +79 -0
- data/test/services/simple.rb +87 -0
- data/test/tc_class-factory.rb +93 -0
- data/test/tc_complex-instantiator.rb +107 -0
- data/test/tc_configuration-point-contrib.rb +74 -0
- data/test/tc_configuration-point-schema.rb +122 -0
- data/test/tc_configuration-point.rb +91 -0
- data/test/tc_default-schema-processor.rb +297 -0
- data/test/tc_identity-instantiator.rb +61 -0
- data/test/tc_interceptors.rb +84 -0
- data/test/tc_logger.rb +131 -0
- data/test/tc_models.rb +176 -0
- data/test/tc_package.rb +165 -0
- data/test/tc_proxy.rb +65 -0
- data/test/tc_registry.rb +141 -0
- data/test/tc_schema.rb +78 -0
- data/test/tc_service-point.rb +178 -0
- data/test/tc_service.rb +70 -0
- data/test/tc_simple-instantiator.rb +61 -0
- data/test/tests.rb +93 -0
- data/tutorial/01/main.rb +7 -0
- data/tutorial/01/package.yml +8 -0
- data/tutorial/01/tutorial.rb +7 -0
- data/tutorial/02/main.rb +10 -0
- data/tutorial/02/package.yml +27 -0
- data/tutorial/02/tutorial.rb +46 -0
- data/tutorial/03/main.rb +24 -0
- data/tutorial/03/package.yml +29 -0
- data/tutorial/03/tutorial.rb +48 -0
- data/tutorial/04/main.rb +24 -0
- data/tutorial/04/package.yml +35 -0
- data/tutorial/04/tutorial.rb +48 -0
- data/tutorial/05/functions/package.yml +16 -0
- data/tutorial/05/functions/services.rb +15 -0
- data/tutorial/05/main.rb +10 -0
- data/tutorial/05/package.yml +35 -0
- data/tutorial/05/tutorial.rb +53 -0
- metadata +260 -0
data/test/tc_proxy.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer.
|
11
|
+
#
|
12
|
+
# * Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# * The names of its contributors may not be used to endorse or promote
|
17
|
+
# products derived from this software without specific prior written
|
18
|
+
# permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
24
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
# =============================================================================
|
32
|
+
#++
|
33
|
+
|
34
|
+
$:.unshift "../lib"
|
35
|
+
|
36
|
+
require 'test/unit'
|
37
|
+
require 'copland/models/proxy'
|
38
|
+
require 'mock'
|
39
|
+
|
40
|
+
class TC_Proxy < Test::Unit::TestCase
|
41
|
+
|
42
|
+
def test_deferred
|
43
|
+
message = ""
|
44
|
+
point = MockServicePoint.new( message )
|
45
|
+
proxy = Copland::ServiceModel::Proxy.new( point )
|
46
|
+
|
47
|
+
assert_equal( "", message )
|
48
|
+
assert proxy.noop
|
49
|
+
assert_equal( "initialized!", message )
|
50
|
+
|
51
|
+
assert proxy.is_a?( MockService )
|
52
|
+
assert_respond_to proxy, :noop
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_instantiate_failed
|
57
|
+
point = MockServicePoint.new( 0 )
|
58
|
+
proxy = Copland::ServiceModel::Proxy.new( point )
|
59
|
+
|
60
|
+
assert_raise( NoMethodError ) { proxy.noop }
|
61
|
+
|
62
|
+
assert_nil proxy.noop
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/test/tc_registry.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer.
|
11
|
+
#
|
12
|
+
# * Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# * The names of its contributors may not be used to endorse or promote
|
17
|
+
# products derived from this software without specific prior written
|
18
|
+
# permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
24
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
# =============================================================================
|
32
|
+
#++
|
33
|
+
|
34
|
+
$:.unshift "../lib"
|
35
|
+
|
36
|
+
require 'test/unit'
|
37
|
+
require 'copland/errors'
|
38
|
+
require 'copland/registry'
|
39
|
+
|
40
|
+
class TC_Registry < Test::Unit::TestCase
|
41
|
+
|
42
|
+
def test_registry_new
|
43
|
+
registry = Copland::Registry.new
|
44
|
+
assert_nil registry.package( "copland" )
|
45
|
+
assert !registry.fixated?
|
46
|
+
registry.fixate!
|
47
|
+
assert registry.fixated?
|
48
|
+
assert_not_nil registry.package( "copland" )
|
49
|
+
assert_equal registry, registry.service( "copland.Registry" )
|
50
|
+
registry.shutdown
|
51
|
+
|
52
|
+
assert_raise( Copland::DisallowedOperationException ) do
|
53
|
+
registry.package( "copland" )
|
54
|
+
end
|
55
|
+
assert_raise( Copland::DisallowedOperationException ) do
|
56
|
+
registry.service( "copland.Registry" )
|
57
|
+
end
|
58
|
+
assert_raise( Copland::DisallowedOperationException ) do
|
59
|
+
registry.configuration_point( "copland.Registry" )
|
60
|
+
end
|
61
|
+
assert_raise( Copland::DisallowedOperationException ) do
|
62
|
+
registry.add_package( "blah" )
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_registry_build
|
67
|
+
registry = Copland::Registry.build File.join( File.dirname( __FILE__ ),
|
68
|
+
"services" )
|
69
|
+
|
70
|
+
assert registry.fixated?
|
71
|
+
assert_not_nil registry.package( "copland" )
|
72
|
+
assert_not_nil registry.package( "service-test" )
|
73
|
+
|
74
|
+
assert !registry.shutdown?
|
75
|
+
assert !registry.logs.closed?
|
76
|
+
registry.shutdown
|
77
|
+
assert registry.shutdown?
|
78
|
+
assert registry.logs.closed?
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_registry_build_bogus_dir
|
82
|
+
registry = nil
|
83
|
+
assert_nothing_raised do
|
84
|
+
registry = Copland::Registry.build "no-such-dir"
|
85
|
+
end
|
86
|
+
assert_not_nil registry.package( "copland" )
|
87
|
+
assert_equal 1, registry.package_count
|
88
|
+
registry.shutdown
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_registry_new_log_opts
|
92
|
+
registry = Copland::Registry.new :log_device => $stdout,
|
93
|
+
:log_default_format => "%Y",
|
94
|
+
:log_default_level => Logger::FATAL
|
95
|
+
|
96
|
+
assert_equal $stdout, registry.logs.device
|
97
|
+
assert_equal "%Y", registry.logs.default_format
|
98
|
+
assert_equal Logger::FATAL, registry.logs.default_level
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_registry_build_log_opts
|
102
|
+
registry = Copland::Registry.build File.join( File.dirname( __FILE__ ),
|
103
|
+
"services" ),
|
104
|
+
:log_device => $stdout,
|
105
|
+
:log_default_format => "%Y",
|
106
|
+
:log_default_level => Logger::FATAL
|
107
|
+
|
108
|
+
assert_equal $stdout, registry.logs.device
|
109
|
+
assert_equal "%Y", registry.logs.default_format
|
110
|
+
assert_equal Logger::FATAL, registry.logs.default_level
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_registry_service_bad
|
114
|
+
registry = Copland::Registry.build File.join( File.dirname( __FILE__ ),
|
115
|
+
"services" )
|
116
|
+
|
117
|
+
assert_raise( Copland::ServicePointNotFound ) do
|
118
|
+
registry.service( "copland.bogus_service" )
|
119
|
+
end
|
120
|
+
|
121
|
+
assert_raise( Copland::ServicePointNotFound ) do
|
122
|
+
registry.service( "bogus_service" )
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_registry_configuration_point_bad
|
127
|
+
registry = Copland::Registry.build File.join( File.dirname( __FILE__ ),
|
128
|
+
"services" )
|
129
|
+
|
130
|
+
point = nil
|
131
|
+
assert_nothing_raised do
|
132
|
+
point = registry.configuration_point( "copland.bogus_point" )
|
133
|
+
end
|
134
|
+
assert_nil point
|
135
|
+
|
136
|
+
assert_raise( Copland::ConfigurationPointNotFound ) do
|
137
|
+
registry.configuration_point( "bogus_point" )
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
data/test/tc_schema.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer.
|
11
|
+
#
|
12
|
+
# * Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# * The names of its contributors may not be used to endorse or promote
|
17
|
+
# products derived from this software without specific prior written
|
18
|
+
# permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
24
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
# =============================================================================
|
32
|
+
#++
|
33
|
+
|
34
|
+
$:.unshift "../lib"
|
35
|
+
|
36
|
+
require 'test/unit'
|
37
|
+
require 'copland'
|
38
|
+
|
39
|
+
class TC_Schema < Test::Unit::TestCase
|
40
|
+
|
41
|
+
def test_schema_load
|
42
|
+
registry = nil
|
43
|
+
|
44
|
+
assert_nothing_raised do
|
45
|
+
registry = Copland::Registry.build(
|
46
|
+
File.join( File.dirname( __FILE__ ), "schema" ),
|
47
|
+
:log_device => STDOUT )
|
48
|
+
end
|
49
|
+
|
50
|
+
cfg = registry.configuration_point( "test.Test3" )
|
51
|
+
|
52
|
+
assert_equal "cast it off!", cfg['g']['h']['c']
|
53
|
+
|
54
|
+
registry.shutdown
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_schema_bad_load
|
58
|
+
assert_raise( Copland::ValidationException ) do
|
59
|
+
Copland::Registry.build(
|
60
|
+
File.join( File.dirname( __FILE__ ), "schema" ),
|
61
|
+
:log_device => STDOUT,
|
62
|
+
:yaml_package_file => "bad-package.yml" )
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_schema_validate
|
67
|
+
registry = Copland::Registry.build(
|
68
|
+
File.join( File.dirname( __FILE__ ), "schema" ),
|
69
|
+
:log_device => STDOUT )
|
70
|
+
|
71
|
+
assert_nothing_raised do
|
72
|
+
registry.service( "test.Object2" )
|
73
|
+
end
|
74
|
+
|
75
|
+
registry.shutdown
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above copyright notice,
|
10
|
+
# this list of conditions and the following disclaimer.
|
11
|
+
#
|
12
|
+
# * Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# * The names of its contributors may not be used to endorse or promote
|
17
|
+
# products derived from this software without specific prior written
|
18
|
+
# permission.
|
19
|
+
#
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
24
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
25
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
# =============================================================================
|
32
|
+
#++
|
33
|
+
|
34
|
+
$:.unshift "../lib"
|
35
|
+
|
36
|
+
require 'test/unit'
|
37
|
+
require 'copland/class-factory'
|
38
|
+
require 'copland/instantiator'
|
39
|
+
require 'copland/models'
|
40
|
+
require 'copland/service-point'
|
41
|
+
require 'mock'
|
42
|
+
|
43
|
+
class TC_ServicePoint < Test::Unit::TestCase
|
44
|
+
|
45
|
+
def setup
|
46
|
+
@registry = MockRegistry.new
|
47
|
+
@package = MockPackage.new( @registry )
|
48
|
+
@svc_point = Copland::ServicePoint.new( @package, "test1" )
|
49
|
+
|
50
|
+
@svc_point.instantiator =
|
51
|
+
Copland::ClassFactory.instance.get(
|
52
|
+
Copland::Instantiator::POOL_NAME,
|
53
|
+
"simple",
|
54
|
+
@svc_point,
|
55
|
+
"services/simple/Simple" )
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_init
|
59
|
+
assert_equal @package.name + ".test1", @svc_point.full_name
|
60
|
+
assert_instance_of Copland::ServiceModel::SingletonDeferredServiceModel,
|
61
|
+
@svc_point.service_model
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_use_service_model
|
65
|
+
@svc_point.use_service_model "prototype"
|
66
|
+
assert_instance_of Copland::ServiceModel::PrototypeServiceModel,
|
67
|
+
@svc_point.service_model
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_add_event_producer
|
71
|
+
@svc_point.add_event_producer "a"
|
72
|
+
assert_equal 1, @svc_point.event_producers.length
|
73
|
+
@svc_point.add_event_producer "b"
|
74
|
+
assert_equal 2, @svc_point.event_producers.length
|
75
|
+
@svc_point.add_event_producer "a"
|
76
|
+
assert_equal 2, @svc_point.event_producers.length
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_add_interceptor
|
80
|
+
@svc_point.add_interceptor "a"
|
81
|
+
assert_equal 1, @svc_point.interceptors.length
|
82
|
+
@svc_point.add_interceptor "b"
|
83
|
+
assert_equal 2, @svc_point.interceptors.length
|
84
|
+
@svc_point.add_interceptor "a"
|
85
|
+
assert_equal 2, @svc_point.interceptors.length
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_instantiator
|
89
|
+
@svc_point.use_service_model "prototype"
|
90
|
+
|
91
|
+
svc = @svc_point.instance
|
92
|
+
assert_not_nil svc
|
93
|
+
assert_instance_of Simple, svc
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_instance_with_block
|
97
|
+
@svc_point.use_service_model "prototype"
|
98
|
+
svc = @svc_point.instance { @attr1 = "hello" }
|
99
|
+
assert_equal "hello", svc.attr1
|
100
|
+
|
101
|
+
@svc_point.use_service_model "prototype-deferred"
|
102
|
+
svc = @svc_point.instance { @attr1 = "world" }
|
103
|
+
assert_equal "world", svc.attr1
|
104
|
+
|
105
|
+
@svc_point.use_service_model "singleton"
|
106
|
+
svc = @svc_point.instance { @attr1 = "take 3" }
|
107
|
+
assert_equal "take 3", svc.attr1
|
108
|
+
svc = @svc_point.instance { @attr1 = "take 4" }
|
109
|
+
assert_equal "take 3", svc.attr1
|
110
|
+
|
111
|
+
@svc_point.use_service_model "singleton-deferred"
|
112
|
+
svc = @svc_point.instance { @attr1 = "take 3" }
|
113
|
+
assert_equal "take 3", svc.attr1
|
114
|
+
svc = @svc_point.instance { @attr1 = "take 4" }
|
115
|
+
assert_equal "take 3", svc.attr1
|
116
|
+
|
117
|
+
@svc_point.use_service_model "threaded"
|
118
|
+
svc = @svc_point.instance { @attr1 = "take 3" }
|
119
|
+
assert_equal "take 3", svc.attr1
|
120
|
+
svc = @svc_point.instance { @attr1 = "take 4" }
|
121
|
+
assert_equal "take 3", svc.attr1
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_fixate_bad_interceptor
|
125
|
+
@package.add_service_point MockServicePoint.new
|
126
|
+
@svc_point.add_pending_interceptor "service"=>"bogus"
|
127
|
+
@svc_point.add_event_producer "point"
|
128
|
+
|
129
|
+
assert_raise( Copland::ServicePointNotFound ) do
|
130
|
+
@svc_point.fixate!
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_fixate_bad_interceptor_package
|
135
|
+
@package.add_service_point MockServicePoint.new
|
136
|
+
@svc_point.add_pending_interceptor "service"=>"bogus.bogus"
|
137
|
+
@svc_point.add_event_producer "point"
|
138
|
+
|
139
|
+
assert_raise( Copland::PackageNotFound ) do
|
140
|
+
@svc_point.fixate!
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_fixate_bad_listener
|
145
|
+
@package.add_service_point MockServicePoint.new
|
146
|
+
@svc_point.add_pending_interceptor "service"=>"point"
|
147
|
+
@svc_point.add_event_producer "bogus"
|
148
|
+
|
149
|
+
assert_raise( Copland::ServicePointNotFound ) do
|
150
|
+
@svc_point.fixate!
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_fixate_bad_listener_package
|
155
|
+
@package.add_service_point MockServicePoint.new
|
156
|
+
@svc_point.add_pending_interceptor "service"=>"point"
|
157
|
+
@svc_point.add_event_producer "bogus.point"
|
158
|
+
|
159
|
+
assert_raise( Copland::PackageNotFound ) do
|
160
|
+
@svc_point.fixate!
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_fixate
|
165
|
+
@package.add_service_point MockServicePoint.new
|
166
|
+
@svc_point.add_pending_interceptor "service"=>"point"
|
167
|
+
@svc_point.add_event_producer "point"
|
168
|
+
|
169
|
+
assert !@svc_point.fixated?
|
170
|
+
@svc_point.fixate!
|
171
|
+
assert @svc_point.fixated?
|
172
|
+
|
173
|
+
assert_raise( Copland::DisallowedOperationException ) do
|
174
|
+
@svc_point.add_pending_interceptor "blah"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|