splunk-sdk-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/CHANGELOG.md +160 -0
  2. data/Gemfile +8 -0
  3. data/LICENSE +177 -0
  4. data/README.md +310 -0
  5. data/Rakefile +40 -0
  6. data/examples/1_connect.rb +51 -0
  7. data/examples/2_manage.rb +103 -0
  8. data/examples/3_blocking_searches.rb +82 -0
  9. data/examples/4_asynchronous_searches.rb +79 -0
  10. data/examples/5_stream_data_to_splunk.rb +79 -0
  11. data/lib/splunk-sdk-ruby.rb +47 -0
  12. data/lib/splunk-sdk-ruby/ambiguous_entity_reference.rb +28 -0
  13. data/lib/splunk-sdk-ruby/atomfeed.rb +323 -0
  14. data/lib/splunk-sdk-ruby/collection.rb +417 -0
  15. data/lib/splunk-sdk-ruby/collection/apps.rb +35 -0
  16. data/lib/splunk-sdk-ruby/collection/case_insensitive_collection.rb +58 -0
  17. data/lib/splunk-sdk-ruby/collection/configuration_file.rb +50 -0
  18. data/lib/splunk-sdk-ruby/collection/configurations.rb +80 -0
  19. data/lib/splunk-sdk-ruby/collection/jobs.rb +136 -0
  20. data/lib/splunk-sdk-ruby/collection/messages.rb +51 -0
  21. data/lib/splunk-sdk-ruby/context.rb +522 -0
  22. data/lib/splunk-sdk-ruby/entity.rb +260 -0
  23. data/lib/splunk-sdk-ruby/entity/index.rb +191 -0
  24. data/lib/splunk-sdk-ruby/entity/job.rb +339 -0
  25. data/lib/splunk-sdk-ruby/entity/message.rb +36 -0
  26. data/lib/splunk-sdk-ruby/entity/saved_search.rb +71 -0
  27. data/lib/splunk-sdk-ruby/entity/stanza.rb +45 -0
  28. data/lib/splunk-sdk-ruby/entity_not_ready.rb +26 -0
  29. data/lib/splunk-sdk-ruby/illegal_operation.rb +27 -0
  30. data/lib/splunk-sdk-ruby/namespace.rb +239 -0
  31. data/lib/splunk-sdk-ruby/resultsreader.rb +716 -0
  32. data/lib/splunk-sdk-ruby/service.rb +339 -0
  33. data/lib/splunk-sdk-ruby/splunk_http_error.rb +49 -0
  34. data/lib/splunk-sdk-ruby/synonyms.rb +50 -0
  35. data/lib/splunk-sdk-ruby/version.rb +27 -0
  36. data/lib/splunk-sdk-ruby/xml_shim.rb +117 -0
  37. data/splunk-sdk-ruby.gemspec +27 -0
  38. data/test/atom_test_data.rb +472 -0
  39. data/test/data/atom/atom_feed_with_message.xml +19 -0
  40. data/test/data/atom/atom_with_feed.xml +99 -0
  41. data/test/data/atom/atom_with_several_entries.xml +101 -0
  42. data/test/data/atom/atom_with_simple_entries.xml +30 -0
  43. data/test/data/atom/atom_without_feed.xml +248 -0
  44. data/test/data/export/4.2.5/export_results.xml +88 -0
  45. data/test/data/export/4.3.5/export_results.xml +87 -0
  46. data/test/data/export/5.0.1/export_results.xml +78 -0
  47. data/test/data/export/5.0.1/nonreporting.xml +232 -0
  48. data/test/data/results/4.2.5/results-empty.xml +0 -0
  49. data/test/data/results/4.2.5/results-preview.xml +255 -0
  50. data/test/data/results/4.2.5/results.xml +336 -0
  51. data/test/data/results/4.3.5/results-empty.xml +0 -0
  52. data/test/data/results/4.3.5/results-preview.xml +1057 -0
  53. data/test/data/results/4.3.5/results.xml +626 -0
  54. data/test/data/results/5.0.2/results-empty.xml +1 -0
  55. data/test/data/results/5.0.2/results-empty_preview.xml +1 -0
  56. data/test/data/results/5.0.2/results-preview.xml +448 -0
  57. data/test/data/results/5.0.2/results.xml +501 -0
  58. data/test/export_test_data.json +360 -0
  59. data/test/resultsreader_test_data.json +1119 -0
  60. data/test/services.server.info.xml +43 -0
  61. data/test/services.xml +111 -0
  62. data/test/test_atomfeed.rb +71 -0
  63. data/test/test_collection.rb +278 -0
  64. data/test/test_configuration_file.rb +124 -0
  65. data/test/test_context.rb +119 -0
  66. data/test/test_entity.rb +95 -0
  67. data/test/test_helper.rb +250 -0
  68. data/test/test_http_error.rb +52 -0
  69. data/test/test_index.rb +91 -0
  70. data/test/test_jobs.rb +319 -0
  71. data/test/test_messages.rb +17 -0
  72. data/test/test_namespace.rb +188 -0
  73. data/test/test_restarts.rb +49 -0
  74. data/test/test_resultsreader.rb +106 -0
  75. data/test/test_roles.rb +41 -0
  76. data/test/test_saved_searches.rb +119 -0
  77. data/test/test_service.rb +65 -0
  78. data/test/test_users.rb +33 -0
  79. data/test/test_xml_shim.rb +28 -0
  80. data/test/testfile.txt +1 -0
  81. metadata +200 -0
