obix 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/Guardfile +5 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +128 -0
  7. data/Rakefile +7 -0
  8. data/lib/obix.rb +55 -0
  9. data/lib/obix/alarms.rb +48 -0
  10. data/lib/obix/builder.rb +45 -0
  11. data/lib/obix/configuration.rb +79 -0
  12. data/lib/obix/errors.rb +6 -0
  13. data/lib/obix/history.rb +65 -0
  14. data/lib/obix/network.rb +76 -0
  15. data/lib/obix/objects.rb +46 -0
  16. data/lib/obix/objects/base.rb +97 -0
  17. data/lib/obix/objects/boolean.rb +13 -0
  18. data/lib/obix/objects/date.rb +15 -0
  19. data/lib/obix/objects/duration.rb +14 -0
  20. data/lib/obix/objects/enumerable.rb +13 -0
  21. data/lib/obix/objects/error.rb +26 -0
  22. data/lib/obix/objects/feed.rb +14 -0
  23. data/lib/obix/objects/float.rb +16 -0
  24. data/lib/obix/objects/integer.rb +15 -0
  25. data/lib/obix/objects/list.rb +14 -0
  26. data/lib/obix/objects/object.rb +20 -0
  27. data/lib/obix/objects/operation.rb +28 -0
  28. data/lib/obix/objects/reference.rb +10 -0
  29. data/lib/obix/objects/string.rb +14 -0
  30. data/lib/obix/objects/time.rb +15 -0
  31. data/lib/obix/objects/uri.rb +13 -0
  32. data/lib/obix/tag.rb +43 -0
  33. data/lib/obix/types.rb +15 -0
  34. data/lib/obix/types/boolean.rb +25 -0
  35. data/lib/obix/types/date.rb +20 -0
  36. data/lib/obix/types/duration.rb +21 -0
  37. data/lib/obix/types/float.rb +18 -0
  38. data/lib/obix/types/integer.rb +18 -0
  39. data/lib/obix/types/string.rb +18 -0
  40. data/lib/obix/types/time.rb +20 -0
  41. data/lib/obix/types/type.rb +17 -0
  42. data/lib/obix/types/uri.rb +28 -0
  43. data/lib/obix/version.rb +3 -0
  44. data/lib/obix/watch.rb +119 -0
  45. data/obix.gemspec +31 -0
  46. data/test/fixtures/alarmqueryout.xml +19 -0
  47. data/test/fixtures/alarmsubject.xml +5 -0
  48. data/test/fixtures/history.xml +9 -0
  49. data/test/fixtures/historyqueryout.xml +15 -0
  50. data/test/fixtures/invalid.xml +1 -0
  51. data/test/fixtures/objects/boolean.xml +1 -0
  52. data/test/fixtures/objects/date.xml +1 -0
  53. data/test/fixtures/objects/duration.xml +1 -0
  54. data/test/fixtures/objects/enumerable.xml +1 -0
  55. data/test/fixtures/objects/error.xml +1 -0
  56. data/test/fixtures/objects/feed.xml +4 -0
  57. data/test/fixtures/objects/float.xml +1 -0
  58. data/test/fixtures/objects/integer.xml +1 -0
  59. data/test/fixtures/objects/list.xml +4 -0
  60. data/test/fixtures/objects/object.xml +1 -0
  61. data/test/fixtures/objects/operation.xml +1 -0
  62. data/test/fixtures/objects/reference.xml +1 -0
  63. data/test/fixtures/objects/string.xml +1 -0
  64. data/test/fixtures/objects/time.xml +1 -0
  65. data/test/fixtures/objects/uri.xml +1 -0
  66. data/test/fixtures/valid.xml +11 -0
  67. data/test/fixtures/watch.xml +8 -0
  68. data/test/fixtures/watchout.xml +5 -0
  69. data/test/fixtures/watchservice.xml +3 -0
  70. data/test/obix/alarms_test.rb +36 -0
  71. data/test/obix/builder_test.rb +32 -0
  72. data/test/obix/configuration_test.rb +32 -0
  73. data/test/obix/history_test.rb +54 -0
  74. data/test/obix/network_test.rb +134 -0
  75. data/test/obix/objects/base_test.rb +54 -0
  76. data/test/obix/objects/boolean_test.rb +17 -0
  77. data/test/obix/objects/date_test.rb +16 -0
  78. data/test/obix/objects/duration_test.rb +16 -0
  79. data/test/obix/objects/enumerable_test.rb +17 -0
  80. data/test/obix/objects/error_test.rb +47 -0
  81. data/test/obix/objects/feed_test.rb +16 -0
  82. data/test/obix/objects/float_test.rb +16 -0
  83. data/test/obix/objects/integer_test.rb +16 -0
  84. data/test/obix/objects/list_test.rb +17 -0
  85. data/test/obix/objects/object_test.rb +17 -0
  86. data/test/obix/objects/operation_test.rb +37 -0
  87. data/test/obix/objects/reference_test.rb +16 -0
  88. data/test/obix/objects/string_test.rb +16 -0
  89. data/test/obix/objects/time_test.rb +16 -0
  90. data/test/obix/objects/uri_test.rb +16 -0
  91. data/test/obix/objects_test.rb +13 -0
  92. data/test/obix/tag_test.rb +42 -0
  93. data/test/obix/types/boolean_test.rb +18 -0
  94. data/test/obix/types/date_test.rb +20 -0
  95. data/test/obix/types/duration_test.rb +18 -0
  96. data/test/obix/types/float_test.rb +18 -0
  97. data/test/obix/types/integer_test.rb +18 -0
  98. data/test/obix/types/string_test.rb +18 -0
  99. data/test/obix/types/time_test.rb +20 -0
  100. data/test/obix/types/uri_test.rb +48 -0
  101. data/test/obix/watch_test.rb +169 -0
  102. data/test/obix_test.rb +42 -0
  103. data/test/test_helper.rb +18 -0
  104. metadata +357 -0
