azure 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +36 -0
  3. data/README.md +3 -0
  4. data/Rakefile +81 -0
  5. data/azure.gemspec +20 -9
  6. data/lib/azure.rb +4 -0
  7. data/lib/azure/atom.rb +170 -0
  8. data/lib/azure/auth.rb +29 -0
  9. data/lib/azure/blobs.rb +620 -0
  10. data/lib/azure/blobs/blob.rb +360 -0
  11. data/lib/azure/blobs/container.rb +209 -0
  12. data/lib/azure/blobs/service.rb +396 -0
  13. data/lib/azure/blobs/shared_access_signature.rb +84 -0
  14. data/lib/azure/blobs/uri.rb +60 -0
  15. data/lib/azure/configuration.rb +121 -0
  16. data/lib/azure/core/auth/shared_key.rb +95 -0
  17. data/lib/azure/core/auth/shared_key_lite.rb +34 -0
  18. data/lib/azure/core/collection.rb +118 -0
  19. data/lib/azure/core/service.rb +43 -0
  20. data/lib/azure/core/signer.rb +32 -0
  21. data/lib/azure/core/utils/interval.rb +97 -0
  22. data/lib/azure/core/utils/queryable.rb +74 -0
  23. data/lib/azure/core/utils/storage_service_properties.rb +83 -0
  24. data/lib/azure/core/utils/string.rb +59 -0
  25. data/lib/azure/error.rb +72 -0
  26. data/lib/azure/queues.rb +272 -0
  27. data/lib/azure/queues/message.rb +174 -0
  28. data/lib/azure/queues/queue.rb +187 -0
  29. data/lib/azure/queues/service.rb +263 -0
  30. data/lib/azure/queues/service_properties.rb +152 -0
  31. data/lib/azure/queues/uri.rb +78 -0
  32. data/lib/azure/request.rb +102 -0
  33. data/lib/azure/response.rb +93 -0
  34. data/lib/azure/service_bus.rb +4 -0
  35. data/lib/azure/service_bus/auth/authorizer.rb +22 -0
  36. data/lib/azure/service_bus/auth/uri.rb +52 -0
  37. data/lib/azure/service_bus/auth/wrap.rb +37 -0
  38. data/lib/azure/service_bus/auth/wrap_service.rb +76 -0
  39. data/lib/azure/service_bus/auth/wrap_token.rb +45 -0
  40. data/lib/azure/service_bus/auth/wrap_token_manager.rb +46 -0
  41. data/lib/azure/service_bus/brokered_message.rb +139 -0
  42. data/lib/azure/service_bus/brokered_message_serializer.rb +113 -0
  43. data/lib/azure/service_bus/queues.rb +194 -0
  44. data/lib/azure/service_bus/queues/queue.rb +100 -0
  45. data/lib/azure/service_bus/queues/queue_serializer.rb +51 -0
  46. data/lib/azure/service_bus/queues/service.rb +154 -0
  47. data/lib/azure/service_bus/queues/uri.rb +80 -0
  48. data/lib/azure/service_bus/rules.rb +110 -0
  49. data/lib/azure/service_bus/rules/rule.rb +97 -0
  50. data/lib/azure/service_bus/rules/service.rb +122 -0
  51. data/lib/azure/service_bus/rules/uri.rb +39 -0
  52. data/lib/azure/service_bus/service_bus_service.rb +22 -0
  53. data/lib/azure/service_bus/subscriptions.rb +170 -0
  54. data/lib/azure/service_bus/subscriptions/service.rb +133 -0
  55. data/lib/azure/service_bus/subscriptions/subscription.rb +164 -0
  56. data/lib/azure/service_bus/subscriptions/subscription_serializer.rb +74 -0
  57. data/lib/azure/service_bus/subscriptions/uri.rb +71 -0
  58. data/lib/azure/service_bus/topics.rb +120 -0
  59. data/lib/azure/service_bus/topics/service.rb +98 -0
  60. data/lib/azure/service_bus/topics/topic.rb +122 -0
  61. data/lib/azure/service_bus/topics/topic_serializer.rb +44 -0
  62. data/lib/azure/service_bus/topics/uri.rb +58 -0
  63. data/lib/azure/service_runtime/client/goal_state_pipe_monitor.rb +21 -0
  64. data/lib/azure/service_runtime/client/goal_state_protocol.rb +18 -0
  65. data/lib/azure/service_runtime/client/runtime_client.rb +135 -0
  66. data/lib/azure/service_runtime/deployment.rb +24 -0
  67. data/lib/azure/service_runtime/local_resource.rb +15 -0
  68. data/lib/azure/service_runtime/role.rb +17 -0
  69. data/lib/azure/service_runtime/role_environment.rb +206 -0
  70. data/lib/azure/service_runtime/role_environment_change.rb +32 -0
  71. data/lib/azure/service_runtime/role_instance.rb +35 -0
  72. data/lib/azure/service_runtime/role_instance_endpoint.rb +14 -0
  73. data/lib/azure/tables.rb +215 -0
  74. data/lib/azure/tables/auth/shared_key.rb +71 -0
  75. data/lib/azure/tables/auth/shared_key_lite.rb +30 -0
  76. data/lib/azure/tables/entities_collection.rb +66 -0
  77. data/lib/azure/tables/entity.rb +127 -0
  78. data/lib/azure/tables/service.rb +211 -0
  79. data/lib/azure/tables/table.rb +129 -0
  80. data/lib/azure/tables/tables_collection.rb +62 -0
  81. data/lib/azure/tables/types.rb +65 -0
  82. data/lib/azure/tables/uri.rb +62 -0
  83. data/test/fixtures/32px-fulls-black.jpg +0 -0
  84. data/test/fixtures/all_containers.xml +20 -0
  85. data/test/fixtures/all_tables.xml +22 -0
  86. data/test/fixtures/create_table_response_entry.xml +15 -0
  87. data/test/fixtures/error.xml +5 -0
  88. data/test/fixtures/insert_entity_response_entry.xml +25 -0
  89. data/test/fixtures/messages.xml +12 -0
  90. data/test/fixtures/query_entities_empty_response.xml +7 -0
  91. data/test/fixtures/query_entities_response.xml +45 -0
  92. data/test/fixtures/queue_service_properties.xml +22 -0
  93. data/test/fixtures/queue_service_properties_original.xml +19 -0
  94. data/test/fixtures/queues.xml +16 -0
  95. data/test/fixtures/sb_default_create_queue_response.xml +23 -0
  96. data/test/fixtures/sb_default_create_topic_response.xml +18 -0
  97. data/test/fixtures/sb_get_access_token_response.txt +1 -0
  98. data/test/fixtures/sb_queues_runtime_peek_message_response_headers.txt +9 -0
  99. data/test/integration/blobs/auth_test.rb +19 -0
  100. data/test/integration/blobs/blob_test.rb +61 -0
  101. data/test/integration/blobs/clear_page_range_test.rb +19 -0
  102. data/test/integration/blobs/copy_test.rb +33 -0
  103. data/test/integration/blobs/create_blobs_test.rb +51 -0
  104. data/test/integration/blobs/create_container_test.rb +13 -0
  105. data/test/integration/blobs/create_snapshot_test.rb +17 -0
  106. data/test/integration/blobs/delete_blob_snapshots_test.rb +19 -0
  107. data/test/integration/blobs/delete_blobs_test.rb +25 -0
  108. data/test/integration/blobs/delete_container_test.rb +24 -0
  109. data/test/integration/blobs/delete_snapshot_test.rb +17 -0
  110. data/test/integration/blobs/get_blob_snapshot_test.rb +18 -0
  111. data/test/integration/blobs/get_blobs_test.rb +31 -0
  112. data/test/integration/blobs/get_page_range_test.rb +19 -0
  113. data/test/integration/blobs/list_blobs_test.rb +39 -0
  114. data/test/integration/blobs/list_containers_test.rb +28 -0
  115. data/test/integration/blobs/manage_blob_leases_test.rb +45 -0
  116. data/test/integration/blobs/manage_blob_metadata_test.rb +51 -0
  117. data/test/integration/blobs/manage_blob_properties_test.rb +25 -0
  118. data/test/integration/blobs/manage_blob_service_properties_test.rb +38 -0
  119. data/test/integration/blobs/manage_container_metadata_test.rb +46 -0
  120. data/test/integration/blobs/manage_container_permissions_test.rb +17 -0
  121. data/test/integration/blobs/update_page_range_test.rb +20 -0
  122. data/test/integration/queues/clear_messages_test.rb +22 -0
  123. data/test/integration/queues/create_queue_test.rb +13 -0
  124. data/test/integration/queues/delete_message_test.rb +42 -0
  125. data/test/integration/queues/delete_queue_test.rb +24 -0
  126. data/test/integration/queues/get_messages_test.rb +39 -0
  127. data/test/integration/queues/list_queues_test.rb +43 -0
  128. data/test/integration/queues/manage_queue_metadata_test.rb +45 -0
  129. data/test/integration/queues/manage_queue_service_properties_test.rb +27 -0
  130. data/test/integration/queues/peek_messages_test.rb +55 -0
  131. data/test/integration/queues/put_message_test.rb +31 -0
  132. data/test/integration/queues/update_message_test.rb +46 -0
  133. data/test/integration/service_bus/auth_test.rb +18 -0
  134. data/test/integration/service_bus/queues/create_queue_test.rb +25 -0
  135. data/test/integration/service_bus/queues/delete_message_from_queue_test.rb +29 -0
  136. data/test/integration/service_bus/queues/delete_queue_test.rb +25 -0
  137. data/test/integration/service_bus/queues/get_queue_test.rb +23 -0
  138. data/test/integration/service_bus/queues/list_queues_test.rb +39 -0
  139. data/test/integration/service_bus/queues/peek_message_from_queue_test.rb +34 -0
  140. data/test/integration/service_bus/queues/read_and_delete_message_from_queue_test.rb +31 -0
  141. data/test/integration/service_bus/queues/send_message_to_queue_test.rb +22 -0
  142. data/test/integration/service_bus/queues/unlock_message_from_queue_test.rb +36 -0
  143. data/test/integration/service_bus/rules/create_rule_test.rb +19 -0
  144. data/test/integration/service_bus/rules/delete_rule_test.rb +17 -0
  145. data/test/integration/service_bus/rules/get_rule_test.rb +21 -0
  146. data/test/integration/service_bus/rules/list_rules_test.rb +24 -0
  147. data/test/integration/service_bus/rules/rule_test.rb +16 -0
  148. data/test/integration/service_bus/subscriptions/create_subscription_test.rb +25 -0
  149. data/test/integration/service_bus/subscriptions/delete_message_from_subscription_test.rb +31 -0
  150. data/test/integration/service_bus/subscriptions/delete_subscription_test.rb +30 -0
  151. data/test/integration/service_bus/subscriptions/fetch_subscription_test.rb +28 -0
  152. data/test/integration/service_bus/subscriptions/list_subscriptions_test.rb +23 -0
  153. data/test/integration/service_bus/subscriptions/peek_lock_message_from_subscription_test.rb +42 -0
  154. data/test/integration/service_bus/subscriptions/read_delete_message_from_subscription_test.rb +36 -0
  155. data/test/integration/service_bus/subscriptions/subscription_test.rb +31 -0
  156. data/test/integration/service_bus/subscriptions/unlock_message_from_subscription_test.rb +43 -0
  157. data/test/integration/service_bus/topics/create_topic_test.rb +25 -0
  158. data/test/integration/service_bus/topics/delete_topic_test.rb +25 -0
  159. data/test/integration/service_bus/topics/get_topic_test.rb +23 -0
  160. data/test/integration/service_bus/topics/list_topics_test.rb +39 -0
  161. data/test/integration/service_bus/topics/send_message_to_topic_test.rb +23 -0
  162. data/test/integration/tables/auth_test.rb +29 -0
  163. data/test/integration/tables/creating_tables_test.rb +16 -0
  164. data/test/integration/tables/delete_entity_test.rb +39 -0
  165. data/test/integration/tables/deleting_table_test.rb +22 -0
  166. data/test/integration/tables/insert_entity_test.rb +23 -0
  167. data/test/integration/tables/merge_entity_test.rb +28 -0
  168. data/test/integration/tables/query_entities_test.rb +131 -0
  169. data/test/integration/tables/query_tables_test.rb +63 -0
  170. data/test/integration/tables/update_entity_test.rb +54 -0
  171. data/test/integration/test_helper.rb +14 -0
  172. data/test/support/blobs.rb +12 -0
  173. data/test/support/env.rb +5 -0
  174. data/test/support/fixtures.rb +22 -0
  175. data/test/support/stubs.rb +28 -0
  176. data/test/support/table_names.rb +44 -0
  177. data/test/test_helper.rb +10 -0
  178. data/test/unit/atom_test.rb +58 -0
  179. data/test/unit/auth_test.rb +24 -0
  180. data/test/unit/blobs/blob_test.rb +5 -0
  181. data/test/unit/blobs/container_test.rb +67 -0
  182. data/test/unit/blobs/service_test.rb +17 -0
  183. data/test/unit/blobs/shared_access_signature_test.rb +66 -0
  184. data/test/unit/blobs_test.rb +156 -0
  185. data/test/unit/core/service_test.rb +57 -0
  186. data/test/unit/core/utils/interval_test.rb +70 -0
  187. data/test/unit/core/utils/queryable_test.rb +69 -0
  188. data/test/unit/core/utils/storage_service_properties_test.rb +66 -0
  189. data/test/unit/error_test.rb +39 -0
  190. data/test/unit/queues/message_test.rb +40 -0
  191. data/test/unit/queues/queue_test.rb +64 -0
  192. data/test/unit/queues/service_properties.rb +35 -0
  193. data/test/unit/request_test.rb +38 -0
  194. data/test/unit/response_test.rb +43 -0
  195. data/test/unit/service_bus/auth/authorizer_test.rb +27 -0
  196. data/test/unit/service_bus/auth/wrap_token_test.rb +28 -0
  197. data/test/unit/service_bus/queues/queue_test.rb +38 -0
  198. data/test/unit/service_bus/topics/topic_test.rb +33 -0
  199. data/test/unit/service_runtime/data/goalstate.xml +9 -0
  200. data/test/unit/service_runtime/data/roleenvironmentdata.xml +29 -0
  201. data/test/unit/service_runtime/data/runtime.xml +6 -0
  202. data/test/unit/service_runtime/role_environment_test.rb +144 -0
  203. data/test/unit/tables/auth/shared_key_lite_test.rb +39 -0
  204. data/test/unit/tables/auth/shared_key_test.rb +45 -0
  205. data/test/unit/tables/entities_collection_test.rb +39 -0
  206. data/test/unit/tables/entity_test.rb +72 -0
  207. data/test/unit/tables/table_test.rb +57 -0
  208. data/test/unit/tables_test.rb +302 -0
  209. data/test/unit/types_test.rb +67 -0
  210. metadata +310 -47
  211. data/LICENSE +0 -0
  212. data/README +0 -0
