rtm 0.1.6 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. data/DISCLAIMER +10 -33
  2. data/LICENSE +201 -0
  3. data/README +32 -3
  4. data/lib/rtm.rb +126 -74
  5. data/lib/rtm/axes.rb +298 -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 +101 -0
  17. data/lib/rtm/extensions.rb +65 -5
  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 +19 -0
  22. data/lib/rtm/io/from_xtm2_libxml.rb +2 -1
  23. data/lib/rtm/io/tmapix_from.rb +155 -0
  24. data/lib/rtm/io/tmapix_to.rb +223 -0
  25. data/lib/rtm/io/to_hash.rb +154 -0
  26. data/lib/rtm/io/to_jtm.rb +53 -103
  27. data/lib/rtm/io/to_rdf.rb +45 -0
  28. data/lib/rtm/io/to_string.rb +21 -8
  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 +59 -100
  32. data/lib/rtm/navigation.rb +23 -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 +166 -0
  44. data/lib/rtm/navigation/topic/traverse.rb +51 -0
  45. data/lib/rtm/navigation/topic/types.rb +109 -0
  46. data/lib/rtm/psi.rb +39 -2
  47. data/lib/rtm/sugar.rb +47 -0
  48. data/lib/rtm/sugar/association/hash_access.rb +46 -0
  49. data/lib/rtm/sugar/occurrence/dynamic_value.rb +58 -0
  50. data/lib/rtm/sugar/occurrence/external.rb +53 -0
  51. data/lib/rtm/sugar/reifiable/reifier.rb +21 -0
  52. data/lib/rtm/sugar/role/counterparts.rb +139 -46
  53. data/lib/rtm/sugar/topic/best_name.rb +74 -0
  54. data/lib/rtm/sugar/topic/characteristics.rb +126 -12
  55. data/lib/rtm/sugar/topic/counterparts.rb +145 -10
  56. data/lib/rtm/sugar/topic/hash_access.rb +140 -30
  57. data/lib/rtm/sugar/topic/scoped.rb +114 -0
  58. data/lib/rtm/sugar/topic/topic_ref.rb +86 -0
  59. data/lib/rtm/sugar/topic/typed.rb +207 -0
  60. data/lib/rtm/sugar/topic_map/query_cache.rb +66 -0
  61. data/lib/rtm/sugar/topic_map/themes.rb +53 -0
  62. data/lib/rtm/sugar/typed/types.rb +38 -0
  63. data/lib/rtm/validation.rb +7 -4
  64. data/lib/rtm/version.rb +30 -0
  65. data/spec/helpers/spec_exampleexamplegroup.rb +14 -0
  66. data/spec/rtm/axes/association_spec.rb +88 -0
  67. data/spec/rtm/axes/associations_spec.rb +60 -0
  68. data/spec/rtm/axes/assocs_names_occs_spec.rb +9 -0
  69. data/spec/rtm/axes/characteristic_spec.rb +90 -0
  70. data/spec/rtm/axes/characteristics_spec.rb +85 -0
  71. data/spec/rtm/axes/string_spec.rb +145 -0
  72. data/spec/rtm/axes/strings_spec.rb +168 -0
  73. data/spec/rtm/axes/topic_spec.rb +124 -0
  74. data/spec/rtm/axes/topics_spec.rb +103 -0
  75. data/spec/rtm/base_spec.rb +32 -0
  76. data/spec/rtm/io/tmapix_from_spec.rb +76 -0
  77. data/spec/rtm/io/tmapix_to_spec.rb +159 -0
  78. data/spec/rtm/io/to_hash_spec.rb +90 -0
  79. data/spec/rtm/io/to_rdf_spec.rb +37 -0
  80. data/spec/rtm/io/to_string_spec.rb +122 -0
  81. data/spec/rtm/io/to_yaml_spec.rb +89 -0
  82. data/spec/rtm/navigation/association/players_spec.rb +58 -0
  83. data/spec/rtm/navigation/association_spec.rb +52 -0
  84. data/spec/rtm/navigation/name/atomify_spec.rb +27 -0
  85. data/spec/rtm/navigation/name/characteristics_spec.rb +34 -0
  86. data/spec/rtm/navigation/name_spec.rb +52 -0
  87. data/spec/rtm/navigation/occurrence/atomify_spec.rb +27 -0
  88. data/spec/rtm/navigation/occurrence/characteristics_spec.rb +34 -0
  89. data/spec/rtm/navigation/occurrence_spec.rb +52 -0
  90. data/spec/rtm/navigation/string_spec.rb +51 -0
  91. data/spec/rtm/navigation/topic/characteristics_spec.rb +55 -0
  92. data/spec/rtm/navigation/topic/indicators_spec.rb +43 -0
  93. data/spec/rtm/navigation/topic/items_spec.rb +44 -0
  94. data/spec/rtm/navigation/topic/locators_spec.rb +44 -0
  95. data/spec/rtm/navigation/topic/players_spec.rb +48 -0
  96. data/spec/rtm/navigation/topic/scope_spec.rb +41 -0
  97. data/spec/rtm/navigation/topic/supertypes_spec.rb +376 -0
  98. data/spec/rtm/navigation/topic/traverse_spec.rb +64 -0
  99. data/spec/rtm/navigation/topic/types_spec.rb +195 -0
  100. data/spec/rtm/navigation/topic_spec.rb +153 -0
  101. data/spec/rtm/sugar/association/hash_access_spec.rb +55 -0
  102. data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +171 -0
  103. data/spec/rtm/sugar/occurrence/external_spec.rb +129 -0
  104. data/spec/rtm/sugar/reifiable/reifier_spec.rb +41 -0
  105. data/spec/rtm/sugar/role/counterparts_spec.rb +193 -0
  106. data/spec/rtm/sugar/topic/best_name_spec.rb +25 -0
  107. data/spec/rtm/sugar/topic/characteristics_spec.rb +333 -0
  108. data/spec/rtm/sugar/topic/counterparts_spec.rb +224 -0
  109. data/spec/rtm/sugar/topic/hash_access_spec.rb +234 -0
  110. data/spec/rtm/sugar/topic/scoped_spec.rb +195 -0
  111. data/spec/rtm/sugar/topic/topic_ref_spec.rb +44 -0
  112. data/spec/rtm/sugar/topic/typed_spec.rb +217 -0
  113. data/spec/rtm/sugar/topic_map/themes_spec.rb +67 -0
  114. data/spec/rtm/sugar/typed/types_spec.rb +24 -0
  115. data/spec/rtm/tmapi/core/association_spec.rb +169 -0
  116. data/spec/rtm/tmapi/core/construct_spec.rb +25 -0
  117. data/spec/rtm/tmapi/core/datatype_aware_spec.rb +236 -0
  118. data/spec/rtm/tmapi/core/name_spec.rb +270 -0
  119. data/spec/rtm/tmapi/core/occurrence_spec.rb +53 -0
  120. data/spec/rtm/tmapi/core/reifiable_spec.rb +168 -0
  121. data/spec/rtm/tmapi/core/role_spec.rb +73 -0
  122. data/spec/rtm/tmapi/core/scoped_spec.rb +441 -0
  123. data/spec/rtm/tmapi/core/topic_map_spec.rb +716 -0
  124. data/spec/rtm/tmapi/core/topic_spec.rb +1468 -0
  125. data/spec/rtm/tmapi/core/typed_spec.rb +112 -0
  126. data/spec/rtm/tmapi/core/variant_spec.rb +52 -0
  127. data/spec/rtm/tmapi/ext/java_util_set_spec.rb +34 -0
  128. data/spec/rtm/tmapi_spec.rb +44 -0
  129. data/spec/rtm/utils/sparql_spec.rb +26 -0
  130. data/spec/rtm_spec.rb +93 -0
  131. data/spec/spec_helper.rb +28 -0
  132. data/test/javalibs/junit-4.5.jar +0 -0
  133. data/test/javalibs/tmapi-2.0-tests.jar +0 -0
  134. data/test/tmapi_tests.rb +25 -0
  135. metadata +169 -65
  136. data/COPYRIGHT +0 -4
  137. data/lib/Rakefile.rb +0 -42
  138. data/lib/activetopicmaps.rb +0 -278
  139. data/lib/rtm/backend/active_record.rb +0 -58
  140. data/lib/rtm/backend/active_record/001_initial_schema.rb +0 -116
  141. data/lib/rtm/backend/active_record/association_and_role.rb +0 -33
  142. data/lib/rtm/backend/active_record/locators.rb +0 -55
  143. data/lib/rtm/backend/active_record/name_variant_occurrence.rb +0 -45
  144. data/lib/rtm/backend/active_record/quaaxtm2rtm.rb +0 -113
  145. data/lib/rtm/backend/active_record/quaaxtm2rtmviews.rb +0 -134
  146. data/lib/rtm/backend/active_record/set_wrapper.rb +0 -98
  147. data/lib/rtm/backend/active_record/tm_construct.rb +0 -62
  148. data/lib/rtm/backend/active_record/tm_delegator.rb +0 -345
  149. data/lib/rtm/backend/active_record/tm_set_delegator.rb +0 -195
  150. data/lib/rtm/backend/active_record/tmdm.rb +0 -298
  151. data/lib/rtm/backend/active_record/topic.rb +0 -87
  152. data/lib/rtm/backend/active_record/topic_map.rb +0 -314
  153. data/lib/rtm/backend/active_record/traverse_associations.rb +0 -87
  154. data/lib/rtm/base.rb +0 -92
  155. data/lib/rtm/connect.rb +0 -92
  156. data/lib/rtm/core_ext.rb +0 -6
  157. data/lib/rtm/io/from_xtm2.rb +0 -263
  158. data/lib/rtm/merging/merging.rb +0 -307
  159. data/lib/rtm/pimp_my_api.rb +0 -28
  160. data/lib/rtm/sugar/topic/identifier_direct.rb +0 -11
  161. data/lib/rtm/sugar/topic/predefined_associations.rb +0 -42
  162. data/lib/run_main_project.rb +0 -16
  163. data/test/base_test.rb +0 -162
