Empact-roxml 2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +18 -0
- data/README.rdoc +122 -0
- data/Rakefile +104 -0
- data/lib/roxml.rb +362 -0
- data/lib/roxml/array.rb +15 -0
- data/lib/roxml/options.rb +175 -0
- data/lib/roxml/string.rb +35 -0
- data/lib/roxml/xml.rb +243 -0
- data/lib/roxml/xml/libxml.rb +63 -0
- data/lib/roxml/xml/rexml.rb +59 -0
- data/roxml.gemspec +78 -0
- data/test/fixtures/book_malformed.xml +5 -0
- data/test/fixtures/book_pair.xml +8 -0
- data/test/fixtures/book_text_with_attribute.xml +5 -0
- data/test/fixtures/book_valid.xml +5 -0
- data/test/fixtures/book_with_authors.xml +7 -0
- data/test/fixtures/book_with_contributions.xml +9 -0
- data/test/fixtures/book_with_contributors.xml +7 -0
- data/test/fixtures/book_with_contributors_attrs.xml +7 -0
- data/test/fixtures/book_with_default_namespace.xml +9 -0
- data/test/fixtures/book_with_depth.xml +6 -0
- data/test/fixtures/book_with_publisher.xml +7 -0
- data/test/fixtures/dictionary_of_attrs.xml +6 -0
- data/test/fixtures/dictionary_of_mixeds.xml +4 -0
- data/test/fixtures/dictionary_of_texts.xml +10 -0
- data/test/fixtures/library.xml +30 -0
- data/test/fixtures/library_uppercase.xml +30 -0
- data/test/fixtures/nameless_ageless_youth.xml +2 -0
- data/test/fixtures/person.xml +1 -0
- data/test/fixtures/person_with_guarded_mothers.xml +13 -0
- data/test/fixtures/person_with_mothers.xml +10 -0
- data/test/mocks/dictionaries.rb +56 -0
- data/test/mocks/mocks.rb +212 -0
- data/test/test_helper.rb +16 -0
- data/test/unit/options_test.rb +62 -0
- data/test/unit/roxml_test.rb +24 -0
- data/test/unit/string_test.rb +11 -0
- data/test/unit/to_xml_test.rb +75 -0
- data/test/unit/xml_attribute_test.rb +34 -0
- data/test/unit/xml_construct_test.rb +19 -0
- data/test/unit/xml_hash_test.rb +54 -0
- data/test/unit/xml_name_test.rb +14 -0
- data/test/unit/xml_namespace_test.rb +36 -0
- data/test/unit/xml_object_test.rb +94 -0
- data/test/unit/xml_text_test.rb +57 -0
- metadata +110 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class TestXMLHash < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@contents = {'quaquaversally' => 'adjective: (of a geological formation) sloping downward from the center in all directions.',
|
6
|
+
'tergiversate' => 'To use evasions or ambiguities; equivocate.'}
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_attrs_hash
|
10
|
+
dict = DictionaryOfAttrs.parse(fixture(:dictionary_of_attrs))
|
11
|
+
assert_equal Hash, dict.definitions.class
|
12
|
+
assert_equal @contents, dict.definitions
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_text_hash
|
16
|
+
assert_equal 'definition', DictionaryOfTexts.tag_refs.only.name
|
17
|
+
assert_equal 'word', DictionaryOfTexts.tag_refs.only.hash.key.name
|
18
|
+
assert_equal 'meaning', DictionaryOfTexts.tag_refs.only.hash.value.name
|
19
|
+
|
20
|
+
dict = DictionaryOfTexts.parse(fixture(:dictionary_of_texts))
|
21
|
+
assert_equal Hash, dict.definitions.class
|
22
|
+
assert_equal @contents, dict.definitions
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_mixed_content_hash
|
26
|
+
dict = DictionaryOfMixeds.parse(fixture(:dictionary_of_mixeds))
|
27
|
+
assert_equal Hash, dict.definitions.class
|
28
|
+
assert_equal @contents, dict.definitions
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_name_hash
|
32
|
+
dict = DictionaryOfNames.parse(fixture(:dictionary_of_names))
|
33
|
+
assert_equal Hash, dict.definitions.class
|
34
|
+
assert_equal @contents, dict.definitions
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_guarded_name_hash
|
38
|
+
dict = DictionaryOfGuardedNames.parse(fixture(:dictionary_of_guarded_names))
|
39
|
+
assert_equal Hash, dict.definitions.class
|
40
|
+
assert_equal @contents, dict.definitions
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_text_name_clashes
|
44
|
+
dict = DictionaryOfNameClashes.parse(fixture(:dictionary_of_name_clashes))
|
45
|
+
assert_equal Hash, dict.definitions.class
|
46
|
+
assert_equal @contents, dict.definitions
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_attr_name_clashes
|
50
|
+
dict = DictionaryOfAttrNameClashes.parse(fixture(:dictionary_of_attr_name_clashes))
|
51
|
+
assert_equal Hash, dict.definitions.class
|
52
|
+
assert_equal @contents, dict.definitions
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class TestXMLName < Test::Unit::TestCase
|
4
|
+
def test_named_books_picked_up
|
5
|
+
named = Library.parse(fixture(:library))
|
6
|
+
assert named.books
|
7
|
+
assert_equal :book, named.books.first.tag_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_nameless_books_missing
|
11
|
+
nameless = LibraryWithBooksOfUnderivableName.parse(fixture(:library))
|
12
|
+
assert nameless.novels.empty?
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class TestXMLNamespaces < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@book = BookWithContributions.parse(fixture(:book_with_default_namespace))
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_default_namespace_doesnt_interfere_with_normal_operation
|
9
|
+
assert_equal("Programming Ruby - 2nd Edition", @book.title)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_default_namespace_is_applied_to_in_element
|
13
|
+
expected_authors = ["David Thomas","Andrew Hunt","Chad Fowler"]
|
14
|
+
assert !@book.contributions.empty?
|
15
|
+
@book.contributions.each do |contributor|
|
16
|
+
assert expected_authors.include?(contributor.name)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_that_rexml_follows_nameless_default_namespace
|
21
|
+
xml = REXML::Document.new(
|
22
|
+
'<container xmlns="http://fakenamespace.org"><node>Yeah, content</node></container>')
|
23
|
+
|
24
|
+
assert_equal "Yeah, content", xml.root.get_elements('node').first.text
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_default_namespace_on_root_node_should_be_found
|
28
|
+
require 'libxml'
|
29
|
+
xml = LibXML::XML::Parser.string(
|
30
|
+
'<container xmlns="http://defaultnamespace.org"><node>Yeah, content</node><node><subnode>Another</subnode></node></container>').parse
|
31
|
+
|
32
|
+
assert_equal nil, xml.find_first('container')
|
33
|
+
assert_equal "Yeah, content", xml.find_first('container:node', 'container:http://defaultnamespace.org').content
|
34
|
+
assert_equal "Another", xml.find_first('container:node/container:subnode', 'container:http://defaultnamespace.org').content
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class TestXMLObject < Test::Unit::TestCase
|
4
|
+
# Test book with text and attribute
|
5
|
+
def test_book_author_text_attribute
|
6
|
+
book = BookWithAuthorTextAttribute.parse(fixture(:book_text_with_attribute))
|
7
|
+
assert_equal("primary",book.author.role)
|
8
|
+
assert_equal("David Thomas",book.author.text)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Test XML object containing list of other XML objects (one-to-many)
|
12
|
+
# In this case, book with contibutions
|
13
|
+
def test_one_to_many_with_container
|
14
|
+
expected_authors = ["David Thomas","Andrew Hunt","Chad Fowler"]
|
15
|
+
book = BookWithContributions.parse(fixture(:book_with_contributions))
|
16
|
+
assert_equal("Programming Ruby - 2nd Edition", book.title)
|
17
|
+
book.contributions.each do |contributor|
|
18
|
+
assert expected_authors.include?(contributor.name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Test XML object containing 1-n other XML objects without container (one-to-many)
|
23
|
+
# In this case, book with contibutions
|
24
|
+
def test_one_to_many_without_container
|
25
|
+
expected_contributors = ["David Thomas","Andrew Hunt","Chad Fowler"]
|
26
|
+
book = BookWithContributors.parse(fixture(:book_with_contributors))
|
27
|
+
assert_equal("Programming Ruby - 2nd Edition", book.title)
|
28
|
+
book.contributors.each do |contributor|
|
29
|
+
assert(expected_contributors.include?(contributor.name))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Test XML object containing one other XML object (one-to-one)
|
34
|
+
# In this case, book with publisher
|
35
|
+
def test_one_to_one
|
36
|
+
book = BookWithPublisher.parse(fixture(:book_with_publisher))
|
37
|
+
assert_equal("Programming Ruby - 2nd Edition", book.title)
|
38
|
+
assert_equal("Pragmatic Bookshelf", book.publisher.name)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Test XML object containing type of self (self-reference)
|
42
|
+
def test_self_reference
|
43
|
+
book = BookPair.parse(fixture(:book_pair))
|
44
|
+
assert_equal("Programming Ruby - 2nd Edition", book.title)
|
45
|
+
assert_equal("Agile Web Development with Rails", book.book.title)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Test three-level composition (one-to-many-to-many)
|
49
|
+
def test_one_to_many_to_many
|
50
|
+
expected_contributors = ["David Thomas","Andrew Hunt","Chad Fowler", "David Heinemeier Hansson"]
|
51
|
+
expected_books = ["Programming Ruby - 2nd Edition", "Agile Web Development with Rails"]
|
52
|
+
library = Library.parse(fixture(:library))
|
53
|
+
assert_equal("Ruby library", library.name)
|
54
|
+
assert !library.books.empty?
|
55
|
+
library.books.each do |book|
|
56
|
+
assert expected_books.include?(book.title)
|
57
|
+
book.contributions.each do |contributor|
|
58
|
+
assert(expected_contributors.include?(contributor.name))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_without_needed_from
|
64
|
+
assert_equal [], UppercaseLibrary.parse(fixture(:library)).books
|
65
|
+
assert_equal [], Library.parse(fixture(:library_uppercase)).books
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_with_needed_from
|
69
|
+
assert Library.parse(fixture(:library)).books
|
70
|
+
assert UppercaseLibrary.parse(fixture(:library_uppercase)).books
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_with_recursion
|
74
|
+
p = PersonWithMother.parse(fixture(:person_with_mothers))
|
75
|
+
assert_equal 'Ben Franklin', p.name
|
76
|
+
assert_equal 'Abiah Folger', p.mother.name
|
77
|
+
assert_equal 'Madeup Mother', p.mother.mother.name
|
78
|
+
assert_equal nil, p.mother.mother.mother
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_with_guarded_recursion
|
82
|
+
p = PersonWithGuardedMother.parse(fixture(:person_with_guarded_mothers))
|
83
|
+
assert_equal 'Ben Franklin', p.name
|
84
|
+
assert_equal 'Abiah Folger', p.mother.name
|
85
|
+
assert_equal 'Madeup Mother', p.mother.mother.name
|
86
|
+
assert_equal nil, p.mother.mother.mother
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_recursive_with_default_initialization
|
90
|
+
p = PersonWithMotherOrMissing.parse(fixture(:person_with_mothers))
|
91
|
+
assert_equal 'Unknown', p.mother.mother.mother.name
|
92
|
+
assert_equal Person, p.mother.mother.mother.class
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class TestXMLText < Test::Unit::TestCase
|
4
|
+
# Test a simple mapping with no composition
|
5
|
+
def test_valid_simple
|
6
|
+
book = Book.parse(fixture(:book_valid))
|
7
|
+
assert_equal("The PickAxe", book.title)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_without_needed_from
|
11
|
+
assert !Library.parse(fixture(:library_uppercase)).name
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_with_needed_from
|
15
|
+
assert_equal "Ruby library", Library.parse(fixture(:library)).name
|
16
|
+
assert_equal "Ruby library", UppercaseLibrary.parse(fixture(:library_uppercase)).name
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_as_array
|
20
|
+
assert_equal ["David Thomas","Andrew Hunt","Dave Thomas"].sort,
|
21
|
+
BookWithAuthors.parse(fixture(:book_with_authors)).authors.sort
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_text_modification
|
25
|
+
person = Person.parse(fixture(:person))
|
26
|
+
assert_equal("Ben Franklin", person.name)
|
27
|
+
person.name = "Fred"
|
28
|
+
xml=person.to_xml.to_s
|
29
|
+
assert(/Fred/=~xml)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_default_initialization
|
33
|
+
person = PersonWithMotherOrMissing.parse(fixture(:nameless_ageless_youth))
|
34
|
+
assert_equal "Anonymous", person.name
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_default_initialization_of_content
|
38
|
+
person = Person.parse(fixture(:nameless_ageless_youth))
|
39
|
+
assert_equal "Unknown", person.name
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_recursive_with_default_initialization
|
43
|
+
p = PersonWithMotherOrMissing.parse(fixture(:person_with_mothers))
|
44
|
+
assert_equal 'Unknown', p.mother.mother.mother.name
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_get_with_block
|
48
|
+
p = Book.parse(fixture(:book_valid))
|
49
|
+
assert_equal 357, p.pages
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_no_name_clashes
|
53
|
+
n = NodeWithNameConflicts.parse(fixture(:node_with_name_conflicts))
|
54
|
+
assert_equal "Just junk... really", n.content
|
55
|
+
assert_equal "Cartwheel", n.name
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Empact-roxml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "2.0"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Woosley
|
8
|
+
- Zak Mandhro
|
9
|
+
- Anders Engstrom
|
10
|
+
- Russ Olsen
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
|
15
|
+
date: 2008-08-13 00:00:00 -07:00
|
16
|
+
default_executable:
|
17
|
+
dependencies: []
|
18
|
+
|
19
|
+
description: ROXML is a Ruby library designed to make it easier for Ruby developers to work with XML. Using simple annotations, it enables Ruby classes to be mapped to XML. ROXML takes care of the marshalling and unmarshalling of mapped attributes so that developers can focus on building first-class Ruby classes. As a result, ROXML simplifies the development of RESTful applications, Web Services, and XML-RPC.
|
20
|
+
email: ben.woosley@gmail.com
|
21
|
+
executables: []
|
22
|
+
|
23
|
+
extensions: []
|
24
|
+
|
25
|
+
extra_rdoc_files: []
|
26
|
+
|
27
|
+
files:
|
28
|
+
- README.rdoc
|
29
|
+
- MIT-LICENSE
|
30
|
+
- Rakefile
|
31
|
+
- roxml.gemspec
|
32
|
+
- lib/roxml.rb
|
33
|
+
- lib/roxml/array.rb
|
34
|
+
- lib/roxml/options.rb
|
35
|
+
- lib/roxml/string.rb
|
36
|
+
- lib/roxml/xml.rb
|
37
|
+
- lib/roxml/xml/libxml.rb
|
38
|
+
- lib/roxml/xml/rexml.rb
|
39
|
+
- test/fixtures/book_malformed.xml
|
40
|
+
- test/fixtures/book_pair.xml
|
41
|
+
- test/fixtures/book_text_with_attribute.xml
|
42
|
+
- test/fixtures/book_valid.xml
|
43
|
+
- test/fixtures/book_with_authors.xml
|
44
|
+
- test/fixtures/book_with_contributions.xml
|
45
|
+
- test/fixtures/book_with_contributors_attrs.xml
|
46
|
+
- test/fixtures/book_with_contributors.xml
|
47
|
+
- test/fixtures/book_with_default_namespace.xml
|
48
|
+
- test/fixtures/book_with_depth.xml
|
49
|
+
- test/fixtures/book_with_publisher.xml
|
50
|
+
- test/fixtures/dictionary_of_attrs.xml
|
51
|
+
- test/fixtures/dictionary_of_mixeds.xml
|
52
|
+
- test/fixtures/dictionary_of_texts.xml
|
53
|
+
- test/fixtures/library_uppercase.xml
|
54
|
+
- test/fixtures/library.xml
|
55
|
+
- test/fixtures/nameless_ageless_youth.xml
|
56
|
+
- test/fixtures/person_with_guarded_mothers.xml
|
57
|
+
- test/fixtures/person_with_mothers.xml
|
58
|
+
- test/fixtures/person.xml
|
59
|
+
- test/mocks/mocks.rb
|
60
|
+
- test/mocks/dictionaries.rb
|
61
|
+
- test/test_helper.rb
|
62
|
+
- test/unit/options_test.rb
|
63
|
+
- test/unit/roxml_test.rb
|
64
|
+
- test/unit/string_test.rb
|
65
|
+
- test/unit/to_xml_test.rb
|
66
|
+
- test/unit/xml_attribute_test.rb
|
67
|
+
- test/unit/xml_construct_test.rb
|
68
|
+
- test/unit/xml_hash_test.rb
|
69
|
+
- test/unit/xml_name_test.rb
|
70
|
+
- test/unit/xml_namespace_test.rb
|
71
|
+
- test/unit/xml_object_test.rb
|
72
|
+
- test/unit/xml_text_test.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://roxml.rubyforge.org
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: "0"
|
85
|
+
version:
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
version:
|
92
|
+
requirements:
|
93
|
+
- none
|
94
|
+
rubyforge_project: roxml
|
95
|
+
rubygems_version: 1.2.0
|
96
|
+
signing_key:
|
97
|
+
specification_version: 2
|
98
|
+
summary: Ruby Object to XML mapping library
|
99
|
+
test_files:
|
100
|
+
- test/unit/options_test.rb
|
101
|
+
- test/unit/roxml_test.rb
|
102
|
+
- test/unit/string_test.rb
|
103
|
+
- test/unit/to_xml_test.rb
|
104
|
+
- test/unit/xml_attribute_test.rb
|
105
|
+
- test/unit/xml_construct_test.rb
|
106
|
+
- test/unit/xml_hash_test.rb
|
107
|
+
- test/unit/xml_name_test.rb
|
108
|
+
- test/unit/xml_namespace_test.rb
|
109
|
+
- test/unit/xml_object_test.rb
|
110
|
+
- test/unit/xml_text_test.rb
|