@@ -0,0 +1,40 @@
1
+ require "test_helper"
2
+ require "azure/queues/queue"
3
+ require "azure/queues/message"
4
+ require "azure/queues/uri"
5
+
6
+ describe Azure::Queues::Message do
7
+
8
+ let :service do
9
+ MiniTest::Mock.new
10
+ end
11
+
12
+ let :queue do
13
+ Azure::Queues::Queue.new(
14
+ "name",
15
+ Azure::Queues::URI.queue("name", {}, "http://username.blob.core.windows.net"),
16
+ {},
17
+ service
18
+ )
19
+ end
20
+
21
+ describe ".from_node" do
22
+ let :node do
23
+ Nokogiri::XML(Fixtures[:messages]) % "QueueMessagesList"
24
+ end
25
+
26
+ subject do
27
+ Azure::Queues::Message.from_node(node) { |m| m.queue = queue }
28
+ end
29
+
30
+ it "parses the node and gets the correct values for each attribute" do
31
+ subject.id.must_equal "5974b586-0df3-4e2d-ad0c-18e3892bfca2"
32
+ subject.insertion_time.must_equal Time.parse("Fri, 09 Oct 2009 21:04:30 GMT")
33
+ subject.expiration_time.must_equal Time.parse("Fri, 16 Oct 2009 21:04:30 GMT")
34
+ subject.pop_receipt.must_equal "YzQ4Yzg1MDItYTc0Ny00OWNjLTkxYTUtZGM0MDFiZDAwYzEw"
35
+ subject.time_next_visible.must_equal Time.parse("Fri, 09 Oct 2009 23:29:20 GMT")
36
+ subject.dequeue_count.must_equal 1
37
+ subject.text.must_equal "PHRlc3Q+dGhpcyBpcyBhIHRlc3QgbWVzc2FnZTwvdGVzdD4="
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,64 @@
1
+ require "test_helper"
2
+ require "azure/queues/queue"
3
+
4
+ describe Azure::Queues::Queue do
5
+ describe ".from_node" do
6
+ let :node do
7
+ Nokogiri::XML(Fixtures[:queues]) % "Queues"
8
+ end
9
+
10
+ subject do
11
+ Azure::Queues::Queue.from_node(node)
12
+ end
13
+
14
+ it "gets the name out of the node" do
15
+ subject.name.must_equal "queue-name"
16
+ end
17
+
18
+ it "gets the url out of the node" do
19
+ subject.url.must_equal URI("http://myaccount.queue.core.windows.net/queue-name")
20
+ end
21
+
22
+ it "gets the metadata out of the node" do
23
+ subject.metadata["Color"].must_equal "red"
24
+ subject.metadata["Shape"].must_equal "square"
25
+ end
26
+ end
27
+
28
+ let :service do
29
+ MiniTest::Mock.new
30
+ end
31
+
32
+ let :queue do
33
+ Azure::Queues::Queue.new(
34
+ "name",
35
+ Azure::Queues::URI.queue("name", {}, "http://myaccount.queue.core.windows.net"),
36
+ {},
37
+ service
38
+ )
39
+ end
40
+
41
+ describe "#delete" do
42
+ it "delegates to the service's #delete implementation" do
43
+ service.expect(:delete, true, [queue])
44
+ queue.delete
45
+ service.verify
46
+ end
47
+ end
48
+
49
+ describe "#load_metadata!" do
50
+ it "delegates to the service's #load_metadata implementation" do
51
+ service.expect(:load_metadata, {}, [queue])
52
+ queue.load_metadata!
53
+ service.verify
54
+ end
55
+ end
56
+
57
+ describe "#save_metadata!" do
58
+ it "delegates to the service's #save_metadata implementation" do
59
+ service.expect(:save_metadata, {}, [queue])
60
+ queue.save_metadata!
61
+ service.verify
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,35 @@
1
+ require "test_helper"
2
+ require "azure/queues/queue"
3
+ require "azure/queues/service_properties"
4
+ require "azure/queues/uri"
5
+
6
+ describe Azure::Queues::ServiceProperties do
7
+ describe ".from_node" do
8
+ let :node do
9
+ Nokogiri::XML(Fixtures[:queue_service_properties]) % "StorageServiceProperties"
10
+ end
11
+
12
+ subject do
13
+ Azure::Queues::ServiceProperties.from_node(node)
14
+ end
15
+
16
+ it "parses the node and gets the correct values for each attribute" do
17
+ subject.logging.must_be :kind_of?, Azure::Queues::ServiceProperties::Logging
18
+ subject.logging.version.must_equal "1.0"
19
+ subject.logging.delete.must_equal true
20
+ subject.logging.read.must_equal false
21
+ subject.logging.write.must_equal true
22
+ subject.logging.retention_policy.must_be :kind_of?, Azure::Queues::ServiceProperties::RetentionPolicy
23
+ subject.logging.retention_policy.enabled.must_equal true
24
+ subject.logging.retention_policy.days.must_equal "7"
25
+
26
+ subject.metrics.must_be :kind_of?, Azure::Queues::ServiceProperties::Metrics
27
+ subject.metrics.version.must_equal "1.0"
28
+ subject.metrics.enabled.must_equal true
29
+ subject.metrics.include_apis.must_equal false
30
+ subject.metrics.retention_policy.must_be :kind_of?, Azure::Queues::ServiceProperties::RetentionPolicy
31
+ subject.metrics.retention_policy.enabled.must_equal true
32
+ subject.metrics.retention_policy.days.must_equal "3"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ require "test_helper"
2
+ require "azure/request"
3
+
4
+ describe Azure::Request do
5
+ describe "#calculate_headers" do
6
+ let :clock do
7
+ clock = MiniTest::Mock.new
8
+ clock.stub(:now, "Sun, 03 May 2012 21:21:52 GMT")
9
+ clock
10
+ end
11
+
12
+ it "sets the Date and x-ms-date headers" do
13
+ request = Azure::Request.new(:get, URI("/"), nil, clock)
14
+
15
+ request.headers["x-ms-date"].must_equal clock.now
16
+ end
17
+
18
+ it "sets the Content-Type" do
19
+ request = Azure::Request.new(:get, URI("/"), "<body/>")
20
+
21
+ request.headers["Content-Type"].must_equal "application/atom+xml; charset=utf-8"
22
+ end
23
+
24
+ it "sets the Content-Type, Length, and MD5 if passed a body" do
25
+ request = Azure::Request.new(:get, URI("/"), "<body/>")
26
+
27
+ request.headers["Content-Length"].must_equal "7"
28
+ request.headers["Content-MD5"].must_equal Base64.strict_encode64(Digest::MD5.digest("<body/>"))
29
+ end
30
+
31
+ it "leaves the Content-Type, Length, and MD5 blank if the body is nil" do
32
+ request = Azure::Request.new(:get, URI("/"))
33
+
34
+ request.headers["Content-Length"].must_equal "0"
35
+ request.headers["Content-MD5"].must_be_nil
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+ require "azure/response"
3
+
4
+ describe Azure::Response do
5
+ it "can act as an error" do
6
+ http_response = MiniTest::Mock.new
7
+ http_response.stub(:body, Fixtures[:error])
8
+ http_response.stub(:code, "409")
9
+
10
+ response = Azure::Response.new(http_response)
11
+
12
+ assert_raises(Azure::HTTPError) do
13
+ raise response
14
+ end
15
+ end
16
+
17
+ it "converts net/http headers into strings" do
18
+ http_response = MiniTest::Mock.new
19
+ http_response.stub(:to_hash, { "Content-Type" => ["text/xml"] })
20
+
21
+ response = Azure::Response.new(http_response)
22
+ response.headers["Content-Type"].must_equal "text/xml"
23
+ end
24
+
25
+ describe Azure::Response::HeaderHash do
26
+ subject do
27
+ Azure::Response::HeaderHash.new(
28
+ "FooBar" => ["1"], "bazqux" => ["2"], "QUXFOO" => ["3"]
29
+ )
30
+ end
31
+
32
+ it "returns the header values as strings, not arrays" do
33
+ subject["FooBar"].must_equal "1"
34
+ subject["bazqux"].must_equal "2"
35
+ subject["QUXFOO"].must_equal "3"
36
+ end
37
+
38
+ it "obtains keys in a case-insensitive fashion" do
39
+ subject["foobar"].must_equal "1"
40
+ subject["BaZqUx"].must_equal "2"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ require "test_helper"
2
+ require "azure/service_bus/auth/authorizer"
3
+ require "azure/service_bus/auth/wrap"
4
+
5
+ describe Azure::ServiceBus::Auth::Authorizer do
6
+ before do
7
+ uri = double(path: "/path")
8
+
9
+ @access_token = "THEACCESSTOKEN"
10
+
11
+ @token_manager = MiniTest::Mock.new
12
+ @token_manager.stub(:get_access_token, @access_token)
13
+
14
+ @signer = Azure::ServiceBus::Auth::Wrap.new('issuer', 'access_key', @token_manager)
15
+
16
+ @request = MiniTest::Mock.new
17
+ @request.stub(:uri, uri)
18
+ @request.stub(:headers, {})
19
+ end
20
+
21
+ it "generates a proper Authorization header" do
22
+ auth = Azure::ServiceBus::Auth::Authorizer.new
23
+ auth.sign(@request, @signer)
24
+
25
+ @request.headers["Authorization"].must_equal "WRAP access_token=\"#{@access_token}\""
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ require "test_helper"
2
+ require "azure/service_bus/auth/wrap_token"
3
+
4
+ describe Azure::ServiceBus::Auth::WrapToken do
5
+
6
+ describe ".parse" do
7
+ let :response do
8
+ Fixtures["sb_get_access_token_response.txt"].read
9
+ end
10
+
11
+ let :expected_token do
12
+ "net.windows.servicebus.action=Listen%2cManage%2cSend&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fgmonfort-sb.accesscontrol.windows.net%2f&Audience=http%3a%2f%2fgmonfort.servicebus.windows.net%2f%24Resources%2fQueues&ExpiresOn=1338862002&Issuer=https%3a%2f%2fgmonfort-sb.accesscontrol.windows.net%2f&HMACSHA256=CFydD48JENdtcaha7TAcH8X4jXRKgFW6X7sRfbbrWBE%3d"
13
+ end
14
+
15
+ let :expected_expire_time do
16
+ "1199"
17
+ end
18
+
19
+ subject do
20
+ Azure::ServiceBus::Auth::WrapToken.parse(response)
21
+ end
22
+
23
+ it "parses the response and gets the correct values for each attribute" do
24
+ subject.access_token.must_equal expected_token
25
+ subject.expire_time.must_equal expected_expire_time
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ require "test_helper"
2
+ require "azure/service_bus/queues/queue"
3
+ require "time"
4
+ require "uri"
5
+
6
+ describe Azure::ServiceBus::Queues::Queue do
7
+ describe ".from_node" do
8
+ let :node do
9
+ Nokogiri::XML(Fixtures[:sb_default_create_queue_response]).remove_namespaces!
10
+ end
11
+
12
+ subject do
13
+ Azure::ServiceBus::Queues::Queue.from_node(node)
14
+ end
15
+
16
+ it "parses the node and gets the correct values for each attribute" do
17
+ subject.id.must_equal URI("https://gmonfort.servicebus.windows.net/gfyhfiwdqg")
18
+ subject.title.must_equal "gfyhfiwdqg"
19
+ subject.published.must_equal Time.parse("2012-06-06T05:00:06Z")
20
+ subject.updated.must_equal Time.parse("2012-06-06T05:00:06Z")
21
+ subject.author_name.must_equal "gmonfort"
22
+ subject.description.must_be :kind_of?, Hash
23
+ subject.description.size.must_equal 11
24
+
25
+ subject.description["LockDuration"].must_equal "PT1M"
26
+ subject.description["MaxSizeInMegabytes"].must_equal "1024"
27
+ subject.description["RequiresDuplicateDetection"].must_equal "false"
28
+ subject.description["RequiresSession"].must_equal "false"
29
+ subject.description["DefaultMessageTimeToLive"].must_equal "P10675199DT2H48M5.4775807S"
30
+ subject.description["DeadLetteringOnMessageExpiration"].must_equal "false"
31
+ subject.description["DuplicateDetectionHistoryTimeWindow"].must_equal "PT10M"
32
+ subject.description["MaxDeliveryCount"].must_equal "10"
33
+ subject.description["EnableBatchedOperations"].must_equal "true"
34
+ subject.description["SizeInBytes"].must_equal "0"
35
+ subject.description["MessageCount"].must_equal "0"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,33 @@
1
+ require "test_helper"
2
+ require "azure/service_bus/topics/topic"
3
+ require "time"
4
+ require "uri"
5
+
6
+ describe Azure::ServiceBus::Topics::Topic do
7
+ describe ".from_node" do
8
+ let :node do
9
+ Nokogiri::XML(Fixtures[:sb_default_create_topic_response]).remove_namespaces!
10
+ end
11
+
12
+ subject do
13
+ Azure::ServiceBus::Topics::Topic.from_node(node)
14
+ end
15
+
16
+ it "parses the node and gets the correct values for each attribute" do
17
+ subject.id.must_equal URI("https://gmonfort.servicebus.windows.net/htsjvyukon")
18
+ subject.title.must_equal "htsjvyukon"
19
+ subject.published.must_equal Time.parse("2012-06-07T19:49:00Z")
20
+ subject.updated.must_equal Time.parse("2012-06-07T19:49:01Z")
21
+ subject.author_name.must_equal "gmonfort"
22
+ subject.description.must_be :kind_of?, Hash
23
+ subject.description.size.must_equal 6
24
+
25
+ subject.description["DefaultMessageTimeToLive"].must_equal "P10675199DT2H48M5.4775807S"
26
+ subject.description["MaxSizeInMegabytes"].must_equal "1024"
27
+ subject.description["RequiresDuplicateDetection"].must_equal "false"
28
+ subject.description["DuplicateDetectionHistoryTimeWindow"].must_equal "PT10M"
29
+ subject.description["EnableBatchedOperations"].must_equal "true"
30
+ subject.description["SizeInBytes"].must_equal "0"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ 21c
2
+ <?xml version="1.0" encoding="utf-8"?>
3
+ <GoalState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
4
+ <Incarnation>1</Incarnation>
5
+ <ExpectedState>Started</ExpectedState>
6
+ <RoleEnvironmentPath>test/unit/service_runtime/data/roleenvironmentdata.xml</RoleEnvironmentPath>
7
+ <CurrentStateEndpoint>test/unit/service_runtime/data/output.xml</CurrentStateEndpoint>
8
+ <Deadline>9999-12-31T23:59:59.9999999</Deadline>
9
+ </GoalState>
@@ -0,0 +1,29 @@
1
+ <?xml version="0.0" encoding="utf-8"?>
2
+ <RoleEnvironment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3
+ <Deployment id="deployment16(130)" emulated="true" />
4
+ <CurrentInstance id="deployment16(130).RubyRole.WorkerRole2_IN_0" roleName="WorkerRole2" faultDomain="0" updateDomain="0">
5
+ <ConfigurationSettings>
6
+ <ConfigurationSetting name="test" value="8" />
7
+ <ConfigurationSetting name="test2" value="string" />
8
+ </ConfigurationSettings>
9
+ <LocalResources>
10
+ <LocalResource name="DiagnosticStore" path="C:\Users\Administrator\AppData\Local\dftmp\Resources\7dbcfc02-ad16-40d3-a943-f407d20bd898\directory\DiagnosticStore\" sizeInMB="4096" />
11
+ <LocalResource name="ruby" path="C:\Users\Administrator\AppData\Local\dftmp\Resources\7dbcfc02-ad16-40d3-a943-f407d20bd898\directory\ruby\" sizeInMB="1000" />
12
+ </LocalResources>
13
+ <Endpoints>
14
+ <Endpoint name="HttpIn" address="127.255.0.1" port="9002" protocol="tcp" />
15
+ <Endpoint name="Internal2" address="127.255.0.1" port="9101" protocol="http" />
16
+ </Endpoints>
17
+ </CurrentInstance>
18
+ <Roles>
19
+ <Role name="WorkerRole">
20
+ <Instances>
21
+ <Instance id="deployment16(130).RubyRole.WorkerRole_IN_0" faultDomain="0" updateDomain="0">
22
+ <Endpoints>
23
+ <Endpoint name="Internal" address="127.255.0.0" port="9100" protocol="http" />
24
+ </Endpoints>
25
+ </Instance>
26
+ </Instances>
27
+ </Role>
28
+ </Roles>
29
+ </RoleEnvironment>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <RuntimeServerDiscovery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3
+ <RuntimeServerEndpoints>
4
+ <RuntimeServerEndpoint version="2011-03-08" path="test/unit/service_runtime/data/goalstate.xml" />
5
+ </RuntimeServerEndpoints>
6
+ </RuntimeServerDiscovery>
@@ -0,0 +1,144 @@
1
+ require 'azure/service_runtime/role_environment'
2
+ require 'eventmachine'
3
+ require 'minitest/autorun'
4
+ require 'em/minitest/spec'
5
+
6
+ describe Azure::ServiceRuntime::RoleEnvironment do
7
+ include EM::MiniTest::Spec
8
+
9
+ before do
10
+ @data_path = "test/unit/service_runtime/data/"
11
+ @runtime_endpoint = "#{@data_path}runtime.xml"
12
+ @output_pipe = "#{@data_path}output.xml"
13
+ end
14
+
15
+ subject do
16
+ Azure::ServiceRuntime::RoleEnvironment.endpoint = @runtime_endpoint
17
+ Azure::ServiceRuntime::RoleEnvironment
18
+ end
19
+
20
+ it "is available" do
21
+ assert subject.is_available?, "must be available"
22
+ end
23
+
24
+ describe ".deployment" do
25
+ it "should retrieve the deployment data correctly" do
26
+ deployment = subject.deployment
27
+
28
+ assert_equal 130, deployment.id
29
+ assert_equal "deployment16(130)", deployment.name
30
+ assert_equal true, deployment.is_emulated?
31
+ end
32
+ end
33
+
34
+ describe ".current_role_instance" do
35
+ it "should retrieve the current role instance properties correctly" do
36
+ role_instance = subject.current_role_instance
37
+
38
+ assert_equal "deployment16(130).RubyRole.WorkerRole2_IN_0", role_instance.id
39
+ assert_equal "WorkerRole2", role_instance.role_name
40
+ assert_equal 0, role_instance.fault_domain
41
+ assert_equal 0, role_instance.update_domain
42
+ end
43
+
44
+ it "should retrieve the endpoints correctly" do
45
+ endpoints = subject.current_role_instance.endpoints
46
+
47
+ assert_equal "HttpIn", endpoints["HttpIn"].name
48
+ assert_equal "127.255.0.1", endpoints["HttpIn"].address
49
+ assert_equal 9002, endpoints["HttpIn"].port
50
+ assert_equal "tcp", endpoints["HttpIn"].protocol
51
+
52
+ assert_equal "Internal2", endpoints["Internal2"].name
53
+ assert_equal "127.255.0.1", endpoints["Internal2"].address
54
+ assert_equal 9101, endpoints["Internal2"].port
55
+ assert_equal "http", endpoints["Internal2"].protocol
56
+ end
57
+
58
+ it "should retrieve the local resources correctly" do
59
+ local_resources = subject.current_role_instance.local_resources
60
+
61
+ assert_equal "DiagnosticStore", local_resources["DiagnosticStore"].name
62
+ assert_equal "C:\\Users\\Administrator\\AppData\\Local\\dftmp\\Resources\\7dbcfc02-ad16-40d3-a943-f407d20bd898\\directory\\DiagnosticStore\\", local_resources["DiagnosticStore"].path
63
+ assert_equal 4096, local_resources["DiagnosticStore"].size
64
+
65
+ assert_equal "ruby", local_resources["ruby"].name
66
+ assert_equal "C:\\Users\\Administrator\\AppData\\Local\\dftmp\\Resources\\7dbcfc02-ad16-40d3-a943-f407d20bd898\\directory\\ruby\\", local_resources["ruby"].path
67
+ assert_equal 1000, local_resources["ruby"].size
68
+ end
69
+
70
+ it "should retrieve the configuration settings correctly" do
71
+ configuration_settings = subject.current_role_instance.configuration_settings
72
+
73
+ assert_equal "8", configuration_settings["test"]
74
+ assert_equal "string", configuration_settings["test2"]
75
+ end
76
+ end
77
+
78
+ describe ".roles" do
79
+ it "should retrieve information about the other roles correctly" do
80
+ roles = subject.roles
81
+
82
+ assert_equal "WorkerRole", roles["WorkerRole"].name
83
+ assert_equal 1, roles["WorkerRole"].instances.size
84
+
85
+ role_instance = roles["WorkerRole"].instances["deployment16(130).RubyRole.WorkerRole_IN_0"]
86
+
87
+ assert_equal "deployment16(130).RubyRole.WorkerRole_IN_0", role_instance.id
88
+ assert_equal 0, role_instance.fault_domain
89
+ assert_equal 0, role_instance.update_domain
90
+ assert_equal "WorkerRole", role_instance.role_name
91
+
92
+ assert_equal({}, role_instance.configuration_settings)
93
+ assert_equal({}, role_instance.local_resources)
94
+ assert_equal 1, role_instance.endpoints.size
95
+
96
+ endpoint = role_instance.endpoints["Internal"]
97
+
98
+ assert_equal "Internal", endpoint.name
99
+ assert_equal "127.255.0.0", endpoint.address
100
+ assert_equal 9100, endpoint.port
101
+ assert_equal "http", endpoint.protocol
102
+ end
103
+ end
104
+
105
+ def assert_status(filename, status)
106
+ request = Nokogiri::XML(File.read(filename))
107
+ assert_equal 1, request.css('CurrentState').size
108
+ assert_equal 1, request.css('CurrentState > StatusLease').size
109
+ assert_equal subject.send(:client_id), request.css('CurrentState > StatusLease')[0]["ClientId"]
110
+ acquire_node = request.css('CurrentState > StatusLease > Acquire')[0]
111
+
112
+ assert_equal "1", acquire_node.css('Incarnation')[0].content
113
+ assert_equal status, acquire_node.css('Status')[0].content
114
+ assert_equal status, acquire_node.css('StatusDetail')[0].content
115
+ assert_equal "9999-12-31T23:59:59.999Z", acquire_node.css('Expiration')[0].content
116
+ end
117
+
118
+ describe ".request_recycle" do
119
+ after do
120
+ File.delete @output_pipe
121
+ end
122
+
123
+ it "should perform a valid recycle request" do
124
+ subject.request_recycle
125
+ assert_status(@output_pipe, "Recycle")
126
+ end
127
+ end
128
+
129
+ describe ".set_status" do
130
+ after do
131
+ File.delete @output_pipe
132
+ end
133
+
134
+ it "should perform a valid status change request to busy status" do
135
+ subject.set_status :busy
136
+ assert_status(@output_pipe, "Busy")
137
+ end
138
+
139
+ it "should perform a valid status change request to ready status" do
140
+ subject.set_status :ready
141
+ assert_status(@output_pipe, "Started")
142
+ end
143
+ end
144
+ end