rtm 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/DISCLAIMER +10 -33
  2. data/LICENSE +201 -0
  3. data/README +3 -3
  4. data/lib/rtm.rb +148 -74
  5. data/lib/rtm/axes.rb +295 -0
  6. data/lib/rtm/axes/association.rb +76 -0
  7. data/lib/rtm/axes/associations.rb +96 -0
  8. data/lib/rtm/axes/assocs_names_occs.rb +56 -0
  9. data/lib/rtm/axes/characteristic.rb +68 -0
  10. data/lib/rtm/axes/characteristics.rb +93 -0
  11. data/lib/rtm/axes/string.rb +76 -0
  12. data/lib/rtm/axes/strings.rb +87 -0
  13. data/lib/rtm/axes/topic.rb +233 -0
  14. data/lib/rtm/axes/topics.rb +280 -0
  15. data/lib/rtm/{backward_compatibility.rb → deprecated/index_property_set.rb} +3 -0
  16. data/lib/rtm/engine.rb +58 -0
  17. data/lib/rtm/extensions.rb +11 -1
  18. data/lib/rtm/{locator_helpers.rb → helpers/locator.rb} +15 -4
  19. data/lib/rtm/{helpers.rb → helpers/no_output.rb} +3 -0
  20. data/lib/rtm/helpers/uri.rb +13 -0
  21. data/lib/rtm/io.rb +18 -0
  22. data/lib/rtm/io/from_xtm2_libxml.rb +2 -1
  23. data/lib/rtm/io/ontopia_io.rb +25 -0
  24. data/lib/rtm/io/tmapix.rb +234 -0
  25. data/lib/rtm/io/to_hash.rb +116 -0
  26. data/lib/rtm/io/to_jtm.rb +53 -103
  27. data/lib/rtm/io/to_rdf.rb +30 -0
  28. data/lib/rtm/io/to_string.rb +8 -6
  29. data/lib/rtm/io/to_xtm1.rb +6 -4
  30. data/lib/rtm/io/to_xtm2.rb +10 -8
  31. data/lib/rtm/io/to_yaml.rb +29 -98
  32. data/lib/rtm/navigation.rb +37 -0
  33. data/lib/rtm/navigation/association/players.rb +25 -0
  34. data/lib/rtm/navigation/name/atomify.rb +19 -0
  35. data/lib/rtm/navigation/name/characteristics.rb +33 -0
  36. data/lib/rtm/navigation/occurrence/atomify.rb +19 -0
  37. data/lib/rtm/navigation/occurrence/characteristics.rb +33 -0
  38. data/lib/rtm/navigation/topic/characteristics.rb +33 -0
  39. data/lib/rtm/navigation/topic/indicators.rb +31 -0
  40. data/lib/rtm/navigation/topic/items.rb +31 -0
  41. data/lib/rtm/navigation/topic/locators.rb +31 -0
  42. data/lib/rtm/navigation/topic/players.rb +27 -0
  43. data/lib/rtm/navigation/topic/supertypes.rb +162 -0
  44. data/lib/rtm/navigation/topic/traverse.rb +51 -0
  45. data/lib/rtm/navigation/topic/types.rb +107 -0
  46. data/lib/rtm/psi.rb +33 -2
  47. data/lib/rtm/sugar.rb +34 -0
  48. data/lib/rtm/sugar/association/hash_access.rb +46 -0
  49. data/lib/rtm/sugar/occurrence/dynamic_value.rb +75 -0
  50. data/lib/rtm/{pimp_my_api.rb → sugar/occurrence/externalize.rb} +3 -0
  51. data/lib/rtm/sugar/role/counterparts.rb +133 -46
  52. data/lib/rtm/sugar/topic/characteristics.rb +126 -12
  53. data/lib/rtm/sugar/topic/counterparts.rb +130 -7
  54. data/lib/rtm/sugar/topic/hash_access.rb +140 -30
  55. data/lib/rtm/sugar/topic/scoped.rb +65 -0
  56. data/lib/rtm/sugar/topic/topic_ref.rb +35 -0
  57. data/lib/rtm/sugar/topic/typed.rb +159 -0
  58. data/lib/rtm/sugar/typed/types.rb +38 -0
  59. data/lib/rtm/validation.rb +8 -5
  60. data/lib/rtm/version.rb +18 -0
  61. data/spec/helpers/spec_exampleexamplegroup.rb +14 -0
  62. data/spec/rtm/axes/association_spec.rb +88 -0
  63. data/spec/rtm/axes/associations_spec.rb +60 -0
  64. data/spec/rtm/axes/assocs_names_occs_spec.rb +9 -0
  65. data/spec/rtm/axes/characteristic_spec.rb +90 -0
  66. data/spec/rtm/axes/characteristics_spec.rb +85 -0
  67. data/spec/rtm/axes/string_spec.rb +145 -0
  68. data/spec/rtm/axes/strings_spec.rb +168 -0
  69. data/spec/rtm/axes/topic_spec.rb +124 -0
  70. data/spec/rtm/axes/topics_spec.rb +103 -0
  71. data/spec/rtm/base_spec.rb +32 -0
  72. data/spec/rtm/io/tmapix_spec.rb +85 -0
  73. data/spec/rtm/navigation/association/players_spec.rb +58 -0
  74. data/spec/rtm/navigation/association_spec.rb +52 -0
  75. data/spec/rtm/navigation/name/atomify_spec.rb +27 -0
  76. data/spec/rtm/navigation/name/characteristics_spec.rb +34 -0
  77. data/spec/rtm/navigation/name_spec.rb +52 -0
  78. data/spec/rtm/navigation/occurrence/atomify_spec.rb +27 -0
  79. data/spec/rtm/navigation/occurrence/characteristics_spec.rb +34 -0
  80. data/spec/rtm/navigation/occurrence_spec.rb +52 -0
  81. data/spec/rtm/navigation/string_spec.rb +51 -0
  82. data/spec/rtm/navigation/topic/characteristics_spec.rb +55 -0
  83. data/spec/rtm/navigation/topic/indicators_spec.rb +43 -0
  84. data/spec/rtm/navigation/topic/items_spec.rb +44 -0
  85. data/spec/rtm/navigation/topic/locators_spec.rb +44 -0
  86. data/spec/rtm/navigation/topic/players_spec.rb +48 -0
  87. data/spec/rtm/navigation/topic/scope_spec.rb +41 -0
  88. data/spec/rtm/navigation/topic/supertypes_spec.rb +376 -0
  89. data/spec/rtm/navigation/topic/traverse_spec.rb +64 -0
  90. data/spec/rtm/navigation/topic/types_spec.rb +195 -0
  91. data/spec/rtm/navigation/topic_spec.rb +153 -0
  92. data/spec/rtm/sugar/association/hash_access_spec.rb +55 -0
  93. data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +16 -0
  94. data/spec/rtm/sugar/role/counterparts_spec.rb +191 -0
  95. data/spec/rtm/sugar/topic/characteristics_spec.rb +318 -0
  96. data/spec/rtm/sugar/topic/counterparts_spec.rb +184 -0
  97. data/spec/rtm/sugar/topic/hash_access_spec.rb +234 -0
  98. data/spec/rtm/sugar/topic/scoped_spec.rb +131 -0
  99. data/spec/rtm/sugar/topic/topic_ref_spec.rb +44 -0
  100. data/spec/rtm/sugar/topic/typed_spec.rb +155 -0
  101. data/spec/rtm/sugar/typed/types_spec.rb +24 -0
  102. data/spec/rtm/tmapi/core/association_spec.rb +169 -0
  103. data/spec/rtm/tmapi/core/construct_spec.rb +25 -0
  104. data/spec/rtm/tmapi/core/name_spec.rb +85 -0
  105. data/spec/rtm/tmapi/core/occurrence_spec.rb +96 -0
  106. data/spec/rtm/tmapi/core/reifiable_spec.rb +168 -0
  107. data/spec/rtm/tmapi/core/role_spec.rb +73 -0
  108. data/spec/rtm/tmapi/core/scoped_spec.rb +403 -0
  109. data/spec/rtm/tmapi/core/topic_map_spec.rb +648 -0
  110. data/spec/rtm/tmapi/core/topic_spec.rb +992 -0
  111. data/spec/rtm/tmapi/core/typed_spec.rb +112 -0
  112. data/spec/rtm/tmapi/core/variant_spec.rb +52 -0
  113. data/spec/rtm/tmapi/ext/java_util_set_spec.rb +34 -0
  114. data/spec/rtm/tmapi_spec.rb +44 -0
  115. data/spec/rtm/utils/sparql_spec.rb +26 -0
  116. data/spec/rtm_spec.rb +94 -0
  117. data/spec/spec_helper.rb +23 -0
  118. data/test/base_unit_test.rb +161 -0
  119. data/test/{base_test.rb → base_unit_test_tmapi.rb} +46 -43
  120. metadata +122 -66
  121. data/COPYRIGHT +0 -4
  122. data/lib/Rakefile.rb +0 -42
  123. data/lib/activetopicmaps.rb +0 -278
  124. data/lib/rtm/backend/active_record.rb +0 -58
  125. data/lib/rtm/backend/active_record/001_initial_schema.rb +0 -116
  126. data/lib/rtm/backend/active_record/association_and_role.rb +0 -33
  127. data/lib/rtm/backend/active_record/locators.rb +0 -55
  128. data/lib/rtm/backend/active_record/name_variant_occurrence.rb +0 -45
  129. data/lib/rtm/backend/active_record/quaaxtm2rtm.rb +0 -113
  130. data/lib/rtm/backend/active_record/quaaxtm2rtmviews.rb +0 -134
  131. data/lib/rtm/backend/active_record/set_wrapper.rb +0 -98
  132. data/lib/rtm/backend/active_record/tm_construct.rb +0 -62
  133. data/lib/rtm/backend/active_record/tm_delegator.rb +0 -345
  134. data/lib/rtm/backend/active_record/tm_set_delegator.rb +0 -195
  135. data/lib/rtm/backend/active_record/tmdm.rb +0 -298
  136. data/lib/rtm/backend/active_record/topic.rb +0 -87
  137. data/lib/rtm/backend/active_record/topic_map.rb +0 -314
  138. data/lib/rtm/backend/active_record/traverse_associations.rb +0 -87
  139. data/lib/rtm/base.rb +0 -92
  140. data/lib/rtm/connect.rb +0 -92
  141. data/lib/rtm/core_ext.rb +0 -6
  142. data/lib/rtm/io/from_xtm2.rb +0 -263
  143. data/lib/rtm/merging/merging.rb +0 -307
  144. data/lib/rtm/sugar/topic/identifier_direct.rb +0 -11
  145. data/lib/rtm/sugar/topic/predefined_associations.rb +0 -42
  146. data/lib/run_main_project.rb +0 -16
