Skip to content
This repository
Browse code

Loading files if PLATFORM available. #jruby

  • Loading branch information...
commit 4c330d630275ab8a62aafa6e7a935faa69214610 1 parent 993bd32
Arun Agrawal authored May 27, 2011
166  activesupport/test/xml_mini/jdom_engine_test.rb
... ...
@@ -1,39 +1,39 @@
1  
-require 'abstract_unit'
2  
-require 'active_support/xml_mini'
3  
-require 'active_support/core_ext/hash/conversions'
4  
-
5 1
 if RUBY_PLATFORM =~ /java/
  2
+  require 'abstract_unit'
  3
+  require 'active_support/xml_mini'
  4
+  require 'active_support/core_ext/hash/conversions'
6 5
 
7  
-class JDOMEngineTest < Test::Unit::TestCase
8  
-  include ActiveSupport
9 6
 
10  
-  def setup
11  
-    @default_backend = XmlMini.backend
12  
-    XmlMini.backend = 'JDOM'
13  
-  end
  7
+  class JDOMEngineTest < Test::Unit::TestCase
  8
+    include ActiveSupport
14 9
 
15  
-  def teardown
16  
-    XmlMini.backend = @default_backend
17  
-  end
  10
+    def setup
  11
+      @default_backend = XmlMini.backend
  12
+      XmlMini.backend  = 'JDOM'
  13
+    end
18 14
 
19  
-  # def test_file_from_xml
20  
-  #   hash = Hash.from_xml(<<-eoxml)
21  
-  #     <blog>
22  
-  #       <logo type="file" name="logo.png" content_type="image/png">
23  
-  #       </logo>
24  
-  #     </blog>
25  
-  #   eoxml
26  
-  #   assert hash.has_key?('blog')
27  
-  #   assert hash['blog'].has_key?('logo')
28  
-  #
29  
-  #   file = hash['blog']['logo']
30  
-  #   assert_equal 'logo.png', file.original_filename
31  
-  #   assert_equal 'image/png', file.content_type
32  
-  # end
33  
-
34  
-  def test_exception_thrown_on_expansion_attack
35  
-    assert_raise NativeException do
36  
-      attack_xml = <<-EOT
  15
+    def teardown
  16
+      XmlMini.backend = @default_backend
  17
+    end
  18
+
  19
+    # def test_file_from_xml
  20
+    #   hash = Hash.from_xml(<<-eoxml)
  21
+    #     <blog>
  22
+    #       <logo type="file" name="logo.png" content_type="image/png">
  23
+    #       </logo>
  24
+    #     </blog>
  25
+    #   eoxml
  26
+    #   assert hash.has_key?('blog')
  27
+    #   assert hash['blog'].has_key?('logo')
  28
+    #
  29
+    #   file = hash['blog']['logo']
  30
+    #   assert_equal 'logo.png', file.original_filename
  31
+    #   assert_equal 'image/png', file.content_type
  32
+    # end
  33
+
  34
+    def test_exception_thrown_on_expansion_attack
  35
+      assert_raise NativeException do
  36
+        attack_xml = <<-EOT
37 37
       <?xml version="1.0" encoding="UTF-8"?>
