ad-framework 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +12 -0
  3. data/README.markdown +36 -0
  4. data/Rakefile +19 -0
  5. data/ad-framework.gemspec +25 -0
  6. data/doc/open_ldap_server.markdown +17 -0
  7. data/extras/adtest.schema +304 -0
  8. data/extras/slapd.conf +10 -0
  9. data/lib/ad-framework.rb +53 -0
  10. data/lib/ad-framework/attribute.rb +35 -0
  11. data/lib/ad-framework/attribute_type.rb +133 -0
  12. data/lib/ad-framework/auxiliary_class.rb +24 -0
  13. data/lib/ad-framework/config.rb +72 -0
  14. data/lib/ad-framework/config/attribute_definition.rb +18 -0
  15. data/lib/ad-framework/config/mapping.rb +26 -0
  16. data/lib/ad-framework/exceptions.rb +17 -0
  17. data/lib/ad-framework/fields.rb +44 -0
  18. data/lib/ad-framework/patterns/callbacks.rb +47 -0
  19. data/lib/ad-framework/patterns/has_schema.rb +127 -0
  20. data/lib/ad-framework/patterns/persistence.rb +67 -0
  21. data/lib/ad-framework/patterns/searchable.rb +117 -0
  22. data/lib/ad-framework/patterns/validations.rb +50 -0
  23. data/lib/ad-framework/schema.rb +118 -0
  24. data/lib/ad-framework/structural_class.rb +61 -0
  25. data/lib/ad-framework/utilities/entry_builder.rb +77 -0
  26. data/lib/ad-framework/utilities/transaction.rb +32 -0
  27. data/lib/ad-framework/utilities/validator.rb +26 -0
  28. data/lib/ad-framework/version.rb +5 -0
  29. data/test/helper.rb +71 -0
  30. data/test/integration/defined_array_test.rb +49 -0
  31. data/test/integration/defined_integer_test.rb +48 -0
  32. data/test/integration/defined_string_test.rb +48 -0
  33. data/test/integration/defined_top_test.rb +101 -0
  34. data/test/integration/defined_user_test.rb +140 -0
  35. data/test/irb.rb +2 -0
  36. data/test/support/factory.rb +67 -0
  37. data/test/support/ldap.yml +6 -0
  38. data/test/support/schema/attribute_types.rb +67 -0
  39. data/test/support/schema/attributes.rb +10 -0
  40. data/test/support/schema/auxiliary_classes.rb +12 -0
  41. data/test/support/schema/structural_classes.rb +46 -0
  42. data/test/support/seed.rb +28 -0
  43. data/test/support/state.rb +29 -0
  44. data/test/unit/ad-framework/attribute_test.rb +84 -0
  45. data/test/unit/ad-framework/attribute_type/class_methods_test.rb +146 -0
  46. data/test/unit/ad-framework/attribute_type_test.rb +114 -0
  47. data/test/unit/ad-framework/auxiliary_class_test.rb +39 -0
  48. data/test/unit/ad-framework/config/attribute_definition_test.rb +26 -0
  49. data/test/unit/ad-framework/config/mapping_test.rb +41 -0
  50. data/test/unit/ad-framework/config_test.rb +121 -0
  51. data/test/unit/ad-framework/fields_test.rb +44 -0
  52. data/test/unit/ad-framework/patterns/callbacks_test.rb +90 -0
  53. data/test/unit/ad-framework/patterns/has_schema/class_methods_test.rb +214 -0
  54. data/test/unit/ad-framework/patterns/has_schema_test.rb +96 -0
  55. data/test/unit/ad-framework/patterns/persistence_test.rb +126 -0
  56. data/test/unit/ad-framework/patterns/searchable_test.rb +201 -0
  57. data/test/unit/ad-framework/patterns/validations_test.rb +113 -0
  58. data/test/unit/ad-framework/schema_test.rb +268 -0
  59. data/test/unit/ad-framework/structural_class_test.rb +64 -0
  60. data/test/unit/ad-framework/utilities/entry_builder_test.rb +107 -0
  61. data/test/unit/ad-framework/utilities/transaction_test.rb +50 -0
  62. data/test/unit/ad-framework/utilities/validator_test.rb +46 -0
  63. data/test/unit/ad-framework_test.rb +116 -0
  64. metadata +225 -0