@@ -0,0 +1,992 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ require File.dirname(__FILE__) + '/../../../spec_helper'
5
+ module RTM::Topic
6
+
7
+ describe self do
8
+ before(:each) do
9
+ @tm = get_used_tm_sys_tm
10
+ end
11
+ after(:each) do
12
+ @tm.close
13
+ end
14
+
15
+ describe "#add_type" do
16
+ before(:each) do
17
+ @t1,@t2,@t3 = @tm.get!(["t1","t2","t3"])
18
+ end
19
+ it "should not create an type-instance-association" do
20
+ @t1.add_type(@t3)
21
+ if implementation_for_spec == :sesametm
22
+ pending "unless engine is SesameTM" do
23
+ @tm.should have(0).associations
24
+ end
25
+ else
26
+ @tm.should have(0).associations
27
+ end
28
+ end
29
+ it "should add a type if argument is a String" do
30
+ @t1.should have(0).types
31
+ @t1.add_type("t2")
32
+ @t1.add_type("t4")
33
+ @tm.get("t4").should_not be_nil
34
+ @t1.should have(2).types
35
+ @t1.types.should include @t2, @tm.get("t4")
36
+ end
37
+ it "should add a type if argument is a Locator" do
38
+ @t1.should have(0).types
39
+ locator1 = @tm.create_locator("t2")
40
+ locator2 = @tm.create_locator("t4")
41
+ @t1.add_type(locator1)
42
+ @t1.add_type(locator2)
43
+ @tm.get("t4").should_not be_nil
44
+ @t1.should have(2).types
45
+ @t1.types.should include @t2, @tm.get("t4")
46
+ end
47
+ it "should add a type if argument is a Topic" do
48
+ @t1.should have(0).types
49
+ @t1.add_type(@t2)
50
+ @t1.add_type(@t3)
51
+ @t1.should have(2).types
52
+ @t1.types.should include @t2, @t3
53
+ end
54
+ it "should raise an error, if no argument is given" do
55
+ lambda{@t1.add_type()}.should raise_error
56
+ end
57
+ it "should not add a type several times" do
58
+ @t1.should have(0).types
59
+ @t1.add_type("t2")
60
+ @t1.should have(1).types
61
+ @t1.types.should include @t2
62
+ @t1.add_type("t2")
63
+ @t1.should have(1).types
64
+ @t1.types.should include @t2
65
+ end
66
+ end
67
+
68
+ describe "#add_types" do
69
+ before(:each) do
70
+ @t1,@t2,@t3 = @tm.get!(["t1","t2","t3"])
71
+ end
72
+ it "should not add a type if no argument is given" do
73
+ @t1.should have(0).types
74
+ @t1.add_types()
75
+ @t1.should have(0).types
76
+ end
77
+ it "should add one type if one argument is given" do
78
+ # adding one
79
+ @t1.should have(0).types
80
+ @t1.add_types(@t2)
81
+ @t1.should have(1).types
82
+ @t1.types.should include @t2
83
+ # adding another
84
+ @t1.add_types("t4")
85
+ @t1.should have(2).types
86
+ @tm.get("t4").should_not be_nil
87
+ @t1.types.should include @t2, @tm.get("t4")
88
+ # adding t2 again -> should still have 2 types
89
+ @t1.add_types(@t2)
90
+ @t1.should have(2).types
91
+ @t1.types.should include @t2, @tm.get("t4")
92
+ end
93
+ it "should add several types if several arguments are given" do
94
+ @t1.should have(0).types
95
+ @t1.add_types(@t2, "t4", @tm.create_locator("t5"))
96
+ @t1.should have(3).types
97
+ @tm.get("t4").should_not be_nil
98
+ @tm.get("t5").should_not be_nil
99
+ @t1.types.should include @t2, @tm.get("t4"), @tm.get("t5")
100
+ end
101
+ it "should add several types if several arrays with arguments are given" do
102
+ @t1.should have(0).types
103
+ @t1.add_types([@t2, "t4"], @t3)
104
+ @t1.should have(3).types
105
+ @tm.get("t4").should_not be_nil
106
+ @t1.types.should include @t2, @tm.get("t4"), @t3
107
+ end
108
+ it "should raise an error if a hash is given" do
109
+ @t1.should have(0).types
110
+ lambda{@t1.add_types([@t2, "t4"], "x" => "y")}.should raise_error
111
+ end
112
+ end
113
+
114
+ describe "#add_instance" do
115
+ before(:each) do
116
+ @t1,@t2,@t3 = @tm.get!(["t1","t2","t3"])
117
+ end
118
+ it "should not create an type-instance-association" do
119
+ @t1.add_instance(@t3)
120
+ if implementation_for_spec == :sesametm
121
+ pending "unless engine is SesameTM" do
122
+ @tm.should have(0).associations
123
+ end
124
+ else
125
+ @tm.should have(0).associations
126
+ end
127
+ end
128
+ it "should add an instance if argument is a String" do
129
+ @t2.should have(0).types
130
+ @tm.get("t4").should be_nil
131
+ @t1.should have(0).instances
132
+ @t1.add_instance("t2")
133
+ @t1.add_instance("t4")
134
+ @tm.get("t4").should_not be_nil
135
+ @t1.should have(2).instances
136
+ @t1.instances.should include @t2, @tm.get("t4")
137
+ @t2.should have(1).types
138
+ @t2.types.should include @t1
139
+ @tm.get("t4").should have(1).types
140
+ @tm.get("t4").types.should include @t1
141
+ end
142
+ it "should add an instance if argument is a Locator" do
143
+ @t2.should have(0).types
144
+ @tm.get("t4").should be_nil
145
+ @t1.should have(0).instances
146
+ locator1 = @tm.create_locator("t2")
147
+ locator2 = @tm.create_locator("t4")
148
+ @t1.add_instance(locator1)
149
+ @t1.add_instance(locator2)
150
+ @tm.get("t4").should_not be_nil
151
+ @t1.should have(2).instances
152
+ @t1.instances.should include @t2, @tm.get("t4")
153
+ @t2.should have(1).types
154
+ @t2.types.should include @t1
155
+ @tm.get("t4").should have(1).types
156
+ @tm.get("t4").types.should include @t1
157
+ end
158
+ it "should add an instance if argument is a Topic" do
159
+ @t2.should have(0).types
160
+ @t3.should have(0).types
161
+ @t1.should have(0).instances
162
+ @t1.add_instance(@t2)
163
+ @t1.add_instance(@t3)
164
+ @t1.should have(2).instances
165
+ @t1.instances.should include @t2, @t3
166
+ @t2.should have(1).types
167
+ @t2.types.should include @t1
168
+ @t3.should have(1).types
169
+ @t3.types.should include @t1
170
+ end
171
+ it "should raise an error, if no argument is given" do
172
+ lambda{@t1.add_instance()}.should raise_error
173
+ end
174
+ it "should not add an instance several times" do
175
+ @t1.should have(0).instances
176
+ @t1.add_instance("t2")
177
+ @t1.should have(1).instances
178
+ @t1.instances.should include @t2
179
+ @t2.should have(1).types
180
+ @t1.add_instance("t2")
181
+ @t1.should have(1).instances
182
+ @t1.instances.should include @t2
183
+ @t2.should have(1).types
184
+ end
185
+ end
186
+
187
+ describe "#add_instances" do
188
+ before(:each) do
189
+ @t1,@t2,@t3 = @tm.get!(["t1","t2","t3"])
190
+ end
191
+ it "should not add an instance if no argument is given" do
192
+ @t1.should have(0).instances
193
+ @t1.add_types()
194
+ @t1.should have(0).instances
195
+ end
196
+ it "should add one instance if one argument is given" do
197
+ # adding one
198
+ @t1.should have(0).instances
199
+ @t2.should have(0).types
200
+ @t1.add_instances(@t2)
201
+ @t1.should have(1).instances
202
+ @t1.instances.should include @t2
203
+ @t2.should have(1).types
204
+ # adding another
205
+ @tm.get("t4").should be_nil
206
+ @t1.add_instances("t4")
207
+ @t1.should have(2).instances
208
+ @tm.get("t4").should_not be_nil
209
+ @t1.instances.should include @t2, @tm.get("t4")
210
+ @tm.get("t4").should have(1).types
211
+ # adding t2 again -> should still have 2 instances
212
+ @t1.add_instances(@t2)
213
+ @t1.should have(2).instances
214
+ @t1.instances.should include @t2, @tm.get("t4")
215
+ @tm.get("t4").should have(1).types
216
+ @t2.should have(1).types
217
+ end
218
+ it "should add several instances if several arguments are given" do
219
+ @t1.should have(0).instances
220
+ @t2.should have(0).types
221
+ @t1.add_instances(@t2, "t4", @tm.create_locator("t5"))
222
+ @t1.should have(3).instances
223
+ @tm.get("t4").should_not be_nil
224
+ @tm.get("t5").should_not be_nil
225
+ @t1.instances.should include @t2, @tm.get("t4"), @tm.get("t5")
226
+ @t2.should have(1).types
227
+ @tm.get("t4").should have(1).types
228
+ @tm.get("t5").should have(1).types
229
+ end
230
+ it "should add several instances if several arrays with arguments are given" do
231
+ @t1.should have(0).instances
232
+ @t1.add_instances([@t2, "t4"], @t3)
233
+ @t1.should have(3).instances
234
+ @tm.get("t4").should_not be_nil
235
+ @t1.instances.should include @t2, @tm.get("t4"), @t3
236
+ end
237
+ it "should raise an error if a hash is given" do
238
+ @t1.should have(0).instances
239
+ lambda{@t1.add_instances([@t2, "t4"], "x" => "y")}.should raise_error
240
+ end
241
+ end
242
+
243
+ describe "#remove_type" do
244
+ before(:each) do
245
+ @t1,@t2,@t3,@t4 = @tm.get!(["t1","t2","t3","t4"])
246
+ @t1.add_type(@t2)
247
+ @t1.add_type(@t3)
248
+ @t1.should have(2).types
249
+ @t1.types.should include @t2, @t3
250
+ end
251
+ it "should remove a type if argument is a String" do
252
+ @t1.remove_type("t2")
253
+ @t1.should have(1).types
254
+ @t1.types.should include @t3
255
+ @t1.remove_type("t3")
256
+ @t1.should have(0).types
257
+ end
258
+ it "should remove a type if argument is a Locator" do
259
+ @t1.remove_type(@tm.create_locator("t2"))
260
+ @t1.should have(1).types
261
+ @t1.types.should include @t3
262
+ @t1.remove_type(@tm.create_locator("t3"))
263
+ @t1.should have(0).types
264
+ end
265
+ it "should remove a type if argument is a Topic" do
266
+ @t1.remove_type(@t2)
267
+ @t1.should have(1).types
268
+ @t1.types.should include @t3
269
+ @t1.remove_type(@t3)
270
+ @t1.should have(0).types
271
+ end
272
+ it "should not remove a type if argument does not match a type of this Topic" do
273
+ @t1.remove_type("t4")
274
+ @t1.should have(2).types
275
+ @t1.remove_type("t5")
276
+ @t1.should have(2).types
277
+ @t1.remove_type(@tm.create_locator("t4"))
278
+ @t1.should have(2).types
279
+ @t1.remove_type(@tm.create_locator("t5"))
280
+ @t1.should have(2).types
281
+ @t1.remove_type(@t4)
282
+ @t1.should have(2).types
283
+ @t1.remove_type(@t5)
284
+ @t1.should have(2).types
285
+ @t1.types.should include @t2, @t3
286
+ end
287
+ end
288
+
289
+ describe "#parent" do
290
+ it "should give back the Topic Map" do
291
+ topic = @tm.create_topic_by("=weihnachtsmann")
292
+ topic.should be_a_kind_of RTM::Topic
293
+ @tm.get("=weihnachtsmann").should be_a_kind_of RTM::Topic
294
+ topic.parent.should be_a_kind_of RTM::TopicMap
295
+ topic.parent.should == @tm
296
+ end
297
+ end
298
+
299
+ describe "#names" do
300
+ before(:each) do
301
+ @topic = @tm.get!("person")
302
+ @value1 = "Bruce"
303
+ @value2 = "Bruce Smith"
304
+ @value3 = "Smith"
305
+ @value4 = "Bru"
306
+ @name1 = @topic.create_name(@value1)
307
+ @name2 = @topic.create_name(@value2)
308
+ @name3 = @topic.create_name("last",@value3)
309
+ @name4 = @topic.create_name("first",@value4,["friends"])
310
+ end
311
+ it "should give back all names of this Topic if no identifier is given" do
312
+ @topic.should have(4).names
313
+ @topic.names.should include @name1, @name2, @name3, @name4
314
+ @topic.names.map{|n| n.value}.should include @value1, @value2, @value3, @value4
315
+ end
316
+ it "should give back no names if the identifier does not reference a Topic" do
317
+ @tm.get("dummy").should be_nil
318
+ @topic.names("dummy").should be_empty
319
+ @tm.get("dummy").should be_nil
320
+ @topic.names(@tm.create_locator("dummy")).should be_empty
321
+ @tm.get("dummy").should be_nil
322
+ end
323
+ it "should give back no names if the identifier is a Topic but no Name type" do
324
+ dummy = @tm.get!("dummy")
325
+ @topic.names("dummy").should be_empty
326
+ @topic.names(dummy).should be_empty
327
+ end
328
+ it "should give back names of this type if an identifier is given and is a name type" do
329
+ @topic.names("first").size.should == 1
330
+ @topic.names("first").should include @name4
331
+ @topic.names("last").size.should == 1
332
+ @topic.names("last").should include @name3
333
+ @topic.names(RTM::PSI[:name_type]).size.should == 2
334
+ @topic.names(RTM::PSI[:name_type]).should include @name1, @name2
335
+ end
336
+ it "should give back names which have the default name type if identifier = :default" do
337
+ @topic.names(:default).size.should == 2
338
+ @topic.names(:default).should include @name1, @name2
339
+ @topic.names(:default).map{|n| n.value}.should include @value1, @value2
340
+ end
341
+ it "should give back names which have one of these identifiers as Name type if an identifier is an Array or an enumeration" do
342
+ @topic.names(["first","last"]).size.should == 2
343
+ @topic.names(["first","last"]).should include @name3, @name4
344
+ @topic.names("first","last").size.should == 2
345
+ @topic.names("first","last").should include @name3, @name4
346
+ @topic.names("first",:default).size.should == 3
347
+ @topic.names("first",:default).should include @name1, @name2, @name4
348
+ @topic.names(:any,"last").size.should == 4
349
+ @topic.names(:any,"last").should include @name1, @name2, @name3, @name4
350
+ @topic.names("last","dummy","first").should == @topic.names(["first","last"])
351
+ end
352
+ end
353
+
354
+ describe "#occurrences" do
355
+ before(:each) do
356
+ @topic = @tm.get!("person")
357
+ @value1 = "18"
358
+ @value2 = "red"
359
+ @value3 = @tm.create_locator("person")
360
+ @value4 = "Leipzig"
361
+ @occurrence1 = @topic.create_occurrence("age",@value1,:scope => ["2009"],:datatype => RTM::PSI[:Integer])
362
+ @occurrence2 = @topic.create_occurrence("favourite_colour", @value2)
363
+ @occurrence3 = @topic.create_occurrence("website",@value3)
364
+ @occurrence4 = @topic.create_occurrence("home",@value4)
365
+ end
366
+ it "should give back all occurrences of this Topic if no identifier is given" do
367
+ @topic.should have(4).occurrences
368
+ @topic.occurrences.should include @occurrence1, @occurrence2, @occurrence3, @occurrence4
369
+ @topic.occurrences.map{|n| n.value}.should include @value1, @value2, @value3.value, @value4
370
+ end
371
+ it "should give back no occurrences if the identifier does not reference a Topic" do
372
+ @tm.get("dummy").should be_nil
373
+ @topic.occurrences("dummy").should be_empty
374
+ @tm.get("dummy").should be_nil
375
+ @topic.occurrences(@tm.create_locator("dummy")).should be_empty
376
+ @tm.get("dummy").should be_nil
377
+ end
378
+ it "should give back no occurrences if the identifier is a Topic but no occurrence type" do
379
+ dummy = @tm.get!("dummy")
380
+ @topic.occurrences("dummy").should be_empty
381
+ @topic.occurrences(dummy).should be_empty
382
+ end
383
+ it "should give back occurrences of this type if an identifier is given and is a occurrence type" do
384
+ @topic.occurrences("age").size.should == 1
385
+ @topic.occurrences("age").should include @occurrence1
386
+ @topic.occurrences("website").size.should == 1
387
+ @topic.occurrences("website").should include @occurrence3
388
+ end
389
+ it "should give back occurrences which have one of these identifiers as occurrence type if an identifier is an Array or an enumeration" do
390
+ @topic.occurrences(["age","favourite_colour"]).size.should == 2
391
+ @topic.occurrences(["age","favourite_colour"]).should include @occurrence1, @occurrence2
392
+ @topic.occurrences("website","home").size.should == 2
393
+ @topic.occurrences("website","home").should include @occurrence3, @occurrence4
394
+ @topic.occurrences(:any,"home").size.should == 4
395
+ @topic.occurrences(:any,"home").should include @occurrence1, @occurrence2, @occurrence3, @occurrence4
396
+ @topic.occurrences("home","dummy","age").should == @topic.occurrences(["home","age"])
397
+ end
398
+ end
399
+
400
+ describe "#create_name" do
401
+ before(:each) do
402
+ @topic = @tm.get!("person")
403
+ @default_name_type = @tm.get!(RTM::PSI[:name_type])
404
+ end
405
+ it "should create a name if only a value is given" do
406
+ value = "George"
407
+ @topic.names.should be_empty
408
+ name = @topic.create_name(value)
409
+ @topic.should have(1).names
410
+ @topic.names.should include name
411
+ name.value.should == value
412
+ name.scope.should be_empty
413
+ name.type.should == @default_name_type
414
+ @topic.names.first.value.should == value
415
+ end
416
+ it "should raise an error if, one argument given, this argument is not a name" do
417
+ lambda{@topic.create_name(@tm.get!("George"))}.should raise_error
418
+ end
419
+ it "should allow to create a name with type as Topic" do
420
+ value = "George"
421
+ name_type = @tm.get!("first")
422
+ name = @topic.create_name(name_type, value)
423
+ name.value.should == value
424
+ name.type.should == name_type
425
+ name.scope.should be_empty
426
+ end
427
+ it "should allow to create a name with type as String" do
428
+ value = "Smith"
429
+ name_type = "last"
430
+ name = @topic.create_name(name_type,value)
431
+ name.value.should == value
432
+ name.type.should == @tm.get(name_type)
433
+ name.scope.should be_empty
434
+ end
435
+ it "should allow to create a name with type as Locator" do
436
+ value = "Smith"
437
+ name_type = @tm.create_locator("last")
438
+ name = @topic.create_name(name_type,value)
439
+ name.value.should == value
440
+ name.type.should == @tm.get(name_type)
441
+ name.scope.should be_empty
442
+ end
443
+ it "should raise an error if scope is not an Array" do
444
+ lambda{@topic.create_name("first","Hans","deutsch")}.should raise_error
445
+ end
446
+ it "should allow to create a name with value and scope-Array with on theme (String)" do
447
+ value = "Hans"
448
+ theme = "german"
449
+ name = @topic.create_name(value,[theme])
450
+ name.value.should == value
451
+ name.scope.size.should == 1
452
+ name.scope.should include(@tm.get(theme))
453
+ end
454
+ it "should allow to create a name with value and scope-Array with on theme (Topic)" do
455
+ value = "Hans"
456
+ theme = @tm.get!("deutsch")
457
+ name = @topic.create_name(value,[theme])
458
+ name.value.should == value
459
+ name.scope.size.should == 1
460
+ name.scope.should include(theme)
461
+ end
462
+ it "should allow to create a name with value and scope-Array with on theme (Locator)" do
463
+ value = "Hans"
464
+ theme = @tm.create_locator("deutsch")
465
+ name = @topic.create_name(value,[theme])
466
+ name.value.should == value
467
+ name.scope.size.should == 1
468
+ name.scope.should include(@tm.get!(theme))
469
+ end
470
+ it "should allow to create a name with value and scope-Array with several themes (Strings)" do
471
+ value = "Hans"
472
+ theme1 = "deutsch1"
473
+ theme2 = @tm.get!("deutsch2")
474
+ theme3 = @tm.create_locator("deutsch3")
475
+ name = @topic.create_name(value,[theme1,theme2,theme3])
476
+ name.value.should == value
477
+ name.scope.size.should == 3
478
+ name.scope.should include(@tm.get(theme1), theme2, @tm.get(theme3))
479
+ end
480
+ it "should not create a name if type is an Array" do
481
+ lambda{@topic.create_name(["first","last"],"Hans")}.should raise_error
482
+ end
483
+ it "should create a name if scope is an empty Array" do
484
+ value = "Hans"
485
+ type = "first"
486
+ name1 = @topic.create_name(type,value,[])
487
+ name1.value.should == value
488
+ name1.type.should == @tm.get(type)
489
+ name1.scope.should be_empty
490
+ end
491
+ end
492
+
493
+ describe "#children" do
494
+ it "should give back all Names and Occurrences parented by a Topic" do
495
+ topic = @tm.create_topic_by("Uni_Leipzig")
496
+ name1 = topic.create_name("Universitaet Leipzig")
497
+ name2 = topic.create_name("University of Leipzig")
498
+ occ1 = topic.create_occurrence("Gruendungsjahr", "1409")
499
+ occ2 = topic.create_occurrence("Webseite", "http://www.uni-leipzig.de")
500
+ topic.should have(4).children
501
+ topic.children.should include(name1, name2, occ1, occ2)
502
+ end
503
+ end
504
+
505
+ describe "#roles" do
506
+ before(:each) do
507
+ @t1,@t2,@t3,@t4,@t5 = @tm.get!(["t1","t2","t3","t4","t5"])
508
+ @t_a1,@t_a2 = @tm.get!(["t_a1","t_a2"])
509
+ @t_r1,@t_r2,@t_r3,@t_r4,@t_r5 = @tm.get!(["t_r1","t_r2","t_r3","t_r4","t_r5"])
510
+ @a1 = @tm.create_association(@t_a1)
511
+ @a2 = @tm.create_association(@t_a2)
512
+ @a3 = @tm.create_association(@t_a1)
513
+ @r1 = @a1.create_role(@t_r1, @t1)
514
+ @r2 = @a1.create_role(@t_r2, @t2)
515
+ @r3 = @a1.create_role(@t_r1, @t4)
516
+ @r4 = @a2.create_role(@t_r1, @t1)
517
+ @r5 = @a2.create_role(@t_r3, @t3)
518
+ @r6 = @a3.create_role(@t_r4, @t1)
519
+ @r7 = @a3.create_role(@t_r5, @t5)
520
+ end
521
+ it "should give back all roles when no arguments are given" do
522
+ @t1.roles.size.should == 3
523
+ @t1.roles.should include(@r1, @r4, @r6)
524
+ @t2.should have(1).roles
525
+ @t3.should have(1).roles
526
+ @t4.should have(1).roles
527
+ @t5.should have(1).roles
528
+ @t1.roles(:any).should == @t1.roles
529
+ end
530
+ it "should give back some roles if the roletype is given" do
531
+ @t1.roles(@t_r1).size.should == 2
532
+ @t1.roles(@t_r1).should include(@r1, @r4)
533
+ end
534
+ it "should give back some roles if several roletypes are given" do
535
+ @t1.roles([@t_r1,@t_r4]).size.should == 3
536
+ @t1.roles([@t_r1,@t_r4]).should include(@r1, @r4, @r6)
537
+ end
538
+ it "should give back some roles if several roletypes and one assoctype are given" do
539
+ @t1.roles([@t_r1, @t_r4], @t_a1).size.should == 2
540
+ @t1.roles([@t_r1, @t_r4], @t_a1).should include(@r1, @r6)
541
+
542
+ @t1.roles([@t_r1, @t_r1, @t_r4], @t_a1).size.should == 2
543
+ end
544
+ it "should give back some roles if several assoctypes and one rolytype are given" do
545
+ @t1.roles(@t_r4,[@t_a1,@t_a2]).size.should == 1
546
+ @t1.roles(@t_r4,[@t_a1,@t_a2]).should include(@r6)
547
+
548
+ @t1.roles(@t_r1,[@t_a1,@t_a2]).size.should == 2
549
+ @t1.roles(@t_r1,[@t_a1,@t_a2]).should include(@r1, @r4)
550
+
551
+ @t1.roles(@t_r1,[@t_a1,@t_a2]).should == @t1.roles([@t_r1],[@t_a1,@t_a2])
552
+ end
553
+ it "should handle Arrays of Arrays" do
554
+ @t1.roles(@t_r1).should == @t1.roles([@t_r1])
555
+ @t1.roles(@t_r1).should == @t1.roles([[@t_r1]])
556
+
557
+ @t1.roles(@t_r4,[@t_a1,@t_a2]).should == @t1.roles(@t_r4,[@t_a1,[@t_a2]])
558
+ end
559
+ it "should give back some roles if several assoctypes and one rolytype are given" do
560
+ @t1.roles(@t_r4,[@t_a1,@t_a2]).size.should == 1
561
+ @t1.roles(@t_r4,[@t_a1,@t_a2]).should include(@r6)
562
+
563
+ @t1.roles(@t_r1,[@t_a1,@t_a2]).size.should == 2
564
+ @t1.roles(@t_r1,[@t_a1,@t_a2]).should include(@r1, @r4)
565
+
566
+ @t1.roles(@t_r1,[@t_a1,@t_a2]).should == @t1.roles([@t_r1],[@t_a1,@t_a2])
567
+ end
568
+ it "should give back some roles if several roletypes and several assoctype are given" do
569
+ @t1.roles([@t_r4,@t_r1],[@t_a1,@t_a2]).size.should == 3
570
+ @t1.roles([@t_r4,@t_r1],[@t_a1,@t_a2]).should include(@r1, @r4, @r6)
571
+ end
572
+ it "should handle Locators" do
573
+ @t1.roles(@tm.create_locator("t_r1")).should == @t1.roles(@t_r1)
574
+ end
575
+ it "should handle IRIs" do
576
+ @t1.roles("t_r1").should == @t1.roles(@t_r1)
577
+ @t1.roles("t_r2").should be_empty
578
+ @t1.roles("t_r").should be_empty
579
+ @t1.roles(["t_r1","t_r4"]).should == @t1.roles([@t_r1,@t_r4])
580
+ @t1.roles(["t_r1", @t_r4], "t_a1").should == @t1.roles([@t_r1, @t_r4], @t_a1)
581
+ @t1.roles("t_r4",[@t_a1,@t_a2]).should == @t1.roles(@t_r4,[@t_a1,@t_a2])
582
+ @t1.roles(["t_r4",@t_r1],["t_a1",@t_a2]).should == @t1.roles([@t_r4,@t_r1],[@t_a1,@t_a2])
583
+ end
584
+ it "should give back an empty Set of Roles" do
585
+ @t1.roles(@t_r2).should be_empty
586
+ @t1.roles(@t_a2).should be_empty
587
+ end
588
+ it "should set roles to roles_played" do
589
+ @t1.roles.should == @t1.roles_played
590
+ end
591
+ end #of describe "#roles"
592
+
593
+ describe "#create_occurrence" do
594
+ before(:each) do
595
+ @topic = @tm.get!("person")
596
+ end
597
+ it "should create an occurrence if only type and value=string is given" do
598
+ occ = @topic.create_occurrence("Geburtsort","Leipzig")
599
+ occ.should be_a_kind_of(RTM::Occurrence)
600
+ @tm.get("Geburtsort").should be_a_kind_of(RTM::Topic)
601
+ occ.type.should == @tm.get("Geburtsort")
602
+ occ.value.should == "Leipzig"
603
+ occ.scope.should respond_to(:each)
604
+ occ.scope.should be_empty
605
+ end
606
+ it "should create an occurrence if only type and value=URI(Locator) is given" do
607
+ t = @tm.get!("Webseite")
608
+ occ = @topic.create_occurrence(t,@tm.create_locator("http://www.uni-leipzig.de/"))
609
+ occ.should be_a_kind_of(RTM::Occurrence)
610
+ occ.type.should == t
611
+ occ.datatype.to_external_form.should == RTM::PSI[:IRI]
612
+ occ.value.should == "http://www.uni-leipzig.de/"
613
+ occ.scope.should respond_to(:each)
614
+ occ.scope.should be_empty
615
+ end
616
+ it "should create an occurrence if only type and value=string and a scope is given" do
617
+ occ = @topic.create_occurrence("Geburtsort","Leipzig",{:scope => ["deutsch"]})
618
+ occ.should be_a_kind_of(RTM::Occurrence)
619
+ @tm.get("Geburtsort").should be_a_kind_of(RTM::Topic)
620
+ occ.type.should == @tm.get("Geburtsort")
621
+ occ.value.should == "Leipzig"
622
+ occ.scope.should respond_to(:each)
623
+ occ.scope.should include(@tm.get("deutsch"))
624
+ occ.datatype.to_external_form.should_not == RTM::PSI[:IRI]
625
+ end
626
+ it "should create an occurrence if several scope-items are given" do
627
+ occ = @topic.create_occurrence("Geburtsort","Leipzig",{:scope => ["deutsch","test"]})
628
+ occ.should be_a_kind_of(RTM::Occurrence)
629
+ @tm.get("Geburtsort").should be_a_kind_of(RTM::Topic)
630
+ occ.type.should == @tm.get("Geburtsort")
631
+ occ.value.should == "Leipzig"
632
+ occ.scope.should respond_to(:each)
633
+ occ.scope.size.should == 2
634
+ occ.scope.should include(@tm.get("deutsch"), @tm.get("test"))
635
+ end
636
+ it "should create an occurrence if only type and value=string and a datatype is given" do
637
+ occ = @topic.create_occurrence("Alter","26",{:datatype => @tm.create_locator(RTM::PSI[:anyType])})
638
+ occ.should be_a_kind_of(RTM::Occurrence)
639
+ @tm.get("Alter").should be_a_kind_of(RTM::Topic)
640
+ occ.type.should == @tm.get("Alter")
641
+ occ.value.should == "26"
642
+ occ.datatype.should == @tm.create_locator(RTM::PSI[:anyType])
643
+ occ.datatype.to_external_form.should ==RTM::PSI[:anyType]
644
+ occ.scope.should respond_to(:each)
645
+ occ.scope.should be_empty
646
+ end
647
+ it "should create an occurrence if type, value=string, datatype and scope is given" do
648
+ occ = @topic.create_occurrence("Heimat","Sachsen",{:datatype => RTM::PSI[:String], :scope => ["deutsch"]})
649
+ occ.should be_a_kind_of(RTM::Occurrence)
650
+ @tm.get("Heimat").should be_a_kind_of(RTM::Topic)
651
+ occ.type.should == @tm.get("Heimat")
652
+ occ.value.should == "Sachsen"
653
+ occ.datatype.should == @tm.create_locator(RTM::PSI[:String])
654
+ occ.datatype.to_external_form.should == RTM::PSI[:String]
655
+ occ.scope.should respond_to(:each)
656
+ occ.scope.should include(@tm.get("deutsch"))
657
+ end
658
+ end #of describe "#create_occurrences"
659
+
660
+ describe "#add_subject_identifier" do
661
+ before(:each) do
662
+ @ii_1 = "http://www.specs.de/ii_1"
663
+ @ii_2 = "http://www.specs.de/ii_2"
664
+ @si_1 = "http://www.specs.de/si_1"
665
+ @si_2 = "http://www.specs.de/si_2"
666
+ @sl_1 = "http://www.specs.de/sl_1"
667
+ @sl_2 = "http://www.specs.de/sl_2"
668
+ end
669
+ it "should add an identifier as subject identifier if the topic already has another si" do
670
+ topic = @tm.get!("si:" + @si_1)
671
+ topic.add_subject_identifier(@si_2)
672
+ topic.items.should be_empty
673
+ topic.indicators.size.should == 2
674
+ topic.indicators.should include @si_1, @si_2
675
+ topic.locators.should be_empty
676
+ end
677
+ it "should add an identifier as subject identifier if the topic already has another ii" do
678
+ topic = @tm.get!("ii:" + @ii_1)
679
+ topic.add_subject_identifier(@si_2)
680
+ topic.items.size.should == 1
681
+ topic.items.should include @ii_1
682
+ topic.indicators.size.should == 1
683
+ topic.indicators.should include @si_2
684
+ topic.locators.should be_empty
685
+ end
686
+ it "should add an identifier as subject identifier if the topic already has another sl" do
687
+ topic = @tm.get!("sl:" + @sl_1)
688
+ topic.add_subject_identifier(@si_2)
689
+ topic.items.should be_empty
690
+ topic.indicators.size.should == 1
691
+ topic.indicators.should include @si_2
692
+ topic.locators.size.should == 1
693
+ topic.locators.should include @sl_1
694
+ end
695
+ it "should not add an identifier as subject identifier if the topic already this identifier as si" do
696
+ topic = @tm.get!("si:" + @si_2)
697
+ topic.add_subject_identifier(@si_2)
698
+ topic.items.should be_empty
699
+ topic.indicators.size.should == 1
700
+ topic.indicators.should include @si_2
701
+ topic.locators.should be_empty
702
+ end
703
+ it "should add an identifier as subject identifier if the topic already has this identifier as ii" do
704
+ topic = @tm.get!("ii:" + @si_2)
705
+ # puts "ii: #{topic.item_identifiers.to_s}"
706
+ # puts "si: #{topic.subject_identifiers.to_s}"
707
+ topic.add_subject_identifier(@si_2)
708
+ # puts "ii: #{topic.item_identifiers.to_s}"
709
+ # puts "si: #{topic.subject_identifiers.to_s}"
710
+ topic.items.size.should == 1
711
+ topic.items.should include @si_2
712
+ topic.indicators.size.should == 1
713
+ topic.indicators.should include @si_2
714
+ topic.locators.should be_empty
715
+ end
716
+ it "should do what? if the topic already has this identifier as sl"
717
+ it "should merge the topic A with another topic B that has the same identifier as ii or si when adding this identifier to A, but throws an exception" do
718
+ topic_a = @tm.get!("ii:" + @ii_1)
719
+ topic_b = @tm.get!("ii:" + @ii_2)
720
+ lambda{topic_a.add_subject_identifier(@ii_2)}.should raise_error
721
+ end
722
+ end # of describe add_subject_indentifier
723
+
724
+ describe "#add_item_identifier" do
725
+ before(:each) do
726
+ @ii_1 = "http://www.specs.de/ii_1"
727
+ @ii_2 = "http://www.specs.de/ii_2"
728
+ @si_1 = "http://www.specs.de/si_1"
729
+ @si_2 = "http://www.specs.de/si_2"
730
+ @sl_1 = "http://www.specs.de/sl_1"
731
+ @sl_2 = "http://www.specs.de/sl_2"
732
+ end
733
+ it "should be tested"
734
+ end #of describe add_item_identifier
735
+
736
+ describe "#add_subject_locator" do
737
+ before(:each) do
738
+ @ii_1 = "http://www.specs.de/ii_1"
739
+ @ii_2 = "http://www.specs.de/ii_2"
740
+ @si_1 = "http://www.specs.de/si_1"
741
+ @si_2 = "http://www.specs.de/si_2"
742
+ @sl_1 = "http://www.specs.de/sl_1"
743
+ @sl_2 = "http://www.specs.de/sl_2"
744
+ end
745
+ it "should be tested"
746
+ end # of describe add_subject_locator
747
+
748
+ describe "#remove_subject_identifier" do
749
+ before(:each) do
750
+ @topic = @tm.get!("si:http://www.example.org/topic1/si_1")
751
+ @topic.add_subject_identifier("http://www.example.org/topic1/si_2")
752
+ @topic.add_item_identifier("http://www.example.org/topic1/ii_1")
753
+ @topic.add_item_identifier("http://www.example.org/topic1/ii_2")
754
+ @topic.add_subject_locator("http://www.example.org/topic1/sl_1")
755
+ @topic.add_subject_locator("http://www.example.org/topic1/sl_2")
756
+ @topic_wo_si = @tm.get!("ii:http://www.example.org/topic2/ii")
757
+ @topic_wo_si.add_subject_locator("http://www.example.org/topic2/sl")
758
+ @topic.should have(2).indicators
759
+ @topic.should have(2).items
760
+ @topic.should have(2).locators
761
+ end
762
+ it "should remove an existing subject identifier if argument is a String" do
763
+ @topic.remove_subject_identifier("http://www.example.org/topic1/si_1")
764
+ @topic.should have(1).indicators
765
+ @topic.indicators.should include "http://www.example.org/topic1/si_2"
766
+ @topic.remove_subject_identifier("http://www.example.org/topic1/si_2")
767
+ @topic.should have(0).indicators
768
+ @topic.should have(2).items
769
+ @topic.should have(2).locators
770
+ end
771
+ it "should remove an existing subject identifier if argument is a Locator" do
772
+ locator1 = @tm.create_locator("http://www.example.org/topic1/si_1")
773
+ locator2 = @tm.create_locator("http://www.example.org/topic1/si_2")
774
+ @topic.remove_subject_identifier(locator1)
775
+ @topic.should have(1).indicators
776
+ @topic.indicators.should include "http://www.example.org/topic1/si_2"
777
+ @topic.remove_subject_identifier(locator2)
778
+ @topic.should have(0).indicators
779
+ @topic.should have(2).items
780
+ @topic.should have(2).locators
781
+ end
782
+ it "should not remove a subject identifier if argument does not refer to an existing si" do
783
+ @topic.remove_subject_identifier("http://www.example.org/topic1/something")
784
+ @topic.should have(2).indicators
785
+ @topic.should have(2).items
786
+ @topic.should have(2).locators
787
+ @topic.remove_subject_identifier(@tm.create_locator("http://www.example.org/topic1/something"))
788
+ @topic.should have(2).indicators
789
+ @topic.should have(2).items
790
+ @topic.should have(2).locators
791
+ end
792
+ it "should not remove a subject identifier if the identifier exists as ii or sl" do
793
+ @topic_wo_si.remove_subject_identifier("http://www.example.org/topic2/ii")
794
+ @topic_wo_si.remove_subject_identifier("http://www.example.org/topic2/sl")
795
+ @topic_wo_si.should have(0).indicators
796
+ @topic_wo_si.should have(1).items
797
+ @topic_wo_si.should have(1).locators
798
+ end
799
+ end #of describe remove_subject_identifier
800
+
801
+ describe "#remove_item_identifier" do
802
+ before(:each) do
803
+ @topic = @tm.get!("si:http://www.example.org/topic1/si_1")
804
+ @topic.add_subject_identifier("http://www.example.org/topic1/si_2")
805
+ @topic.add_item_identifier("http://www.example.org/topic1/ii_1")
806
+ @topic.add_item_identifier("http://www.example.org/topic1/ii_2")
807
+ @topic.add_subject_locator("http://www.example.org/topic1/sl_1")
808
+ @topic.add_subject_locator("http://www.example.org/topic1/sl_2")
809
+ @topic_wo_ii = @tm.get!("si:http://www.example.org/topic2/si")
810
+ @topic_wo_ii.add_subject_locator("http://www.example.org/topic2/sl")
811
+ @topic.should have(2).indicators
812
+ @topic.should have(2).items
813
+ @topic.should have(2).locators
814
+ end
815
+ it "should remove an existing item identifier if argument is a String" do
816
+ @topic.remove_item_identifier("http://www.example.org/topic1/ii_1")
817
+ @topic.should have(1).items
818
+ @topic.items.should include "http://www.example.org/topic1/ii_2"
819
+ @topic.remove_item_identifier("http://www.example.org/topic1/ii_2")
820
+ @topic.should have(2).indicators
821
+ @topic.should have(0).items
822
+ @topic.should have(2).locators
823
+ end
824
+ it "should remove an existing item identifier if argument is a Locator" do
825
+ locator1 = @tm.create_locator("http://www.example.org/topic1/ii_1")
826
+ locator2 = @tm.create_locator("http://www.example.org/topic1/ii_2")
827
+ @topic.remove_item_identifier(locator1)
828
+ @topic.should have(1).items
829
+ @topic.items.should include "http://www.example.org/topic1/ii_2"
830
+ @topic.remove_item_identifier(locator2)
831
+ @topic.should have(2).indicators
832
+ @topic.should have(0).items
833
+ @topic.should have(2).locators
834
+ end
835
+ it "should not remove an item identifier if argument does not refer to an existing ii" do
836
+ @topic.remove_item_identifier("http://www.example.org/topic1/something")
837
+ @topic.should have(2).indicators
838
+ @topic.should have(2).items
839
+ @topic.should have(2).locators
840
+ @topic.remove_item_identifier(@tm.create_locator("http://www.example.org/topic1/something"))
841
+ @topic.should have(2).indicators
842
+ @topic.should have(2).items
843
+ @topic.should have(2).locators
844
+ end
845
+ it "should not remove an item identifier if the identifier exists as si or sl" do
846
+ @topic_wo_ii.remove_item_identifier("http://www.example.org/topic2/si")
847
+ @topic_wo_ii.remove_item_identifier("http://www.example.org/topic2/sl")
848
+ @topic_wo_ii.should have(1).indicators
849
+ @topic_wo_ii.should have(0).items
850
+ @topic_wo_ii.should have(1).locators
851
+ end
852
+ end #of describe remove_item_identifier
853
+
854
+ describe "#remove_subject_locator" do
855
+ before(:each) do
856
+ @topic = @tm.get!("si:http://www.example.org/topic1/si_1")
857
+ @topic.add_subject_identifier("http://www.example.org/topic1/si_2")
858
+ @topic.add_item_identifier("http://www.example.org/topic1/ii_1")
859
+ @topic.add_item_identifier("http://www.example.org/topic1/ii_2")
860
+ @topic.add_subject_locator("http://www.example.org/topic1/sl_1")
861
+ @topic.add_subject_locator("http://www.example.org/topic1/sl_2")
862
+ @topic_wo_sl = @tm.get!("ii:http://www.example.org/topic2/ii")
863
+ @topic_wo_sl.add_subject_identifier("http://www.example.org/topic2/si")
864
+ @topic.should have(2).indicators
865
+ @topic.should have(2).items
866
+ @topic.should have(2).locators
867
+ end
868
+ it "should remove an existing subject locator if argument is a String" do
869
+ @topic.remove_subject_locator("http://www.example.org/topic1/sl_1")
870
+ @topic.should have(1).locators
871
+ @topic.locators.should include "http://www.example.org/topic1/sl_2"
872
+ @topic.remove_subject_locator("http://www.example.org/topic1/sl_2")
873
+ @topic.should have(2).indicators
874
+ @topic.should have(2).items
875
+ @topic.should have(0).locators
876
+ end
877
+ it "should remove an existing subject locator if argument is a Locator" do
878
+ locator1 = @tm.create_locator("http://www.example.org/topic1/sl_1")
879
+ locator2 = @tm.create_locator("http://www.example.org/topic1/sl_2")
880
+ @topic.remove_subject_locator(locator1)
881
+ @topic.should have(1).locators
882
+ @topic.locators.should include "http://www.example.org/topic1/sl_2"
883
+ @topic.remove_subject_locator(locator2)
884
+ @topic.should have(2).indicators
885
+ @topic.should have(2).items
886
+ @topic.should have(0).locators
887
+ end
888
+ it "should not remove a subject locator if argument does not refer to an existing sl" do
889
+ @topic.remove_subject_locator("http://www.example.org/topic1/something")
890
+ @topic.should have(2).indicators
891
+ @topic.should have(2).items
892
+ @topic.should have(2).locators
893
+ @topic.remove_subject_locator(@tm.create_locator("http://www.example.org/topic1/something"))
894
+ @topic.should have(2).indicators
895
+ @topic.should have(2).items
896
+ @topic.should have(2).locators
897
+ end
898
+ it "should not remove a subject locator if the identifier exists as ii or si" do
899
+ @topic_wo_sl.remove_subject_locator("http://www.example.org/topic2/ii")
900
+ @topic_wo_sl.remove_subject_locator("http://www.example.org/topic2/si")
901
+ @topic_wo_sl.should have(1).indicators
902
+ @topic_wo_sl.should have(1).items
903
+ @topic_wo_sl.should have(0).locators
904
+ end
905
+ end #of describe remove_subject_locator
906
+
907
+ describe "#reified" do
908
+ before(:each) do
909
+ end
910
+ it "should be tested ..."
911
+ end
912
+
913
+ describe "#reified=" do
914
+ before(:each) do
915
+ @topic = @tm.get!("Hans")
916
+ @name = @topic.create_name("firstname","Hans")
917
+ @occ = @topic.create_occurrence("birthyear","2000")
918
+ @variant = @name.create_variant("Hansi",["home"])
919
+ @assoc = @tm.create_association("mother-child")
920
+ @role = @assoc.create_role("child","Hans")
921
+ @a_reifier = @tm.get!("test_reifier")
922
+ end
923
+ it "should set self as reifier for the identifier (a Name)" do
924
+ @name.reifier.should be_nil
925
+ @a_reifier.reified = @name
926
+ @name.reifier.should == @a_reifier
927
+ end
928
+ it "should set self as reifier for the identifier (a Variant)" do
929
+ @variant.reifier.should be_nil
930
+ @a_reifier.reified = @variant
931
+ @variant.reifier.should == @a_reifier
932
+ end
933
+ it "should set self as reifier for the identifier (an Occurrence)" do
934
+ @occ.reifier.should be_nil
935
+ @a_reifier.reified = @occ
936
+ @occ.reifier.should == @a_reifier
937
+ end
938
+ it "should set self as reifier for the identifier (an Association)" do
939
+ @assoc.reifier.should be_nil
940
+ @a_reifier.reified = @assoc
941
+ @assoc.reifier.should == @a_reifier
942
+ end
943
+ it "should set self as reifier for the identifier (a Role)" do
944
+ @role.reifier.should be_nil
945
+ @a_reifier.reified = @role
946
+ @role.reifier.should == @a_reifier
947
+ end
948
+ it "should set self as reifier for the identifier (a TopicMap)" do
949
+ @tm.reifier.should be_nil
950
+ @a_reifier.reified = @tm
951
+ @tm.reifier.should == @a_reifier
952
+ end
953
+ it "should overwrite a previous reifier if identifier already had a reifier" do
954
+ @name.reifier = "dummy_reifier"
955
+ @name.reifier.should == @tm.get("dummy_reifier")
956
+ @a_reifier.reified = @name
957
+ @name.reifier.should == @a_reifier
958
+ end
959
+ it "should raise an error if this Topic already refies a Reifiable Construct" do
960
+ @name.reifier = @a_reifier
961
+ lambda{@a_reifier.reified = @occ}
962
+ end
963
+ it "should raise an error if the identifier is not a Reifiable" do
964
+ lambda{@a_reifier.reified = "test"}.should raise_error
965
+ end
966
+ end
967
+
968
+ describe "#remove" do
969
+ before(:each) do
970
+ @topic1 = @tm.get!("topic1")
971
+ @topic2 = @tm.get!("topic2")
972
+ @name = @topic1.create_name("firstname","Hans")
973
+ @occurrence = @topic1.create_occurrence("birthyear","2000")
974
+ @tm.should have(4).topics
975
+ end
976
+ it "should remove this topic from the container (topic map)" do
977
+ @tm.literal_index.getOccurrences("2000").size.should == 1
978
+ @tm.literal_index.getNames("Hans").size.should == 1
979
+ @topic1.remove
980
+ @tm.should have(3).topics
981
+ @topic2.remove
982
+ @tm.should have(2).topics
983
+ @tm.literal_index.getOccurrences("2000").size.should == 0
984
+ @tm.literal_index.getNames("Hans").size.should == 0
985
+ end
986
+ end
987
+ end # of describe self
988
+
989
+ end # of module
990
+
991
+
992
+