38 38
       <!DOCTYPE member [
39 39
         <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
@@ -47,91 +47,91 @@ def test_exception_thrown_on_expansion_attack
47 47
       <member>
48 48
       &a;
49 49
       </member>
50  
-      EOT
51  
-      Hash.from_xml(attack_xml)
  50
+        EOT
  51
+        Hash.from_xml(attack_xml)
  52
+      end
52 53
     end
53  
-  end
54 54
 
55  
-  def test_setting_JDOM_as_backend
56  
-    XmlMini.backend = 'JDOM'
57  
-    assert_equal XmlMini_JDOM, XmlMini.backend
58  
-  end
  55
+    def test_setting_JDOM_as_backend
  56
+      XmlMini.backend = 'JDOM'
  57
+      assert_equal XmlMini_JDOM, XmlMini.backend
  58
+    end
59 59
 
60  
-  def test_blank_returns_empty_hash
61  
-    assert_equal({}, XmlMini.parse(nil))
62  
-    assert_equal({}, XmlMini.parse(''))
63  
-  end
  60
+    def test_blank_returns_empty_hash
  61
+      assert_equal({}, XmlMini.parse(nil))
  62
+      assert_equal({}, XmlMini.parse(''))
  63
+    end
64 64
 
65  
-  def test_array_type_makes_an_array
66  
-    assert_equal_rexml(<<-eoxml)
  65
+    def test_array_type_makes_an_array
  66
+      assert_equal_rexml(<<-eoxml)
67 67
       <blog>
68 68
         <posts type="array">
69 69
           <post>a post</post>
70 70
           <post>another post</post>
71 71
         </posts>
72 72
       </blog>
73  
-    eoxml
74  
-  end
  73
+      eoxml
  74
+    end
75 75
 
76  
-  def test_one_node_document_as_hash
77  
-    assert_equal_rexml(<<-eoxml)
  76
+    def test_one_node_document_as_hash
  77
+      assert_equal_rexml(<<-eoxml)
78 78
     <products/>
79  
-    eoxml
80  
-  end
  79
+      eoxml
  80
+    end
81 81
 
82  
-  def test_one_node_with_attributes_document_as_hash
83  
-    assert_equal_rexml(<<-eoxml)
  82
+    def test_one_node_with_attributes_document_as_hash
  83
+      assert_equal_rexml(<<-eoxml)
84 84
     <products foo="bar"/>
85  
-    eoxml
86  
-  end
  85
+      eoxml
  86
+    end
87 87
 
88  
-  def test_products_node_with_book_node_as_hash
89  
-    assert_equal_rexml(<<-eoxml)
  88
+    def test_products_node_with_book_node_as_hash
  89
+      assert_equal_rexml(<<-eoxml)
90 90
     <products>
91 91
       <book name="awesome" id="12345" />
92 92
     </products>
93  
-    eoxml
94  
-  end
  93
+      eoxml
  94
+    end
95 95
 
96  
-  def test_products_node_with_two_book_nodes_as_hash
97  
-    assert_equal_rexml(<<-eoxml)
  96
+    def test_products_node_with_two_book_nodes_as_hash
  97
+      assert_equal_rexml(<<-eoxml)
98 98
     <products>
99 99
       <book name="awesome" id="12345" />
100 100
       <book name="america" id="67890" />
101 101
     </products>
102  
-    eoxml
103  
-  end
  102
+      eoxml
  103
+    end
104 104
 
105  
-  def test_single_node_with_content_as_hash
106  
-    assert_equal_rexml(<<-eoxml)
  105
+    def test_single_node_with_content_as_hash
  106
+      assert_equal_rexml(<<-eoxml)
107 107
       <products>
108 108
         hello world
109 109
       </products>
110  
-    eoxml
111  
-  end
  110
+      eoxml
  111
+    end
112 112
 
113  
-  def test_children_with_children
114  
-    assert_equal_rexml(<<-eoxml)
  113
+    def test_children_with_children
  114
+      assert_equal_rexml(<<-eoxml)
115 115
     <root>
116 116
       <products>
117 117
         <book name="america" id="67890" />
118 118
       </products>
119 119
     </root>
120  
-    eoxml
121  
-  end
  120
+      eoxml
  121
+    end
122 122
 
123  
-  def test_children_with_text
124  
-    assert_equal_rexml(<<-eoxml)
  123
+    def test_children_with_text
  124
+      assert_equal_rexml(<<-eoxml)
125 125
     <root>
126 126
       <products>
127 127
         hello everyone
128 128
       </products>
129 129
     </root>
130  
-    eoxml
131  
-  end
  130
+      eoxml
  131
+    end
132 132
 
133  
-  def test_children_with_non_adjacent_text
134  
-    assert_equal_rexml(<<-eoxml)
  133
+    def test_children_with_non_adjacent_text
  134
+      assert_equal_rexml(<<-eoxml)
135 135
     <root>
136 136
       good
137 137
       <products>
@@ -139,15 +139,15 @@ def test_children_with_non_adjacent_text
139 139
       </products>
140 140
       morning
141 141
     </root>
142  
-    eoxml
143  
-  end
  142
+      eoxml
  143
+    end
144 144
 
145  
-  private
146  
-  def assert_equal_rexml(xml)
147  
-    hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) }
148  
-    assert_equal(hash, XmlMini.parse(xml))
  145
+    private
  146
+    def assert_equal_rexml(xml)
  147
+      hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) }
  148
+      assert_equal(hash, XmlMini.parse(xml))
  149
+    end
149 150
   end
150  
-end
151 151
 
152 152
 else
153 153
   # don't run these test because we aren't running in JRuby

0 notes on commit 4c330d6

Please sign in to comment.
Something went wrong with that request. Please try again.