goz 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+
6
+ require 'goz/test_case'
7
+
8
+
9
+ class TestEventType < Goz::TestCase
10
+
11
+ def setup
12
+ super
13
+
14
+ @names = %w( admin_add admin_remove
15
+ group_add group_remove group_sync
16
+ group_service_add group_service_remove group_service_sync
17
+ member_add member_remove
18
+ service_add service_remove service_sync
19
+ user_add user_remove user_sync
20
+ )
21
+ end
22
+
23
+
24
+ def test_event_types
25
+ Goz::Database.instance { |db| assert_equal 16, db[:event_types].count }
26
+
27
+ Goz::EventType.order(:id).each_with_index do |event_type, idx|
28
+ assert_kind_of Goz::EventType, event_type
29
+ assert_equal @names[idx], event_type.name
30
+ end
31
+ end
32
+
33
+ def test_event_types_hash
34
+ assert_equal 16, Goz::EventType::TYPES.size
35
+ @names.each_with_index do |name, idx|
36
+ assert_not_nil Goz::EventType::TYPES[name]
37
+ assert_equal Goz::EventType::TYPES[name], idx + 1
38
+
39
+ assert_not_nil Goz::EventType.const_get( name.upcase.to_s )
40
+ assert_equal Goz::EventType.const_get( name.upcase.to_s ), idx + 1
41
+
42
+ assert_equal Goz::EventType::TYPES[name], Goz::EventType.const_get( name.upcase.to_s )
43
+ end
44
+ end
45
+
46
+ end
47
+
@@ -4,13 +4,18 @@ require 'simplecov'
4
4
  SimpleCov.start
5
5
 
6
6
  require 'goz'
7
- require 'test/unit'
7
+ require 'goz/test_case'
8
8
 
9
9
 
10
- class TestGoz < Test::Unit::TestCase
10
+ class TestGoz < Goz::TestCase
11
+
12
+ def setup
13
+ super
14
+ end
15
+
11
16
 
12
17
  def test_version
13
- assert_equal '0.0.2', Goz::VERSION
18
+ assert_equal '0.0.3', Goz::VERSION
14
19
  end
15
20
 
16
21
  end
