adaptation 0.0.1 → 0.0.2

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.
@@ -38,6 +38,13 @@ end
38
38
 
39
39
  class Test::Unit::TestCase
40
40
 
41
+ # Asserts that a message[link:/classes/Adaptation/Message.html] in a xml
42
+ # fixture file is converted into an Adaptation::Message that if serialized
43
+ # again to xml is equivalent to the xml data in the initial fixture file.
44
+ # An Adaptation::Message object cretaed from a xml fixture, will only
45
+ # have the xml tags specified in its class definition (using has_one,
46
+ # has_many, has_text...) so this assertion can be useful to check that
47
+ # the class is defined correctly.
41
48
  def assert_parsed message_symbol
42
49
  data, message_object = load_message_fixture message_symbol
43
50
 
@@ -53,6 +60,13 @@ class Test::Unit::TestCase
53
60
  end
54
61
  end
55
62
 
63
+ # Asserts that a message[link:/classes/Adaptation/Message.html] in a xml
64
+ # fixture file is converted into an Adaptation::Message that if serialized
65
+ # again to xml is not equivalent to the xml data in the initial fixture file.
66
+ # An Adaptation::Message object cretaed from a xml fixture, will only
67
+ # have the xml tags specified in its class definition (using has_one,
68
+ # has_many, has_text...) so this assertion can be useful to check that
69
+ # undesired xml tags are filtered.
56
70
  def assert_not_parsed message_symbol
57
71
  data, message_object = load_message_fixture message_symbol
58
72
 
@@ -63,10 +77,14 @@ class Test::Unit::TestCase
63
77
  parsed_data.to_s,
64
78
  message_object.to_xml.to_s
65
79
  assert_block error do
66
- message_object.to_xml.to_s != parsed_data.to_s
80
+ #message_object.to_xml.to_s != parsed_data.to_s
81
+ !compare_xml_elements parsed_data.root, message_object.to_xml
67
82
  end
68
83
  end
69
84
 
85
+ # Asserts that an Adaptation::Message message[link:/classes/Adaptation/Message.html]
86
+ # build from a xml fixture file passes all the validations specified in the
87
+ # class definition.
70
88
  def assert_validates message_symbol
71
89
  data, message_object = load_message_fixture message_symbol
72
90
  error = build_message error,
@@ -78,6 +96,9 @@ class Test::Unit::TestCase
78
96
  end
79
97
  end
80
98
 
99
+ # Asserts that an Adaptation::Message message[link:/classes/Adaptation/Message.html],
100
+ # build from a xml fixture file doesn't pass all the validations specified in
101
+ # the class definition.
81
102
  def assert_not_validates message_symbol
82
103
  data, message_object = load_message_fixture message_symbol
83
104
  error = build_message error,
@@ -88,6 +109,10 @@ class Test::Unit::TestCase
88
109
  end
89
110
  end
90
111
 
112
+ # Asserts that a message[link:/classes/Adaptation/Message.html] has been
113
+ # published in test environment. This means that the
114
+ # message[link:/classes/Adaptation/Message.html] will be searched where
115
+ # the mock object <em>test/mocks/test/publish.rb</em> left it.
91
116
  def assert_message_published xml_message
92
117
  # build Message object with xml_data
93
118
  message_type = xml_message[1..(xml_message.index(/(>| )/) - 1)]
@@ -95,7 +120,7 @@ class Test::Unit::TestCase
95
120
  message_object = message_class.to_object(xml_message)
96
121
 
97
122
  # check for all messages "published" in the mom (that's file /tmp/mom.txt),
98
- # if any line corresponds to the message passes as a parameter.
123
+ # if any line corresponds to the message passed as a parameter.
99
124
  message_found = false
