burlap 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +38 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +16 -0
- data/Rakefile +31 -0
- data/burlap.gemspec +32 -0
- data/lib/active_support/ordered_hash.rb +179 -0
- data/lib/burlap/array.rb +18 -0
- data/lib/burlap/base_tag.rb +105 -0
- data/lib/burlap/call.rb +38 -0
- data/lib/burlap/core_ext/array.rb +7 -0
- data/lib/burlap/core_ext/boolean.rb +11 -0
- data/lib/burlap/core_ext/float.rb +5 -0
- data/lib/burlap/core_ext/hash.rb +5 -0
- data/lib/burlap/core_ext/integer.rb +10 -0
- data/lib/burlap/core_ext/nil.rb +5 -0
- data/lib/burlap/core_ext/object.rb +13 -0
- data/lib/burlap/core_ext/string.rb +5 -0
- data/lib/burlap/core_ext/symbol.rb +6 -0
- data/lib/burlap/core_ext/time.rb +5 -0
- data/lib/burlap/core_ext.rb +10 -0
- data/lib/burlap/default_resolver.rb +100 -0
- data/lib/burlap/error.rb +3 -0
- data/lib/burlap/fault.rb +6 -0
- data/lib/burlap/hash.rb +72 -0
- data/lib/burlap/listener.rb +34 -0
- data/lib/burlap/node.rb +48 -0
- data/lib/burlap/version.rb +3 -0
- data/lib/burlap.rb +47 -0
- data/lib/core_ext/time_burlap_iso8601.rb +32 -0
- data/spec/burlap/array_spec.rb +28 -0
- data/spec/burlap/call_spec.rb +126 -0
- data/spec/burlap/core_ext/array_spec.rb +123 -0
- data/spec/burlap/core_ext/class_spec.rb +24 -0
- data/spec/burlap/core_ext/false_class_spec.rb +17 -0
- data/spec/burlap/core_ext/float_spec.rb +15 -0
- data/spec/burlap/core_ext/hash_spec.rb +15 -0
- data/spec/burlap/core_ext/integer_spec.rb +28 -0
- data/spec/burlap/core_ext/nil_class_spec.rb +15 -0
- data/spec/burlap/core_ext/object_spec.rb +62 -0
- data/spec/burlap/core_ext/string_spec.rb +27 -0
- data/spec/burlap/core_ext/symbol_spec.rb +15 -0
- data/spec/burlap/core_ext/time_spec.rb +23 -0
- data/spec/burlap/core_ext/true_class_spec.rb +17 -0
- data/spec/burlap/default_resolver_spec.rb +140 -0
- data/spec/burlap/error_spec.rb +7 -0
- data/spec/burlap/hash_spec.rb +234 -0
- data/spec/burlap/listener_spec.rb +31 -0
- data/spec/burlap/node_spec.rb +39 -0
- data/spec/burlap_spec.rb +55 -0
- data/spec/data/no_such_method.burlap +1 -0
- data/spec/data/record_not_found.burlap +1 -0
- data/spec/spec_helper.rb +13 -0
- metadata +224 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Hash do
|
4
|
+
describe "#to_burlap" do
|
5
|
+
subject(:burlap) { { some: "hash" }.to_burlap }
|
6
|
+
|
7
|
+
it "returns a string" do
|
8
|
+
expect(burlap).to be_a_kind_of(String)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "is correct" do
|
12
|
+
expect(burlap).to eq("<map><type></type><string>some</string><string>hash</string></map>")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Integer do
|
4
|
+
describe "#to_burlap" do
|
5
|
+
# https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html
|
6
|
+
# maximum value an int can have, 2**31-1.
|
7
|
+
# minimum value an int can have, -2**31.
|
8
|
+
context "when within 32bit signed limits" do
|
9
|
+
it "encodes the Integer as 'int'" do
|
10
|
+
expect(5.to_burlap).to eq("<int>5</int>")
|
11
|
+
expect(-5.to_burlap).to eq("<int>-5</int>")
|
12
|
+
|
13
|
+
expect(2_147_483_647.to_burlap).to eq("<int>2147483647</int>")
|
14
|
+
expect(-2_147_483_648.to_burlap).to eq("<int>-2147483648</int>")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when outside 32bit signed limits" do
|
19
|
+
it "encodes the Integer as 'java.math.BigDecimal'" do
|
20
|
+
expect(2_147_483_648.to_burlap).to eq("<map><type>java.math.BigDecimal</type><string>value</string><string>2147483648</string></map>")
|
21
|
+
expect(-2_147_483_649.to_burlap).to eq("<map><type>java.math.BigDecimal</type><string>value</string><string>-2147483649</string></map>")
|
22
|
+
|
23
|
+
expect(999_999_999_999_999_999.to_burlap).to eq("<map><type>java.math.BigDecimal</type><string>value</string><string>999999999999999999</string></map>")
|
24
|
+
expect(-999_999_999_999_999_999.to_burlap).to eq("<map><type>java.math.BigDecimal</type><string>value</string><string>-999999999999999999</string></map>")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe NilClass do
|
4
|
+
describe "#to_burlap" do
|
5
|
+
subject(:burlap) { nil.to_burlap }
|
6
|
+
|
7
|
+
it "returns a string" do
|
8
|
+
expect(burlap).to be_a_kind_of(String)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "is correct" do
|
12
|
+
expect(burlap).to eq("<null></null>")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Object do
|
4
|
+
describe "#to_burlap" do
|
5
|
+
subject(:burlap) { described_class.new.to_burlap }
|
6
|
+
|
7
|
+
it "returns a string" do
|
8
|
+
expect(burlap).to be_a_kind_of(String)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "invokes Burlap::Hash with type of classname" do
|
12
|
+
hash = instance_double(Burlap::Hash)
|
13
|
+
expect(Burlap::Hash).to receive(:[]).with([], "Object").and_return(hash)
|
14
|
+
expect(hash).to receive(:to_burlap).and_return("<my>xml</my>")
|
15
|
+
|
16
|
+
expect(burlap).to eq("<my>xml</my>")
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with instance variables" do
|
20
|
+
subject(:burlap) { InstanceVariablesObject.new.to_burlap }
|
21
|
+
|
22
|
+
let(:klass) do
|
23
|
+
Class.new do
|
24
|
+
def initialize
|
25
|
+
@one = 1
|
26
|
+
@two = "something here"
|
27
|
+
@three = :bingo
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
before do
|
33
|
+
stub_const("InstanceVariablesObject", klass)
|
34
|
+
@doc = Nokogiri::XML(@result)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns a string" do
|
38
|
+
expect(burlap).to be_a_kind_of(String)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "decompiles into burlap" do
|
42
|
+
xml_string = <<-XML
|
43
|
+
<map>
|
44
|
+
<type>InstanceVariablesObject</type>
|
45
|
+
|
46
|
+
<string>one</string>
|
47
|
+
<int>1</int>
|
48
|
+
|
49
|
+
<string>three</string>
|
50
|
+
<string>bingo</string>
|
51
|
+
|
52
|
+
<string>two</string>
|
53
|
+
<string>something here</string>
|
54
|
+
</map>
|
55
|
+
XML
|
56
|
+
|
57
|
+
format_xml_as_burlap(xml_string)
|
58
|
+
expect(burlap).to eq(xml_string)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe String do
|
4
|
+
describe "#to_burlap" do
|
5
|
+
subject(:burlap) { input_string.to_burlap }
|
6
|
+
|
7
|
+
context "with normal string" do
|
8
|
+
let(:input_string) { "some string" }
|
9
|
+
|
10
|
+
it "returns a string" do
|
11
|
+
expect(burlap).to be_a_kind_of(described_class)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "is correct" do
|
15
|
+
expect(burlap).to eq("<string>some string</string>")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with html unsafe content" do
|
20
|
+
let(:input_string) { "<script type='text/js'>hello</script>" }
|
21
|
+
|
22
|
+
it "returns escaped html" do
|
23
|
+
expect(burlap).to match(%r{<script type='text/js'>hello</script>})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Symbol do
|
4
|
+
describe "#to_burlap" do
|
5
|
+
subject(:burlap) { :some_value.to_burlap }
|
6
|
+
|
7
|
+
it "returns a string" do
|
8
|
+
expect(burlap).to be_a_kind_of(String)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "is correct" do
|
12
|
+
expect(burlap).to eq("<string>some_value</string>")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Time do
|
4
|
+
describe "#to_burlap" do
|
5
|
+
subject(:burlap) { described_class.utc(2011, 9, 11, 10, 0).to_burlap }
|
6
|
+
|
7
|
+
it "returns a string" do
|
8
|
+
expect(burlap).to be_a_kind_of(String)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "is correct" do
|
12
|
+
expect(burlap).to eq("<date>20110911T100000.000Z</date>")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "does not contain dashes" do
|
16
|
+
expect(burlap).not_to include("-")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "does not contain colons" do
|
20
|
+
expect(burlap).not_to include(":")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe TrueClass do
|
4
|
+
describe "#to_burlap" do
|
5
|
+
before do
|
6
|
+
@result = true.to_burlap
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns a string" do
|
10
|
+
expect(@result).to be_a_kind_of(String)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "is correct" do
|
14
|
+
expect(@result).to eq("<boolean>1</boolean>")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Burlap::DefaultResolver do
|
4
|
+
subject(:resolver) { described_class.new }
|
5
|
+
|
6
|
+
describe "#mappings" do
|
7
|
+
it "defaults to a hash" do
|
8
|
+
expect(resolver.mappings).to eq({})
|
9
|
+
end
|
10
|
+
|
11
|
+
context "when passed a name and block" do
|
12
|
+
it "stores a single mapping" do
|
13
|
+
expect(resolver.mappings["first"]).to be_nil
|
14
|
+
|
15
|
+
resolver.mappings("first") do
|
16
|
+
"result of call"
|
17
|
+
end
|
18
|
+
|
19
|
+
result = resolver.mappings["first"]
|
20
|
+
|
21
|
+
expect(result).not_to be_nil
|
22
|
+
expect(result).to be_a_kind_of(Proc)
|
23
|
+
expect(result.call).to eq("result of call")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when passed more than one name at once" do
|
28
|
+
it "stores the same block against multiple mappings" do
|
29
|
+
resolver.mappings("first", "second") do
|
30
|
+
"result of call"
|
31
|
+
end
|
32
|
+
|
33
|
+
result = resolver.mappings["first"]
|
34
|
+
expect(result).not_to be_nil
|
35
|
+
expect(result).to respond_to(:call)
|
36
|
+
expect(result.call).to eq("result of call")
|
37
|
+
|
38
|
+
result = resolver.mappings["second"]
|
39
|
+
expect(result).not_to be_nil
|
40
|
+
expect(result).to respond_to(:call)
|
41
|
+
expect(result.call).to eq("result of call")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe ".convert_to_native" do
|
47
|
+
subject(:resolver) { Burlap.resolver }
|
48
|
+
|
49
|
+
context "when input is 'int'" do
|
50
|
+
let(:burlap_tag) { Burlap::BaseTag.new(name: "int", value: "15") }
|
51
|
+
|
52
|
+
it "is parsed into ruby" do
|
53
|
+
expect(resolver.convert_to_native(burlap_tag)).to eq(15)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when input is 'double" do
|
58
|
+
let(:burlap_tag) { Burlap::BaseTag.new(name: "double", value: "1.5") }
|
59
|
+
|
60
|
+
it "is parsed into ruby" do
|
61
|
+
expect(resolver.convert_to_native(burlap_tag)).to eq(1.5)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when input is 'string" do
|
66
|
+
let(:burlap_tag) { Burlap::BaseTag.new(name: "string", value: "some string value") }
|
67
|
+
|
68
|
+
it "is parsed into ruby" do
|
69
|
+
expect(resolver.convert_to_native(burlap_tag)).to eq("some string value")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when input is 'null" do
|
74
|
+
let(:burlap_tag) { Burlap::BaseTag.new(name: "null", value: "") }
|
75
|
+
|
76
|
+
it "is parsed into ruby" do
|
77
|
+
expect(resolver.convert_to_native(burlap_tag)).to eq(nil)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when input is 'with 'boolean'" do
|
82
|
+
let(:burlap_tag) { Burlap::BaseTag.new(name: "boolean", value: value) }
|
83
|
+
|
84
|
+
context "with true (1)" do
|
85
|
+
let(:value) { "1" }
|
86
|
+
|
87
|
+
it "parses true" do
|
88
|
+
expect(resolver.convert_to_native(burlap_tag)).to be(true)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "with false (0)" do
|
93
|
+
let(:value) { "0" }
|
94
|
+
|
95
|
+
it "parses false" do
|
96
|
+
expect(resolver.convert_to_native(burlap_tag)).to be(false)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe ".parse" do
|
102
|
+
subject(:parsed_burlap) { Burlap.parse(burlap) }
|
103
|
+
|
104
|
+
context "with empty array" do
|
105
|
+
let(:burlap) { "<list><type>[java.lang.Integer</type><length>0</length></list>" }
|
106
|
+
|
107
|
+
it "parses an empty array" do
|
108
|
+
expect(parsed_burlap).to eq([])
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "when single element" do
|
113
|
+
let(:burlap) { "<list><type>[string</type><length>1</length><string>1</string></list>" }
|
114
|
+
|
115
|
+
it "parses an array" do
|
116
|
+
expect(parsed_burlap).to eq(["1"])
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "when multiple elements" do
|
121
|
+
let(:burlap) { %{<list><type></type><length>3</length><int>0</int><double>1.3</double><string>foobar</string></list>} }
|
122
|
+
|
123
|
+
it "parses an array" do
|
124
|
+
expect(parsed_burlap).to eq([0, 1.3, "foobar"])
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "with 'base64' encoded" do
|
129
|
+
let(:burlap) { "<base64>#{encoded}</base64>" }
|
130
|
+
let(:decoded) { "some string of some text" }
|
131
|
+
let(:encoded) { Base64.encode64(decoded) }
|
132
|
+
|
133
|
+
it "parses and return as a string" do
|
134
|
+
expect(parsed_burlap).to be_a_kind_of(String)
|
135
|
+
expect(parsed_burlap).to eq(decoded)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Burlap::Hash do
|
4
|
+
it "inherits from ordered hash" do
|
5
|
+
expect(described_class.ancestors).to include(ActiveSupport::OrderedHash)
|
6
|
+
end
|
7
|
+
|
8
|
+
it { is_expected.to respond_to(:__type__) }
|
9
|
+
it { is_expected.to respond_to(:__type__=) }
|
10
|
+
|
11
|
+
describe "#__type__" do
|
12
|
+
it "defaults to an empty string" do
|
13
|
+
expect(described_class.new.__type__).to eq("")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#[]" do
|
18
|
+
subject(:burlap_hash) { described_class[input] }
|
19
|
+
|
20
|
+
context "when input is a Hash" do
|
21
|
+
let(:input) { {} }
|
22
|
+
|
23
|
+
it "is compatible with Hash#[]" do
|
24
|
+
expect(burlap_hash.keys).to eq([])
|
25
|
+
expect(burlap_hash.values).to eq([])
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is empty string" do
|
29
|
+
expect(burlap_hash.__type__).to eq("")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when one argument is given" do
|
34
|
+
let(:input) { { "one" => "two", "three" => "four" } }
|
35
|
+
|
36
|
+
it "is compatible with Hash#[]" do
|
37
|
+
expect(burlap_hash.keys).to eq(%w[one three])
|
38
|
+
expect(burlap_hash.values).to eq(%w[two four])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "is empty string" do
|
42
|
+
expect(burlap_hash.__type__).to eq("")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when a __type__ is passed" do
|
47
|
+
let(:input) { { some: "options", __type__: "is ignored" } }
|
48
|
+
|
49
|
+
it "is compatible with Hash#[]" do
|
50
|
+
expect(burlap_hash.keys).to eq(%i[some __type__])
|
51
|
+
expect(burlap_hash.values).to eq(["options", "is ignored"])
|
52
|
+
end
|
53
|
+
|
54
|
+
it "is empty string" do
|
55
|
+
expect(burlap_hash.__type__).to eq("")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when a second argument sets type directly" do
|
60
|
+
subject(:burlap_hash) { described_class[input, "com.java.hashmap"] }
|
61
|
+
|
62
|
+
context "without a passed __type__" do
|
63
|
+
let(:input) { { some: "options" } }
|
64
|
+
|
65
|
+
it "is compatible with Hash#[]" do
|
66
|
+
expect(burlap_hash.keys).to eq([:some])
|
67
|
+
expect(burlap_hash.values).to eq(["options"])
|
68
|
+
end
|
69
|
+
|
70
|
+
it "sets __type__ directly" do
|
71
|
+
expect(burlap_hash.__type__).to eq("com.java.hashmap")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "with a passed __type__" do
|
76
|
+
let(:input) { { some: "options", __type__: "is ignored" } }
|
77
|
+
|
78
|
+
it "is compatible with Hash#[]" do
|
79
|
+
expect(burlap_hash.keys).to eq(%i[some __type__])
|
80
|
+
expect(burlap_hash.values).to eq(["options", "is ignored"])
|
81
|
+
end
|
82
|
+
|
83
|
+
it "sets __type__ directly" do
|
84
|
+
expect(burlap_hash.__type__).to eq("com.java.hashmap")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#inspect" do
|
91
|
+
subject(:burlap_hash) { described_class[[%w[one two], [:three, 4]], "Fred"] }
|
92
|
+
|
93
|
+
it "does not contain OrderedHash" do
|
94
|
+
expect(burlap_hash.inspect).not_to include("OrderedHash")
|
95
|
+
end
|
96
|
+
|
97
|
+
it "starts with Burlap::Hash" do
|
98
|
+
expect(burlap_hash.inspect).to match(/#<Burlap::Hash/)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "contains the hash, inspected" do
|
102
|
+
expect(burlap_hash.inspect).to include(%({"one"=>"two", :three=>4}))
|
103
|
+
end
|
104
|
+
|
105
|
+
it "contains the type, inspected" do
|
106
|
+
expect(burlap_hash.inspect).to include(%{__type__="Fred"})
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#to_burlap" do
|
111
|
+
subject(:burlap) { burlap_hash.to_burlap }
|
112
|
+
|
113
|
+
let(:burlap_hash) { described_class[{ value: "something" }, "org.ruby-lang.string"] }
|
114
|
+
|
115
|
+
context "wrapping a string" do
|
116
|
+
# <map>
|
117
|
+
# <type>org.ruby-lang.string</type>
|
118
|
+
# <string>value</string>
|
119
|
+
# <string>something</string>
|
120
|
+
# </map>
|
121
|
+
|
122
|
+
it "returns a string" do
|
123
|
+
expect(burlap).to be_a_kind_of(String)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "has a map root" do
|
127
|
+
expect(burlap).to match(/^<map>/)
|
128
|
+
expect(burlap).to match(%r{</map>$})
|
129
|
+
end
|
130
|
+
|
131
|
+
it "has a nested type node" do
|
132
|
+
expect(burlap).to match(%r{<type>org.ruby-lang.string</type>})
|
133
|
+
end
|
134
|
+
|
135
|
+
it "has nested value nodes" do
|
136
|
+
expect(burlap).to match(%r{<string>value</string>})
|
137
|
+
expect(burlap).to match(%r{<string>something</string>})
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "wrapping multiple keys" do
|
142
|
+
let(:burlap_hash) { described_class[[["name", "caius durling"], ["age", 101]], "burlap.user"] }
|
143
|
+
|
144
|
+
before do
|
145
|
+
@doc = Nokogiri::XML(burlap)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "returns a string" do
|
149
|
+
expect(burlap).to be_a_kind_of(String)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "is correct" do
|
153
|
+
xml_string = <<-XML
|
154
|
+
<map>
|
155
|
+
<type>burlap.user</type>
|
156
|
+
<string>name</string>
|
157
|
+
<string>caius durling</string>
|
158
|
+
<string>age</string>
|
159
|
+
<int>101</int>
|
160
|
+
</map>
|
161
|
+
XML
|
162
|
+
|
163
|
+
format_xml_as_burlap(xml_string)
|
164
|
+
expect(burlap).to eq(xml_string)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "has a type element" do
|
168
|
+
expect(burlap).to match(%r{<type>burlap.user</type>})
|
169
|
+
end
|
170
|
+
|
171
|
+
it "has a name keypair" do
|
172
|
+
expect(burlap).to match(%r{<string>name</string><string>caius durling</string>})
|
173
|
+
end
|
174
|
+
|
175
|
+
it "has an age keypair" do
|
176
|
+
expect(burlap).to match(%r{<string>age</string><int>101</int>})
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context "wrapping nested keys" do
|
181
|
+
let(:burlap_hash) { described_class[[["people", { "name" => "caius durling", "age" => 101 }]], "burlap-peoples"] }
|
182
|
+
|
183
|
+
it "returns a string" do
|
184
|
+
expect(burlap).to be_a_kind_of(String)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "is generated properly, including nested elements" do
|
188
|
+
xml_string = <<-XML
|
189
|
+
<map>
|
190
|
+
<type>burlap-peoples</type>
|
191
|
+
|
192
|
+
<string>people</string>
|
193
|
+
<map>
|
194
|
+
<type></type>
|
195
|
+
|
196
|
+
<string>name</string>
|
197
|
+
<string>caius durling</string>
|
198
|
+
|
199
|
+
<string>age</string>
|
200
|
+
<int>101</int>
|
201
|
+
</map>
|
202
|
+
|
203
|
+
</map>
|
204
|
+
XML
|
205
|
+
xml_string.gsub!(/(^|\n)\s*/m, "")
|
206
|
+
expect(burlap).to eq(xml_string)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context "wrapping empty arrays" do
|
211
|
+
let(:burlap_hash) { described_class[{ numbers: [] }] }
|
212
|
+
|
213
|
+
it "returns a string" do
|
214
|
+
expect(burlap).to be_a_kind_of(String)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "is generated properly" do
|
218
|
+
xml_string = <<-XML
|
219
|
+
<map>
|
220
|
+
<type></type>
|
221
|
+
|
222
|
+
<string>numbers</string>
|
223
|
+
<list>
|
224
|
+
<type></type>
|
225
|
+
<length>0</length>
|
226
|
+
</list>
|
227
|
+
</map>
|
228
|
+
XML
|
229
|
+
xml_string.gsub!(/(^|\n)\s*/m, "")
|
230
|
+
expect(burlap).to eq(xml_string)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Burlap::Listener do
|
4
|
+
describe ".parse" do
|
5
|
+
subject(:result) { Burlap.parse(reply) }
|
6
|
+
|
7
|
+
context "when response is no such method" do
|
8
|
+
let(:reply) { File.read("spec/data/no_such_method.burlap") }
|
9
|
+
|
10
|
+
before { raise if reply.nil? }
|
11
|
+
|
12
|
+
it "parses successfully" do
|
13
|
+
expect(result).to be_a_kind_of(OpenStruct)
|
14
|
+
expect(result.code).to eq("NoSuchMethodException")
|
15
|
+
expect(result.message).to eq("The service has no method named: getUserID")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "when response is record not found" do
|
20
|
+
let(:reply) { File.read("spec/data/record_not_found.burlap") }
|
21
|
+
|
22
|
+
before { raise if reply.nil? }
|
23
|
+
|
24
|
+
it "parses successfully" do
|
25
|
+
expect(result).to be_a_kind_of(Burlap::Fault)
|
26
|
+
expect(result.code).to eq("ServiceException")
|
27
|
+
expect(result.message).to eq("No row with the given identifier exists: [com.sapienter.jbilling.server.user.db.UserDTO#21]")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Burlap::Node do
|
4
|
+
describe "#to_burlap" do
|
5
|
+
subject(:burlap) { described_class.new(name: "name", value: value).to_burlap }
|
6
|
+
|
7
|
+
context "with a string" do
|
8
|
+
let(:value) { "updateUser" }
|
9
|
+
|
10
|
+
it "returns a string" do
|
11
|
+
expect(burlap).to be_a_kind_of(String)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "puts name in brackets" do
|
15
|
+
expect(burlap).to eq("<name>updateUser</name>")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with UTF8 characters" do
|
20
|
+
let(:value) { "Håva" }
|
21
|
+
|
22
|
+
it "uses decimal escaping for utf8 characters" do
|
23
|
+
expect(burlap).to eq(%{<name>Håva</name>})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with nested XML" do
|
28
|
+
let(:value) { "<length>1</length>" }
|
29
|
+
|
30
|
+
it "returns a string" do
|
31
|
+
expect(burlap).to be_a_kind_of(String)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "does not escape the value containing XML" do
|
35
|
+
expect(burlap).to eq("<name><length>1</length></name>")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|