@@ -0,0 +1,180 @@
1
+ # encoding: utf-8
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+
6
+ require 'goz/group'
7
+ require 'goz/test_case'
8
+
9
+
10
+ class TestGroup < Goz::TestCase
11
+
12
+ def setup
13
+ super
14
+
15
+ @display_name = 'Foo : Bar' # XXX
16
+ @identifier = 'd3b07384d113edec49eaa6238ad5ff00' # XXX
17
+ @name = 'foo:bar' # XXX
18
+ end
19
+
20
+
21
+ def test_default_initialization
22
+ blockable = false
23
+ group = Goz::Group.new do |group|
24
+ assert_kind_of Goz::Group, group
25
+ assert_nil group.display_name
26
+ assert_nil group.identifier
27
+ assert_nil group.name
28
+ assert_nil group.created_at
29
+ assert_nil group.modified_at
30
+ assert_nil group.synchronized_at
31
+ blockable = true
32
+ end
33
+ assert blockable, 'works as block'
34
+ assert_kind_of Goz::Group, group
35
+ assert_kind_of Goz::Group, Goz::Group.new
36
+ assert_nil group.display_name
37
+ assert_nil group.identifier
38
+ assert_nil group.name
39
+ assert_nil group.created_at
40
+ assert_nil group.modified_at
41
+ assert_nil group.synchronized_at
42
+ end
43
+
44
+ def test_find_by_name_for_group_that_does_not_exist
45
+ assert_nil Goz::Group.find_by_name @groups[:a][:name]
46
+ end
47
+
48
+ def test_create_with_invalid_parameters
49
+ assert_raise(RuntimeError, 'invalid display_name') { Goz::Group.create(nil) }
50
+ assert_raise(RuntimeError, 'invalid display_name') {
51
+ Goz::Group.create( :identifier => @identifier,
52
+ :name => @name
53
+ )
54
+ }
55
+ assert_raise(RuntimeError, 'invalid display_name') {
56
+ Goz::Group.create( :display_name => '',
57
+ :identifier => @identifier,
58
+ :name => @name
59
+ )
60
+ }
61
+ assert_raise(RuntimeError, 'invalid identifier') {
62
+ Goz::Group.create( :display_name => @display_name,
63
+ :name => @name
64
+ )
65
+ }
66
+ assert_raise(RuntimeError, 'invalid identifier') {
67
+ Goz::Group.create( :display_name => @display_name,
68
+ :identifier => '',
69
+ :name => @name
70
+ )
71
+ }
72
+ assert_raise(RuntimeError, 'invalid name') {
73
+ Goz::Group.create( :display_name => @display_name,
74
+ :identifier => @identifier
75
+ )
76
+ }
77
+ assert_raise(RuntimeError, 'invalid name') {
78
+ Goz::Group.create( :display_name => @display_name,
79
+ :identifier => @identifier,
80
+ :name => ''
81
+ )
82
+ }
83
+ end
84
+
85
+ def test_create
86
+ t = Time.now
87
+ g = Goz::Group.create( :display_name => @display_name,
88
+ :identifier => @identifier,
89
+ :name => @name
90
+ )
91
+ assert_not_nil g
92
+ assert_kind_of Goz::Group, g
93
+ assert_equal @display_name, g.display_name
94
+ assert_equal @identifier, g.identifier
95
+ assert_equal @name, g.name
96
+ assert_not_nil g.created_at
97
+ assert g.created_at >= t
98
+ end
99
+
100
+ def test_update
101
+ g = Goz::Group.create( :display_name => @display_name,
102
+ :identifier => @identifier,
103
+ :name => @name
104
+ )
105
+ g.name = g.name.reverse
106
+ g.save
107
+
108
+ assert_not_nil g.modified_at
109
+ assert_kind_of Time, g.modified_at
110
+ assert g.modified_at > g.created_at
111
+
112
+ assert_nil g.synchronized_at
113
+ end
114
+
115
+ def test_equality
116
+ g1 = Goz::Group.create( :display_name => @display_name,
117
+ :identifier => @identifier,
118
+ :name => @name
119
+ )
120
+ assert_not_nil g1
121
+
122
+ g2 = Goz::Group.find_by_name( g1.name )
123
+ assert_not_nil g2
124
+ assert_equal g1, g2
125
+
126
+ g3 = Goz::Group.create( :display_name => @display_name.reverse,
127
+ :identifier => @identifier.reverse,
128
+ :name => @name.reverse
129
+ )
130
+ assert_not_nil g3
131
+ assert_not_equal g1, g3
132
+ assert_not_equal g2, g3
133
+ end
134
+
135
+ def test_find_by_name_and_persistence
136
+ g1 = Goz::Group.find_by_name(@name)
137
+ assert_nil g1
138
+
139
+ g1 = Goz::Group.create( :display_name => @display_name,
140
+ :identifier => @identifier,
141
+ :name => @name
142
+ )
143
+
144
+ g2 = Goz::Group.find_by_name(@name)
145
+ assert_not_nil g2
146
+ assert_kind_of Goz::Group, g2
147
+ assert_equal g1, g2
148
+ end
149
+
150
+ def test_sync
151
+ g = Goz::Group.create @groups[:a]
152
+ assert_nil g.synchronized_at
153
+
154
+ t = Time.now
155
+ assert g.sync
156
+
157
+ assert_not_nil g.modified_at
158
+ assert g.modified_at > t
159
+ assert_not_nil g.synchronized_at
160
+ assert g.synchronized_at > t
161
+
162
+ t = Time.now
163
+ assert !g.sync
164
+
165
+ assert_not_nil g.modified_at
166
+ assert g.modified_at < t
167
+ assert_not_nil g.synchronized_at
168
+ assert g.synchronized_at < t
169
+
170
+ t = Time.now
171
+ assert g.sync(true)
172
+
173
+ assert_not_nil g.modified_at
174
+ assert g.modified_at > t
175
+ assert_not_nil g.synchronized_at
176
+ assert g.synchronized_at > t
177
+ end
178
+
179
+ end
180
+
@@ -0,0 +1,241 @@
1
+ # encoding: utf-8
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+
6
+ require 'goz/group'
7
+ require 'goz/group_service'
8
+ require 'goz/test_case'
9
+ require 'goz/service'
10
+
11
+
12
+ class TestGroupService < Goz::TestCase
13
+
14
+ def setup
15
+ super
16
+ end
17
+
18
+
19
+ def test_no_group_services
20
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
21
+ [ :a, :b ].each do |sym|
22
+ g = Goz::Group.create @groups[sym]
23
+ assert_not_nil g.services
24
+ assert_kind_of Array, g.services
25
+ assert_equal 0, g.services.size
26
+
27
+ s = Goz::Service.create @services[sym]
28
+ assert_not_nil s.groups
29
+ assert_kind_of Array, s.groups
30
+ assert_equal 0, s.groups.size
31
+ end
32
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
33
+ end
34
+
35
+ def test_add_group_to_service
36
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
37
+
38
+ g = Goz::Group.create( @groups[:a] )
39
+ s = Goz::Service.create( @services[:a] )
40
+
41
+ s.add_group(g)
42
+ s.save
43
+
44
+ assert_equal 1, g.services.size
45
+ assert_equal s, g.services.first
46
+ assert_equal 1, s.groups.size
47
+ assert_equal g, s.groups.first
48
+ Goz::Database.instance do |db|
49
+ assert_equal 1, db[:group_services].count
50
+ first = db[:group_services].first
51
+ assert_equal g.id, first[:group_id]
52
+ assert_equal s.id, first[:service_id]
53
+ end
54
+ end
55
+
56
+ def test_add_service_to_group
57
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
58
+
59
+ g = Goz::Group.create( @groups[:a] )
60
+ s = Goz::Service.create( @services[:a] )
61
+
62
+ g.add_service(s)
63
+ g.save
64
+
65
+ assert_equal 1, g.services.size
66
+ assert_equal s, g.services.first
67
+ assert_equal 1, s.groups.size
68
+ assert_equal g, s.groups.first
69
+ Goz::Database.instance do |db|
70
+ assert_equal 1, db[:group_services].count
71
+ first = db[:group_services].first
72
+ assert_equal g.id, first[:group_id]
73
+ assert_equal s.id, first[:service_id]
74
+ end
75
+ end
76
+
77
+ def test_remove_group_from_service
78
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
79
+
80
+ g = Goz::Group.create( @groups[:a] )
81
+ s = Goz::Service.create( @services[:a] )
82
+
83
+ s.add_group(g)
84
+ s.save
85
+
86
+ assert_equal 1, g.services.size
87
+ assert_equal s, g.services.first
88
+ assert_equal 1, s.groups.size
89
+ assert_equal g, s.groups.first
90
+
91
+ s.remove_group(g)
92
+ s.save
93
+ assert_equal 0, g.services.size
94
+ assert_equal 0, s.groups.size
95
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
96
+ end
97
+
98
+ def test_remove_service_from_group
99
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
100
+
101
+ g = Goz::Group.create( @groups[:a] )
102
+ s = Goz::Service.create( @services[:a] )
103
+
104
+ g.add_service(s)
105
+ g.save
106
+
107
+ assert_equal 1, g.services.size
108
+ assert_equal s, g.services.first
109
+ assert_equal 1, s.groups.size
110
+ assert_equal g, s.groups.first
111
+
112
+ g.remove_service(s)
113
+ g.save
114
+ assert_equal 0, g.services.size
115
+ assert_equal 0, s.groups.size
116
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
117
+ end
118
+
119
+ def test_add_duplicate_group_to_service
120
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
121
+
122
+ g = Goz::Group.create( @groups[:a] )
123
+ s = Goz::Service.create( @services[:a] )
124
+
125
+ s.add_group(g)
126
+ s.save
127
+
128
+ assert_equal 1, g.services.size
129
+ assert_equal s, g.services.first
130
+ assert_equal 1, s.groups.size
131
+ assert_equal g, s.groups.first
132
+
133
+ assert_raise(Sequel::DatabaseError) { s.add_group(g) }
134
+ assert_equal 1, s.groups.size
135
+ assert_equal [ g ], s.groups
136
+
137
+ Goz::Database.instance do |db|
138
+ assert_equal 1, db[:group_services].count
139
+ first = db[:group_services].first
140
+ assert_equal g.id, first[:group_id]
141
+ assert_equal s.id, first[:service_id]
142
+ end
143
+ end
144
+
145
+ def test_add_duplicate_service_to_group
146
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
147
+
148
+ g = Goz::Group.create( @groups[:a] )
149
+ s = Goz::Service.create( @services[:a] )
150
+
151
+ g.add_service(s)
152
+ g.save
153
+
154
+ assert_equal 1, g.services.size
155
+ assert_equal s, g.services.first
156
+ assert_equal 1, s.groups.size
157
+ assert_equal g, s.groups.first
158
+
159
+ assert_raise(Sequel::DatabaseError) { g.add_service(s) }
160
+ assert_equal 1, s.groups.size
161
+ assert_equal [ g ], s.groups
162
+
163
+ Goz::Database.instance do |db|
164
+ assert_equal 1, db[:group_services].count
165
+ first = db[:group_services].first
166
+ assert_equal g.id, first[:group_id]
167
+ assert_equal s.id, first[:service_id]
168
+ end
169
+ end
170
+
171
+ def test_delete_group
172
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
173
+ g = Goz::Group.create( @groups[:a] )
174
+ s = Goz::Service.create( @services[:a] )
175
+
176
+ g.add_service(s)
177
+ g.save
178
+
179
+ assert_equal 1, g.services.size
180
+ assert_equal s, g.services.first
181
+ assert_equal 1, s.groups.size
182
+ assert_equal g, s.groups.first
183
+
184
+ g.destroy
185
+ assert_nil Goz::Group.find_by_name( g.name )
186
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
187
+
188
+ s.reload
189
+ assert_equal [], s.groups
190
+ end
191
+
192
+ def test_delete_service
193
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
194
+ g = Goz::Group.create( @groups[:a] )
195
+ s = Goz::Service.create( @services[:a] )
196
+
197
+ s.add_group(g)
198
+ s.save
199
+
200
+ assert_equal 1, g.services.size
201
+ assert_equal s, g.services.first
202
+ assert_equal 1, s.groups.size
203
+ assert_equal g, s.groups.first
204
+
205
+ s.destroy
206
+ assert_nil Goz::Service.find_by_name( s.name )
207
+ Goz::Database.instance { |db| assert_equal 0, db[:group_services].count }
208
+
209
+ g.reload
210
+ assert_equal [], g.services
211
+ end
212
+
213
+ def test_sync
214
+ g = Goz::Group.create @groups[:a]
215
+ s = Goz::Service.create @services[:a]
216
+ g.add_service(s)
217
+ gs = Goz::GroupService.find( :group_id => g.id, :service_id => s.id )
218
+ assert_not_nil gs
219
+ assert_nil s.synchronized_at
220
+
221
+ t = Time.now
222
+ assert gs.sync
223
+
224
+ assert_not_nil gs.synchronized_at
225
+ assert gs.synchronized_at > t
226
+
227
+ t = Time.now
228
+ assert !gs.sync
229
+
230
+ assert_not_nil gs.synchronized_at
231
+ assert gs.synchronized_at < t
232
+
233
+ t = Time.now
234
+ assert gs.sync(true)
235
+
236
+ assert_not_nil gs.synchronized_at
237
+ assert gs.synchronized_at > t
238
+ end
239
+
240
+ end
241
+