100
125
  File.open('/tmp/mom.txt', 'r').each{ |line|
101
126
  mom_message = REXML::Document.new line
@@ -114,6 +139,16 @@ class Test::Unit::TestCase
114
139
 
115
140
  end
116
141
 
142
+ # Asserts a database exists. To do so this method tries to establish a
143
+ # connection with the specified database. Conection information must
144
+ # be provided with a hash:
145
+ # <tt>:database</tt>:: <tt>=> database name</tt>
146
+ # <tt>:host</tt>:: <tt>=> database host</tt>
147
+ # <tt>:username</tt>:: <tt>=> database user</tt>
148
+ # <tt>:password</tt>:: <tt>=> database password</tt>
149
+ # <tt>:adapter</tt>:: <tt>=> database type (default is "mysql")</tt>
150
+ # These options correspond to those in
151
+ # Activerecord::Base.establish_conection[http://ar.rubyonrails.com/classes/ActiveRecord/Base.html#M000370]
117
152
  def assert_database_present db_settings_hash
118
153
  update_activerecord_test_configuration db_settings_hash
119
154
 
@@ -138,6 +173,18 @@ class Test::Unit::TestCase
138
173
 
139
174
  end
140
175
 
176
+ # Asserts a database doesn't exist. To do so this method tries to establish a
177
+ # connection with the specified database. Connection information must
178
+ # be provided with a hash. This method assert if connection fails, but that
179
+ # could also mean that provided connection hash is wrong. The connection options
180
+ # are the same as in assert_database_present:
181
+ # <tt>:database</tt>:: <tt>=> database name</tt>
182
+ # <tt>:host</tt>:: <tt>=> database host</tt>
183
+ # <tt>:username</tt>:: <tt>=> database user</tt>
184
+ # <tt>:password</tt>:: <tt>=> database password</tt>
185
+ # <tt>:adapter</tt>:: <tt>=> database type (default is "mysql")</tt>
186
+ # These options correspond to those in
187
+ # Activerecord::Base.establish_conection[http://ar.rubyonrails.com/classes/ActiveRecord/Base.html#M000370]
141
188
  def assert_database_not_present db_settings_hash
142
189
  update_activerecord_test_configuration db_settings_hash
143
190
 
@@ -162,12 +209,6 @@ class Test::Unit::TestCase
162
209
 
163
210
  end
164
211
 
165
- def update_activerecord_test_configuration db_settings_hash
166
- unless db_settings_hash.nil?
167
- ActiveRecord::Base.configurations.update("test" => db_settings_hash)
168
- end
169
- end
170
-
171
212
  def assert_file_present file
172
213
  error = build_message error,
173
214
  "? not found",
@@ -185,8 +226,34 @@ class Test::Unit::TestCase
185
226
  !File.exists?(file)
186
227
  end
187
228
  end
229
+
230
+ # Builds a message[link:/classes/Adaptation/Message.html] from a xml fixture
231
+ # file and processes it the same way mesages from the mom are processed by
232
+ # adaptation, but using a test environment. Published messages will be
233
+ # published to a mock MOM.
234
+ def message message_symbol
235
+ # build a message object from fixture
236
+ message_xml, message_object = load_message_fixture message_symbol
237
+
238
+ # load mock objects
239
+ Dir["test/mocks/test/*.rb"].each do |f|
240
+ require f
241
+ end
188
242
 
189
- def get_message_fixture fixture_name
243
+ # clean mom (delete mom.txt file)
244
+ mom_mock_file = 'test/mocks/test/mom.txt'
245
+ if File.exists? mom_mock_file
246
+ File.delete mom_mock_file
247
+ end
248
+
249
+ # process message
250
+ @adaptor.process message_object
251
+
252
+ end
253
+
254
+ private
255
+
256
+ def get_message_fixture fixture_name #:nodoc:
190
257
  fixture_file = ADAPTOR_ROOT + '/test/fixtures/' + fixture_name + '.xml'
191
258
  fixture_contents = ""
192
259
  File.open(fixture_file).each { |line|
@@ -197,7 +264,7 @@ class Test::Unit::TestCase
197
264
  fixture_contents.chomp
198
265
  end
199
266
 
200
- def load_message_fixture fixture_symbol
267
+ def load_message_fixture fixture_symbol #:nodoc:
201
268
  data = get_message_fixture(fixture_symbol.to_s)
202
269
  class_name = self.class.to_s.gsub("Test", "")
203
270
  class_name = class_name.gsub("Adaptor", "")
@@ -205,8 +272,8 @@ class Test::Unit::TestCase
205
272
  message_object = message_class.to_object(data)
206
273
  [data, message_object]
207
274
  end
208
-
209
- def get_class_object(searched_class)
275
+
276
+ def get_class_object(searched_class) #:nodoc:
210
277
  class_object = nil
211
278
  ObjectSpace.each_object(Class){|aClass|
212
279
  class_object = aClass if aClass.to_s == searched_class
@@ -218,27 +285,7 @@ class Test::Unit::TestCase
218
285
  end
219
286
  end
220
287
 
221
- def message message_symbol
222
- # build a message object from fixture
223
- message_xml, message_object = load_message_fixture message_symbol
224
-
225
- # load mock objects
226
- Dir["test/mocks/test/*.rb"].each do |f|
227
- require f
228
- end
229
-
230
- # clean mom (delete mom.txt file)
231
- mom_mock_file = 'test/mocks/test/mom.txt'
232
- if File.exists? mom_mock_file
233
- File.delete mom_mock_file
234
- end
235
-
236
- # process message
237
- @adaptor.process message_object
238
-
239
- end
240
-
241
- def compare_xml_elements element1, element2
288
+ def compare_xml_elements element1, element2 #:nodoc:
242
289
  if element1.has_attributes?
243
290
  if !elements2.has_attributes?
244
291
  return false
@@ -279,4 +326,10 @@ class Test::Unit::TestCase
279
326
  return true
280
327
  end
281
328
 
329
+ def update_activerecord_test_configuration db_settings_hash #:nodoc:
330
+ unless db_settings_hash.nil?
331
+ ActiveRecord::Base.configurations.update("test" => db_settings_hash)
332
+ end
333
+ end
334
+
282
335
  end
@@ -6,7 +6,7 @@ class MessageGenerator < Rails::Generator::NamedBase
6
6
  m.class_collisions class_path, class_name, "#{class_name}Test"
7
7
 
8
8
  # Model, test, and fixture directories.
9
- m.directory File.join('app/mmessages', class_path)
9
+ m.directory File.join('app/messages', class_path)
10
10
  m.directory File.join('test/unit', class_path)
11
11
  m.directory File.join('test/fixtures', class_path)
12
12
 
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: adaptation
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
6
+ version: 0.0.2
7
7
  date: 2007-04-30 00:00:00 +02:00
8
8
  summary: Framework to facilitate web-application interaction.
9
9
  require_paths: