adaptation 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +12 -4
- data/helpers/test.rb +11 -0
- data/lib/adaptation/adaptor.rb +5 -1
- data/lib/adaptation/base.rb +35 -17
- data/lib/adaptation/message.rb +3 -1
- data/lib/adaptation/test/test_help.rb +35 -46
- data/lib/rails_generator/generators/applications/app/app_generator.rb +4 -0
- data/lib/rails_generator/generators/components/adaptor/templates/functional_test.rb +0 -1
- data/lib/rails_generator/lookup.rb +2 -1
- metadata +63 -62
data/CHANGELOG
CHANGED
@@ -7,8 +7,16 @@
|
|
7
7
|
* 0.0.6
|
8
8
|
- forced to use ROXML version 1.2
|
9
9
|
* 0.0.7
|
10
|
-
-
|
10
|
+
- documentation update + Message class clean up
|
11
11
|
* 0.0.8
|
12
|
-
-
|
13
|
-
Three class methods have been added in Validateable module to fix that
|
14
|
-
-
|
12
|
+
- activerecord 2.2.2 broke our tests, because it has some new methods not present in Adaptation::Message class.
|
13
|
+
Three class methods have been added in Validateable module to fix that
|
14
|
+
- removed comment when starting console
|
15
|
+
* 0.0.9
|
16
|
+
- publish method in Adaptor class uses oappublish command configured in settings.yml
|
17
|
+
- added method get_message_from_fixture in tests
|
18
|
+
- in tests, the 'message' method gets from the message itself the adaptor that must
|
19
|
+
process it, not from the test class (so def setup @adaptor=... end; is no longer mandatory)
|
20
|
+
- in tests, the 'load_message_from_fixture' method gets from the fixture itself the message class
|
21
|
+
to load, not from the test class
|
22
|
+
- fixed publish and assert_message_published methods for testing
|
data/helpers/test.rb
ADDED
data/lib/adaptation/adaptor.rb
CHANGED
@@ -9,6 +9,10 @@ module Adaptation
|
|
9
9
|
# script/generate adaptor hello
|
10
10
|
#
|
11
11
|
class Adaptor
|
12
|
+
|
13
|
+
def logger
|
14
|
+
Adaptation::Base.logger
|
15
|
+
end
|
12
16
|
|
13
17
|
def publish *options
|
14
18
|
message_object = nil
|
@@ -22,7 +26,7 @@ module Adaptation
|
|
22
26
|
end
|
23
27
|
|
24
28
|
xml = message_object.to_xml
|
25
|
-
unless system("oappublish '#{$config["application"]}' '#{xml}'")
|
29
|
+
unless system("#{$config["oappublish"]} '#{$config["application"]}' '#{xml}'")
|
26
30
|
puts "Problem publishing: #{xml}"
|
27
31
|
end
|
28
32
|
end
|
data/lib/adaptation/base.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
module Adaptation
|
2
2
|
|
3
|
-
class
|
3
|
+
class Initializer
|
4
|
+
|
5
|
+
def self.run
|
6
|
+
|
7
|
+
unless defined? $environment
|
8
|
+
$environment = "development"
|
9
|
+
end
|
4
10
|
|
5
|
-
|
6
|
-
|
7
|
-
|
11
|
+
if File.exists?("config/settings.yml")
|
12
|
+
$config = YAML::load(File.open("#{ADAPTOR_ROOT}/config/settings.yml"))[$environment]
|
13
|
+
end
|
8
14
|
|
9
15
|
# require all adaptors
|
10
16
|
Dir["#{ADAPTOR_ROOT}/app/adaptors/*.rb"].each do |f|
|
@@ -21,15 +27,37 @@ module Adaptation
|
|
21
27
|
require f
|
22
28
|
end
|
23
29
|
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
class Base
|
36
|
+
|
37
|
+
attr_reader :logger
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
|
41
|
+
Initializer.run
|
42
|
+
|
24
43
|
# connect with database -> this could also be avoided?
|
25
44
|
if File.exists?("#{ADAPTOR_ROOT}/config/database.yml")
|
26
|
-
|
27
|
-
ActiveRecord::Base.configurations.update(
|
45
|
+
environment_configurations = YAML::load(File.open("#{ADAPTOR_ROOT}/config/database.yml"))[$environment]
|
46
|
+
ActiveRecord::Base.configurations.update($environment => environment_configurations)
|
28
47
|
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[$environment])
|
29
48
|
end
|
49
|
+
|
50
|
+
@@logger = Logger.new("#{ADAPTOR_ROOT}/log/#{$environment}.log")
|
51
|
+
ActiveRecord::Base.logger = @@logger
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.logger
|
56
|
+
@@logger
|
30
57
|
end
|
31
58
|
|
32
59
|
def process(xml_message)
|
60
|
+
|
33
61
|
# dirty method to discover the message type
|
34
62
|
message_type = xml_message[1..(xml_message.index(/(>| |\/)/) - 1)]
|
35
63
|
|
@@ -48,21 +76,11 @@ module Adaptation
|
|
48
76
|
puts "WARNING:Message doesn't validate!"
|
49
77
|
return
|
50
78
|
end
|
51
|
-
|
79
|
+
|
52
80
|
adaptor.process message
|
53
81
|
end
|
54
82
|
|
55
83
|
def get_class_object(searched_class)
|
56
|
-
#class_object = nil
|
57
|
-
#ObjectSpace.each_object(Class){|aClass|
|
58
|
-
# class_object = aClass if aClass.to_s == searched_class
|
59
|
-
#}
|
60
|
-
#if class_object.nil?
|
61
|
-
# #puts "Unknown class #{searched_class}."
|
62
|
-
# raise Exception.new("Unknown class #{searched_class}.")
|
63
|
-
#else
|
64
|
-
# return class_object
|
65
|
-
#end
|
66
84
|
Object.const_get searched_class
|
67
85
|
end
|
68
86
|
|
data/lib/adaptation/message.rb
CHANGED
@@ -1,37 +1,13 @@
|
|
1
1
|
#set environment
|
2
2
|
$environment = "test"
|
3
|
-
|
4
|
-
|
5
|
-
end
|
3
|
+
|
4
|
+
Adaptation::Initializer.run
|
6
5
|
|
7
6
|
# for adaptations that require models from a rails application, sometimes
|
8
7
|
# rails needs to load the environment.rb from the rails app. When this happens
|
9
8
|
# the following variable must be set.
|
10
9
|
ENV['RAILS_ENV'] = "test"
|
11
10
|
|
12
|
-
# connect to test database
|
13
|
-
require 'active_record'
|
14
|
-
|
15
|
-
if File.exists?("config/database.yml")
|
16
|
-
test_configurations = YAML::load(File.open("config/database.yml"))[$environment]
|
17
|
-
ActiveRecord::Base.configurations.update("test" => test_configurations)
|
18
|
-
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[$environment])
|
19
|
-
end
|
20
|
-
|
21
|
-
if File.exists?("log")
|
22
|
-
ActiveRecord::Base.logger = Logger.new("#{ADAPTOR_ROOT}/log/test.log")
|
23
|
-
end
|
24
|
-
|
25
|
-
# load messages
|
26
|
-
Dir["#{ADAPTOR_ROOT}/app/messages/*.rb"].reject{|f| f =~ /\/_/}.each do |f|
|
27
|
-
require f
|
28
|
-
end
|
29
|
-
|
30
|
-
# load models
|
31
|
-
Dir["#{ADAPTOR_ROOT}/app/models/*.rb"].each do |f|
|
32
|
-
require f
|
33
|
-
end
|
34
|
-
|
35
11
|
if File.exists?("config/database.yml")
|
36
12
|
begin
|
37
13
|
require 'active_record/fixtures'
|
@@ -60,7 +36,6 @@ class Test::Unit::TestCase
|
|
60
36
|
parsed_data.to_s,
|
61
37
|
message_object.to_xml.to_s
|
62
38
|
assert_block error do
|
63
|
-
#message_object.to_xml.to_s == parsed_data.to_s
|
64
39
|
compare_xml_elements parsed_data.root, message_object.to_xml
|
65
40
|
end
|
66
41
|
end
|
@@ -82,7 +57,6 @@ class Test::Unit::TestCase
|
|
82
57
|
parsed_data.to_s,
|
83
58
|
message_object.to_xml.to_s
|
84
59
|
assert_block error do
|
85
|
-
#message_object.to_xml.to_s != parsed_data.to_s
|
86
60
|
!compare_xml_elements parsed_data.root, message_object.to_xml
|
87
61
|
end
|
88
62
|
end
|
@@ -116,28 +90,41 @@ class Test::Unit::TestCase
|
|
116
90
|
|
117
91
|
# Asserts that a message[link:/classes/Adaptation/Message.html] has been
|
118
92
|
# published in test environment. This means that the
|
119
|
-
# message[link:/classes/Adaptation/Message.html] will be searched
|
120
|
-
# the mock object <em>test/mocks/test/publish.rb</em> left it.
|
93
|
+
# message[link:/classes/Adaptation/Message.html] will be searched in the
|
94
|
+
# file where the mock object <em>test/mocks/test/publish.rb</em> left it.
|
95
|
+
# The file that fakes the mom is deleted every time <em>message<em> method
|
96
|
+
# is called.
|
121
97
|
def assert_message_published xml_message
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
98
|
+
message_object = xml_message
|
99
|
+
|
100
|
+
if message_object.is_a?(String)
|
101
|
+
# build Message object with xml_data
|
102
|
+
message_type = xml_message[1..(xml_message.index(/(>| )/) - 1)]
|
103
|
+
message_class = get_class_object(message_type.capitalize)
|
104
|
+
message_object = message_class.to_object(xml_message)
|
105
|
+
end
|
126
106
|
|
127
107
|
# check for all messages "published" in the mom (that's file /tmp/mom.txt),
|
128
108
|
# if any line corresponds to the message passed as a parameter.
|
129
109
|
message_found = false
|
130
|
-
|
110
|
+
expected = published = ""
|
111
|
+
File.open(ADAPTOR_ROOT + '/test/mocks/test/mom.txt', 'r').each{ |line|
|
131
112
|
mom_message = REXML::Document.new line
|
132
|
-
|
113
|
+
published = line.chop
|
114
|
+
expected = message_object.to_xml.to_s
|
115
|
+
if compare_xml_elements mom_message.root, message_object.to_xml
|
133
116
|
message_found = true
|
134
117
|
break
|
135
118
|
end
|
136
119
|
}
|
137
120
|
|
138
|
-
error = build_message
|
139
|
-
|
140
|
-
|
121
|
+
error = build_message(error,
|
122
|
+
"? message not published:\n \
|
123
|
+
Expected : ?\n \
|
124
|
+
Published: ?\n",
|
125
|
+
message_object.class,
|
126
|
+
expected,
|
127
|
+
published)
|
141
128
|
assert_block error do
|
142
129
|
message_found
|
143
130
|
end
|
@@ -165,7 +152,6 @@ class Test::Unit::TestCase
|
|
165
152
|
begin
|
166
153
|
connection = ActiveRecord::Base.connection
|
167
154
|
rescue Exception => e
|
168
|
-
puts "Database error message: #{e}"
|
169
155
|
database_exists = false
|
170
156
|
end
|
171
157
|
|
@@ -201,7 +187,6 @@ class Test::Unit::TestCase
|
|
201
187
|
begin
|
202
188
|
connection = ActiveRecord::Base.connection
|
203
189
|
rescue Exception => e
|
204
|
-
puts "Database says: #{e} (not necessarily bad)"
|
205
190
|
database_exists = false
|
206
191
|
end
|
207
192
|
|
@@ -246,14 +231,19 @@ class Test::Unit::TestCase
|
|
246
231
|
end
|
247
232
|
|
248
233
|
# clean mom (delete mom.txt file)
|
249
|
-
mom_mock_file = 'test/mocks/test/mom.txt'
|
234
|
+
mom_mock_file = ADAPTOR_ROOT + '/test/mocks/test/mom.txt'
|
250
235
|
if File.exists? mom_mock_file
|
251
236
|
File.delete mom_mock_file
|
252
237
|
end
|
253
238
|
|
254
|
-
|
255
|
-
|
239
|
+
Adaptation::Base.new.process message_xml
|
240
|
+
|
241
|
+
end
|
256
242
|
|
243
|
+
# Retuns a message[link:/classes/Adaptation/Message.html] object
|
244
|
+
# from a fixture, without processing it
|
245
|
+
def get_message_from_fixture message_symbol
|
246
|
+
load_message_fixture(message_symbol)[1]
|
257
247
|
end
|
258
248
|
|
259
249
|
private
|
@@ -271,8 +261,7 @@ class Test::Unit::TestCase
|
|
271
261
|
|
272
262
|
def load_message_fixture fixture_symbol #:nodoc:
|
273
263
|
data = get_message_fixture(fixture_symbol.to_s)
|
274
|
-
class_name =
|
275
|
-
class_name = class_name.gsub("Adaptor", "")
|
264
|
+
class_name = data[1..(data.index(/(>| )/) - 1)].capitalize
|
276
265
|
message_class = get_class_object(class_name)
|
277
266
|
message_object = message_class.to_object(data)
|
278
267
|
[data, message_object]
|
@@ -195,7 +195,8 @@ module Rails
|
|
195
195
|
|
196
196
|
# Yield latest versions of generator gems.
|
197
197
|
def each
|
198
|
-
Gem::
|
198
|
+
dependency = Gem::Dependency.new(/_generator$/, Gem::Requirement.default)
|
199
|
+
Gem::cache.search(dependency).inject({}) { |latest, gem|
|
199
200
|
hem = latest[gem.name]
|
200
201
|
latest[gem.name] = gem if hem.nil? or gem.version > hem.version
|
201
202
|
latest
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adaptation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavi Vila Morell
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-23 00:00:00 +01:00
|
13
13
|
default_executable: adaptation
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,94 +42,95 @@ extensions: []
|
|
42
42
|
extra_rdoc_files:
|
43
43
|
- README
|
44
44
|
files:
|
45
|
-
- bin/subscribe
|
46
|
-
- bin/destroy
|
47
|
-
- bin/breakpointer
|
48
|
-
- bin/about
|
49
|
-
- bin/adaptation
|
50
45
|
- bin/generate
|
46
|
+
- bin/about
|
47
|
+
- bin/breakpointer
|
51
48
|
- bin/console
|
49
|
+
- bin/adaptation
|
52
50
|
- bin/mom
|
51
|
+
- bin/subscribe
|
52
|
+
- bin/destroy
|
53
|
+
- lib/rails_generator
|
54
|
+
- lib/ruby_version_check.rb
|
55
|
+
- lib/breakpoint_client.rb
|
56
|
+
- lib/binding_of_caller.rb
|
53
57
|
- lib/breakpoint.rb
|
54
|
-
- lib/
|
55
|
-
- lib/adaptation/base.rb
|
56
|
-
- lib/adaptation/console
|
57
|
-
- lib/adaptation/console/environment.rb
|
58
|
-
- lib/adaptation/version.rb
|
59
|
-
- lib/adaptation/mom.rb
|
60
|
-
- lib/adaptation/message.rb
|
61
|
-
- lib/adaptation/adaptor.rb
|
62
|
-
- lib/adaptation/druby_subscriber.rb
|
63
|
-
- lib/adaptation/test
|
64
|
-
- lib/adaptation/test/fake_fixtures.rb
|
65
|
-
- lib/adaptation/test/test_help.rb
|
66
|
-
- lib/adaptation/validateable.rb
|
58
|
+
- lib/rails_generator.rb
|
67
59
|
- lib/commands.rb
|
68
|
-
- lib/
|
69
|
-
- lib/
|
70
|
-
- lib/
|
60
|
+
- lib/adaptation.rb
|
61
|
+
- lib/commands
|
62
|
+
- lib/adaptation
|
63
|
+
- lib/rails_generator/scripts
|
64
|
+
- lib/rails_generator/manifest.rb
|
71
65
|
- lib/rails_generator/base.rb
|
66
|
+
- lib/rails_generator/simple_logger.rb
|
67
|
+
- lib/rails_generator/generators
|
72
68
|
- lib/rails_generator/commands.rb
|
73
69
|
- lib/rails_generator/lookup.rb
|
74
|
-
- lib/rails_generator/manifest.rb
|
75
|
-
- lib/rails_generator/generated_attribute.rb
|
76
70
|
- lib/rails_generator/scripts.rb
|
77
|
-
- lib/rails_generator/
|
71
|
+
- lib/rails_generator/generated_attribute.rb
|
72
|
+
- lib/rails_generator/options.rb
|
73
|
+
- lib/rails_generator/spec.rb
|
78
74
|
- lib/rails_generator/scripts/update.rb
|
79
75
|
- lib/rails_generator/scripts/destroy.rb
|
80
76
|
- lib/rails_generator/scripts/generate.rb
|
81
|
-
- lib/rails_generator/spec.rb
|
82
|
-
- lib/rails_generator/generators
|
83
|
-
- lib/rails_generator/generators/applications
|
84
|
-
- lib/rails_generator/generators/applications/app
|
85
|
-
- lib/rails_generator/generators/applications/app/USAGE
|
86
|
-
- lib/rails_generator/generators/applications/app/app_generator.rb
|
87
77
|
- lib/rails_generator/generators/components
|
88
|
-
- lib/rails_generator/generators/
|
89
|
-
- lib/rails_generator/generators/components/model/USAGE
|
90
|
-
- lib/rails_generator/generators/components/model/templates
|
91
|
-
- lib/rails_generator/generators/components/model/templates/unit_test.rb
|
92
|
-
- lib/rails_generator/generators/components/model/templates/fixtures.yml
|
93
|
-
- lib/rails_generator/generators/components/model/templates/migration.rb
|
94
|
-
- lib/rails_generator/generators/components/model/templates/model.rb
|
95
|
-
- lib/rails_generator/generators/components/model/model_generator.rb
|
78
|
+
- lib/rails_generator/generators/applications
|
96
79
|
- lib/rails_generator/generators/components/message
|
97
|
-
- lib/rails_generator/generators/components/
|
80
|
+
- lib/rails_generator/generators/components/adaptor
|
81
|
+
- lib/rails_generator/generators/components/model
|
98
82
|
- lib/rails_generator/generators/components/message/templates
|
99
|
-
- lib/rails_generator/generators/components/message/
|
83
|
+
- lib/rails_generator/generators/components/message/USAGE
|
84
|
+
- lib/rails_generator/generators/components/message/message_generator.rb
|
100
85
|
- lib/rails_generator/generators/components/message/templates/message.rb
|
101
86
|
- lib/rails_generator/generators/components/message/templates/fixtures.xml
|
102
|
-
- lib/rails_generator/generators/components/message/
|
103
|
-
- lib/rails_generator/generators/components/adaptor
|
104
|
-
- lib/rails_generator/generators/components/adaptor/USAGE
|
87
|
+
- lib/rails_generator/generators/components/message/templates/unit_test.rb
|
88
|
+
- lib/rails_generator/generators/components/adaptor/adaptor_generator.rb
|
105
89
|
- lib/rails_generator/generators/components/adaptor/templates
|
106
|
-
- lib/rails_generator/generators/components/adaptor/
|
90
|
+
- lib/rails_generator/generators/components/adaptor/USAGE
|
107
91
|
- lib/rails_generator/generators/components/adaptor/templates/functional_test.rb
|
108
|
-
- lib/rails_generator/generators/components/adaptor/
|
109
|
-
- lib/
|
110
|
-
- lib/rails_generator
|
111
|
-
- lib/
|
112
|
-
- lib/
|
113
|
-
- lib/
|
92
|
+
- lib/rails_generator/generators/components/adaptor/templates/adaptor.rb
|
93
|
+
- lib/rails_generator/generators/components/model/model_generator.rb
|
94
|
+
- lib/rails_generator/generators/components/model/templates
|
95
|
+
- lib/rails_generator/generators/components/model/USAGE
|
96
|
+
- lib/rails_generator/generators/components/model/templates/model.rb
|
97
|
+
- lib/rails_generator/generators/components/model/templates/fixtures.yml
|
98
|
+
- lib/rails_generator/generators/components/model/templates/unit_test.rb
|
99
|
+
- lib/rails_generator/generators/components/model/templates/migration.rb
|
100
|
+
- lib/rails_generator/generators/applications/app
|
101
|
+
- lib/rails_generator/generators/applications/app/app_generator.rb
|
102
|
+
- lib/rails_generator/generators/applications/app/USAGE
|
103
|
+
- lib/commands/subscribe.rb
|
114
104
|
- lib/commands/breakpointer.rb
|
115
|
-
- lib/commands/
|
105
|
+
- lib/commands/destroy.rb
|
116
106
|
- lib/commands/about.rb
|
117
107
|
- lib/commands/adaptor_path.rb
|
118
|
-
- lib/commands/subscribe.rb
|
119
|
-
- lib/commands/destroy.rb
|
120
108
|
- lib/commands/generate.rb
|
121
|
-
- lib/
|
122
|
-
-
|
109
|
+
- lib/commands/console.rb
|
110
|
+
- lib/adaptation/version.rb
|
111
|
+
- lib/adaptation/test
|
112
|
+
- lib/adaptation/validateable.rb
|
113
|
+
- lib/adaptation/base.rb
|
114
|
+
- lib/adaptation/message.rb
|
115
|
+
- lib/adaptation/druby_subscriber.rb
|
116
|
+
- lib/adaptation/console
|
117
|
+
- lib/adaptation/mom.rb
|
118
|
+
- lib/adaptation/adaptor.rb
|
119
|
+
- lib/adaptation/test/fake_fixtures.rb
|
120
|
+
- lib/adaptation/test/test_help.rb
|
121
|
+
- lib/adaptation/console/environment.rb
|
123
122
|
- helpers/test_helper.rb
|
123
|
+
- helpers/publish.rb
|
124
|
+
- helpers/test.rb
|
124
125
|
- doc/README_FOR_APP
|
125
|
-
- configs/databases
|
126
|
-
- configs/databases/mysql.yml
|
127
126
|
- configs/mom.yml
|
128
|
-
- configs/settings.yml
|
129
127
|
- configs/empty.log
|
128
|
+
- configs/settings.yml
|
129
|
+
- configs/databases
|
130
130
|
- configs/boot.rb
|
131
|
-
-
|
131
|
+
- configs/databases/mysql.yml
|
132
132
|
- dispatches/publish.rb
|
133
|
+
- dispatches/dispatch.rb
|
133
134
|
- README
|
134
135
|
- CHANGELOG
|
135
136
|
- fresh_rakefile
|