copland 0.8.0
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/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
|
@@ -0,0 +1,84 @@
|
|
|
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_Interceptors < Test::Unit::TestCase
|
|
41
|
+
|
|
42
|
+
def setup
|
|
43
|
+
@registry = Copland::Registry.build(
|
|
44
|
+
File.join( File.dirname( __FILE__ ), "services" ),
|
|
45
|
+
:log_device => $stdout )
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def teardown
|
|
49
|
+
@registry.shutdown
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_simple
|
|
53
|
+
service = @registry.service( "service-test.Intercepted1" )
|
|
54
|
+
cfg = @registry.configuration_point( "service-test.Messages" )
|
|
55
|
+
|
|
56
|
+
assert cfg.empty?
|
|
57
|
+
service.echo "a"
|
|
58
|
+
assert_equal [ "A" ], cfg
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_ordering_error
|
|
62
|
+
service = @registry.service( "service-test.InterceptorOrderingError1" )
|
|
63
|
+
|
|
64
|
+
assert_raise( Copland::OrderingException ) do
|
|
65
|
+
service.echo "a"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
service = @registry.service( "service-test.InterceptorOrderingError2" )
|
|
69
|
+
|
|
70
|
+
assert_raise( Copland::OrderingException ) do
|
|
71
|
+
service.echo "a"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_ordering
|
|
76
|
+
service = @registry.service( "service-test.InterceptorOrdering1" )
|
|
77
|
+
cfg = @registry.configuration_point( "service-test.Messages" )
|
|
78
|
+
|
|
79
|
+
assert cfg.empty?
|
|
80
|
+
service.echo "a"
|
|
81
|
+
assert_equal [ "C", "B", "A" ], cfg
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
data/test/tc_logger.rb
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
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 'copland/log-factory'
|
|
37
|
+
require 'test/unit'
|
|
38
|
+
require 'mock'
|
|
39
|
+
|
|
40
|
+
class TC_Logger < Test::Unit::TestCase
|
|
41
|
+
|
|
42
|
+
def test_log_filename
|
|
43
|
+
factory = Copland::LogFactory.new :config_file => 'bogus'
|
|
44
|
+
assert_equal Copland::LogFactory::DEFAULT_LOG_FILENAME,
|
|
45
|
+
factory.device.filename
|
|
46
|
+
factory.close
|
|
47
|
+
assert factory.closed?
|
|
48
|
+
|
|
49
|
+
factory = Copland::LogFactory.new :config_file => 'bogus',
|
|
50
|
+
:filename => './sample.log'
|
|
51
|
+
assert_equal "./sample.log", factory.device.filename
|
|
52
|
+
factory.close
|
|
53
|
+
|
|
54
|
+
factory = Copland::LogFactory.new :config_file => 'bogus',
|
|
55
|
+
:device => STDOUT
|
|
56
|
+
assert_equal STDOUT, factory.device
|
|
57
|
+
factory.close
|
|
58
|
+
|
|
59
|
+
assert !STDOUT.closed?
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_log_config
|
|
63
|
+
factory = Copland::LogFactory.new
|
|
64
|
+
assert_equal "./sample.log", factory.device.filename
|
|
65
|
+
assert_equal "%Y-%m-%d %H:%M:%S", factory.default_format
|
|
66
|
+
assert_equal Logger::INFO, factory.default_level
|
|
67
|
+
factory.close
|
|
68
|
+
|
|
69
|
+
factory = Copland::LogFactory.new :config_file => 'custom-logger.yml'
|
|
70
|
+
assert_equal "./custom.log", factory.device.filename
|
|
71
|
+
assert_equal "date %Y-%m-%d %H:%M:%S", factory.default_format
|
|
72
|
+
assert_equal Logger::FATAL, factory.default_level
|
|
73
|
+
factory.close
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_log_options
|
|
77
|
+
factory = Copland::LogFactory.new :default_format => "%Y",
|
|
78
|
+
:default_level => Logger::FATAL
|
|
79
|
+
assert_equal "%Y", factory.default_format
|
|
80
|
+
assert_equal Logger::FATAL, factory.default_level
|
|
81
|
+
factory.close
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_log_get
|
|
85
|
+
factory = Copland::LogFactory.new
|
|
86
|
+
|
|
87
|
+
log1a = factory.get( "test.log1" )
|
|
88
|
+
log2 = factory.get( "test.log2" )
|
|
89
|
+
log1b = factory.get( "test.log1" )
|
|
90
|
+
|
|
91
|
+
assert_equal log1a.id, log1b.id
|
|
92
|
+
assert_not_equal log1a.id, log2.id
|
|
93
|
+
|
|
94
|
+
factory.close
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_log_write
|
|
98
|
+
io = MockLogIO.new
|
|
99
|
+
factory = Copland::LogFactory.new :device => io
|
|
100
|
+
|
|
101
|
+
log = factory.get( "test.log1" )
|
|
102
|
+
|
|
103
|
+
# the config file has DEBUG turned off...
|
|
104
|
+
log.debug "test"
|
|
105
|
+
assert_equal "", io.message
|
|
106
|
+
|
|
107
|
+
log.info "test"
|
|
108
|
+
assert_match( /INFO -- test.log1: test/, io.message )
|
|
109
|
+
|
|
110
|
+
factory.close
|
|
111
|
+
assert_equal "<closed>", io.message
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def test_levels
|
|
115
|
+
io = MockLogIO.new
|
|
116
|
+
factory = Copland::LogFactory.new :device => io
|
|
117
|
+
|
|
118
|
+
log = factory.get( "level.log1" )
|
|
119
|
+
|
|
120
|
+
log.info "test"
|
|
121
|
+
assert_equal "", io.message
|
|
122
|
+
|
|
123
|
+
log = factory.get( "level.test.log1" )
|
|
124
|
+
|
|
125
|
+
log.debug "test"
|
|
126
|
+
assert_match( /DEBUG -- level.test.log1: test/, io.message )
|
|
127
|
+
|
|
128
|
+
factory.close
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
end
|
data/test/tc_models.rb
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
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/errors'
|
|
39
|
+
require 'copland/models'
|
|
40
|
+
require 'mock'
|
|
41
|
+
|
|
42
|
+
class TC_Models < Test::Unit::TestCase
|
|
43
|
+
|
|
44
|
+
def setup
|
|
45
|
+
@factory = Factory.new( Copland::ServiceModel::POOL_NAME )
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_factory
|
|
49
|
+
point = MockServicePoint.new
|
|
50
|
+
|
|
51
|
+
assert_instance_of( Copland::ServiceModel::PrototypeServiceModel,
|
|
52
|
+
@factory.get( "prototype", point ) )
|
|
53
|
+
assert_instance_of( Copland::ServiceModel::PrototypeDeferredServiceModel,
|
|
54
|
+
@factory.get( "prototype-deferred", point ) )
|
|
55
|
+
assert_instance_of( Copland::ServiceModel::SingletonServiceModel,
|
|
56
|
+
@factory.get( "singleton", point ) )
|
|
57
|
+
assert_instance_of( Copland::ServiceModel::SingletonDeferredServiceModel,
|
|
58
|
+
@factory.get( "singleton-deferred", point ) )
|
|
59
|
+
assert_instance_of( Copland::ServiceModel::ThreadedServiceModel,
|
|
60
|
+
@factory.get( "threaded", point ) )
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_invalid_model
|
|
64
|
+
point = MockServicePoint.new
|
|
65
|
+
|
|
66
|
+
assert_raise( Copland::NoSuchRegisteredClassException ) do
|
|
67
|
+
@factory.get( "bogus", point )
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_prototype_instance
|
|
72
|
+
message = ""
|
|
73
|
+
point = MockServicePoint.new( message )
|
|
74
|
+
model = @factory.get( "prototype", point )
|
|
75
|
+
|
|
76
|
+
obj1 = model.instance
|
|
77
|
+
assert_instance_of( MockService, obj1 )
|
|
78
|
+
assert_equal( "initialized!", message )
|
|
79
|
+
|
|
80
|
+
obj2 = model.instance
|
|
81
|
+
assert_instance_of( MockService, obj2 )
|
|
82
|
+
|
|
83
|
+
assert_not_equal obj1.id, obj2.id
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def test_prototype_deferred_instance
|
|
87
|
+
message = ""
|
|
88
|
+
point = MockServicePoint.new( message )
|
|
89
|
+
model = @factory.get( "prototype-deferred", point )
|
|
90
|
+
|
|
91
|
+
obj1 = model.instance
|
|
92
|
+
assert_instance_of( Copland::ServiceModel::Proxy, obj1 )
|
|
93
|
+
assert_equal( "", message )
|
|
94
|
+
|
|
95
|
+
obj2 = model.instance
|
|
96
|
+
assert_instance_of( Copland::ServiceModel::Proxy, obj2 )
|
|
97
|
+
|
|
98
|
+
assert_not_equal obj1.id, obj2.id
|
|
99
|
+
|
|
100
|
+
assert_equal( "", message )
|
|
101
|
+
obj1.noop
|
|
102
|
+
assert_equal( "initialized!", message )
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_singleton_instance
|
|
106
|
+
message = ""
|
|
107
|
+
point = MockServicePoint.new( message )
|
|
108
|
+
model = @factory.get( "singleton", point )
|
|
109
|
+
|
|
110
|
+
obj1 = model.instance
|
|
111
|
+
assert_instance_of( MockService, obj1 )
|
|
112
|
+
assert_equal( "initialized!", message )
|
|
113
|
+
|
|
114
|
+
obj2 = model.instance
|
|
115
|
+
assert_instance_of( MockService, obj2 )
|
|
116
|
+
|
|
117
|
+
assert_equal obj1.id, obj2.id
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def test_singleton_deferred_instance
|
|
121
|
+
message = ""
|
|
122
|
+
point = MockServicePoint.new( message )
|
|
123
|
+
model = @factory.get( "singleton-deferred", point )
|
|
124
|
+
|
|
125
|
+
obj1 = model.instance
|
|
126
|
+
assert_instance_of( Copland::ServiceModel::Proxy, obj1 )
|
|
127
|
+
assert_equal( "", message )
|
|
128
|
+
|
|
129
|
+
obj2 = model.instance
|
|
130
|
+
assert_instance_of( Copland::ServiceModel::Proxy, obj2 )
|
|
131
|
+
|
|
132
|
+
assert_equal obj1.id, obj2.id
|
|
133
|
+
|
|
134
|
+
assert_equal( "", message )
|
|
135
|
+
obj1.noop
|
|
136
|
+
assert_equal( "initialized!", message )
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def test_threaded_instance
|
|
140
|
+
message = ""
|
|
141
|
+
point = MockServicePoint.new( message )
|
|
142
|
+
model = @factory.get( "threaded", point )
|
|
143
|
+
|
|
144
|
+
obj1 = model.instance
|
|
145
|
+
assert_instance_of( Copland::ServiceModel::Proxy, obj1 )
|
|
146
|
+
assert_equal( "", message )
|
|
147
|
+
|
|
148
|
+
obj2 = model.instance
|
|
149
|
+
assert_instance_of( Copland::ServiceModel::Proxy, obj2 )
|
|
150
|
+
|
|
151
|
+
assert_equal obj1.id, obj2.id
|
|
152
|
+
|
|
153
|
+
assert_equal( "", message )
|
|
154
|
+
obj1.noop
|
|
155
|
+
assert_equal( "initialized!", message )
|
|
156
|
+
|
|
157
|
+
t = Thread.new do
|
|
158
|
+
obj3 = model.instance
|
|
159
|
+
assert_not_equal obj1.id, obj3.id
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
t.join
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def test_name
|
|
166
|
+
point = MockServicePoint.new()
|
|
167
|
+
|
|
168
|
+
[ "prototype", "prototype-deferred",
|
|
169
|
+
"singleton", "singleton-deferred",
|
|
170
|
+
"threaded" ].each do |model|
|
|
171
|
+
# begin
|
|
172
|
+
assert_equal model, @factory.get( model, point ).name
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
end
|
data/test/tc_package.rb
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
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/package'
|
|
39
|
+
require 'copland/schema'
|
|
40
|
+
require 'mock'
|
|
41
|
+
|
|
42
|
+
class TC_Package < Test::Unit::TestCase
|
|
43
|
+
|
|
44
|
+
TEST_PACKAGE_NAME = "copland.test"
|
|
45
|
+
|
|
46
|
+
def setup
|
|
47
|
+
@registry = MockRegistry.new
|
|
48
|
+
@package = Copland::Package.new( @registry, TEST_PACKAGE_NAME )
|
|
49
|
+
@registry.add_package @package
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_create
|
|
53
|
+
assert_equal @registry, @package.registry
|
|
54
|
+
assert_equal TEST_PACKAGE_NAME, @package.name
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_description
|
|
58
|
+
assert_nil @package.description
|
|
59
|
+
|
|
60
|
+
@package.description = "X"
|
|
61
|
+
assert_equal "X", @package.description
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_find_schema
|
|
65
|
+
p2 = Copland::Package.new( @registry, "other" )
|
|
66
|
+
@registry.add_package p2
|
|
67
|
+
|
|
68
|
+
schema = Copland::Schema.new( "TestSchema", nil, nil, nil, nil, nil, nil )
|
|
69
|
+
p2.add_schema schema
|
|
70
|
+
|
|
71
|
+
assert_raise( Copland::PackageNotFound ) do
|
|
72
|
+
p2.find_schema( "copland.other.TestSchema" )
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
assert_raise( Copland::SchemaNotFound ) do
|
|
76
|
+
p2.find_schema( "copland.test.TestSchema" )
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
assert_raise( Copland::SchemaNotFound ) do
|
|
80
|
+
@package.find_schema( "TestSchema" )
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
temp = nil
|
|
84
|
+
assert_nothing_raised do
|
|
85
|
+
temp = @package.find_schema( "other.TestSchema" )
|
|
86
|
+
end
|
|
87
|
+
assert_same schema, temp
|
|
88
|
+
|
|
89
|
+
temp = nil
|
|
90
|
+
assert_nothing_raised do
|
|
91
|
+
temp = p2.find_schema( "TestSchema" )
|
|
92
|
+
end
|
|
93
|
+
assert_same schema, temp
|
|
94
|
+
|
|
95
|
+
temp = nil
|
|
96
|
+
assert_nothing_raised do
|
|
97
|
+
temp = p2.find_schema( "other.TestSchema" )
|
|
98
|
+
end
|
|
99
|
+
assert_same schema, temp
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_service_points
|
|
103
|
+
assert_equal 0, @package.service_points.length
|
|
104
|
+
|
|
105
|
+
point = MockServicePoint.new
|
|
106
|
+
@package.add_service_point point
|
|
107
|
+
|
|
108
|
+
assert_equal 1, @package.service_points.length
|
|
109
|
+
p2 = @package.service_point( "point" )
|
|
110
|
+
|
|
111
|
+
assert_equal point.id, p2.id
|
|
112
|
+
|
|
113
|
+
svc = @package.service( "point" )
|
|
114
|
+
assert_instance_of MockService, svc
|
|
115
|
+
|
|
116
|
+
svc = @package.service_point( "bogus" )
|
|
117
|
+
assert_nil svc
|
|
118
|
+
|
|
119
|
+
assert_raise( Copland::ServicePointNotFound ) do
|
|
120
|
+
@package.service( "bogus" )
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def test_configuration_points
|
|
125
|
+
assert_equal 0, @package.configuration_points.length
|
|
126
|
+
|
|
127
|
+
cfg = MockConfigurationPoint.new
|
|
128
|
+
@package.add_configuration_point cfg
|
|
129
|
+
|
|
130
|
+
assert_equal 1, @package.configuration_points.length
|
|
131
|
+
p2 = @package.configuration_point( "point" )
|
|
132
|
+
|
|
133
|
+
assert_equal cfg.id, p2.id
|
|
134
|
+
|
|
135
|
+
p2 = @package.configuration_point( "bogus" )
|
|
136
|
+
assert_nil p2
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def test_fixate_bad_package
|
|
140
|
+
@package.add_pending_contribution "bogus.conf_point", [ "a", "b", "c" ]
|
|
141
|
+
assert_raise( Copland::PackageNotFound ) { @package.fixate! }
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def test_fixate_bad_contribution
|
|
145
|
+
@package.add_pending_contribution "conf_point", [ "a", "b", "c" ]
|
|
146
|
+
assert_raise( Copland::ConfigurationPointNotFound ) { @package.fixate! }
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def test_fixate
|
|
150
|
+
cfg = MockConfigurationPoint.new
|
|
151
|
+
@package.add_configuration_point cfg
|
|
152
|
+
|
|
153
|
+
@package.add_pending_contribution cfg.name, "hello"
|
|
154
|
+
|
|
155
|
+
assert !@package.fixated?
|
|
156
|
+
@package.fixate!
|
|
157
|
+
assert @package.fixated?
|
|
158
|
+
|
|
159
|
+
assert_raise( Copland::DisallowedOperationException ) do
|
|
160
|
+
@package.add_pending_contribution cfg.name, "hello"
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
end
|
|
165
|
+
|