@@ -0,0 +1,43 @@
1
+ <ns0:feed xmlns:ns0="http://www.w3.org/2005/Atom">
2
+ <ns0:title>server-info</ns0:title>
3
+ <ns0:id>https://localhost/services/server/info</ns0:id>
4
+ <ns0:updated>2011-07-01T16:53:53-07:00</ns0:updated>
5
+ <ns0:generator version="101089" />
6
+ <ns0:author>
7
+ <ns0:name>Splunk</ns0:name>
8
+ </ns0:author>
9
+ <ns1:totalResults xmlns:ns1="http://a9.com/-/spec/opensearch/1.1/">1</ns1:totalResults>
10
+ <ns1:itemsPerPage xmlns:ns1="http://a9.com/-/spec/opensearch/1.1/">30</ns1:itemsPerPage>
11
+ <ns1:startIndex xmlns:ns1="http://a9.com/-/spec/opensearch/1.1/">0</ns1:startIndex>
12
+ <ns1:messages xmlns:ns1="http://dev.splunk.com/ns/rest" />
13
+ <ns0:entry>
14
+ <ns0:title>server-info</ns0:title>
15
+ <ns0:id>https://localhost/services/server/info/server-info</ns0:id>
16
+ <ns0:updated>2011-07-01T16:53:53-07:00</ns0:updated>
17
+ <ns0:link href="/services/server/info/server-info" rel="alternate" />
18
+ <ns0:author>
19
+ <ns0:name>system</ns0:name>
20
+ </ns0:author>
21
+ <ns0:link href="/services/server/info/server-info" rel="list" />
22
+ <ns0:content type="text/xml">
23
+ <ns1:dict xmlns:ns1="http://dev.splunk.com/ns/rest">
24
+ <ns1:key name="build">101089</ns1:key>
25
+ <ns1:key name="cpu_arch">i386</ns1:key>
26
+ <ns1:key name="eai:acl"><ns1:dict><ns1:key name="app" /><ns1:key name="can_write">0</ns1:key><ns1:key name="modifiable">0</ns1:key><ns1:key name="owner">system</ns1:key><ns1:key name="perms"><ns1:dict><ns1:key name="read"><ns1:list><ns1:item>*</ns1:item></ns1:list></ns1:key><ns1:key name="write"><ns1:list /></ns1:key></ns1:dict></ns1:key><ns1:key name="sharing">system</ns1:key></ns1:dict></ns1:key>
27
+ <ns1:key name="guid">3FD18BC4-010D-4845-AD51-27963CB17412</ns1:key>
28
+ <ns1:key name="isFree">0</ns1:key>
29
+ <ns1:key name="isTrial">0</ns1:key>
30
+ <ns1:key name="licenseKeys"><ns1:list><ns1:item>E4BF242DB47AB54B5F9DC69D00E65A4BD4E89F917B93D0FA611EDF85ABFC639D</ns1:item></ns1:list></ns1:key>
31
+ <ns1:key name="licenseSignature">3af106e3af0db73ca69339684cad26eb</ns1:key>
32
+ <ns1:key name="licenseState">OK</ns1:key>
33
+ <ns1:key name="master_guid">3FD18BC4-010D-4845-AD51-27963CB17412</ns1:key>
34
+ <ns1:key name="mode">normal</ns1:key>
35
+ <ns1:key name="os_build">Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386</ns1:key>
36
+ <ns1:key name="os_name">Darwin</ns1:key>
37
+ <ns1:key name="os_version">10.8.0</ns1:key>
38
+ <ns1:key name="serverName">blovering.local</ns1:key>
39
+ <ns1:key name="version">4.3</ns1:key>
40
+ </ns1:dict>
41
+ </ns0:content>
42
+ </ns0:entry>
43
+ </ns0:feed>
data/test/services.xml ADDED
@@ -0,0 +1,111 @@
1
+ <ns0:feed xmlns:ns0="http://www.w3.org/2005/Atom">
2
+ <ns0:title>services</ns0:title>
3
+ <ns0:id>https://localhost/services/</ns0:id>
4
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
5
+ <ns0:generator version="101089" />
6
+ <ns0:author>
7
+ <ns0:name>Splunk</ns0:name>
8
+ </ns0:author>
9
+ <ns0:entry>
10
+ <ns0:title>alerts</ns0:title>
11
+ <ns0:id>https://localhost/services/alerts</ns0:id>
12
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
13
+ <ns0:link href="/services/alerts" rel="alternate" />
14
+ </ns0:entry>
15
+ <ns0:entry>
16
+ <ns0:title>apps</ns0:title>
17
+ <ns0:id>https://localhost/services/apps</ns0:id>
18
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
19
+ <ns0:link href="/services/apps" rel="alternate" />
20
+ </ns0:entry>
21
+ <ns0:entry>
22
+ <ns0:title>authentication</ns0:title>
23
+ <ns0:id>https://localhost/services/authentication</ns0:id>
24
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
25
+ <ns0:link href="/services/authentication" rel="alternate" />
26
+ </ns0:entry>
27
+ <ns0:entry>
28
+ <ns0:title>authorization</ns0:title>
29
+ <ns0:id>https://localhost/services/authorization</ns0:id>
30
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
31
+ <ns0:link href="/services/authorization" rel="alternate" />
32
+ </ns0:entry>
33
+ <ns0:entry>
34
+ <ns0:title>data</ns0:title>
35
+ <ns0:id>https://localhost/services/data</ns0:id>
36
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
37
+ <ns0:link href="/services/data" rel="alternate" />
38
+ </ns0:entry>
39
+ <ns0:entry>
40
+ <ns0:title>deployment</ns0:title>
41
+ <ns0:id>https://localhost/services/deployment</ns0:id>
42
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
43
+ <ns0:link href="/services/deployment" rel="alternate" />
44
+ </ns0:entry>
45
+ <ns0:entry>
46
+ <ns0:title>licenser</ns0:title>
47
+ <ns0:id>https://localhost/services/licenser</ns0:id>
48
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
49
+ <ns0:link href="/services/licenser" rel="alternate" />
50
+ </ns0:entry>
51
+ <ns0:entry>
52
+ <ns0:title>messages</ns0:title>
53
+ <ns0:id>https://localhost/services/messages</ns0:id>
54
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
55
+ <ns0:link href="/services/messages" rel="alternate" />
56
+ </ns0:entry>
57
+ <ns0:entry>
58
+ <ns0:title>configs</ns0:title>
59
+ <ns0:id>https://localhost/services/configs</ns0:id>
60
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
61
+ <ns0:link href="/services/configs" rel="alternate" />
62
+ </ns0:entry>
63
+ <ns0:entry>
64
+ <ns0:title>saved</ns0:title>
65
+ <ns0:id>https://localhost/services/saved</ns0:id>
66
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
67
+ <ns0:link href="/services/saved" rel="alternate" />
68
+ </ns0:entry>
69
+ <ns0:entry>
70
+ <ns0:title>scheduled</ns0:title>
71
+ <ns0:id>https://localhost/services/scheduled</ns0:id>
72
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
73
+ <ns0:link href="/services/scheduled" rel="alternate" />
74
+ </ns0:entry>
75
+ <ns0:entry>
76
+ <ns0:title>search</ns0:title>
77
+ <ns0:id>https://localhost/services/search</ns0:id>
78
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
79
+ <ns0:link href="/services/search" rel="alternate" />
80
+ </ns0:entry>
81
+ <ns0:entry>
82
+ <ns0:title>server</ns0:title>
83
+ <ns0:id>https://localhost/services/server</ns0:id>
84
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
85
+ <ns0:link href="/services/server" rel="alternate" />
86
+ </ns0:entry>
87
+ <ns0:entry>
88
+ <ns0:title>streams</ns0:title>
89
+ <ns0:id>https://localhost/services/streams</ns0:id>
90
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
91
+ <ns0:link href="/services/streams" rel="alternate" />
92
+ </ns0:entry>
93
+ <ns0:entry>
94
+ <ns0:title>broker</ns0:title>
95
+ <ns0:id>https://localhost/services/broker</ns0:id>
96
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
97
+ <ns0:link href="/services/broker" rel="alternate" />
98
+ </ns0:entry>
99
+ <ns0:entry>
100
+ <ns0:title>clustering</ns0:title>
101
+ <ns0:id>https://localhost/services/clustering</ns0:id>
102
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
103
+ <ns0:link href="/services/clustering" rel="alternate" />
104
+ </ns0:entry>
105
+ <ns0:entry>
106
+ <ns0:title>masterlm</ns0:title>
107
+ <ns0:id>https://localhost/services/masterlm</ns0:id>
108
+ <ns0:updated>2011-07-01T16:52:51-07:00</ns0:updated>
109
+ <ns0:link href="/services/masterlm" rel="alternate" />
110
+ </ns0:entry>
111
+ </ns0:feed>
@@ -0,0 +1,71 @@
1
+ require_relative "test_helper"
2
+ require "splunk-sdk-ruby"
3
+
4
+ include Splunk
5
+
6
+ # URI's classes compare by object identity, which is exactly what we
7
+ # *don't* want to do. Instead we use simple textual identity.
8
+ module URI
9
+ class Generic
10
+ def ==(other)
11
+ return self.to_s == other.to_s
12
+ end
13
+ end
14
+
15
+ class HTTPS
16
+ def ==(other)
17
+ return self.to_s == other.to_s
18
+ end
19
+ end
20
+
21
+ class HTTP
22
+ def ==(other)
23
+ return self.to_s == other.to_s
24
+ end
25
+ end
26
+ end
27
+
28
+ class TestAtomFeed < Test::Unit::TestCase
29
+ # If Nokogiri is available, we'll test AtomFeed against both it
30
+ # and REXML. Otherwise, we'll print a warning and test only against
31
+ # REXML. REXML is part of the standard library in Ruby 1.9, so it will
32
+ # always be present.
33
+ if nokogiri_available?
34
+ xml_libraries = [:nokogiri, :rexml]
35
+ else
36
+ xml_libraries = [:rexml]
37
+ puts "Nokogiri not installed. Skipping."
38
+ end
39
+
40
+ test_cases = eval(open("test/atom_test_data.rb").read())
41
+
42
+ xml_libraries.each do |xml_library|
43
+ test_cases.each_entry do |filename, expected|
44
+ define_method("test_#{xml_library}_#{filename}".intern()) do
45
+ file = File.open("test/data/atom/#{filename}.xml")
46
+ feed = Splunk::AtomFeed.new(file)
47
+
48
+ # To make debugging easy, test the metadata a key at
49
+ # a time, since Test::Unit doesn't display diffs.
50
+ # Then test the whole thing at the end to make sure it all matches.
51
+ expected[:metadata].each_entry do |key, value|
52
+ assert_equal([filename, key, value],
53
+ [filename, key, feed.metadata[key]])
54
+ end
55
+ assert_equal(expected[:metadata], feed.metadata)
56
+
57
+ # To make debugging easy, test each key of each entry
58
+ # separately, since Test::Unit doesn't display diffs.
59
+ # Then test the whole thing at the end to make sure it all matches.
60
+ expected[:entries].each_with_index do |entry, index|
61
+ entry.each_entry do |key, value|
62
+ assert_equal([filename, index, key, value],
63
+ [filename, index, key, feed.entries[index][key]])
64
+ end
65
+ end
66
+ assert_equal(expected[:entries], feed.entries)
67
+ end
68
+ end
69
+ end
70
+ end
71
+
@@ -0,0 +1,278 @@
1
+ require_relative 'test_helper'
2
+ require 'splunk-sdk-ruby'
3
+
4
+ include Splunk
5
+
6
+ class TestCollection < TestCaseWithSplunkConnection
7
+ def teardown
8
+ c = Collection.new(@service, ["saved", "searches"])
9
+ c.delete_if() { |e| e.name.start_with?("delete-me") }
10
+ super
11
+ end
12
+
13
+ def test_constructor
14
+ resource = [temporary_name(), temporary_name()]
15
+ c = Collection.new(@service, resource)
16
+ assert_equal(@service, c.service)
17
+ assert_equal(resource, c.resource)
18
+ assert_equal(Entity, c.entity_class)
19
+ end
20
+
21
+ def test_constructor_with_entity_class
22
+ resource = [temporary_name(), temporary_name()]
23
+ c = Collection.new(@service, resource, TestCollection)
24
+ assert_equal(@service, c.service)
25
+ assert_equal(resource, c.resource)
26
+ assert_equal(TestCollection, c.entity_class)
27
+ end
28
+
29
+ def test_each_without_pagination
30
+ n_entities = 0
31
+ @service.apps.each(:count => 5) do |entity|
32
+ assert_true(entity.is_a?(Entity))
33
+ n_entities += 1
34
+ end
35
+ assert_true(n_entities <= 5)
36
+ end
37
+
38
+ def test_each_with_offset_and_count
39
+ entities = []
40
+ @service.apps.each(:count => 5) do |entity|
41
+ entities << entity.name
42
+ end
43
+
44
+ entities_with_offset = []
45
+ @service.apps.each(:count => entities.length-1, :offset => 1) do |entity|
46
+ entities_with_offset << entity.name
47
+ end
48
+
49
+ assert_equal(entities[1..4], entities_with_offset)
50
+ end
51
+
52
+ def test_each_with_pagination
53
+ total = 5 + rand(15)
54
+ page_size = 1 + rand(3)
55
+
56
+ entities = []
57
+ @service.apps.each(:count => total) do |entity|
58
+ entities << entity.name
59
+ end
60
+
61
+ entities_with_pagination = []
62
+ @service.apps.each(:count => total, :page_size => page_size) do |entity|
63
+ entities_with_pagination << entity.name
64
+ end
65
+
66
+ assert_equal(entities, entities_with_pagination)
67
+ end
68
+
69
+ def test_has_key
70
+ c = @service.apps
71
+ @service.apps.each(:count => 3) do |entity|
72
+ assert_true(c.has_key?(entity.name))
73
+ assert_true(c.contains?(entity.name))
74
+ assert_true(c.include?(entity.name))
75
+ assert_true(c.key?(entity.name))
76
+ assert_true(c.member?(entity.name))
77
+ end
78
+
79
+ name = "nonexistant saved search"
80
+ assert_false(c.has_key?(name))
81
+ assert_false(c.contains?(name))
82
+ assert_false(c.include?(name))
83
+ assert_false(c.key?(name))
84
+ assert_false(c.member?(name))
85
+ end
86
+
87
+ def test_create_and_delete
88
+ search_name = temporary_name()
89
+ search = "search index=_internal | head 10"
90
+
91
+ c = Collection.new(@service, ["saved", "searches"])
92
+
93
+ c.create(search_name, :search => search)
94
+ assert_true(c.has_key?(search_name))
95
+
96
+ assert_equal(search_name,
97
+ c.fetch(search_name).name)
98
+ assert_equal(search_name,
99
+ c[search_name].name)
100
+
101
+ c.delete(search_name)
102
+ assert_false(c.has_key?(search_name))
103
+ end
104
+
105
+ def test_create_twice
106
+ search_name = temporary_name()
107
+ search = "search index=_internal | head 10"
108
+
109
+ c = Collection.new(@service, ["saved", "searches"])
110
+
111
+ c.create(search_name, :search => search)
112
+ assert_true(c.has_key?(search_name))
113
+
114
+ assert_raises(SplunkHTTPError) { c.create(search_name, :search => search) }
115
+
116
+ c.delete(search_name)
117
+ assert_false(c.has_key?(search_name))
118
+ end
119
+
120
+ def test_name_collisions
121
+ search_name = temporary_name()
122
+ search = "search * | head 5"
123
+
124
+ saved_searches = Collection.new(@service, ["saved", "searches"])
125
+ ss1 = saved_searches.create(search_name,
126
+ :search => search,
127
+ :namespace => Splunk::namespace(:sharing => "app",
128
+ :app => "search"))
129
+ ss2 = saved_searches.create(search_name, :search => search,
130
+ :namespace => Splunk::namespace(:sharing => "user",
131
+ :app => "search",
132
+ :owner => "admin"))
133
+
134
+ wildcard_service_args = @splunkrc.clone()
135
+ wildcard_service_args[:namespace] = Splunk::namespace(:sharing => "user",
136
+ :owner => "-",
137
+ :app => "-")
138
+ wildcard_service = Context.new(wildcard_service_args).login()
139
+
140
+ wildcard_saved_searches =
141
+ Collection.new(wildcard_service, ["saved", "searches"])
142
+ assert_true(wildcard_saved_searches.has_key?(search_name))
143
+
144
+ assert_raises(Splunk::AmbiguousEntityReference) do
145
+ wildcard_saved_searches.fetch(search_name)
146
+ end
147
+
148
+ assert_raises(Splunk::AmbiguousEntityReference) do
149
+ wildcard_saved_searches[search_name]
150
+ end
151
+
152
+ assert_equal(search_name,
153
+ wildcard_saved_searches.fetch(
154
+ search_name,
155
+ Splunk::namespace(:sharing => "app",
156
+ :app => "search")).name)
157
+ assert_equal(search_name,
158
+ wildcard_saved_searches.fetch(
159
+ search_name,
160
+ Splunk::namespace(:sharing => "user",
161
+ :app => "search",
162
+ :owner => "admin")).name)
163
+
164
+ assert_raises(StandardError) do
165
+ wildcard_saved_searches.delete(search_name)
166
+ end
167
+
168
+ # The order here is important. The app/search namespace
169
+ # will delete both of the saved searches; user/search/admin
170
+ # will only delete that particular one.
171
+ wildcard_saved_searches.delete(search_name,
172
+ namespace=Splunk::namespace(:sharing => "user",
173
+ :app => "search",
174
+ :owner => "admin"))
175
+ assert_true(wildcard_saved_searches.has_key?(search_name))
176
+ wildcard_saved_searches.delete(search_name,
177
+ namespace=Splunk::namespace(:sharing => "app", :app => "search"))
178
+
179
+ assert_false(wildcard_saved_searches.has_key?(search_name))
180
+ end
181
+
182
+ def test_values
183
+ es = @service.apps.values(:count => 3)
184
+ assert_true(es.length <= 3)
185
+ es.each do |entity|
186
+ assert_true(entity.is_a?(Entity))
187
+ end
188
+ end
189
+
190
+ def test_each_equivales_values
191
+ assert_equal(
192
+ @service.apps.each().to_a().map() { |e| e.name },
193
+ @service.apps.values.map() { |e| e.name }
194
+ )
195
+ end
196
+
197
+ def test_length
198
+ c = @service.apps
199
+ assert_equal(c.values().length(), c.length())
200
+ assert_equal(c.values().length(), c.size())
201
+ end
202
+
203
+
204
+ def test_select
205
+ a = @service.apps.select() { |e| e.name == "search" }.to_a
206
+ assert_equal(1, a.length)
207
+ assert_equal("search", a[0].name)
208
+ end
209
+
210
+ def test_reject
211
+ a = @service.apps.reject() { |e| e.name != "search" }.to_a
212
+ assert_equal(1, a.length)
213
+ assert_equal("search", a[0].name)
214
+ end
215
+
216
+ def test_fetch_nonexistant
217
+ assert_nil(@service.apps.fetch("this does not exist"))
218
+ end
219
+
220
+ def test_assoc
221
+ name, entity = @service.apps.assoc("search")
222
+ assert_equal("search", name)
223
+ assert_equal("search", entity.name)
224
+
225
+ assert_nil(@service.apps.assoc("this does not exist"))
226
+ end
227
+
228
+ def test_keys
229
+ keys = @service.apps.keys()
230
+ assert_equal(@service.apps.values().map() { |e| e.name },
231
+ keys)
232
+ end
233
+
234
+ def test_each_key
235
+ assert_equal(@service.apps.keys(), @service.apps.each_key.to_a)
236
+ end
237
+
238
+ def test_each_pair
239
+ keys = []
240
+ @service.apps.each_pair do |key, value|
241
+ assert_equal(key, value.name)
242
+ keys << key
243
+ end
244
+ assert_equal(@service.apps.keys(), keys)
245
+ end
246
+
247
+ def test_each_value
248
+ keys = []
249
+ @service.apps.each_value do |value|
250
+ keys << value.name
251
+ end
252
+ assert_equal(@service.apps.keys(), keys)
253
+ end
254
+
255
+ def test_empty
256
+ assert_false(@service.apps.empty?)
257
+ end
258
+
259
+ def test_delete_if
260
+ c = Collection.new(@service, ["saved", "searches"])
261
+
262
+ c.create(temporary_name(), :search => "search *")
263
+ c.create(temporary_name(), :search => "search *")
264
+ c.create(temporary_name(), :search => "search *")
265
+ assert_equal(
266
+ 3,
267
+ c.select() { |e| e.name.start_with?("delete-me") }.to_a.length()
268
+ )
269
+
270
+ c.delete_if() { |e| e.name.start_with?("delete-me") }
271
+
272
+ assert_equal(
273
+ 0,
274
+ c.select() { |e| e.name.start_with?("delete-me") }.to_a.length()
275
+ )
276
+ end
277
+
278
+ end