libis-tools 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.travis.yml +37 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +289 -0
- data/Rakefile +6 -0
- data/lib/libis-tools.rb +1 -0
- data/lib/libis/tools.rb +16 -0
- data/lib/libis/tools/assert.rb +41 -0
- data/lib/libis/tools/checksum.rb +84 -0
- data/lib/libis/tools/command.rb +40 -0
- data/lib/libis/tools/config.rb +160 -0
- data/lib/libis/tools/dc_record.rb +47 -0
- data/lib/libis/tools/extend/empty.rb +7 -0
- data/lib/libis/tools/extend/hash.rb +107 -0
- data/lib/libis/tools/extend/ostruct.rb +3 -0
- data/lib/libis/tools/extend/string.rb +85 -0
- data/lib/libis/tools/extend/struct.rb +29 -0
- data/lib/libis/tools/logger.rb +71 -0
- data/lib/libis/tools/mets_file.rb +575 -0
- data/lib/libis/tools/parameter.rb +172 -0
- data/lib/libis/tools/sharepoint_mapping.rb +118 -0
- data/lib/libis/tools/sharepoint_record.rb +260 -0
- data/lib/libis/tools/version.rb +5 -0
- data/lib/libis/tools/xml_document.rb +574 -0
- data/libis-tools.gemspec +39 -0
- data/spec/assert_spec.rb +65 -0
- data/spec/checksum_spec.rb +132 -0
- data/spec/command_spec.rb +68 -0
- data/spec/config_spec.rb +86 -0
- data/spec/data/test.data +9 -0
- data/spec/data/test.xml +8 -0
- data/spec/data/test.yml +1 -0
- data/spec/logger_spec.rb +107 -0
- data/spec/parameter_container_spec.rb +83 -0
- data/spec/parameter_spec.rb +139 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/test.xsd +20 -0
- data/spec/xmldocument_spec.rb +413 -0
- data/test/test_helper.rb +7 -0
- data/test/webservices/test_ca_item_info.rb +59 -0
- data/test/webservices/test_ca_search.rb +35 -0
- metadata +244 -0
data/libis-tools.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'libis/tools/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'libis-tools'
|
10
|
+
spec.version = ::Libis::Tools::VERSION
|
11
|
+
spec.date = Date.today.to_s
|
12
|
+
|
13
|
+
spec.summary = %q{LIBIS toolbox.}
|
14
|
+
spec.description = %q{Some tool classes for other LIBIS gems.}
|
15
|
+
|
16
|
+
spec.authors = ['Kris Dekeyser']
|
17
|
+
spec.email = ['kris.dekeyser@libis.be']
|
18
|
+
spec.homepage = 'https://github.com/Kris-LIBIS/LIBIS_Tools'
|
19
|
+
spec.license = 'MIT'
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0")
|
22
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
|
+
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.3'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
30
|
+
spec.add_development_dependency 'simplecov', '~> 0.9'
|
31
|
+
spec.add_development_dependency 'equivalent-xml', '~> 0.5'
|
32
|
+
|
33
|
+
spec.add_runtime_dependency 'backports', '~> 3.6'
|
34
|
+
spec.add_runtime_dependency 'savon', '~> 2.0'
|
35
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6'
|
36
|
+
spec.add_runtime_dependency 'gyoku', '~> 1.2'
|
37
|
+
spec.add_runtime_dependency 'nori', '~> 2.4'
|
38
|
+
|
39
|
+
end
|
data/spec/assert_spec.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
require 'libis/tools/assert'
|
4
|
+
|
5
|
+
describe 'Assert' do
|
6
|
+
|
7
|
+
before :example do
|
8
|
+
$DEBUG = true
|
9
|
+
end
|
10
|
+
|
11
|
+
after :example do
|
12
|
+
$DEBUG = false
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should throw an assert exception when statement is false' do
|
16
|
+
|
17
|
+
message = 'Testing the assert with false.'
|
18
|
+
expect {
|
19
|
+
assert(false, message)
|
20
|
+
}.to raise_error(AssertionFailure, message)
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should only throw an assert in debug mode' do
|
25
|
+
|
26
|
+
$DEBUG = false
|
27
|
+
expect {
|
28
|
+
assert(false, 'Testing the assert with false.')
|
29
|
+
}.to_not raise_error
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should not throw an assert if statement is true' do
|
34
|
+
|
35
|
+
expect {
|
36
|
+
assert(true, 'Testing the assert with true.')
|
37
|
+
}.to_not raise_error
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should throw an assert on nil' do
|
42
|
+
|
43
|
+
message = 'Testing the assert with nil.'
|
44
|
+
expect {
|
45
|
+
assert(nil, message)
|
46
|
+
}.to raise_error(AssertionFailure, message)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should check the given block if present' do
|
50
|
+
|
51
|
+
message = 'block test'
|
52
|
+
expect {
|
53
|
+
assert(message) do
|
54
|
+
false
|
55
|
+
end
|
56
|
+
}.to raise_error(AssertionFailure, message)
|
57
|
+
|
58
|
+
expect {
|
59
|
+
assert(message) do
|
60
|
+
true
|
61
|
+
end
|
62
|
+
}.to_not raise_error
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
require 'libis/tools/checksum'
|
4
|
+
|
5
|
+
describe 'Checksum' do
|
6
|
+
|
7
|
+
file = File.absolute_path(File.join(File.dirname(__FILE__), 'data', 'test.data'))
|
8
|
+
|
9
|
+
def hex2base64(hexdigest)
|
10
|
+
[[hexdigest].pack('H*')].pack('m0')
|
11
|
+
end
|
12
|
+
|
13
|
+
def hex2string(hexdigest)
|
14
|
+
[hexdigest].pack('H*')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should calculate MD5 checksum' do
|
18
|
+
|
19
|
+
checksum_type = :MD5
|
20
|
+
digest = 'fe249d8dd45a39793f315fb0734ffe2c'
|
21
|
+
expect(::Libis::Tools::Checksum.hexdigest(file, checksum_type)).to eq digest
|
22
|
+
expect(::Libis::Tools::Checksum.base64digest(file, checksum_type)).to eq hex2base64(digest)
|
23
|
+
expect(::Libis::Tools::Checksum.digest(file, checksum_type)).to eq hex2string(digest)
|
24
|
+
|
25
|
+
checksum = ::Libis::Tools::Checksum.new(checksum_type)
|
26
|
+
|
27
|
+
expect(checksum.hexdigest(file)).to eq digest
|
28
|
+
expect(checksum.base64digest(file)).to eq hex2base64(digest)
|
29
|
+
expect(checksum.digest(file)).to eq hex2string(digest)
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should calculate RMD160 checksum' do
|
34
|
+
|
35
|
+
unless defined? JRUBY_VERSION
|
36
|
+
|
37
|
+
checksum_type = :RMD160
|
38
|
+
|
39
|
+
digest = '17c9eaad9ccbaad0e030c2c5d60fd9d58255cc39'
|
40
|
+
expect(::Libis::Tools::Checksum.hexdigest(file, checksum_type)).to eq digest
|
41
|
+
expect(::Libis::Tools::Checksum.base64digest(file, checksum_type)).to eq hex2base64(digest)
|
42
|
+
expect(::Libis::Tools::Checksum.digest(file, checksum_type)).to eq hex2string(digest)
|
43
|
+
|
44
|
+
checksum = ::Libis::Tools::Checksum.new(checksum_type)
|
45
|
+
|
46
|
+
expect(checksum.hexdigest(file)).to eq digest
|
47
|
+
expect(checksum.base64digest(file)).to eq hex2base64(digest)
|
48
|
+
expect(checksum.digest(file)).to eq hex2string(digest)
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should calculate SHA1 checksum' do
|
55
|
+
|
56
|
+
checksum_type = :SHA1
|
57
|
+
|
58
|
+
digest = 'e8f322d186699807a98a0cefb5015acf1554f954'
|
59
|
+
expect(::Libis::Tools::Checksum.hexdigest(file, checksum_type)).to eq digest
|
60
|
+
expect(::Libis::Tools::Checksum.base64digest(file, checksum_type)).to eq hex2base64(digest)
|
61
|
+
expect(::Libis::Tools::Checksum.digest(file, checksum_type)).to eq hex2string(digest)
|
62
|
+
|
63
|
+
checksum = ::Libis::Tools::Checksum.new(checksum_type)
|
64
|
+
|
65
|
+
expect(checksum.hexdigest(file)).to eq digest
|
66
|
+
expect(checksum.base64digest(file)).to eq hex2base64(digest)
|
67
|
+
expect(checksum.digest(file)).to eq hex2string(digest)
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should calculate SHA256 checksum' do
|
72
|
+
|
73
|
+
checksum_type = :SHA256
|
74
|
+
|
75
|
+
digest = '2a742e643dd79427738bdc0ebd0d2837f998fe2101a964c2d5014905d331bbc4'
|
76
|
+
expect(::Libis::Tools::Checksum.hexdigest(file, checksum_type)).to eq digest
|
77
|
+
expect(::Libis::Tools::Checksum.base64digest(file, checksum_type)).to eq hex2base64(digest)
|
78
|
+
expect(::Libis::Tools::Checksum.digest(file, checksum_type)).to eq hex2string(digest)
|
79
|
+
|
80
|
+
checksum = ::Libis::Tools::Checksum.new(checksum_type)
|
81
|
+
|
82
|
+
expect(checksum.hexdigest(file)).to eq digest
|
83
|
+
expect(checksum.base64digest(file)).to eq hex2base64(digest)
|
84
|
+
expect(checksum.digest(file)).to eq hex2string(digest)
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should calculate SHA384 checksum' do
|
89
|
+
|
90
|
+
checksum_type = :SHA384
|
91
|
+
|
92
|
+
digest = '71083b74394f49db6149ad9147103f7693ec823183750ce32a2215bbd7ee5e75212e2d794243c7e76c7318a4ddcf9a56'
|
93
|
+
expect(::Libis::Tools::Checksum.hexdigest(file, checksum_type)).to eq digest
|
94
|
+
expect(::Libis::Tools::Checksum.base64digest(file, checksum_type)).to eq hex2base64(digest)
|
95
|
+
expect(::Libis::Tools::Checksum.digest(file, checksum_type)).to eq hex2string(digest)
|
96
|
+
|
97
|
+
checksum = ::Libis::Tools::Checksum.new(checksum_type)
|
98
|
+
|
99
|
+
expect(checksum.hexdigest(file)).to eq digest
|
100
|
+
expect(checksum.base64digest(file)).to eq hex2base64(digest)
|
101
|
+
expect(checksum.digest(file)).to eq hex2string(digest)
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should calculate SHA512 checksum' do
|
106
|
+
|
107
|
+
checksum_type = :SHA512
|
108
|
+
|
109
|
+
digest = '10964f5272729c2670ccad67754284fb06cca1387270c184c2edbcd032700548297916c8e109a10e019c25b86c646e95a3456c465f83d571502889f97b483e6f'
|
110
|
+
expect(::Libis::Tools::Checksum.hexdigest(file, checksum_type)).to eq digest
|
111
|
+
expect(::Libis::Tools::Checksum.base64digest(file, checksum_type)).to eq hex2base64(digest)
|
112
|
+
expect(::Libis::Tools::Checksum.digest(file, checksum_type)).to eq hex2string(digest)
|
113
|
+
|
114
|
+
checksum = ::Libis::Tools::Checksum.new(checksum_type)
|
115
|
+
|
116
|
+
expect(checksum.hexdigest(file)).to eq digest
|
117
|
+
expect(checksum.base64digest(file)).to eq hex2base64(digest)
|
118
|
+
expect(checksum.digest(file)).to eq hex2string(digest)
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should not know how to calculate ABC checksum' do
|
123
|
+
|
124
|
+
checksum_type = :ABC
|
125
|
+
|
126
|
+
expect {
|
127
|
+
::Libis::Tools::Checksum.hexdigest(file, checksum_type)
|
128
|
+
}.to raise_error(RuntimeError, "Checksum type 'ABC' not supported.")
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
require 'libis/tools/command'
|
4
|
+
|
5
|
+
describe 'Command' do
|
6
|
+
|
7
|
+
around(:example) do |test|
|
8
|
+
dir = Dir.pwd
|
9
|
+
Dir.chdir(File.join(File.dirname(__FILE__),'data'))
|
10
|
+
test.run
|
11
|
+
Dir.chdir(dir)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should run ls command' do
|
15
|
+
|
16
|
+
result = Libis::Tools::Command.run('ls')
|
17
|
+
|
18
|
+
expect(result[:out]).to eq %w'test.data test.xml test.yml'
|
19
|
+
expect(result[:err]).to eq []
|
20
|
+
expect(result[:status]).to eq 0
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should run ls command with an option' do
|
25
|
+
|
26
|
+
result = Libis::Tools::Command.run('ls', '-l')
|
27
|
+
|
28
|
+
output = result[:out]
|
29
|
+
expect(output.size).to eq 4
|
30
|
+
expect(output.first).to match /^total \d+$/
|
31
|
+
expect(output[1]).to match /^-[rwx-]{9}.+test.data$/
|
32
|
+
expect(output[2]).to match /^-[rwx-]{9}.+test.xml$/
|
33
|
+
expect(output[3]).to match /^-[rwx-]{9}.+test.yml$/
|
34
|
+
|
35
|
+
expect(result[:err]).to eq []
|
36
|
+
expect(result[:status]).to eq 0
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should run ls command with multiple options' do
|
41
|
+
|
42
|
+
result = Libis::Tools::Command.run('ls', '-l', '-a', '-p')
|
43
|
+
|
44
|
+
output = result[:out]
|
45
|
+
expect(output.size).to eq 6
|
46
|
+
expect(output.first).to match /^total \d+$/
|
47
|
+
expect(output[1]).to match /^d[rwx-]{9}.+\d+.+\.\/$/
|
48
|
+
expect(output[2]).to match /^d[rwx-]{9}.+\d+.+\.\.\/$/
|
49
|
+
expect(output[3]).to match /^-[rwx-]{9}.+test.data$/
|
50
|
+
expect(output[4]).to match /^-[rwx-]{9}.+test.xml$/
|
51
|
+
expect(output[5]).to match /^-[rwx-]{9}.+test.yml$/
|
52
|
+
|
53
|
+
expect(result[:err]).to eq []
|
54
|
+
expect(result[:status]).to eq 0
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should capture error output and status' do
|
59
|
+
|
60
|
+
result = Libis::Tools::Command.run('ls', 'abc')
|
61
|
+
expect(result[:out]).to eq []
|
62
|
+
expect(result[:err].size).to eq 1
|
63
|
+
expect(result[:err][0]).to match /ls: cannot access abc: No such file or directory/
|
64
|
+
expect(result[:status]).to eq 2
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
require 'libis/tools/config'
|
4
|
+
|
5
|
+
describe 'Config' do
|
6
|
+
|
7
|
+
test_file = File.join(File.dirname(__FILE__), 'data', 'test.yml')
|
8
|
+
config = ::Libis::Tools::Config
|
9
|
+
config << { appname: 'LIBIS Default' }
|
10
|
+
|
11
|
+
it 'should initialize' do
|
12
|
+
expect(config.appname).to eq 'LIBIS Default'
|
13
|
+
expect(config.logger).to be_a ::Logger
|
14
|
+
end
|
15
|
+
|
16
|
+
# noinspection RubyResolve
|
17
|
+
it 'should define setters' do
|
18
|
+
config[:test_value] = 5
|
19
|
+
expect(config.test_value).to eq 5
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should load from file' do
|
23
|
+
config << test_file
|
24
|
+
expect(config.process).to eq 'Test Configuration'
|
25
|
+
end
|
26
|
+
|
27
|
+
# noinspection RubyResolve
|
28
|
+
it 'should allow to set and get in different ways' do
|
29
|
+
config.test_value = 10
|
30
|
+
expect(config.test_value).to be 10
|
31
|
+
expect(config['test_value']).to be 10
|
32
|
+
expect(config[:test_value]).to be 10
|
33
|
+
expect(config.instance.test_value).to be 10
|
34
|
+
expect(config.instance['test_value']).to be 10
|
35
|
+
expect(config.instance[:test_value]).to be 10
|
36
|
+
|
37
|
+
config[:test_value] = 11
|
38
|
+
expect(config.test_value).to be 11
|
39
|
+
expect(config['test_value']).to be 11
|
40
|
+
expect(config[:test_value]).to be 11
|
41
|
+
expect(config.instance.test_value).to be 11
|
42
|
+
expect(config.instance['test_value']).to be 11
|
43
|
+
expect(config.instance[:test_value]).to be 11
|
44
|
+
|
45
|
+
config['test_value'] = 12
|
46
|
+
expect(config.test_value).to be 12
|
47
|
+
expect(config['test_value']).to be 12
|
48
|
+
expect(config[:test_value]).to be 12
|
49
|
+
expect(config.instance.test_value).to be 12
|
50
|
+
expect(config.instance['test_value']).to be 12
|
51
|
+
expect(config.instance[:test_value]).to be 12
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should allow to set and get on class and instance' do
|
55
|
+
expect(config.appname).to be config.instance.appname
|
56
|
+
expect(config['appname']).to be config.instance.appname
|
57
|
+
expect(config[:appname]).to be config.instance.appname
|
58
|
+
expect(config.instance['appname']).to be config.instance.appname
|
59
|
+
expect(config.instance[:appname]).to be config.instance.appname
|
60
|
+
|
61
|
+
config.instance[:appname] = 'Test App'
|
62
|
+
expect(config.appname).to be == 'Test App'
|
63
|
+
end
|
64
|
+
|
65
|
+
# noinspection RubyResolve
|
66
|
+
it 'should reset only values loaded from file' do
|
67
|
+
config[:appname] = 'foo'
|
68
|
+
config[:process] = 'bar'
|
69
|
+
config[:baz] = 'qux'
|
70
|
+
|
71
|
+
expect(config.appname).to eq 'foo'
|
72
|
+
expect(config.process).to eq 'bar'
|
73
|
+
expect(config.baz).to eq 'qux'
|
74
|
+
|
75
|
+
config.reload
|
76
|
+
expect(config.appname).to eq 'LIBIS Default'
|
77
|
+
expect(config.process).to eq 'Test Configuration'
|
78
|
+
expect(config.baz).to eq 'qux'
|
79
|
+
|
80
|
+
config.reload!
|
81
|
+
expect(config.appname).to eq 'LIBIS Default'
|
82
|
+
expect(config.process).to eq 'Test Configuration'
|
83
|
+
expect(config.baz).to be_nil
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
data/spec/data/test.data
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ultricies condimentum suscipit. Sed nec suscipit sapien. Nullam eget magna fringilla, dignissim justo quis, eleifend sapien. Maecenas quis euismod nunc. Etiam aliquam tellus quis urna pretium ornare. Cras placerat, magna imperdiet vestibulum molestie, sem ante bibendum tortor, nec dapibus augue ligula dictum mauris. In nibh lacus, pellentesque nec posuere non, lacinia et diam. Aliquam dictum, augue sed finibus feugiat, lorem arcu ullamcorper metus, non commodo metus neque sit amet elit. Suspendisse id arcu consequat, euismod leo id, tempus velit. Ut diam leo, pulvinar sed nulla nec, volutpat suscipit ligula. Vestibulum ac erat mauris. Quisque posuere lacus a rutrum faucibus. Sed convallis risus vel congue scelerisque. Vestibulum nec nunc eu massa imperdiet sagittis.
|
2
|
+
|
3
|
+
Praesent quis felis congue, consequat odio vitae, rhoncus turpis. Suspendisse potenti. Donec rutrum leo vitae ex imperdiet molestie. Vivamus efficitur mi vitae sem porta, vel pretium lacus auctor. Maecenas ac finibus quam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vestibulum magna metus, commodo ac ligula vestibulum, aliquet volutpat lacus. Curabitur faucibus nec erat et laoreet. Suspendisse bibendum a tortor non mattis.
|
4
|
+
|
5
|
+
Curabitur odio turpis, tempus in accumsan aliquet, convallis in elit. Nullam in iaculis turpis, nec pulvinar urna. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Integer mattis erat id auctor ultrices. In placerat euismod elit maximus accumsan. Nullam et enim consectetur, interdum libero sit amet, rutrum risus. Donec eleifend nec erat vel tincidunt. Maecenas pellentesque malesuada fermentum. Cras nisi dolor, dictum eu sagittis quis, consectetur suscipit mi. Cras metus ipsum, porttitor sit amet dignissim id, condimentum eget nunc. Suspendisse potenti.
|
6
|
+
|
7
|
+
Fusce ante ipsum, tincidunt eget mollis sagittis, consectetur ut ligula. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam augue felis, dictum eget felis non, euismod pharetra libero. Nunc bibendum sollicitudin est vel vulputate. Maecenas et convallis erat. Nullam rutrum molestie justo, sit amet vulputate ligula commodo a. Quisque quis neque id ex sodales aliquam ac id nulla. Nunc ut ligula ut augue placerat vulputate. Donec sed volutpat nibh, et aliquam sapien. Quisque scelerisque et augue faucibus venenatis. Sed viverra, mi ut vestibulum egestas, ante metus pulvinar justo, at aliquet enim nulla eu elit. Aliquam malesuada lectus in tellus euismod, id semper metus tristique.
|
8
|
+
|
9
|
+
Pellentesque tincidunt nisl ac dolor ornare feugiat. Vivamus dignissim iaculis nunc. Suspendisse et odio velit. Vivamus urna odio, tincidunt id elementum sit amet, dictum vel tortor. Vivamus rutrum magna at nibh sodales, eu venenatis lorem malesuada. Sed bibendum eros eros, vitae aliquam nunc iaculis ac. Maecenas facilisis ipsum in tellus ultricies ornare. Integer finibus eget ante eu consectetur. Nullam rutrum nunc quis sollicitudin pellentesque.
|
data/spec/data/test.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<patron>
|
3
|
+
<name>Harry Potter</name>
|
4
|
+
<barcode library="Hogwarts Library">1234567890</barcode>
|
5
|
+
<access_level>student</access_level>
|
6
|
+
<email>harry.potter@hogwarts.edu</email>
|
7
|
+
<email>hpotter@JKRowling.com</email>
|
8
|
+
</patron>
|
data/spec/data/test.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
process: 'Test Configuration'
|
data/spec/logger_spec.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
require 'libis/tools/config'
|
4
|
+
require 'libis/tools/logger'
|
5
|
+
|
6
|
+
describe 'Logger' do
|
7
|
+
|
8
|
+
class TestLogger
|
9
|
+
include ::Libis::Tools::Logger
|
10
|
+
attr_accessor :options
|
11
|
+
def initialize
|
12
|
+
@options = {}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
before(:context) do
|
17
|
+
end
|
18
|
+
|
19
|
+
before(:example) do
|
20
|
+
::Libis::Tools::Config[:appname] = ''
|
21
|
+
@logoutput = StringIO.new
|
22
|
+
::Libis::Tools::Config.logger = ::Logger.new @logoutput
|
23
|
+
::Libis::Tools::Config.logger.level = ::Logger::DEBUG
|
24
|
+
@test_logger = TestLogger.new
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should log debug output' do
|
28
|
+
@test_logger.debug 'Debug message'
|
29
|
+
output = @logoutput.string.lines.map(&:chomp)
|
30
|
+
expect(output.size).to eq 1
|
31
|
+
expect(output.first).to match /^D, \[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6} #\d+\] DEBUG -- TestLogger: Debug message$/
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should log info output' do
|
35
|
+
@test_logger.info 'Info message'
|
36
|
+
output = @logoutput.string.lines.map(&:chomp)
|
37
|
+
expect(output.size).to eq 1
|
38
|
+
expect(output.first).to match /^I, \[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6} #\d+\] INFO -- TestLogger: Info message$/
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should log warning output' do
|
42
|
+
@test_logger.warn 'Warning message'
|
43
|
+
output = @logoutput.string.lines.map(&:chomp)
|
44
|
+
expect(output.size).to eq 1
|
45
|
+
expect(output.first).to match /^W, \[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6} #\d+\] WARN -- TestLogger: Warning message$/
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should log error output' do
|
49
|
+
@test_logger.error 'Error message'
|
50
|
+
output = @logoutput.string.lines.map(&:chomp)
|
51
|
+
expect(output.size).to eq 1
|
52
|
+
expect(output.first).to match /^E, \[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6} #\d+\] ERROR -- TestLogger: Error message$/
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should log fatal output' do
|
56
|
+
@test_logger.fatal 'Fatal message'
|
57
|
+
output = @logoutput.string.lines.map(&:chomp)
|
58
|
+
expect(output.size).to eq 1
|
59
|
+
expect(output.first).to match /^F, \[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6} #\d+\] FATAL -- TestLogger: Fatal message$/
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should be quiet when asked to' do
|
63
|
+
@test_logger.options[:quiet] = true
|
64
|
+
|
65
|
+
@test_logger.debug 'Debug message'
|
66
|
+
output = @logoutput.string.lines.map(&:chomp)
|
67
|
+
# noinspection RubyResolve
|
68
|
+
expect(output).to be_empty
|
69
|
+
|
70
|
+
@test_logger.info 'Info message'
|
71
|
+
output = @logoutput.string.lines.map(&:chomp)
|
72
|
+
# noinspection RubyResolve
|
73
|
+
expect(output).to be_empty
|
74
|
+
|
75
|
+
@test_logger.warn 'Warn message'
|
76
|
+
output = @logoutput.string.lines.map(&:chomp)
|
77
|
+
# noinspection RubyResolve
|
78
|
+
expect(output).to be_empty
|
79
|
+
|
80
|
+
@test_logger.error 'Error message'
|
81
|
+
output = @logoutput.string.lines.map(&:chomp)
|
82
|
+
# noinspection RubyResolve
|
83
|
+
expect(output).not_to be_empty
|
84
|
+
|
85
|
+
@test_logger.fatal 'Fatal message'
|
86
|
+
output = @logoutput.string.lines.map(&:chomp)
|
87
|
+
# noinspection RubyResolve
|
88
|
+
expect(output).not_to be_empty
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should display application name in log' do
|
92
|
+
::Libis::Tools::Config[:appname] = 'Test Application'
|
93
|
+
@test_logger.info 'Info message'
|
94
|
+
output = @logoutput.string.lines.map(&:chomp)
|
95
|
+
expect(output.size).to eq 1
|
96
|
+
expect(output.first).to match /^I, \[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6} #\d+\] INFO -- Test Application: Info message$/
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should display name value in log' do
|
100
|
+
@test_logger.define_singleton_method(:name) { 'Logger for testing' }
|
101
|
+
@test_logger.info 'Info message'
|
102
|
+
output = @logoutput.string.lines.map(&:chomp)
|
103
|
+
expect(output.size).to eq 1
|
104
|
+
expect(output.first).to match /^I, \[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6} #\d+\] INFO -- Logger for testing: Info message$/
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|