@@ -0,0 +1,1468 @@
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 "#remove_instance" do
290
+ before(:each) do
291
+ @t1,@t2,@t3,@t4 = @tm.get!(["t1","t2","t3","t4"])
292
+ @t1.add_type(@t2)
293
+ @t1.add_type(@t3)
294
+ @t4.add_type(@t2)
295
+ @t2.should have(2).instances
296
+ @t2.instances.should include @t1, @t4
297
+ end
298
+ it "should remove an instance if argument is a String" do
299
+ @t2.remove_instance("t1")
300
+ @t2.should have(1).instances
301
+ @t2.instances.should include @t4
302
+ @t2.remove_instance("t4")
303
+ @t2.should have(0).instances
304
+ end
305
+ it "should remove an instance if argument is a Locator" do
306
+ @t2.remove_instance(@tm.create_locator("t4"))
307
+ @t2.should have(1).instances
308
+ @t2.instances.should include @t1
309
+ @t2.remove_instance(@tm.create_locator("t1"))
310
+ @t2.should have(0).instances
311
+ end
312
+ it "should remove an instance if argument is a Topic" do
313
+ @t2.remove_instance(@t1)
314
+ @t2.should have(1).instances
315
+ @t2.instances.should include @t4
316
+ @t2.remove_instance(@t4)
317
+ @t2.should have(0).instances
318
+ end
319
+ it "should not remove an instance if argument does not match an instance of this Topic" do
320
+ @t2.remove_instance("t3")
321
+ @t2.should have(2).instances
322
+ @t2.remove_instance("t5")
323
+ @t2.should have(2).instances
324
+ @t2.remove_instance(@tm.create_locator("t3"))
325
+ @t2.should have(2).instances
326
+ @t2.remove_instance(@tm.create_locator("t5"))
327
+ @t2.should have(2).instances
328
+ @t2.remove_instance(@t3)
329
+ @t2.should have(2).instances
330
+ @t2.remove_instance(@t5)
331
+ @t2.should have(2).instances
332
+ @t2.instances.should include @t1, @t4
333
+ end
334
+ end
335
+
336
+ describe "#parent" do
337
+ it "should give back the Topic Map" do
338
+ topic = @tm.create_topic_by("=weihnachtsmann")
339
+ topic.should be_a_kind_of RTM::Topic
340
+ @tm.get("=weihnachtsmann").should be_a_kind_of RTM::Topic
341
+ topic.parent.should be_a_kind_of RTM::TopicMap
342
+ topic.parent.should == @tm
343
+ end
344
+ end
345
+
346
+ describe "#names" do
347
+ before(:each) do
348
+ @topic = @tm.get!("person")
349
+ @value1 = "Bruce"
350
+ @value2 = "Bruce Smith"
351
+ @value3 = "Smith"
352
+ @value4 = "Bru"
353
+ @name1 = @topic.create_name(@value1)
354
+ @name2 = @topic.create_name(@value2)
355
+ @name3 = @topic.create_name("last",@value3)
356
+ @name4 = @topic.create_name("first",@value4,["friends"])
357
+ end
358
+ it "should give back all names of this Topic if no identifier is given" do
359
+ @topic.should have(4).names
360
+ @topic.names.should include @name1, @name2, @name3, @name4
361
+ @topic.names.map{|n| n.value}.should include @value1, @value2, @value3, @value4
362
+ end
363
+ it "should give back no names if the identifier does not reference a Topic" do
364
+ @tm.get("dummy").should be_nil
365
+ @topic.names("dummy").should be_empty
366
+ @tm.get("dummy").should be_nil
367
+ @topic.names(@tm.create_locator("dummy")).should be_empty
368
+ @tm.get("dummy").should be_nil
369
+ end
370
+ it "should give back no names if the identifier is a Topic but no Name type" do
371
+ dummy = @tm.get!("dummy")
372
+ @topic.names("dummy").should be_empty
373
+ @topic.names(dummy).should be_empty
374
+ end
375
+ it "should give back names of this type if an identifier is given and is a name type" do
376
+ @topic.names("first").size.should == 1
377
+ @topic.names("first").should include @name4
378
+ @topic.names("last").size.should == 1
379
+ @topic.names("last").should include @name3
380
+ @topic.names(RTM::PSI[:name_type]).size.should == 2
381
+ @topic.names(RTM::PSI[:name_type]).should include @name1, @name2
382
+ end
383
+ it "should give back names which have the default name type if identifier = :default" do
384
+ @topic.names(:default).size.should == 2
385
+ @topic.names(:default).should include @name1, @name2
386
+ @topic.names(:default).map{|n| n.value}.should include @value1, @value2
387
+ end
388
+ it "should give back names which have one of these identifiers as Name type if an identifier is an Array or an enumeration" do
389
+ @topic.names(["first","last"]).size.should == 2
390
+ @topic.names(["first","last"]).should include @name3, @name4
391
+ @topic.names("first","last").size.should == 2
392
+ @topic.names("first","last").should include @name3, @name4
393
+ @topic.names("first",:default).size.should == 3
394
+ @topic.names("first",:default).should include @name1, @name2, @name4
395
+ @topic.names(:any,"last").size.should == 4
396
+ @topic.names(:any,"last").should include @name1, @name2, @name3, @name4
397
+ @topic.names("last","dummy","first").should == @topic.names(["first","last"])
398
+ end
399
+ end
400
+
401
+ describe "#occurrences" do
402
+ before(:each) do
403
+ @topic = @tm.get!("person")
404
+ @value1 = "18"
405
+ @value2 = "red"
406
+ @value3 = @tm.create_locator("person")
407
+ @value4 = "Leipzig"
408
+ @occurrence1 = @topic.create_occurrence("age",@value1,:scope => ["2009"],:datatype => RTM::PSI[:Integer])
409
+ @occurrence2 = @topic.create_occurrence("favourite_colour", @value2)
410
+ @occurrence3 = @topic.create_occurrence("website",@value3)
411
+ @occurrence4 = @topic.create_occurrence("home",@value4)
412
+ end
413
+ it "should give back all occurrences of this Topic if no identifier is given" do
414
+ @topic.should have(4).occurrences
415
+ @topic.occurrences.should include @occurrence1, @occurrence2, @occurrence3, @occurrence4
416
+ @topic.occurrences.map{|n| n.value}.should include @value1, @value2, @value3.value, @value4
417
+ end
418
+ it "should give back no occurrences if the identifier does not reference a Topic" do
419
+ @tm.get("dummy").should be_nil
420
+ @topic.occurrences("dummy").should be_empty
421
+ @tm.get("dummy").should be_nil
422
+ @topic.occurrences(@tm.create_locator("dummy")).should be_empty
423
+ @tm.get("dummy").should be_nil
424
+ end
425
+ it "should give back no occurrences if the identifier is a Topic but no occurrence type" do
426
+ dummy = @tm.get!("dummy")
427
+ @topic.occurrences("dummy").should be_empty
428
+ @topic.occurrences(dummy).should be_empty
429
+ end
430
+ it "should give back occurrences of this type if an identifier is given and is a occurrence type" do
431
+ @topic.occurrences("age").size.should == 1
432
+ @topic.occurrences("age").should include @occurrence1
433
+ @topic.occurrences("website").size.should == 1
434
+ @topic.occurrences("website").should include @occurrence3
435
+ end
436
+ it "should give back occurrences which have one of these identifiers as occurrence type if an identifier is an Array or an enumeration" do
437
+ @topic.occurrences(["age","favourite_colour"]).size.should == 2
438
+ @topic.occurrences(["age","favourite_colour"]).should include @occurrence1, @occurrence2
439
+ @topic.occurrences("website","home").size.should == 2
440
+ @topic.occurrences("website","home").should include @occurrence3, @occurrence4
441
+ @topic.occurrences(:any,"home").size.should == 4
442
+ @topic.occurrences(:any,"home").should include @occurrence1, @occurrence2, @occurrence3, @occurrence4
443
+ @topic.occurrences("home","dummy","age").should == @topic.occurrences(["home","age"])
444
+ end
445
+ end
446
+
447
+ describe "#create_name" do
448
+ before(:each) do
449
+ @topic = @tm.get!("person")
450
+ @default_name_type = @tm.get!(RTM::PSI[:name_type])
451
+ end
452
+ it "should create a name if only a value is given" do
453
+ value = "George"
454
+ @topic.names.should be_empty
455
+ name = @topic.create_name(value)
456
+ @topic.should have(1).names
457
+ @topic.names.should include name
458
+ name.value.should == value
459
+ name.scope.should be_empty
460
+ name.type.should == @default_name_type
461
+ @topic.names.first.value.should == value
462
+ end
463
+ it "should raise an error if, one argument given, this argument is not a name" do
464
+ lambda{@topic.create_name(@tm.get!("George"))}.should raise_error
465
+ end
466
+ it "should allow to create a name with type as Topic" do
467
+ value = "George"
468
+ name_type = @tm.get!("first")
469
+ name = @topic.create_name(name_type, value)
470
+ name.value.should == value
471
+ name.type.should == name_type
472
+ name.scope.should be_empty
473
+ end
474
+ it "should allow to create a name with type as String" do
475
+ value = "Smith"
476
+ name_type = "last"
477
+ name = @topic.create_name(name_type,value)
478
+ name.value.should == value
479
+ name.type.should == @tm.get(name_type)
480
+ name.scope.should be_empty
481
+ end
482
+ it "should allow to create a name with type as Locator" do
483
+ value = "Smith"
484
+ name_type = @tm.create_locator("last")
485
+ name = @topic.create_name(name_type,value)
486
+ name.value.should == value
487
+ name.type.should == @tm.get(name_type)
488
+ name.scope.should be_empty
489
+ end
490
+ it "should raise an error if scope is not an Array" do
491
+ lambda{@topic.create_name("first","Hans","deutsch")}.should raise_error
492
+ end
493
+ it "should allow to create a name with value and scope-Array with on theme (String)" do
494
+ value = "Hans"
495
+ theme = "german"
496
+ name = @topic.create_name(value,[theme])
497
+ name.value.should == value
498
+ name.scope.size.should == 1
499
+ name.scope.should include(@tm.get(theme))
500
+ end
501
+ it "should allow to create a name with value and scope-Array with on theme (Topic)" do
502
+ value = "Hans"
503
+ theme = @tm.get!("deutsch")
504
+ name = @topic.create_name(value,[theme])
505
+ name.value.should == value
506
+ name.scope.size.should == 1
507
+ name.scope.should include(theme)
508
+ end
509
+ it "should allow to create a name with value and scope-Array with on theme (Locator)" do
510
+ value = "Hans"
511
+ theme = @tm.create_locator("deutsch")
512
+ name = @topic.create_name(value,[theme])
513
+ name.value.should == value
514
+ name.scope.size.should == 1
515
+ name.scope.should include(@tm.get!(theme))
516
+ end
517
+ it "should allow to create a name with value and scope-Array with several themes (Strings)" do
518
+ value = "Hans"
519
+ theme1 = "deutsch1"
520
+ theme2 = @tm.get!("deutsch2")
521
+ theme3 = @tm.create_locator("deutsch3")
522
+ name = @topic.create_name(value,[theme1,theme2,theme3])
523
+ name.value.should == value
524
+ name.scope.size.should == 3
525
+ name.scope.should include(@tm.get(theme1), theme2, @tm.get(theme3))
526
+ end
527
+ it "should not create a name if type is an Array" do
528
+ lambda{@topic.create_name(["first","last"],"Hans")}.should raise_error
529
+ end
530
+ it "should create a name if scope is an empty Array" do
531
+ value = "Hans"
532
+ type = "first"
533
+ name1 = @topic.create_name(type,value,[])
534
+ name1.value.should == value
535
+ name1.type.should == @tm.get(type)
536
+ name1.scope.should be_empty
537
+ end
538
+ end
539
+
540
+ describe "#children" do
541
+ it "should give back all Names and Occurrences parented by a Topic" do
542
+ topic = @tm.create_topic_by("Uni_Leipzig")
543
+ name1 = topic.create_name("Universitaet Leipzig")
544
+ name2 = topic.create_name("University of Leipzig")
545
+ occ1 = topic.create_occurrence("Gruendungsjahr", "1409")
546
+ occ2 = topic.create_occurrence("Webseite", "http://www.example.org/uni-leipzig")
547
+ topic.should have(4).children
548
+ topic.children.should include(name1, name2, occ1, occ2)
549
+ end
550
+ end
551
+
552
+ describe "#roles" do
553
+ before(:each) do
554
+ @t1,@t2,@t3,@t4,@t5 = @tm.get!(["t1","t2","t3","t4","t5"])
555
+ @t_a1,@t_a2 = @tm.get!(["t_a1","t_a2"])
556
+ @t_r1,@t_r2,@t_r3,@t_r4,@t_r5 = @tm.get!(["t_r1","t_r2","t_r3","t_r4","t_r5"])
557
+ @a1 = @tm.create_association(@t_a1)
558
+ @a2 = @tm.create_association(@t_a2)
559
+ @a3 = @tm.create_association(@t_a1)
560
+ @r1 = @a1.create_role(@t_r1, @t1)
561
+ @r2 = @a1.create_role(@t_r2, @t2)
562
+ @r3 = @a1.create_role(@t_r1, @t4)
563
+ @r4 = @a2.create_role(@t_r1, @t1)
564
+ @r5 = @a2.create_role(@t_r3, @t3)
565
+ @r6 = @a3.create_role(@t_r4, @t1)
566
+ @r7 = @a3.create_role(@t_r5, @t5)
567
+ end
568
+ it "should give back all roles when no arguments are given" do
569
+ @t1.roles.size.should == 3
570
+ @t1.roles.should include(@r1, @r4, @r6)
571
+ @t2.should have(1).roles
572
+ @t3.should have(1).roles
573
+ @t4.should have(1).roles
574
+ @t5.should have(1).roles
575
+ @t1.roles(:any).should == @t1.roles
576
+ end
577
+ it "should give back some roles if the roletype is given" do
578
+ @t1.roles(@t_r1).size.should == 2
579
+ @t1.roles(@t_r1).should include(@r1, @r4)
580
+ end
581
+ it "should give back some roles if several roletypes are given" do
582
+ @t1.roles([@t_r1,@t_r4]).size.should == 3
583
+ @t1.roles([@t_r1,@t_r4]).should include(@r1, @r4, @r6)
584
+ end
585
+ it "should give back some roles if several roletypes and one assoctype are given" do
586
+ @t1.roles([@t_r1, @t_r4], @t_a1).size.should == 2
587
+ @t1.roles([@t_r1, @t_r4], @t_a1).should include(@r1, @r6)
588
+
589
+ @t1.roles([@t_r1, @t_r1, @t_r4], @t_a1).size.should == 2
590
+ end
591
+ it "should give back some roles if several assoctypes and one rolytype are given" do
592
+ @t1.roles(@t_r4,[@t_a1,@t_a2]).size.should == 1
593
+ @t1.roles(@t_r4,[@t_a1,@t_a2]).should include(@r6)
594
+
595
+ @t1.roles(@t_r1,[@t_a1,@t_a2]).size.should == 2
596
+ @t1.roles(@t_r1,[@t_a1,@t_a2]).should include(@r1, @r4)
597
+
598
+ @t1.roles(@t_r1,[@t_a1,@t_a2]).should == @t1.roles([@t_r1],[@t_a1,@t_a2])
599
+ end
600
+ it "should handle Arrays of Arrays" do
601
+ @t1.roles(@t_r1).should == @t1.roles([@t_r1])
602
+ @t1.roles(@t_r1).should == @t1.roles([[@t_r1]])
603
+
604
+ @t1.roles(@t_r4,[@t_a1,@t_a2]).should == @t1.roles(@t_r4,[@t_a1,[@t_a2]])
605
+ end
606
+ it "should give back some roles if several assoctypes and one rolytype are given" do
607
+ @t1.roles(@t_r4,[@t_a1,@t_a2]).size.should == 1
608
+ @t1.roles(@t_r4,[@t_a1,@t_a2]).should include(@r6)
609
+
610
+ @t1.roles(@t_r1,[@t_a1,@t_a2]).size.should == 2
611
+ @t1.roles(@t_r1,[@t_a1,@t_a2]).should include(@r1, @r4)
612
+
613
+ @t1.roles(@t_r1,[@t_a1,@t_a2]).should == @t1.roles([@t_r1],[@t_a1,@t_a2])
614
+ end
615
+ it "should give back some roles if several roletypes and several assoctype are given" do
616
+ @t1.roles([@t_r4,@t_r1],[@t_a1,@t_a2]).size.should == 3
617
+ @t1.roles([@t_r4,@t_r1],[@t_a1,@t_a2]).should include(@r1, @r4, @r6)
618
+ end
619
+ it "should handle Locators" do
620
+ @t1.roles(@tm.create_locator("t_r1")).should == @t1.roles(@t_r1)
621
+ end
622
+ it "should handle IRIs" do
623
+ @t1.roles("t_r1").should == @t1.roles(@t_r1)
624
+ @t1.roles("t_r2").should be_empty
625
+ @t1.roles("t_r").should be_empty
626
+ @t1.roles(["t_r1","t_r4"]).should == @t1.roles([@t_r1,@t_r4])
627
+ @t1.roles(["t_r1", @t_r4], "t_a1").should == @t1.roles([@t_r1, @t_r4], @t_a1)
628
+ @t1.roles("t_r4",[@t_a1,@t_a2]).should == @t1.roles(@t_r4,[@t_a1,@t_a2])
629
+ @t1.roles(["t_r4",@t_r1],["t_a1",@t_a2]).should == @t1.roles([@t_r4,@t_r1],[@t_a1,@t_a2])
630
+ end
631
+ it "should give back an empty Set of Roles" do
632
+ @t1.roles(@t_r2).should be_empty
633
+ @t1.roles(@t_a2).should be_empty
634
+ end
635
+ it "should set roles to roles_played" do
636
+ @t1.roles.should == @t1.roles_played
637
+ end
638
+ end #of describe "#roles"
639
+
640
+ describe "#create_occurrence" do
641
+ before(:each) do
642
+ @topic = @tm.get!("person")
643
+ end
644
+ after(:each) do
645
+ end
646
+ describe "with false arguments" do
647
+ it "should raise an error if type is a String and the value's datatype is not supported" do
648
+ lambda{@topic.create_occurrence("Age", {:a => :b})}.should raise_error
649
+ end
650
+ it "should not raise an error if type is String, datatype is given, the value's datatype is not supported but the value may be converted to string" do
651
+ lambda{:a.to_s}.should_not raise_error
652
+ lambda{@topic.create_occurrence("Age", :a, :datatype => RTM::PSI[:String])}.should_not raise_error
653
+ end
654
+ it "should raise an error if type is a Locator and the value's type is not supported" do
655
+ lambda{@topic.create_occurrence(@tm.create_locator("Age"), {:a => :b})}.should raise_error
656
+ end
657
+ it "should raise an error if type is a Topic and the value's type is not supported" do
658
+ lambda{@topic.create_occurrence(@tm.get!("Age"), {:a => :b})}.should raise_error
659
+ end
660
+ it "should raise an error if scope is not an array"
661
+ it "should raise an error if datatype is not of type String or Locator"
662
+ it "should raise an error if datatype is nil" do
663
+ @occ = @topic.create_occurrence("birthplace","Leipzig", :datatype => nil)
664
+ end
665
+ end
666
+ describe "given type and value" do
667
+ after(:each) do
668
+ @occ.should be_a_kind_of(RTM::Occurrence)
669
+ @occ.scope.should respond_to(:each)
670
+ @occ.scope.should be_empty
671
+ end
672
+ describe "and type is a String" do
673
+ it "should create an occurrence if value is a String" do
674
+ @occ = @topic.create_occurrence("birthplace","Leipzig")
675
+ @tm.get("birthplace").should be_a_kind_of(RTM::Topic)
676
+ @occ.type.should == @tm.get("birthplace")
677
+ @occ.value.should == "Leipzig"
678
+ @occ.datatype.should == @tm.create_locator(RTM::PSI[:String])
679
+ end
680
+ it "should create an occurrence if value is a Locator" do
681
+ @occ = @topic.create_occurrence("Website" ,@tm.create_locator("http://www.example.org/uni-leipzig"))
682
+ @tm.get("Website").should be_a_kind_of(RTM::Topic)
683
+ @occ.type.should == @tm.get("Website")
684
+ @occ.datatype.to_external_form.should == RTM::PSI[:IRI]
685
+ @occ.value.should == "http://www.example.org/uni-leipzig"
686
+ end
687
+ it "should create an occurrnce if value is a Float" do
688
+ @occ = @topic.create_occurrence("Age", 23.5)
689
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
690
+ @occ.type.should == @tm.get("Age")
691
+ @occ.datatype.to_external_form.should == RTM::PSI[:Float]
692
+ @occ.value.should == "23.5"
693
+ end
694
+ it "should create an occurrence if value is a Fixum" do
695
+ @occ = @topic.create_occurrence("Age", 23)
696
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
697
+ @occ.type.should == @tm.get("Age")
698
+ @occ.datatype.to_external_form.should == RTM::PSI[:Long]
699
+ @occ.value.should == "23"
700
+ end
701
+ it "should create an occurrence if value is Bignum" do
702
+ number = 9999999999999999999
703
+ number.class.should == Bignum
704
+ @occ = @topic.create_occurrence("Age", number)
705
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
706
+ @occ.type.should == @tm.get("Age")
707
+ @occ.datatype.to_external_form.should == RTM::PSI[:Integer]
708
+ @occ.value.should == number.to_s
709
+ end
710
+ end
711
+ describe "and type is a Locator" do
712
+ it "should create an occurrence if value is a String" do
713
+ @occ = @topic.create_occurrence(@tm.create_locator("birthplace"),"Leipzig")
714
+ @tm.get("birthplace").should be_a_kind_of(RTM::Topic)
715
+ @occ.type.should == @tm.get("birthplace")
716
+ @occ.value.should == "Leipzig"
717
+ @occ.datatype.should == @tm.create_locator(RTM::PSI[:String])
718
+ end
719
+ it "should create an occurrence if value is an IRI" do
720
+ @occ = @topic.create_occurrence(@tm.create_locator("Website"), @tm.create_locator("http://www.example.org/uni-leipzig"))
721
+ @tm.get("Website").should be_a_kind_of(RTM::Topic)
722
+ @occ.type.should == @tm.get("Website")
723
+ @occ.value.should == "http://www.example.org/uni-leipzig"
724
+ @occ.datatype.should == @tm.create_locator(RTM::PSI[:IRI])
725
+ end
726
+ it "should create an occurrnce if value is a Float" do
727
+ @occ = @topic.create_occurrence(@tm.create_locator("Age"), 23.5)
728
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
729
+ @occ.type.should == @tm.get("Age")
730
+ @occ.datatype.to_external_form.should == RTM::PSI[:Float]
731
+ @occ.value.should == "23.5"
732
+ end
733
+ it "should create an occurrence if value is a Fixum" do
734
+ @occ = @topic.create_occurrence(@tm.create_locator("Age"), 23)
735
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
736
+ @occ.type.should == @tm.get("Age")
737
+ @occ.datatype.to_external_form.should == RTM::PSI[:Long]
738
+ @occ.value.should == "23"
739
+ end
740
+ it "should create an occurrence if value is Bignum" do
741
+ number = 9999999999999999999
742
+ number.class.should == Bignum
743
+ @occ = @topic.create_occurrence(@tm.create_locator("Age"), number)
744
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
745
+ @occ.type.should == @tm.get("Age")
746
+ @occ.datatype.to_external_form.should == RTM::PSI[:Integer]
747
+ @occ.value.should == number.to_s
748
+ end
749
+ end
750
+ describe "and type is a Topic" do
751
+ it "should create an occurrence if value is a String" do
752
+ type = @tm.get!("Website")
753
+ @occ = @topic.create_occurrence(type, "http://www.example.org/uni-leipzig")
754
+ @occ.type.should == type
755
+ @occ.datatype.to_external_form.should == RTM::PSI[:String]
756
+ @occ.value.should == "http://www.example.org/uni-leipzig"
757
+ end
758
+ it "should create an occurrence if value is an IRI" do
759
+ type = @tm.get!("Website")
760
+ @occ = @topic.create_occurrence(type, @tm.create_locator("http://www.example.org/uni-leipzig"))
761
+ @occ.type.should == type
762
+ @occ.datatype.to_external_form.should == RTM::PSI[:IRI]
763
+ @occ.value.should == "http://www.example.org/uni-leipzig"
764
+ end
765
+ it "should create an occurrnce if value is a Float" do
766
+ type = @tm.get!("Age")
767
+ @occ = @topic.create_occurrence(type, 23.5)
768
+ @occ.type.should == type
769
+ @occ.datatype.to_external_form.should == RTM::PSI[:Float]
770
+ @occ.value.should == "23.5"
771
+ end
772
+ it "should create an occurrence if value is a Fixum" do
773
+ type = @tm.get!("Age")
774
+ @occ = @topic.create_occurrence(type, 23)
775
+ @occ.type.should == type
776
+ @occ.datatype.to_external_form.should == RTM::PSI[:Long]
777
+ @occ.value.should == "23"
778
+ end
779
+ it "should create an occurrence if value is Bignum" do
780
+ number = 9999999999999999999
781
+ number.class.should == Bignum
782
+ type = @tm.get!("Age")
783
+ @occ = @topic.create_occurrence(type, number)
784
+ @occ.type.should == type
785
+ @occ.datatype.to_external_form.should == RTM::PSI[:Integer]
786
+ @occ.value.should == number.to_s
787
+ end
788
+ end
789
+ end
790
+ describe "given type, value and datatype" do
791
+ after(:each) do
792
+ @occ.should be_a_kind_of(RTM::Occurrence)
793
+ @occ.scope.should respond_to(:each)
794
+ @occ.scope.should be_empty
795
+ end
796
+ describe "and type is a String" do
797
+ describe "and value is a String" do
798
+ it "should create an occurrence if datatype is xsd:String" do
799
+ @occ = @topic.create_occurrence("birthplace","Leipzig", :datatype => RTM::PSI[:String])
800
+ @tm.get("birthplace").should be_a_kind_of(RTM::Topic)
801
+ @occ.type.should == @tm.get("birthplace")
802
+ @occ.value.should == "Leipzig"
803
+ @occ.datatype.should == @tm.create_locator(RTM::PSI[:String])
804
+ end
805
+ it "should create an occurrence if datatype is xsd:anyURI ?"
806
+ it "should create an occurrence if datatype is xsd:float ?"
807
+ it "should create an occurrence if datatype is xsd:long ?"
808
+ it "should create an occurrence if datatype is xsd:integer ?"
809
+ it "should create an occurrence if datatype is xsd:?? ?"
810
+ end
811
+ describe "and value is a Locator" do
812
+ it "should create an occurrence if datatype is xsd:String" do
813
+ @occ = @topic.create_occurrence("Website" ,@tm.create_locator("http://www.example.org/uni-leipzig"), :datatype => RTM::PSI[:String])
814
+ @tm.get("Website").should be_a_kind_of(RTM::Topic)
815
+ @occ.type.should == @tm.get("Website")
816
+ @occ.datatype.to_external_form.should == RTM::PSI[:String]
817
+ @occ.value.should == "http://www.example.org/uni-leipzig"
818
+ end
819
+ it "should create an occurrence if datatype is xsd:anyURI ?"
820
+ it "should create an occurrence if datatype is xsd:float ?"
821
+ it "should create an occurrence if datatype is xsd:long ?"
822
+ it "should create an occurrence if datatype is xsd:integer ?"
823
+ it "should create an occurrence if datatype is xsd:?? ?"
824
+ end
825
+ describe "and value is a Float" do
826
+ it "should create an occurrence if datatype is xsd:String" do
827
+ @occ = @topic.create_occurrence("Age", 23.5, :datatype => RTM::PSI[:String])
828
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
829
+ @occ.type.should == @tm.get("Age")
830
+ @occ.datatype.to_external_form.should == RTM::PSI[:String]
831
+ @occ.value.should == "23.5"
832
+ end
833
+ it "should create an occurrence if datatype is xsd:anyURI ?"
834
+ it "should create an occurrence if datatype is xsd:float ?"
835
+ it "should create an occurrence if datatype is xsd:long ?"
836
+ it "should create an occurrence if datatype is xsd:integer ?"
837
+ it "should create an occurrence if datatype is xsd:?? ?"
838
+ end
839
+ describe "and value is a Fixnum" do
840
+ it "should create an occurrence if datatype is xsd:String" do
841
+ @occ = @topic.create_occurrence("Age", 23, :datatype => RTM::PSI[:String])
842
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
843
+ @occ.type.should == @tm.get("Age")
844
+ @occ.datatype.to_external_form.should == RTM::PSI[:String]
845
+ @occ.value.should == "23"
846
+ end
847
+ it "should create an occurrence if datatype is xsd:anyURI ?"
848
+ it "should create an occurrence if datatype is xsd:float ?"
849
+ it "should create an occurrence if datatype is xsd:long ?"
850
+ it "should create an occurrence if datatype is xsd:integer ?"
851
+ it "should create an occurrence if datatype is xsd:?? ?"
852
+ end
853
+ describe "and value is a Bignum" do
854
+ it "should create an occurrence if datatype is xsd:String" do
855
+ number = 9999999999999999999
856
+ number.class.should == Bignum
857
+ @occ = @topic.create_occurrence("Age", number, :datatype => RTM::PSI[:String])
858
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
859
+ @occ.type.should == @tm.get("Age")
860
+ @occ.datatype.to_external_form.should == RTM::PSI[:String]
861
+ @occ.value.should == number.to_s
862
+ end
863
+ it "should create an occurrence if datatype is xsd:anyURI ?"
864
+ it "should create an occurrence if datatype is xsd:float ?"
865
+ it "should create an occurrence if datatype is xsd:long ?"
866
+ it "should create an occurrence if datatype is xsd:integer ?"
867
+ it "should create an occurrence if datatype is xsd:?? ?"
868
+ end
869
+ end
870
+ it "should create an occurrence if type is a Locator and value and datatype is given" do
871
+ @occ = @topic.create_occurrence(@tm.create_locator("birthplace"), "Leipzig", :datatype => RTM::PSI[:IRI])
872
+ @tm.get("birthplace").should be_a_kind_of(RTM::Topic)
873
+ @occ.type.should == @tm.get("birthplace")
874
+ @occ.value.should == "http://www.topicmapslab.de/Leipzig"
875
+ @occ.datatype.should == @tm.create_locator(RTM::PSI[:IRI])
876
+ end
877
+ it "should create an occurrence if type is a Topic and value and datatype is given" do
878
+ type = @tm.get!("Website")
879
+ @occ = @topic.create_occurrence(type, "1", :datatype => RTM::PSI[:String])
880
+ @occ.type.should == type
881
+ @occ.datatype.to_external_form.should == RTM::PSI[:String]
882
+ @occ.value.should == "1"
883
+ end
884
+ end
885
+ describe "given type, value and scope" do
886
+ after(:each) do
887
+ @occ.should be_a_kind_of(RTM::Occurrence)
888
+ @occ.scope.should respond_to(:each)
889
+ end
890
+ describe "given one theme" do
891
+ after(:each) do
892
+ @occ.scope.size.should == 1
893
+ @occ.scope.should include(@tm.get("test_theme"))
894
+ end
895
+ it "should create an occurrence if type is a String and value is a String" do
896
+ @occ = @topic.create_occurrence("birthplace","Leipzig", :scope => ["test_theme"])
897
+ @tm.get("birthplace").should be_a_kind_of(RTM::Topic)
898
+ @occ.type.should == @tm.get("birthplace")
899
+ @occ.value.should == "Leipzig"
900
+ @occ.datatype.should == @tm.create_locator(RTM::PSI[:String])
901
+ end
902
+ it "should create an occurrence if type is a String and value is a Locator" do
903
+ @occ = @topic.create_occurrence("Website" ,@tm.create_locator("http://www.example.org/uni-leipzig"), :scope => ["test_theme"])
904
+ @tm.get("Website").should be_a_kind_of(RTM::Topic)
905
+ @occ.type.should == @tm.get("Website")
906
+ @occ.datatype.to_external_form.should == RTM::PSI[:IRI]
907
+ @occ.value.should == "http://www.example.org/uni-leipzig"
908
+ end
909
+ it "should create an occurrnce if type is a String and value is a Float" do
910
+ @occ = @topic.create_occurrence("Age", 23.5, :scope => ["test_theme"])
911
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
912
+ @occ.type.should == @tm.get("Age")
913
+ @occ.datatype.to_external_form.should == RTM::PSI[:Float]
914
+ @occ.value.should == "23.5"
915
+ end
916
+ it "should create an occurrence if type is a String and value is a Fixum" do
917
+ @occ = @topic.create_occurrence("Age", 23, :scope => ["test_theme"])
918
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
919
+ @occ.type.should == @tm.get("Age")
920
+ @occ.datatype.to_external_form.should == RTM::PSI[:Long]
921
+ @occ.value.should == "23"
922
+ end
923
+ it "should create an occurrence if type is a String and value is Bignum" do
924
+ number = 9999999999999999999
925
+ number.class.should == Bignum
926
+ @occ = @topic.create_occurrence("Age", number, :scope => ["test_theme"])
927
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
928
+ @occ.type.should == @tm.get("Age")
929
+ @occ.datatype.to_external_form.should == RTM::PSI[:Integer]
930
+ @occ.value.should == number.to_s
931
+ end
932
+ it "should create an occurrence if type is a Locator and value is a String" do
933
+ @occ = @topic.create_occurrence(@tm.create_locator("birthplace"), "Leipzig", :scope => ["test_theme"])
934
+ @tm.get("birthplace").should be_a_kind_of(RTM::Topic)
935
+ @occ.type.should == @tm.get("birthplace")
936
+ @occ.value.should == "Leipzig"
937
+ @occ.datatype.should == @tm.create_locator(RTM::PSI[:String])
938
+ end
939
+ it "should create an occurrence if type is a Locator and value is an IRI" do
940
+ @occ = @topic.create_occurrence(@tm.create_locator("Website"), @tm.create_locator("http://www.example.org/uni-leipzig"), :scope => ["test_theme"])
941
+ @tm.get("Website").should be_a_kind_of(RTM::Topic)
942
+ @occ.type.should == @tm.get("Website")
943
+ @occ.value.should == "http://www.example.org/uni-leipzig"
944
+ @occ.datatype.should == @tm.create_locator(RTM::PSI[:IRI])
945
+ end
946
+ it "should create an occurrnce if type is a Locator and value is a Float" do
947
+ @occ = @topic.create_occurrence(@tm.create_locator("Age"), 23.5, :scope => ["test_theme"])
948
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
949
+ @occ.type.should == @tm.get("Age")
950
+ @occ.datatype.to_external_form.should == RTM::PSI[:Float]
951
+ @occ.value.should == "23.5"
952
+ end
953
+ it "should create an occurrence if type is a Locator and value is a Fixum" do
954
+ @occ = @topic.create_occurrence(@tm.create_locator("Age"), 23, :scope => ["test_theme"])
955
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
956
+ @occ.type.should == @tm.get("Age")
957
+ @occ.datatype.to_external_form.should == RTM::PSI[:Long]
958
+ @occ.value.should == "23"
959
+ end
960
+ it "should create an occurrence if type is a Locator and value is Bignum" do
961
+ number = 9999999999999999999
962
+ number.class.should == Bignum
963
+ @occ = @topic.create_occurrence(@tm.create_locator("Age"), number, :scope => ["test_theme"])
964
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
965
+ @occ.type.should == @tm.get("Age")
966
+ @occ.datatype.to_external_form.should == RTM::PSI[:Integer]
967
+ @occ.value.should == number.to_s
968
+ end
969
+ it "should create an occurrence if type is a Topic and value is a String" do
970
+ type = @tm.get!("Website")
971
+ @occ = @topic.create_occurrence(type, "http://www.example.org/uni-leipzig", :scope => ["test_theme"])
972
+ @occ.type.should == type
973
+ @occ.datatype.to_external_form.should == RTM::PSI[:String]
974
+ @occ.value.should == "http://www.example.org/uni-leipzig"
975
+ end
976
+ it "should create an occurrence if type is a Topic and value is an IRI" do
977
+ type = @tm.get!("Website")
978
+ @occ = @topic.create_occurrence(type, @tm.create_locator("http://www.example.org/uni-leipzig"), :scope => ["test_theme"])
979
+ @occ.type.should == type
980
+ @occ.datatype.to_external_form.should == RTM::PSI[:IRI]
981
+ @occ.value.should == "http://www.example.org/uni-leipzig"
982
+ end
983
+ it "should create an occurrnce if type is a Topic and value is a Float" do
984
+ type = @tm.get!("Age")
985
+ @occ = @topic.create_occurrence(type, 23.5, :scope => ["test_theme"])
986
+ @occ.type.should == type
987
+ @occ.datatype.to_external_form.should == RTM::PSI[:Float]
988
+ @occ.value.should == "23.5"
989
+ end
990
+ it "should create an occurrence if type is a Topic and value is a Fixum" do
991
+ type = @tm.get!("Age")
992
+ @occ = @topic.create_occurrence(type, 23, :scope => ["test_theme"])
993
+ @occ.type.should == type
994
+ @occ.datatype.to_external_form.should == RTM::PSI[:Long]
995
+ @occ.value.should == "23"
996
+ end
997
+ it "should create an occurrence if type is a Topic and value is Bignum" do
998
+ number = 9999999999999999999
999
+ number.class.should == Bignum
1000
+ type = @tm.get!("Age")
1001
+ @occ = @topic.create_occurrence(type, number, :scope => ["test_theme"])
1002
+ @occ.type.should == type
1003
+ @occ.datatype.to_external_form.should == RTM::PSI[:Integer]
1004
+ @occ.value.should == number.to_s
1005
+ end
1006
+ end
1007
+ describe "given several themes" do
1008
+ before(:each) do
1009
+ @locator_theme = @tm.create_locator("test_theme2")
1010
+ @locator_theme.should be_a_kind_of RTM::Locator
1011
+ @topic_theme = @tm.get!("test_theme3")
1012
+ @topic_theme.should be_a_kind_of RTM::Topic
1013
+ end
1014
+ after(:each) do
1015
+ @occ.scope.size.should == 3
1016
+ @occ.scope.should include(@tm.get("test_theme1"), @tm.get("test_theme2"), @tm.get("test_theme3"))
1017
+ end
1018
+ it "should create an occurrence if type is a String and value is a String" do
1019
+ @occ = @topic.create_occurrence("birthplace","Leipzig", :scope => ["test_theme1", @locator_theme, @topic_theme])
1020
+ @tm.get("birthplace").should be_a_kind_of(RTM::Topic)
1021
+ @occ.type.should == @tm.get("birthplace")
1022
+ @occ.value.should == "Leipzig"
1023
+ @occ.datatype.should == @tm.create_locator(RTM::PSI[:String])
1024
+ end
1025
+ it "should create an occurrence if type is a String and value is a Locator" do
1026
+ @occ = @topic.create_occurrence("Website" ,@tm.create_locator("http://www.example.org/uni-leipzig"), :scope => ["test_theme1", @locator_theme, @topic_theme])
1027
+ @tm.get("Website").should be_a_kind_of(RTM::Topic)
1028
+ @occ.type.should == @tm.get("Website")
1029
+ @occ.datatype.to_external_form.should == RTM::PSI[:IRI]
1030
+ @occ.value.should == "http://www.example.org/uni-leipzig"
1031
+ end
1032
+ it "should create an occurrnce if type is a String and value is a Float" do
1033
+ @occ = @topic.create_occurrence("Age", 23.5, :scope => ["test_theme1", @locator_theme, @topic_theme])
1034
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
1035
+ @occ.type.should == @tm.get("Age")
1036
+ @occ.datatype.to_external_form.should == RTM::PSI[:Float]
1037
+ @occ.value.should == "23.5"
1038
+ end
1039
+ it "should create an occurrence if type is a String and value is a Fixum" do
1040
+ @occ = @topic.create_occurrence("Age", 23, :scope => ["test_theme1", @locator_theme, @topic_theme])
1041
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
1042
+ @occ.type.should == @tm.get("Age")
1043
+ @occ.datatype.to_external_form.should == RTM::PSI[:Long]
1044
+ @occ.value.should == "23"
1045
+ end
1046
+ it "should create an occurrence if type is a String and value is Bignum" do
1047
+ number = 9999999999999999999
1048
+ number.class.should == Bignum
1049
+ @occ = @topic.create_occurrence("Age", number, :scope => ["test_theme1", @locator_theme, @topic_theme])
1050
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
1051
+ @occ.type.should == @tm.get("Age")
1052
+ @occ.datatype.to_external_form.should == RTM::PSI[:Integer]
1053
+ @occ.value.should == number.to_s
1054
+ end
1055
+ it "should create an occurrence if type is a Locator and value is a String" do
1056
+ @occ = @topic.create_occurrence(@tm.create_locator("birthplace"), "Leipzig", :scope => ["test_theme1", @locator_theme, @topic_theme])
1057
+ @tm.get("birthplace").should be_a_kind_of(RTM::Topic)
1058
+ @occ.type.should == @tm.get("birthplace")
1059
+ @occ.value.should == "Leipzig"
1060
+ @occ.datatype.should == @tm.create_locator(RTM::PSI[:String])
1061
+ end
1062
+ it "should create an occurrence if type is a Locator and value is an IRI" do
1063
+ @occ = @topic.create_occurrence(@tm.create_locator("Website"), @tm.create_locator("http://www.example.org/uni-leipzig"), :scope => ["test_theme1", @locator_theme, @topic_theme])
1064
+ @tm.get("Website").should be_a_kind_of(RTM::Topic)
1065
+ @occ.type.should == @tm.get("Website")
1066
+ @occ.value.should == "http://www.example.org/uni-leipzig"
1067
+ @occ.datatype.should == @tm.create_locator(RTM::PSI[:IRI])
1068
+ end
1069
+ it "should create an occurrnce if type is a Locator and value is a Float" do
1070
+ @occ = @topic.create_occurrence(@tm.create_locator("Age"), 23.5, :scope => ["test_theme1", @locator_theme, @topic_theme])
1071
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
1072
+ @occ.type.should == @tm.get("Age")
1073
+ @occ.datatype.to_external_form.should == RTM::PSI[:Float]
1074
+ @occ.value.should == "23.5"
1075
+ end
1076
+ it "should create an occurrence if type is a Locator and value is a Fixum" do
1077
+ @occ = @topic.create_occurrence(@tm.create_locator("Age"), 23, :scope => ["test_theme1", @locator_theme, @topic_theme])
1078
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
1079
+ @occ.type.should == @tm.get("Age")
1080
+ @occ.datatype.to_external_form.should == RTM::PSI[:Long]
1081
+ @occ.value.should == "23"
1082
+ end
1083
+ it "should create an occurrence if type is a Locator and value is Bignum" do
1084
+ number = 9999999999999999999
1085
+ number.class.should == Bignum
1086
+ @occ = @topic.create_occurrence(@tm.create_locator("Age"), number, :scope => ["test_theme1", @locator_theme, @topic_theme])
1087
+ @tm.get("Age").should be_a_kind_of(RTM::Topic)
1088
+ @occ.type.should == @tm.get("Age")
1089
+ @occ.datatype.to_external_form.should == RTM::PSI[:Integer]
1090
+ @occ.value.should == number.to_s
1091
+ end
1092
+ it "should create an occurrence if type is a Topic and value is a String" do
1093
+ type = @tm.get!("Website")
1094
+ @occ = @topic.create_occurrence(type, "http://www.example.org/uni-leipzig", :scope => ["test_theme1", @locator_theme, @topic_theme])
1095
+ @occ.type.should == type
1096
+ @occ.datatype.to_external_form.should == RTM::PSI[:String]
1097
+ @occ.value.should == "http://www.example.org/uni-leipzig"
1098
+ end
1099
+ it "should create an occurrence if type is a Topic and value is an IRI" do
1100
+ type = @tm.get!("Website")
1101
+ @occ = @topic.create_occurrence(type, @tm.create_locator("http://www.example.org/uni-leipzig"), :scope => ["test_theme1", @locator_theme, @topic_theme])
1102
+ @occ.type.should == type
1103
+ @occ.datatype.to_external_form.should == RTM::PSI[:IRI]
1104
+ @occ.value.should == "http://www.example.org/uni-leipzig"
1105
+ end
1106
+ it "should create an occurrnce if type is a Topic and value is a Float" do
1107
+ type = @tm.get!("Age")
1108
+ @occ = @topic.create_occurrence(type, 23.5, :scope => ["test_theme1", @locator_theme, @topic_theme])
1109
+ @occ.type.should == type
1110
+ @occ.datatype.to_external_form.should == RTM::PSI[:Float]
1111
+ @occ.value.should == "23.5"
1112
+ end
1113
+ it "should create an occurrence if type is a Topic and value is a Fixum" do
1114
+ type = @tm.get!("Age")
1115
+ @occ = @topic.create_occurrence(type, 23, :scope => ["test_theme1", @locator_theme, @topic_theme])
1116
+ @occ.type.should == type
1117
+ @occ.datatype.to_external_form.should == RTM::PSI[:Long]
1118
+ @occ.value.should == "23"
1119
+ end
1120
+ it "should create an occurrence if type is a Topic and value is Bignum" do
1121
+ number = 9999999999999999999
1122
+ number.class.should == Bignum
1123
+ type = @tm.get!("Age")
1124
+ @occ = @topic.create_occurrence(type, number, :scope => ["test_theme1", @locator_theme, @topic_theme])
1125
+ @occ.type.should == type
1126
+ @occ.datatype.to_external_form.should == RTM::PSI[:Integer]
1127
+ @occ.value.should == number.to_s
1128
+ end
1129
+ end
1130
+ end
1131
+ describe "given type, value, datatype and scope" do
1132
+ it "should be tested"
1133
+ end
1134
+ end #of describe "#create_occurrences"
1135
+
1136
+ describe "#add_subject_identifier" do
1137
+ before(:each) do
1138
+ @ii_1 = "http://www.example.org/ii_1"
1139
+ @ii_2 = "http://www.example.org/ii_2"
1140
+ @si_1 = "http://www.example.org/si_1"
1141
+ @si_2 = "http://www.example.org/si_2"
1142
+ @sl_1 = "http://www.example.org/sl_1"
1143
+ @sl_2 = "http://www.example.org/sl_2"
1144
+ end
1145
+ it "should add an identifier as subject identifier if the topic already has another si" do
1146
+ topic = @tm.get!("si:" + @si_1)
1147
+ topic.add_subject_identifier(@si_2)
1148
+ topic.items.should be_empty
1149
+ topic.indicators.size.should == 2
1150
+ topic.indicators.should include @si_1, @si_2
1151
+ topic.locators.should be_empty
1152
+ end
1153
+ it "should add an identifier as subject identifier if the topic already has another ii" do
1154
+ topic = @tm.get!("ii:" + @ii_1)
1155
+ topic.add_subject_identifier(@si_2)
1156
+ topic.items.size.should == 1
1157
+ topic.items.should include @ii_1
1158
+ topic.indicators.size.should == 1
1159
+ topic.indicators.should include @si_2
1160
+ topic.locators.should be_empty
1161
+ end
1162
+ it "should add an identifier as subject identifier if the topic already has another sl" do
1163
+ topic = @tm.get!("sl:" + @sl_1)
1164
+ topic.add_subject_identifier(@si_2)
1165
+ topic.items.should be_empty
1166
+ topic.indicators.size.should == 1
1167
+ topic.indicators.should include @si_2
1168
+ topic.locators.size.should == 1
1169
+ topic.locators.should include @sl_1
1170
+ end
1171
+ it "should not add an identifier as subject identifier if the topic already this identifier as si" do
1172
+ topic = @tm.get!("si:" + @si_2)
1173
+ topic.add_subject_identifier(@si_2)
1174
+ topic.items.should be_empty
1175
+ topic.indicators.size.should == 1
1176
+ topic.indicators.should include @si_2
1177
+ topic.locators.should be_empty
1178
+ end
1179
+ it "should add an identifier as subject identifier if the topic already has this identifier as ii" do
1180
+ topic = @tm.get!("ii:" + @si_2)
1181
+ # puts "ii: #{topic.item_identifiers.to_s}"
1182
+ # puts "si: #{topic.subject_identifiers.to_s}"
1183
+ topic.add_subject_identifier(@si_2)
1184
+ # puts "ii: #{topic.item_identifiers.to_s}"
1185
+ # puts "si: #{topic.subject_identifiers.to_s}"
1186
+ topic.items.size.should == 1
1187
+ topic.items.should include @si_2
1188
+ topic.indicators.size.should == 1
1189
+ topic.indicators.should include @si_2
1190
+ topic.locators.should be_empty
1191
+ end
1192
+ it "should do what? if the topic already has this identifier as sl"
1193
+ 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
1194
+ topicA = @tm.get!("ii:" + @ii_1)
1195
+ topicB = @tm.get!("ii:" + @ii_2)
1196
+ lambda{topicA.add_subject_identifier(@ii_2)}.should raise_error
1197
+ end
1198
+ end # of describe add_subject_indentifier
1199
+
1200
+ describe "#add_item_identifier" do
1201
+ before(:each) do
1202
+ @ii_1 = "http://www.example.org/ii_1"
1203
+ @ii_2 = "http://www.example.org/ii_2"
1204
+ @si_1 = "http://www.example.org/si_1"
1205
+ @si_2 = "http://www.example.org/si_2"
1206
+ @sl_1 = "http://www.example.org/sl_1"
1207
+ @sl_2 = "http://www.example.org/sl_2"
1208
+ end
1209
+ it "should be tested"
1210
+ end #of describe add_item_identifier
1211
+
1212
+ describe "#add_subject_locator" do
1213
+ before(:each) do
1214
+ @ii_1 = "http://www.example.org/ii_1"
1215
+ @ii_2 = "http://www.example.org/ii_2"
1216
+ @si_1 = "http://www.example.org/si_1"
1217
+ @si_2 = "http://www.example.org/si_2"
1218
+ @sl_1 = "http://www.example.org/sl_1"
1219
+ @sl_2 = "http://www.example.org/sl_2"
1220
+ end
1221
+ it "should be tested"
1222
+ end # of describe add_subject_locator
1223
+
1224
+ describe "#remove_subject_identifier" do
1225
+ before(:each) do
1226
+ @topic = @tm.get!("si:http://www.example.org/topic1/si_1")
1227
+ @topic.add_subject_identifier("http://www.example.org/topic1/si_2")
1228
+ @topic.add_item_identifier("http://www.example.org/topic1/ii_1")
1229
+ @topic.add_item_identifier("http://www.example.org/topic1/ii_2")
1230
+ @topic.add_subject_locator("http://www.example.org/topic1/sl_1")
1231
+ @topic.add_subject_locator("http://www.example.org/topic1/sl_2")
1232
+ @topic_wo_si = @tm.get!("ii:http://www.example.org/topic2/ii")
1233
+ @topic_wo_si.add_subject_locator("http://www.example.org/topic2/sl")
1234
+ @topic.should have(2).indicators
1235
+ @topic.should have(2).items
1236
+ @topic.should have(2).locators
1237
+ end
1238
+ it "should remove an existing subject identifier if argument is a String" do
1239
+ @topic.remove_subject_identifier("http://www.example.org/topic1/si_1")
1240
+ @topic.should have(1).indicators
1241
+ @topic.indicators.should include "http://www.example.org/topic1/si_2"
1242
+ @topic.remove_subject_identifier("http://www.example.org/topic1/si_2")
1243
+ @topic.should have(0).indicators
1244
+ @topic.should have(2).items
1245
+ @topic.should have(2).locators
1246
+ end
1247
+ it "should remove an existing subject identifier if argument is a Locator" do
1248
+ locator1 = @tm.create_locator("http://www.example.org/topic1/si_1")
1249
+ locator2 = @tm.create_locator("http://www.example.org/topic1/si_2")
1250
+ @topic.remove_subject_identifier(locator1)
1251
+ @topic.should have(1).indicators
1252
+ @topic.indicators.should include "http://www.example.org/topic1/si_2"
1253
+ @topic.remove_subject_identifier(locator2)
1254
+ @topic.should have(0).indicators
1255
+ @topic.should have(2).items
1256
+ @topic.should have(2).locators
1257
+ end
1258
+ it "should not remove a subject identifier if argument does not refer to an existing si" do
1259
+ @topic.remove_subject_identifier("http://www.example.org/topic1/something")
1260
+ @topic.should have(2).indicators
1261
+ @topic.should have(2).items
1262
+ @topic.should have(2).locators
1263
+ @topic.remove_subject_identifier(@tm.create_locator("http://www.example.org/topic1/something"))
1264
+ @topic.should have(2).indicators
1265
+ @topic.should have(2).items
1266
+ @topic.should have(2).locators
1267
+ end
1268
+ it "should not remove a subject identifier if the identifier exists as ii or sl" do
1269
+ @topic_wo_si.remove_subject_identifier("http://www.example.org/topic2/ii")
1270
+ @topic_wo_si.remove_subject_identifier("http://www.example.org/topic2/sl")
1271
+ @topic_wo_si.should have(0).indicators
1272
+ @topic_wo_si.should have(1).items
1273
+ @topic_wo_si.should have(1).locators
1274
+ end
1275
+ end #of describe remove_subject_identifier
1276
+
1277
+ describe "#remove_item_identifier" do
1278
+ before(:each) do
1279
+ @topic = @tm.get!("si:http://www.example.org/topic1/si_1")
1280
+ @topic.add_subject_identifier("http://www.example.org/topic1/si_2")
1281
+ @topic.add_item_identifier("http://www.example.org/topic1/ii_1")
1282
+ @topic.add_item_identifier("http://www.example.org/topic1/ii_2")
1283
+ @topic.add_subject_locator("http://www.example.org/topic1/sl_1")
1284
+ @topic.add_subject_locator("http://www.example.org/topic1/sl_2")
1285
+ @topic_wo_ii = @tm.get!("si:http://www.example.org/topic2/si")
1286
+ @topic_wo_ii.add_subject_locator("http://www.example.org/topic2/sl")
1287
+ @topic.should have(2).indicators
1288
+ @topic.should have(2).items
1289
+ @topic.should have(2).locators
1290
+ end
1291
+ it "should remove an existing item identifier if argument is a String" do
1292
+ @topic.remove_item_identifier("http://www.example.org/topic1/ii_1")
1293
+ @topic.should have(1).items
1294
+ @topic.items.should include "http://www.example.org/topic1/ii_2"
1295
+ @topic.remove_item_identifier("http://www.example.org/topic1/ii_2")
1296
+ @topic.should have(2).indicators
1297
+ @topic.should have(0).items
1298
+ @topic.should have(2).locators
1299
+ end
1300
+ it "should remove an existing item identifier if argument is a Locator" do
1301
+ locator1 = @tm.create_locator("http://www.example.org/topic1/ii_1")
1302
+ locator2 = @tm.create_locator("http://www.example.org/topic1/ii_2")
1303
+ @topic.remove_item_identifier(locator1)
1304
+ @topic.should have(1).items
1305
+ @topic.items.should include "http://www.example.org/topic1/ii_2"
1306
+ @topic.remove_item_identifier(locator2)
1307
+ @topic.should have(2).indicators
1308
+ @topic.should have(0).items
1309
+ @topic.should have(2).locators
1310
+ end
1311
+ it "should not remove an item identifier if argument does not refer to an existing ii" do
1312
+ @topic.remove_item_identifier("http://www.example.org/topic1/something")
1313
+ @topic.should have(2).indicators
1314
+ @topic.should have(2).items
1315
+ @topic.should have(2).locators
1316
+ @topic.remove_item_identifier(@tm.create_locator("http://www.example.org/topic1/something"))
1317
+ @topic.should have(2).indicators
1318
+ @topic.should have(2).items
1319
+ @topic.should have(2).locators
1320
+ end
1321
+ it "should not remove an item identifier if the identifier exists as si or sl" do
1322
+ @topic_wo_ii.remove_item_identifier("http://www.example.org/topic2/si")
1323
+ @topic_wo_ii.remove_item_identifier("http://www.example.org/topic2/sl")
1324
+ @topic_wo_ii.should have(1).indicators
1325
+ @topic_wo_ii.should have(0).items
1326
+ @topic_wo_ii.should have(1).locators
1327
+ end
1328
+ end #of describe remove_item_identifier
1329
+
1330
+ describe "#remove_subject_locator" do
1331
+ before(:each) do
1332
+ @topic = @tm.get!("si:http://www.example.org/topic1/si_1")
1333
+ @topic.add_subject_identifier("http://www.example.org/topic1/si_2")
1334
+ @topic.add_item_identifier("http://www.example.org/topic1/ii_1")
1335
+ @topic.add_item_identifier("http://www.example.org/topic1/ii_2")
1336
+ @topic.add_subject_locator("http://www.example.org/topic1/sl_1")
1337
+ @topic.add_subject_locator("http://www.example.org/topic1/sl_2")
1338
+ @topic_wo_sl = @tm.get!("ii:http://www.example.org/topic2/ii")
1339
+ @topic_wo_sl.add_subject_identifier("http://www.example.org/topic2/si")
1340
+ @topic.should have(2).indicators
1341
+ @topic.should have(2).items
1342
+ @topic.should have(2).locators
1343
+ end
1344
+ it "should remove an existing subject locator if argument is a String" do
1345
+ @topic.remove_subject_locator("http://www.example.org/topic1/sl_1")
1346
+ @topic.should have(1).locators
1347
+ @topic.locators.should include "http://www.example.org/topic1/sl_2"
1348
+ @topic.remove_subject_locator("http://www.example.org/topic1/sl_2")
1349
+ @topic.should have(2).indicators
1350
+ @topic.should have(2).items
1351
+ @topic.should have(0).locators
1352
+ end
1353
+ it "should remove an existing subject locator if argument is a Locator" do
1354
+ locator1 = @tm.create_locator("http://www.example.org/topic1/sl_1")
1355
+ locator2 = @tm.create_locator("http://www.example.org/topic1/sl_2")
1356
+ @topic.remove_subject_locator(locator1)
1357
+ @topic.should have(1).locators
1358
+ @topic.locators.should include "http://www.example.org/topic1/sl_2"
1359
+ @topic.remove_subject_locator(locator2)
1360
+ @topic.should have(2).indicators
1361
+ @topic.should have(2).items
1362
+ @topic.should have(0).locators
1363
+ end
1364
+ it "should not remove a subject locator if argument does not refer to an existing sl" do
1365
+ @topic.remove_subject_locator("http://www.example.org/topic1/something")
1366
+ @topic.should have(2).indicators
1367
+ @topic.should have(2).items
1368
+ @topic.should have(2).locators
1369
+ @topic.remove_subject_locator(@tm.create_locator("http://www.example.org/topic1/something"))
1370
+ @topic.should have(2).indicators
1371
+ @topic.should have(2).items
1372
+ @topic.should have(2).locators
1373
+ end
1374
+ it "should not remove a subject locator if the identifier exists as ii or si" do
1375
+ @topic_wo_sl.remove_subject_locator("http://www.example.org/topic2/ii")
1376
+ @topic_wo_sl.remove_subject_locator("http://www.example.org/topic2/si")
1377
+ @topic_wo_sl.should have(1).indicators
1378
+ @topic_wo_sl.should have(1).items
1379
+ @topic_wo_sl.should have(0).locators
1380
+ end
1381
+ end #of describe remove_subject_locator
1382
+
1383
+ describe "#reified" do
1384
+ before(:each) do
1385
+ end
1386
+ it "should be tested ..."
1387
+ end
1388
+
1389
+ describe "#reified=" do
1390
+ before(:each) do
1391
+ @topic = @tm.get!("Hans")
1392
+ @name = @topic.create_name("firstname","Hans")
1393
+ @occ = @topic.create_occurrence("birthyear","2000")
1394
+ @variant = @name.create_variant("Hansi",["home"])
1395
+ @assoc = @tm.create_association("mother-child")
1396
+ @role = @assoc.create_role("child","Hans")
1397
+ @a_reifier = @tm.get!("test_reifier")
1398
+ end
1399
+ it "should set self as reifier for the identifier (a Name)" do
1400
+ @name.reifier.should be_nil
1401
+ @a_reifier.reified = @name
1402
+ @name.reifier.should == @a_reifier
1403
+ end
1404
+ it "should set self as reifier for the identifier (a Variant)" do
1405
+ @variant.reifier.should be_nil
1406
+ @a_reifier.reified = @variant
1407
+ @variant.reifier.should == @a_reifier
1408
+ end
1409
+ it "should set self as reifier for the identifier (an Occurrence)" do
1410
+ @occ.reifier.should be_nil
1411
+ @a_reifier.reified = @occ
1412
+ @occ.reifier.should == @a_reifier
1413
+ end
1414
+ it "should set self as reifier for the identifier (an Association)" do
1415
+ @assoc.reifier.should be_nil
1416
+ @a_reifier.reified = @assoc
1417
+ @assoc.reifier.should == @a_reifier
1418
+ end
1419
+ it "should set self as reifier for the identifier (a Role)" do
1420
+ @role.reifier.should be_nil
1421
+ @a_reifier.reified = @role
1422
+ @role.reifier.should == @a_reifier
1423
+ end
1424
+ it "should set self as reifier for the identifier (a TopicMap)" do
1425
+ @tm.reifier.should be_nil
1426
+ @a_reifier.reified = @tm
1427
+ @tm.reifier.should == @a_reifier
1428
+ end
1429
+ it "should overwrite a previous reifier if identifier already had a reifier" do
1430
+ @name.reifier = "dummy_reifier"
1431
+ @name.reifier.should == @tm.get("dummy_reifier")
1432
+ @a_reifier.reified = @name
1433
+ @name.reifier.should == @a_reifier
1434
+ end
1435
+ it "should raise an error if this Topic already refies a Reifiable Construct" do
1436
+ @name.reifier = @a_reifier
1437
+ lambda{@a_reifier.reified = @occ}
1438
+ end
1439
+ it "should raise an error if the identifier is not a Reifiable" do
1440
+ lambda{@a_reifier.reified = "test"}.should raise_error
1441
+ end
1442
+ end
1443
+
1444
+ describe "#remove" do
1445
+ before(:each) do
1446
+ @topic1 = @tm.get!("topic1")
1447
+ @topic2 = @tm.get!("topic2")
1448
+ @name = @topic1.create_name("firstname","Hans")
1449
+ @occurrence = @topic1.create_occurrence("birthyear","2000")
1450
+ @tm.should have(4).topics
1451
+ end
1452
+ it "should remove this topic from the container (topic map)" do
1453
+ @tm.literal_index.getOccurrences("2000").size.should == 1
1454
+ @tm.literal_index.getNames("Hans").size.should == 1
1455
+ @topic1.remove
1456
+ @tm.should have(3).topics
1457
+ @topic2.remove
1458
+ @tm.should have(2).topics
1459
+ @tm.literal_index.getOccurrences("2000").size.should == 0
1460
+ @tm.literal_index.getNames("Hans").size.should == 0
1461
+ end
1462
+ end
1463
+ end # of describe self
1464
+
1465
+ end # of module
1466
+
1467
+
1468
+