@@ -0,0 +1,17 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class BooleanTest < MiniTest::Unit::TestCase
8
+
9
+ def test_parses_booleans
10
+ object = OBIX.parse string: fixture("objects/boolean.xml")
11
+
12
+ assert_instance_of OBIX::Objects::Boolean, object
13
+ assert_equal true, object.val
14
+ assert_equal "http://example.org/range", object.range
15
+ end
16
+
17
+ end
@@ -0,0 +1,16 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class DateTest < MiniTest::Unit::TestCase
8
+
9
+ def test_parses_strings
10
+ object = OBIX.parse string: fixture("objects/date.xml")
11
+
12
+ assert_instance_of OBIX::Objects::Date, object
13
+ assert_equal Date.parse("2007-11-26"), object.val
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class DurationTest < MiniTest::Unit::TestCase
8
+
9
+ def test_parses_durations
10
+ object = OBIX.parse string: fixture("objects/duration.xml")
11
+
12
+ assert_instance_of OBIX::Objects::Duration, object
13
+ assert_equal 15, object.val
14
+ end
15
+
16
+ end
@@ -0,0 +1,17 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class EnumerableTest < MiniTest::Unit::TestCase
8
+
9
+ def test_parses_enumerables
10
+ object = OBIX.parse string: fixture("objects/enumerable.xml")
11
+
12
+ assert_instance_of OBIX::Objects::Enumerable, object
13
+ assert_equal "/enums/OffSlowFast", object.range
14
+ assert_equal "slow", object.val
15
+ end
16
+
17
+ end
@@ -0,0 +1,47 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class ErrorTest < MiniTest::Unit::TestCase
8
+ def test_raises_errors
9
+ builder = OBIX::Builder.new do |obix|
10
+ obix.err display: "uh oh"
11
+ end
12
+
13
+ assert_raises OBIX::Error do
14
+ builder.object.raise
15
+ end
16
+ end
17
+
18
+ def test_raises_bad_uri_errors
19
+ builder = OBIX::Builder.new do |obix|
20
+ obix.err display: "uh oh", is: "obix:BadUriErr"
21
+ end
22
+
23
+ assert_raises OBIX::BadURIError do
24
+ builder.object.raise
25
+ end
26
+ end
27
+
28
+ def test_raises_unsupported_errors
29
+ builder = OBIX::Builder.new do |obix|
30
+ obix.err display: "uh oh", is: "obix:UnsupportedErr"
31
+ end
32
+
33
+ assert_raises OBIX::UnsupportedError do
34
+ builder.object.raise
35
+ end
36
+ end
37
+
38
+ def test_raises_permission_errors
39
+ builder = OBIX::Builder.new do |obix|
40
+ obix.err display: "uh oh", is: "obix:PermissionErr"
41
+ end
42
+
43
+ assert_raises OBIX::PermissionError do
44
+ builder.object.raise
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,16 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class FeedTest < MiniTest::Unit::TestCase
8
+
9
+ def test_parses_feeds
10
+ object = OBIX.parse string: fixture("objects/feed.xml")
11
+
12
+ assert_instance_of OBIX::Objects::Feed, object
13
+ assert_equal "obix:Alarm", object.of
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class FloatTest < MiniTest::Unit::TestCase
8
+
9
+ def test_parses_floats
10
+ object = OBIX.parse string: fixture("objects/float.xml")
11
+
12
+ assert_instance_of OBIX::Objects::Float, object
13
+ assert_equal 41.06, object.val
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class IntegerTest < MiniTest::Unit::TestCase
8
+
9
+ def test_parses_integers
10
+ object = OBIX.parse string: fixture("objects/integer.xml")
11
+
12
+ assert_instance_of OBIX::Objects::Integer, object
13
+ assert_equal 52, object.val
14
+ end
15
+
16
+ end
@@ -0,0 +1,17 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class ListTest < MiniTest::Unit::TestCase
8
+
9
+ def test_parses_booleans
10
+ object = OBIX.parse string: fixture("objects/list.xml")
11
+
12
+ assert_instance_of OBIX::Objects::List, object
13
+ assert_equal "obix:str", object.of
14
+ assert_equal 2, object.objects.size
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+ require "active_support/all"
5
+
6
+ require "test_helper"
7
+
8
+ class ObjectTest < MiniTest::Unit::TestCase
9
+
10
+ def test_parses_objects
11
+ object = OBIX.parse string: fixture("objects/object.xml")
12
+
13
+ assert_instance_of OBIX::Objects::Object, object
14
+ assert_equal "object", object.name
15
+ end
16
+
17
+ end
@@ -0,0 +1,37 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class OperationTest < MiniTest::Unit::TestCase
8
+ def test_parses_operations
9
+ operation = OBIX.parse string: fixture("objects/operation.xml")
10
+
11
+ assert_instance_of OBIX::Objects::Operation, operation
12
+ assert_equal "http://domain/operate", operation.href
13
+ assert_equal "obix:Nil", operation.in
14
+ assert_equal "obix:Nil", operation.out
15
+ end
16
+
17
+ def test_invokes_operations
18
+ operation = OBIX.parse string: fixture("objects/operation.xml")
19
+
20
+ object = OBIX::Objects::Object.new
21
+
22
+ OBIX::Network.
23
+ expects(
24
+ :post
25
+ ).
26
+ with(
27
+ 'http://domain/operate', object
28
+ ).
29
+ returns(
30
+ fixture "objects/string.xml"
31
+ )
32
+
33
+ result = operation.invoke object
34
+
35
+ assert_instance_of OBIX::Objects::String, result
36
+ end
37
+ end
@@ -0,0 +1,16 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class ReferenceTest < MiniTest::Unit::TestCase
8
+
9
+ def test_parses_references
10
+ object = OBIX.parse file: "test/fixtures/objects/reference.xml"
11
+
12
+ assert_instance_of OBIX::Objects::Reference, object
13
+ assert_equal "http://obix.org/", object.href
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class StringTest < MiniTest::Unit::TestCase
8
+
9
+ def test_parses_strings
10
+ object = OBIX.parse string: fixture("objects/string.xml")
11
+
12
+ assert_instance_of OBIX::Objects::String, object
13
+ assert_equal "hello world", object.val
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class TimeTest < MiniTest::Unit::TestCase
8
+
9
+ def test_parses_strings
10
+ object = OBIX.parse string: fixture("objects/time.xml")
11
+
12
+ assert_instance_of OBIX::Objects::Time, object
13
+ assert_equal Time.parse("2005-03-09 13:30:00 UTC"), object.val
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+
5
+ require "test_helper"
6
+
7
+ class URITest < MiniTest::Unit::TestCase
8
+
9
+ def test_parses_uris
10
+ object = OBIX.parse file: "test/fixtures/objects/uri.xml"
11
+
12
+ assert_instance_of OBIX::Objects::URI, object
13
+ assert_equal "http://obix.org/", object.val
14
+ end
15
+
16
+ end
@@ -0,0 +1,13 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+ require "nokogiri"
5
+ require "active_support/all"
6
+
7
+ require "test_helper"
8
+
9
+ class ObjectsTest < MiniTest::Unit::TestCase
10
+ def test_list
11
+ assert_equal 15, OBIX::Objects.list.size
12
+ end
13
+ end
@@ -0,0 +1,42 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+ require "nokogiri"
5
+ require "active_support/all"
6
+
7
+ require "test_helper"
8
+
9
+ class TagTest < MiniTest::Unit::TestCase
10
+ class Dummy < OBIX::Objects::Base
11
+ tag :dummy
12
+
13
+ attribute :foo, type: OBIX::Types::String
14
+ attribute :default, default: "default"
15
+ end
16
+
17
+ def test_tag
18
+ dummy = Dummy.new
19
+
20
+ assert_equal :dummy, dummy.tag
21
+ end
22
+
23
+ def test_get_attribute
24
+ dummy = Dummy.new
25
+ dummy.foo = "foo"
26
+
27
+ assert_equal "foo", dummy.foo
28
+ end
29
+
30
+ def test_set_attribute
31
+ dummy = Dummy.new
32
+ dummy.foo = "bar"
33
+
34
+ assert_equal "bar", dummy.foo
35
+ end
36
+
37
+ def test_default_attribute
38
+ dummy = Dummy.new
39
+
40
+ assert_equal "default", dummy.default
41
+ end
42
+ end
@@ -0,0 +1,18 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+ require "nokogiri"
5
+ require "active_support/all"
6
+
7
+ require "test_helper"
8
+
9
+ class BooleanTest < MiniTest::Unit::TestCase
10
+ def setup
11
+ @object = OBIX::Objects::Object.new
12
+ @type = OBIX::Types::Boolean.new @object
13
+ end
14
+
15
+ def test_cast
16
+ assert_equal true, @type.cast("true")
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+ require "nokogiri"
5
+ require "active_support/all"
6
+
7
+ require "test_helper"
8
+
9
+ class DateTest < MiniTest::Unit::TestCase
10
+ def setup
11
+ @object = OBIX::Objects::Object.new
12
+ @type = OBIX::Types::Date.new @object
13
+ end
14
+
15
+ def test_cast
16
+ date = "2007-11-26"
17
+
18
+ assert_equal Date.parse(date), @type.cast(date)
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+ require "nokogiri"
5
+ require "active_support/all"
6
+
7
+ require "test_helper"
8
+
9
+ class DurationTest < MiniTest::Unit::TestCase
10
+ def setup
11
+ @object = OBIX::Objects::Object.new
12
+ @type = OBIX::Types::Duration.new @object
13
+ end
14
+
15
+ def test_cast
16
+ assert_equal 15, @type.cast("PT15S")
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require "obix"
2
+ require "minitest/unit"
3
+ require "minitest/autorun"
4
+ require "nokogiri"
5
+ require "active_support/all"
6
+
7
+ require "test_helper"
8
+
9
+ class FloatTest < MiniTest::Unit::TestCase
10
+ def setup
11
+ @object = OBIX::Objects::Object.new
12
+ @type = OBIX::Types::Float.new @object
13
+ end
14
+
15
+ def test_cast
16
+ assert_equal 25.5, @type.cast("25.5")
17
+ end
18
+ end