ass_tests 1.0.0.alpha

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.
@@ -0,0 +1,50 @@
1
+ module AssTest
2
+ module OleFixt
3
+ class Abstract
4
+ attr_reader :ole_connector
5
+ def initialize(ole_connector)
6
+ @ole_connector = ole_connector
7
+ end
8
+
9
+ def fill(obj, **fields)
10
+ fields.each do |f, v|
11
+ obj.send("#{f}=".to_sym, v)
12
+ end
13
+ obj
14
+ end
15
+ private :fill
16
+
17
+ def fill_table(obj, table_name, rows = [])
18
+ table = obj.send(table_name.to_sym)
19
+ rows.each do |row|
20
+ fill(table.add, **row)
21
+ end
22
+ table
23
+ end
24
+ private :fill_table
25
+ end
26
+ def self.catalog(ole_connector)
27
+ Catalog.new(ole_connector)
28
+ end
29
+ class Catalog < Abstract
30
+ def new_(method, md_name, fields, tables)
31
+ r = ole_connector.catalogs.send(md_name.to_sym).send(method)
32
+ fill(r, fields)
33
+ tables.each do |table, rows|
34
+ fill_table(r, table, rows)
35
+ end
36
+ fill(r, fields)
37
+ yield r if block_given?
38
+ r.write
39
+ r.ref
40
+ end
41
+ private :new_
42
+ def new_item(md_name, fields = {}, tables = {}, &block)
43
+ new_(:createItem, md_name, fields, tables, &block)
44
+ end
45
+ def new_folder(md_name, fields = {}, tables = {}, &block)
46
+ new_(:createFolder, md_name, fields, tables, &block)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,341 @@
1
+ module AssTests
2
+ module InfoBases
3
+ require 'ass_tests/info_bases/info_base'
4
+ module DSL
5
+ module Describer
6
+ class AbstractDescriber
7
+ def ib(&block)
8
+ instance_eval(&block) if block_given?
9
+ InfoBase.new(ib_name, connection_string, external?, options)
10
+ end
11
+
12
+ def external?
13
+ instance_of? ExternalIb
14
+ end
15
+ end
16
+
17
+ module DescribeOptions
18
+ def options
19
+ @options ||= InfoBase.ALL_OPTIONS.clone
20
+ end
21
+
22
+ def method_missing(method, *args)
23
+ if options.key? method
24
+ options[method] = args[0]
25
+ else
26
+ fail NoMethodError, method.to_s
27
+ end
28
+ end
29
+ end
30
+
31
+ class ExternalIb < AbstractDescriber
32
+ include DescribeOptions
33
+
34
+ attr_reader :ib_name, :connection_string
35
+
36
+ def initialize(ib_name, connection_string)
37
+ @ib_name = ib_name
38
+ @connection_string = AssLauncher::Support::ConnectionString\
39
+ .new(connection_string.to_s)
40
+ end
41
+ end
42
+
43
+ module CommonDescriber
44
+ attr_reader :ib_name, :connection_string
45
+ alias_method :cs, :connection_string
46
+
47
+ private :connection_string, :cs
48
+ def initialize(ib_name)
49
+ @ib_name = ib_name
50
+ @connection_string = init_connection_string
51
+ end
52
+
53
+ def user(value)
54
+ cs.usr = value
55
+ end
56
+
57
+ def password(value)
58
+ cs.pwd = value
59
+ end
60
+
61
+ def locale(value)
62
+ cs.locale = value
63
+ end
64
+ end
65
+
66
+ class FileIb < AbstractDescriber
67
+ include CommonDescriber
68
+ include DescribeOptions
69
+
70
+ def directory(d)
71
+ cs.file = File.join(d, ib_name.to_s)
72
+ end
73
+
74
+ def init_connection_string
75
+ AssLauncher::Support::ConnectionString::File\
76
+ .new({file: default_path})
77
+ end
78
+ private :init_connection_string
79
+
80
+ def default_path
81
+ File.join(AssTests.config.test_infobase_directory, ib_name.to_s)
82
+ end
83
+ private :default_path
84
+ end
85
+
86
+ class ServerIb < AbstractDescriber
87
+ module Helpers
88
+ require 'shellwords'
89
+ require 'optparse'
90
+
91
+ module Parser
92
+ def options_help
93
+ options.to_a
94
+ end
95
+
96
+ def opts
97
+ @opts ||= OptionParser.new
98
+ end
99
+
100
+ def parse_str(str)
101
+ parse Shellwords.shellwords(str.to_s)
102
+ end
103
+
104
+ def presult
105
+ @presult ||= {}
106
+ end
107
+ private :presult
108
+ end
109
+
110
+ class ServerConnection
111
+ include AssMaintainer::InfoBase::ServerIb::EnterpriseServers::ServerConnection
112
+ extend Parser
113
+ def self.options
114
+ opts.on('-H', '--host HOST:PORT') do |v|
115
+ presult[:host_port] = v
116
+ end
117
+ opts.on('-U', '--user [USER_NAME]') do |v|
118
+ presult[:user] = v
119
+ end
120
+ opts.on('-P', '--password [PASSWORD]') do |v|
121
+ presult[:password] = v
122
+ end
123
+ opts
124
+ end
125
+
126
+ def self.parse(argv)
127
+ options.parse! argv
128
+ new presult[:host_port], presult[:user], presult[:password]
129
+ end
130
+ end
131
+
132
+ class AgentConnection < ServerConnection
133
+ def self.parse(argv)
134
+ super(argv).to_server_agent
135
+ end
136
+
137
+ def to_server_agent
138
+ AssMaintainer::InfoBase::ServerIb::EnterpriseServers::ServerAgent.new(host_port,
139
+ user,
140
+ password)
141
+ end
142
+ end
143
+
144
+ class ClasterConnection < ServerConnection
145
+ def fill_cs(cs)
146
+ cs.srvr = host_port.to_s
147
+ cs.susr = user
148
+ cs.spwd = password
149
+ end
150
+
151
+ def to_connstr
152
+ r = ""
153
+ r << "Srvr=\"#{host_port}\";"
154
+ r << "SUsr=\"#{user}\";" if user
155
+ r << "SPwd=\"#{password}\";" if password
156
+ r
157
+ end
158
+ end
159
+
160
+ class DbConnection < ServerConnection
161
+ def fill_cs(cs)
162
+ cs.dbsrvr = host_port.to_s
163
+ cs.dbuid = user
164
+ cs.dbpwd = password
165
+ end
166
+
167
+ def to_connstr
168
+ r = ""
169
+ r << "DBSrvr=\"#{host_port}\";"
170
+ r << "DBUID=\"#{user}\";" if user
171
+ r << "DBPwd=\"#{password}\";" if password
172
+ r
173
+ end
174
+ end
175
+
176
+ class Db < DbConnection
177
+ extend Parser
178
+ def self.options
179
+ opts = super
180
+ opts.on("-D" ,"--dbms [#{AssLauncher::Support::ConnectionString::\
181
+ Server::DBMS_VALUES.join(' | ')}]",
182
+ 'Type of DB for connection string') do |v|
183
+ presult[:dbms] = v
184
+ end
185
+ opts.on('-N','--db-name [DBNAME]','Name of databse') do |v|
186
+ presult[:name] = v
187
+ end
188
+ opts.on('-C','--create-db [Y|N]',
189
+ 'Crate databse if not exists. Default Y') do |v|
190
+ presult[:create_db] = v
191
+ end
192
+ opts
193
+ end
194
+
195
+ def self.parse(argv)
196
+ options.parse! argv
197
+ srv_conn = DbConnection.new(
198
+ presult[:host_port], presult[:user], presult[:password])
199
+ new presult[:name], srv_conn, presult[:dbms], presult[:create_db]
200
+ end
201
+
202
+ attr_reader :name, :srv_conn, :create_db, :dbms
203
+ def initialize(name, srv_conn, dbms, create_db)
204
+ fail ArgumentError, "DB name require" if name.to_s.empty?
205
+ fail ArgumentError unless srv_conn.instance_of? DbConnection
206
+ @name = name
207
+ @srv_conn = srv_conn
208
+ @dbms = dbms || fail(ArgumentError, "Require DBMS")
209
+ @create_db = create_db || 'Y'
210
+ end
211
+
212
+ def fill_cs(cs)
213
+ srv_conn.fill_cs(cs)
214
+ cs.db = name
215
+ cs.dbms = dbms
216
+ cs.crsqldb = create_db
217
+ end
218
+
219
+ def to_connstr
220
+ r = srv_conn.to_connstr
221
+ r << "DB=\"#{name}\";"
222
+ r << "DBMS=\"#{dbms}\";"
223
+ r << "CrSQLDB=\"#{create_db}\";" if create_db
224
+ r
225
+ end
226
+ end
227
+ end
228
+
229
+ include CommonDescriber
230
+ include DescribeOptions
231
+
232
+ def agent(str)
233
+ @agent = Helpers::AgentConnection.parse_str(str) unless str.to_s.empty?
234
+ end
235
+
236
+ def claster(str)
237
+ @claster = Helpers::ClasterConnection.parse_str(str)
238
+ @claster.fill_cs(cs)
239
+ end
240
+
241
+ def db(str)
242
+ @db = Helpers::Db.parse_str(str)
243
+ @db.fill_cs(cs)
244
+ end
245
+
246
+ def schjobdn
247
+ cs.schjobdn = 'Y'
248
+ end
249
+
250
+ def ib(&block)
251
+ ib = super
252
+ # FIXME: ib.server_agent = @agent || def_agent
253
+ ib
254
+ end
255
+
256
+ def init_connection_string
257
+ @connection_string = AssLauncher::Support::ConnectionString::Server\
258
+ .new({srvr: 'localhost:1540', ref: ib_name.to_s})
259
+ init_connections
260
+ @connection_string
261
+ end
262
+ private :init_connection_string
263
+
264
+ def def_db
265
+ @db ||= Helpers::Db\
266
+ .parse_str(AssTests.config.test_infobase_db\
267
+ + " --db-name #{ib_name}")
268
+ end
269
+ private :def_db
270
+
271
+ def def_agent
272
+ @agent ||= Helpers::AgentConnection\
273
+ .parse_str(AssTests.config.test_infobase_server_agent)
274
+ end
275
+ private :def_agent
276
+
277
+ def def_claster
278
+ @claster ||= Helpers::ClasterConnection\
279
+ .parse_str(AssTests.config.test_infobase_claster)
280
+ end
281
+ private :def_claster
282
+
283
+ def init_connections
284
+ def_db.fill_cs(cs)
285
+ def_claster.fill_cs(cs)
286
+ end
287
+ private :init_connections
288
+ end
289
+ end
290
+
291
+ def self.file(ib_name, &block)
292
+ Describer::FileIb.new(ib_name).ib(&block)
293
+ end
294
+
295
+ def self.server(ib_name, &block)
296
+ Describer::ServerIb.new(ib_name).ib(&block)
297
+ end
298
+
299
+ def self.external(ib_name, connection_string, &block)
300
+ Describer::ExternalIb.new(ib_name, connection_string).ib(&block)
301
+ end
302
+ end
303
+
304
+ def pull
305
+ @pull ||= {}
306
+ end
307
+ private :pull
308
+
309
+ def [](name)
310
+ fail ArgumentError, "InfoBase `#{name}' not discribed" unless\
311
+ pull.key? name
312
+ ib = pull[name]
313
+ ib.make unless ib.read_only?
314
+ fail 'External infobse must be exists' if ib.read_only? && !ib.exists?
315
+ ib
316
+ end
317
+
318
+ def describe(&block)
319
+ fail ArgumentError, 'Require block' unless block_given?
320
+ instance_eval(&block)
321
+ end
322
+
323
+ def add(ib)
324
+ fail ArgumentError, "Ib #{ib.name} already described" if pull.key? ib.name
325
+ pull[ib.name] = ib
326
+ end
327
+
328
+ def file(ib_name, &block)
329
+ add(DSL.file(ib_name, &block))
330
+ end
331
+
332
+ def server(ib_name, &block)
333
+ add(DSL.server(ib_name, &block))
334
+ end
335
+
336
+ def external(ib_name, connection_string, &block)
337
+ add(DSL.external(ib_name, connection_string, &block))
338
+ end
339
+ extend self
340
+ end
341
+ end
@@ -0,0 +1,143 @@
1
+ module AssTests
2
+ module InfoBases
3
+ require 'ass_maintainer/info_base'
4
+ class InfoBase < AssMaintainer::InfoBase
5
+ # see {#initialize}
6
+ OPTIONS = {
7
+ template: nil,
8
+ fixtures: nil,
9
+ }
10
+
11
+ OPTIONS.each_key do |key|
12
+ define_method key do
13
+ options[key]
14
+ end
15
+ end
16
+
17
+ def self.ALL_OPTIONS()
18
+ AssMaintainer::InfoBase::OPTIONS.merge OPTIONS
19
+ end
20
+
21
+ # @param name [String]
22
+ # @param connection_string [String AssLauncher::Support::ConnectionString]
23
+ # @param read_only [false true] flag for read_only infobase
24
+ # @option options [String #src_root] :template path to template like a
25
+ # +.cf+, +.dt+ file or dir of XML files. If respond to +#src_root+ then
26
+ # +#src_root+ must returns path to dir of XML files
27
+ # @option options [#call] :fixtures object for fill InfoBase data.
28
+ # Must hase method #call accepts {InfoBase} argumet
29
+ # @note +options+ may includes other options defined for
30
+ # +AssMaintainer::InfoBase+
31
+ def initialize(name, connection_string, read_only = true, **options)
32
+ super name, connection_string, read_only, **OPTIONS.merge(options)
33
+ end
34
+
35
+ attr_reader :template_loaded
36
+ alias_method :template_loaded?, :template_loaded
37
+
38
+ attr_reader :fixtures_loaded
39
+ alias_method :fixtures_loaded?, :fixtures_loaded
40
+
41
+ def built?
42
+ exists? && (template_loaded? || false) && (fixtures_loaded? || false)
43
+ end
44
+
45
+ def make_infobase!
46
+ super
47
+ load_template!
48
+ load_fixtures!
49
+ self
50
+ end
51
+ private :make_infobase!
52
+
53
+ def load_template!
54
+ fail AssMaintainer::InfoBase::MethodDenied, :load_template! if\
55
+ read_only?
56
+ load_template
57
+ @template_loaded = true
58
+ end
59
+
60
+ def load_fixtures!
61
+ fail AssMaintainer::InfoBase::MethodDenied, :load_fixtures! if\
62
+ read_only?
63
+ fixtures.call(self) if fixtures
64
+ @fixtures_loaded = true
65
+ end
66
+
67
+ def erase_data!
68
+ fail AssMaintainer::InfoBase::MethodDenied, :erase_data! if read_only?
69
+ designer do
70
+ eraseData
71
+ end.run.wait.result.verify!
72
+ true
73
+ end
74
+
75
+ def reload_fixtures!
76
+ erase_data!
77
+ load_fixtures!
78
+ end
79
+
80
+ # @api private
81
+ def template_type
82
+ return :cf if template_cf?
83
+ return :dt if template_dt?
84
+ return :src if template_src?
85
+ template.to_s
86
+ end
87
+
88
+ # @api private
89
+ def file_template?(ext)
90
+ template.to_s =~ %r{\.#{ext}\z} && File.file?(template.to_s)
91
+ end
92
+
93
+ # @api private
94
+ def template_cf?
95
+ file_template? 'cf'
96
+ end
97
+
98
+ # @api private
99
+ def template_dt?
100
+ file_template? 'dt'
101
+ end
102
+
103
+ # @api private
104
+ def template_src?
105
+ File.file?(File.join(src_root, 'Configuration.xml')) if src_root
106
+ end
107
+
108
+ def src_root
109
+ return template if template.is_a? String
110
+ return template.src_root if template.respond_to?(:src_root)
111
+ end
112
+ private :src_root
113
+
114
+ # @api private
115
+ def load_template
116
+ return unless template
117
+ case template_type
118
+ when :cf then load_cf
119
+ when :dt then load_dt
120
+ when :src then load_src
121
+ else
122
+ fail "Invalid template: #{template}"
123
+ end
124
+ template_type
125
+ end
126
+
127
+ # @api private
128
+ def load_src
129
+ cfg.load_xml(src_root) && db_cfg.update
130
+ end
131
+
132
+ # @api private
133
+ def load_dt
134
+ restore!(template)
135
+ end
136
+
137
+ # @api private
138
+ def load_cf
139
+ cfg.load(template) && db_cfg.update
140
+ end
141
+ end
142
+ end
143
+ end