@@ -0,0 +1,214 @@
1
+ require 'assert'
2
+
3
+ module AD::Framework::Patterns::HasSchema
4
+
5
+ class ClassMethodsTest < Assert::Context
6
+ desc "AD::Framework::Patterns::HasSchema class"
7
+ setup do
8
+ @module = AD::Framework::Patterns::HasSchema
9
+ @structural_class = Factory.structural_class do
10
+ attributes :name, :display_name
11
+ end
12
+ end
13
+ subject{ @structural_class }
14
+
15
+ should "return an instance of AD::Framework::Schema with #schema" do
16
+ assert_instance_of AD::Framework::Schema, subject.schema
17
+ end
18
+ end
19
+
20
+ class SetLdapNameTest < ClassMethodsTest
21
+ desc "setting ldap name"
22
+ setup do
23
+ @new_value = "awesomeness"
24
+ @structural_class.ldap_name(@new_value)
25
+ end
26
+
27
+ should "set the schema's ldap name" do
28
+ assert_match @new_value, subject.schema.ldap_name
29
+ end
30
+ end
31
+
32
+ class SetTreebaseTest < ClassMethodsTest
33
+ desc "setting treebase"
34
+ setup do
35
+ @new_value = "CN=container"
36
+ @structural_class.treebase(@new_value)
37
+ end
38
+
39
+ should "set the schema's treebase with a call to #treebase" do
40
+ assert_match @new_value, subject.schema.treebase
41
+ end
42
+ end
43
+
44
+ class SetRdnTest < ClassMethodsTest
45
+ desc "setting rdn"
46
+ setup do
47
+ @new_value = "name"
48
+ @structural_class.rdn(@new_value)
49
+ end
50
+
51
+ should "set the schema's rdn with a call to #rdn" do
52
+ assert_equal @new_value, subject.schema.rdn
53
+ end
54
+ end
55
+
56
+ class SetAttributesTest < ClassMethodsTest
57
+ desc "setting attributes"
58
+ setup do
59
+ @values = [ :name, :display_name ]
60
+ @structural_class.schema.expects(:add_attributes).with(@values)
61
+ end
62
+
63
+ should "add attributes to the schema" do
64
+ values = @values
65
+ assert_nothing_raised{ subject.attributes(*values) }
66
+ end
67
+ end
68
+
69
+ class SetReadAttributesTest < ClassMethodsTest
70
+ desc "setting read attributes"
71
+ setup do
72
+ @values = [ :name, :display_name ]
73
+ @structural_class.schema.expects(:add_read_attributes).with(@values)
74
+ end
75
+
76
+ should "add read attributes to the schema" do
77
+ values = @values
78
+ assert_nothing_raised{ subject.read_attributes(*values) }
79
+ end
80
+ end
81
+
82
+ class SetWriteAttributesTest < ClassMethodsTest
83
+ desc "setting write attributes"
84
+ setup do
85
+ @values = [ :name, :display_name ]
86
+ @structural_class.schema.expects(:add_write_attributes).with(@values)
87
+ end
88
+
89
+ should "add write attributes to the schema" do
90
+ values = @values
91
+ assert_nothing_raised{ subject.write_attributes(*values) }
92
+ end
93
+ end
94
+
95
+ class SetMustSetTest < ClassMethodsTest
96
+ desc "setting mandatory attributes"
97
+ setup do
98
+ @values = [ :name ]
99
+ @structural_class.schema.expects(:add_mandatory).with(@values)
100
+ end
101
+
102
+ should "add mandatory attributes to the schema" do
103
+ values = @values
104
+ assert_nothing_raised{ subject.must_set(*values) }
105
+ end
106
+ end
107
+
108
+ class BeforeCreateTest < ClassMethodsTest
109
+ desc "adding a before_create callback"
110
+ setup do
111
+ @values = [ :do_something_amazing, :another_amazing_thing ]
112
+ @structural_class.schema.expects(:add_callback).with(:before, :create, @values)
113
+ end
114
+
115
+ should "add callbacks to the schema" do
116
+ values = @values
117
+ assert_nothing_raised{ subject.before_create(*values) }
118
+ end
119
+ end
120
+
121
+ class BeforeUpdateTest < ClassMethodsTest
122
+ desc "adding a before_update callback"
123
+ setup do
124
+ @values = [ :do_something_amazing, :another_amazing_thing ]
125
+ @structural_class.schema.expects(:add_callback).with(:before, :update, @values)
126
+ end
127
+
128
+ should "add callbacks to the schema" do
129
+ values = @values
130
+ assert_nothing_raised{ subject.before_update(*values) }
131
+ end
132
+ end
133
+
134
+ class BeforeSaveTest < ClassMethodsTest
135
+ desc "adding a before_save callback"
136
+ setup do
137
+ @values = [ :do_something_amazing, :another_amazing_thing ]
138
+ @structural_class.schema.expects(:add_callback).with(:before, :create, @values)
139
+ @structural_class.schema.expects(:add_callback).with(:before, :update, @values)
140
+ end
141
+
142
+ should "add callbacks for create and update to the schema" do
143
+ values = @values
144
+ assert_nothing_raised{ subject.before_save(*values) }
145
+ end
146
+ end
147
+
148
+ class BeforeDestroyTest < ClassMethodsTest
149
+ desc "adding a before_destroy callback"
150
+ setup do
151
+ @values = [ :do_something_amazing, :another_amazing_thing ]
152
+ @structural_class.schema.expects(:add_callback).with(:before, :destroy, @values)
153
+ end
154
+
155
+ should "add callbacks to the schema" do
156
+ values = @values
157
+ assert_nothing_raised{ subject.before_destroy(*values) }
158
+ end
159
+ end
160
+
161
+ class AfterCreateTest < ClassMethodsTest
162
+ desc "adding a after_create callback"
163
+ setup do
164
+ @values = [ :do_something_amazing, :another_amazing_thing ]
165
+ @structural_class.schema.expects(:add_callback).with(:after, :create, @values)
166
+ end
167
+
168
+ should "add callbacks to the schema" do
169
+ values = @values
170
+ assert_nothing_raised{ subject.after_create(*values) }
171
+ end
172
+ end
173
+
174
+ class AfterUpdateTest < ClassMethodsTest
175
+ desc "adding a after_update callback"
176
+ setup do
177
+ @values = [ :do_something_amazing, :another_amazing_thing ]
178
+ @structural_class.schema.expects(:add_callback).with(:after, :update, @values)
179
+ end
180
+
181
+ should "add callbacks to the schema" do
182
+ values = @values
183
+ assert_nothing_raised{ subject.after_update(*values) }
184
+ end
185
+ end
186
+
187
+ class AfterSaveTest < ClassMethodsTest
188
+ desc "adding a after_save callback"
189
+ setup do
190
+ @values = [ :do_something_amazing, :another_amazing_thing ]
191
+ @structural_class.schema.expects(:add_callback).with(:after, :create, @values)
192
+ @structural_class.schema.expects(:add_callback).with(:after, :update, @values)
193
+ end
194
+
195
+ should "add callbacks for create and update to the schema" do
196
+ values = @values
197
+ assert_nothing_raised{ subject.after_save(*values) }
198
+ end
199
+ end
200
+
201
+ class AfterDestroyTest < ClassMethodsTest
202
+ desc "adding a after_destroy callback"
203
+ setup do
204
+ @values = [ :do_something_amazing, :another_amazing_thing ]
205
+ @structural_class.schema.expects(:add_callback).with(:after, :destroy, @values)
206
+ end
207
+
208
+ should "add callbacks to the schema" do
209
+ values = @values
210
+ assert_nothing_raised{ subject.after_destroy(*values) }
211
+ end
212
+ end
213
+
214
+ end
@@ -0,0 +1,96 @@
1
+ require 'assert'
2
+
3
+ module AD::Framework::Patterns::HasSchema
4
+
5
+ class BaseTest < Assert::Context
6
+ desc "AD::Framework::Patterns::HasSchema"
7
+ setup do
8
+ @structural_class = Factory.structural_class do
9
+ treebase "CN=Something, DC=example, DC=com"
10
+ attributes :name, :display_name
11
+ end
12
+ @instance = @structural_class.new({ :name => "someone", :display_name => "Someone" })
13
+ end
14
+ subject{ @instance }
15
+
16
+ should have_instance_methods :schema, :dn, :attributes, :attributes=
17
+ should have_class_methods :schema, :ldap_name, :treebase, :rdn, :attributes
18
+ should have_class_methods :read_attributes, :write_attributes, :must_set
19
+ should have_class_methods :before_create, :before_update, :before_save, :before_destroy
20
+ should have_class_methods :after_create, :after_update, :after_save, :after_destroy
21
+
22
+ should "return it's class's schema wtih a call to #schema" do
23
+ assert_equal subject.class.schema.klass, subject.schema.klass
24
+ end
25
+ should "return a hash of the attributes and their values with a call to #attributes" do
26
+ expected = subject.schema.attributes.inject({}) do |h, a|
27
+ h.merge({ a.to_sym => subject.send(a) })
28
+ end
29
+ assert_equal expected, subject.attributes
30
+ end
31
+ end
32
+
33
+ class DnTest < BaseTest
34
+ desc "dn method"
35
+ setup do
36
+ @distinguished_name = "CN=distinguishedname, #{subject.schema.treebase}"
37
+ @dn = "CN=dn, #{subject.schema.treebase}"
38
+ @built_dn = "CN=#{subject.send(subject.schema.rdn)}, #{subject.schema.treebase}"
39
+ @instance.fields[:distinguishedname] = @distinguished_name
40
+ @instance.fields[:dn] = @dn
41
+ end
42
+ subject{ @instance }
43
+
44
+ should "return the distinguished name field" do
45
+ assert_equal @distinguished_name, subject.dn
46
+ end
47
+ end
48
+
49
+ class DnWithoutDistinguishedNameTest < DnTest
50
+ desc "without the distinguishedname field"
51
+ setup do
52
+ @instance.fields[:distinguishedname] = nil
53
+ end
54
+
55
+ should "return the dn field" do
56
+ assert_equal @dn, subject.dn
57
+ end
58
+ end
59
+
60
+ class DnWithNoFieldsTest < DnWithoutDistinguishedNameTest
61
+ desc "and without the dn field"
62
+ setup do
63
+ @instance.fields[:dn] = nil
64
+ end
65
+
66
+ should "return a concatenation of the rdn field and the treebase" do
67
+ assert_equal @built_dn, subject.dn
68
+ end
69
+ end
70
+
71
+ class SetObjectAttributesTest < BaseTest
72
+ desc "setting attributes"
73
+ setup do
74
+ @new_attributes = { :name => "amazing", :display_name => "Amazing" }
75
+ @instance.attributes = @new_attributes
76
+ end
77
+
78
+ should "set multiple attributes" do
79
+ assert_equal @new_attributes[:name], subject.name
80
+ assert_equal @new_attributes[:display_name], subject.display_name
81
+ end
82
+ end
83
+
84
+ class SetAttributesWithInvalidTest < BaseTest
85
+ desc "setting attributes with ignored key/values"
86
+ setup do
87
+ @new_attributes = { :something => "something" }
88
+ end
89
+
90
+ should "be ignored" do
91
+ new_attributes = @new_attributes
92
+ assert_nothing_raised{ subject.attributes = new_attributes }
93
+ end
94
+ end
95
+
96
+ end
@@ -0,0 +1,126 @@
1
+ require 'assert'
2
+
3
+ module AD::Framework::Patterns::Persistence
4
+
5
+ class BaseTest < Assert::Context
6
+ desc "the persistence pattern"
7
+ setup do
8
+ @structural_class = Factory.structural_class do
9
+ ldap_name "persistenceTestObject"
10
+ attributes :name, :system_flags
11
+ end
12
+ @instance = @structural_class.new({ :name => "test", :system_flags => 1 })
13
+ @mock_connection = mock()
14
+ @instance.stubs(:connection).returns(@mock_connection)
15
+ end
16
+ subject{ @instance }
17
+
18
+ should have_instance_methods :new_entry?, :save, :create, :update, :destroy
19
+ should have_class_methods :create
20
+
21
+ should "return true with #new_entry?" do
22
+ assert_equal true, subject.new_entry?
23
+ end
24
+ should "call #create with #save" do
25
+ subject.expects(:create)
26
+ assert_nothing_raised{ subject.save }
27
+ end
28
+ end
29
+
30
+ class WithDistinguishedNameFieldTest < BaseTest
31
+ desc "with a distinguishedname field set"
32
+ setup do
33
+ @instance.fields[:distinguishedname] = "distinguishedname"
34
+ end
35
+
36
+ should "return false with #new_entry?" do
37
+ assert_equal false, subject.new_entry?
38
+ end
39
+ should "call #create with #save" do
40
+ subject.expects(:update)
41
+ assert_nothing_raised{ subject.save }
42
+ end
43
+ end
44
+
45
+ class WithDnFieldTest < BaseTest
46
+ desc "with a dn field set"
47
+ setup do
48
+ @instance.fields[:dn] = "dn"
49
+ end
50
+
51
+ should "return false with #new_entry?" do
52
+ assert_equal false, subject.new_entry?
53
+ end
54
+ should "call #create with #save" do
55
+ subject.expects(:update)
56
+ assert_nothing_raised{ subject.save }
57
+ end
58
+ end
59
+
60
+ class CreateObjectTest < BaseTest
61
+ desc "create method"
62
+ setup do
63
+ @set_dn = @instance.dn
64
+ fields = @instance.fields.dup
65
+ fields[:objectclass] = @instance.schema.object_classes.collect(&:ldap_name).compact
66
+ fields[:distinguishedname] = @set_dn
67
+ @set_attributes = fields.to_hash
68
+ @mock_connection.expects(:add).with({ :dn => @set_dn, :attributes => @set_attributes })
69
+ @instance.expects(:reload)
70
+ end
71
+
72
+ should "call add on it's connection with the fields, including dn and objectclass" do
73
+ assert_nothing_raised{ @instance.create }
74
+ end
75
+ end
76
+
77
+ class UpdateObjectTest < BaseTest
78
+ desc "update method"
79
+ setup do
80
+ @instance.fields[:dn] = @instance.dn
81
+ @instance.attributes = { :name => "new name", :system_flags => 12 }
82
+ @mock_connection.expects(:open).yields(@mock_connection)
83
+ @instance.fields.changes.each do |name, value|
84
+ @mock_connection.expects(:replace_attribute).with(@instance.dn, name, value)
85
+ end
86
+ @instance.expects(:reload)
87
+ end
88
+
89
+ should "call replace attribute for every changed field" do
90
+ assert_nothing_raised{ subject.update }
91
+ end
92
+ end
93
+
94
+ class DestroyObjectTest < BaseTest
95
+ desc "destroy method"
96
+ setup do
97
+ @instance.fields[:dn] = @instance.dn
98
+ @mock_connection.expects(:delete).with(@instance.dn)
99
+ end
100
+
101
+ should "call delete on the connection" do
102
+ assert_nothing_raised{ subject.destroy }
103
+ end
104
+ end
105
+
106
+ class CreateClassMethodTest < Assert::Context
107
+ desc "create on the class"
108
+ setup do
109
+ @structural_class = Factory.structural_class do
110
+ ldap_name "persistenceClassTestObject"
111
+ attributes :name, :system_flags
112
+ end
113
+ @attributes = { :name => "from class", :system_flags => 5 }
114
+ mock_entry = mock()
115
+ @structural_class.expects(:new).returns(mock_entry).with(@attributes)
116
+ mock_entry.expects(:create)
117
+ end
118
+ subject{ @structural_class }
119
+
120
+ should "call create on a new entry build with attributes passed to it" do
121
+ attributes = @attributes
122
+ assert_nothing_raised{ subject.create(attributes) }
123
+ end
124
+ end
125
+
126
+ end
@@ -0,0 +1,201 @@
1
+ require 'assert'
2
+
3
+ module AD::Framework::Patterns::Searchable
4
+
5
+ class BaseTest < Assert::Context
6
+ desc "AD::Framework::Searchable"
7
+ setup do
8
+ @structural_class = Factory.structural_class do
9
+ ldap_name "searchableTestObject"
10
+ treebase "OU=Random"
11
+ end
12
+ AD::Framework.register_structural_class(@structural_class)
13
+ @fields = { "objectclass" => [ @structural_class.schema.ldap_name ] }
14
+ instance_fields = @fields.dup.merge({ "dn" => "CN=something, DC=example, DC=com" })
15
+ @instance = @structural_class.new({ :fields => instance_fields })
16
+ end
17
+ subject{ @instance }
18
+
19
+ should have_instance_methods :reload
20
+ should have_class_methods :find, :first, :all
21
+
22
+ teardown do
23
+ AD::Framework.defined_object_classes.delete(@structural_class.ldap_name.to_sym)
24
+ end
25
+ end
26
+
27
+ class ReloadTest < BaseTest
28
+ desc "reload method"
29
+ setup do
30
+ @search_args = {
31
+ :objectclass__eq => @instance.class.ldap_name, :base => @instance.treebase, :size => 1
32
+ }
33
+ @distinguishedname = "distinguishedname test"
34
+ @dn = "dn test"
35
+ @instance.fields[:distinguishedname] = @distinguishedname
36
+ @instance.fields[:dn] = @dn
37
+ @mock_connection = mock()
38
+ @instance.expects(:connection).returns(@mock_connection)
39
+ end
40
+ end
41
+
42
+ class WithDistinguishedNameTest < ReloadTest
43
+ desc "with distinguishedname field set"
44
+ setup do
45
+ @search_args[:dn__eq] = @instance.fields[:distinguishedname]
46
+ @mock_connection.expects(:search).with(@search_args).returns([ @fields ])
47
+ end
48
+
49
+ should "call search on it's connection with the distinguishedname field" do
50
+ assert_nothing_raised{ subject.reload }
51
+ end
52
+ end
53
+
54
+ class WithDnTest < ReloadTest
55
+ desc "without distinguishedname and with dn field set"
56
+ setup do
57
+ @instance.fields[:distinguishedname] = nil
58
+ @search_args[:dn__eq] = @instance.fields[:dn]
59
+ @mock_connection.expects(:search).with(@search_args).returns([ @fields ])
60
+ end
61
+
62
+ should "call search on it's connection with the dn field" do
63
+ assert_nothing_raised{ subject.reload }
64
+ end
65
+ end
66
+
67
+ class WithInvalidDnTest < ReloadTest
68
+ desc "with an invalid dn"
69
+ setup do
70
+ @instance.fields[:distinguishedname] = @instance.fields[:dn] = nil
71
+ @search_args[:dn__eq] = nil
72
+ @mock_connection.expects(:search).with(@search_args).returns([])
73
+ end
74
+ should "raise a not found exception if the search returns no entries" do
75
+ assert_raises(AD::Framework::EntryNotFound){ subject.reload }
76
+ end
77
+ end
78
+
79
+ class FirstMethodTest < BaseTest
80
+ desc "first method"
81
+ setup do
82
+ @structural_class = Factory.structural_class do
83
+ ldap_name "firstSearchableTestObject"
84
+ end
85
+ @first_args = { :name => "someone" }
86
+ @search_args = {
87
+ :name => @first_args[:name], :objectclass__eq => @structural_class.ldap_name,
88
+ :base => @structural_class.treebase, :size => 1
89
+ }
90
+ @mock_connection = mock()
91
+ @structural_class.expects(:connection).returns(@mock_connection)
92
+ @mock_connection.expects(:search).with(@search_args).returns([ @fields ])
93
+ end
94
+ subject{ @structural_class }
95
+
96
+ should "search with the args passed and return a single entry" do
97
+ found = nil
98
+ assert_nothing_raised{ found = subject.first(@first_args) }
99
+ assert found
100
+ assert_equal @fields, found.fields
101
+ end
102
+ end
103
+
104
+ class AllMethodTest < BaseTest
105
+ desc "all method"
106
+ setup do
107
+ @structural_class = Factory.structural_class do
108
+ ldap_name "allSearchableTestObject"
109
+ end
110
+ @all_args = { :where => { :name => "*some*" } }
111
+ @search_args = {
112
+ :name => @all_args[:where][:name], :objectclass__eq => @structural_class.ldap_name,
113
+ :base => @structural_class.treebase
114
+ }
115
+ @mock_connection = mock()
116
+ @structural_class.expects(:connection).returns(@mock_connection)
117
+ @mock_connection.expects(:search).with(@search_args).returns([ @fields.dup, @fields.dup ])
118
+ end
119
+ subject{ @structural_class }
120
+
121
+ should "search with the args passed and return multiple entries" do
122
+ all = nil
123
+ assert_nothing_raised{ all = subject.all(@all_args) }
124
+ assert_instance_of Array, all
125
+ all.each{|found| assert_equal(@fields, found.fields) }
126
+ end
127
+ end
128
+
129
+ class FindMethodWithDnTest < BaseTest
130
+ desc "find method with a dn"
131
+ setup do
132
+ @structural_class = Factory.structural_class do
133
+ ldap_name "findWithDNSearchableTestObject"
134
+ end
135
+ @dn = "CN=someone, #{@structural_class.treebase}"
136
+ @search_args = {
137
+ :dn__eq => @dn, :objectclass__eq => @structural_class.ldap_name,
138
+ :base => @structural_class.treebase, :size => 1
139
+ }
140
+ @mock_connection = mock()
141
+ @structural_class.expects(:connection).returns(@mock_connection)
142
+ @mock_connection.expects(:search).with(@search_args).returns([ @fields ])
143
+ end
144
+ subject{ @structural_class }
145
+
146
+ should "return an entry with a matching dn" do
147
+ found = nil
148
+ assert_nothing_raised{ found = subject.find(@dn) }
149
+ assert found
150
+ assert_equal(@fields, found.fields)
151
+ end
152
+ end
153
+
154
+ class FindMethodWithRdnTest < BaseTest
155
+ desc "find method with a rdn"
156
+ setup do
157
+ @structural_class = Factory.structural_class do
158
+ ldap_name "findWithRDNSearchableTestObject"
159
+ end
160
+ @rdn = "someone"
161
+ @search_args = {
162
+ :dn__eq => "CN=#{@rdn}, #{@structural_class.treebase}", :base => @structural_class.treebase,
163
+ :objectclass__eq => @structural_class.ldap_name, :size => 1
164
+ }
165
+ @mock_connection = mock()
166
+ @structural_class.expects(:connection).returns(@mock_connection)
167
+ @mock_connection.expects(:search).with(@search_args).returns([ @fields ])
168
+ end
169
+ subject{ @structural_class }
170
+
171
+ should "return an entry with a matching rdn" do
172
+ found = nil
173
+ assert_nothing_raised{ found = subject.find(@rdn) }
174
+ assert found
175
+ assert_equal(@fields, found.fields)
176
+ end
177
+ end
178
+
179
+ class FindMethodWithNotResultTest < BaseTest
180
+ desc "find method that returns no result"
181
+ setup do
182
+ @structural_class = Factory.structural_class do
183
+ ldap_name "findWithDNSearchableTestObject"
184
+ end
185
+ @dn = "CN=someone, #{@structural_class.treebase}"
186
+ @search_args = {
187
+ :dn__eq => @dn, :objectclass__eq => @structural_class.ldap_name,
188
+ :base => @structural_class.treebase, :size => 1
189
+ }
190
+ @mock_connection = mock()
191
+ @structural_class.expects(:connection).returns(@mock_connection)
192
+ @mock_connection.expects(:search).with(@search_args).returns([])
193
+ end
194
+ subject{ @structural_class }
195
+
196
+ should "raise an error when no entry is found" do
197
+ assert_raises(AD::Framework::EntryNotFound){ subject.find(@dn) }
198
+ end
199
+ end
200
+
201
+ end