rtm 0.2.0 → 0.2.1

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 (88) hide show
  1. data/README +38 -3
  2. data/lib/rtm.rb +25 -47
  3. data/lib/rtm/axes.rb +7 -4
  4. data/lib/rtm/axes/association.rb +1 -1
  5. data/lib/rtm/axes/associations.rb +1 -1
  6. data/lib/rtm/axes/characteristic.rb +1 -1
  7. data/lib/rtm/axes/characteristics.rb +1 -1
  8. data/lib/rtm/axes/topic.rb +3 -3
  9. data/lib/rtm/axes/topics.rb +3 -3
  10. data/lib/rtm/engine.rb +48 -5
  11. data/lib/rtm/extensions.rb +58 -8
  12. data/lib/rtm/io.rb +2 -1
  13. data/lib/rtm/io/tmapix_from.rb +155 -0
  14. data/lib/rtm/io/tmapix_to.rb +223 -0
  15. data/lib/rtm/io/to_hash.rb +79 -41
  16. data/lib/rtm/io/to_jtm.rb +1 -1
  17. data/lib/rtm/io/to_rdf.rb +20 -5
  18. data/lib/rtm/io/to_string.rb +13 -2
  19. data/lib/rtm/io/to_yaml.rb +39 -11
  20. data/lib/rtm/navigation.rb +1 -15
  21. data/lib/rtm/navigation/association/players.rb +1 -1
  22. data/lib/rtm/navigation/name/characteristics.rb +1 -1
  23. data/lib/rtm/navigation/occurrence/characteristics.rb +1 -1
  24. data/lib/rtm/navigation/topic/characteristics.rb +1 -1
  25. data/lib/rtm/navigation/topic/players.rb +1 -1
  26. data/lib/rtm/navigation/topic/supertypes.rb +21 -17
  27. data/lib/rtm/navigation/topic/traverse.rb +1 -1
  28. data/lib/rtm/navigation/topic/types.rb +6 -4
  29. data/lib/rtm/psi.rb +6 -0
  30. data/lib/rtm/sugar.rb +42 -29
  31. data/lib/rtm/sugar/association/hash_access.rb +3 -3
  32. data/lib/rtm/sugar/occurrence/dynamic_value.rb +39 -56
  33. data/lib/rtm/sugar/occurrence/external.rb +53 -0
  34. data/lib/rtm/sugar/reifiable/reifier.rb +21 -0
  35. data/lib/rtm/sugar/role/counterparts.rb +12 -6
  36. data/lib/rtm/sugar/topic/best_name.rb +74 -0
  37. data/lib/rtm/sugar/topic/characteristics.rb +10 -10
  38. data/lib/rtm/sugar/topic/counterparts.rb +131 -119
  39. data/lib/rtm/sugar/topic/scoped.rb +102 -53
  40. data/lib/rtm/sugar/topic/topic_ref.rb +63 -12
  41. data/lib/rtm/sugar/topic/typed.rb +50 -2
  42. data/lib/rtm/sugar/topic_map/query_cache.rb +66 -0
  43. data/lib/rtm/sugar/topic_map/themes.rb +53 -0
  44. data/lib/rtm/sugar/typed/types.rb +1 -1
  45. data/lib/rtm/validation.rb +2 -2
  46. data/lib/rtm/version.rb +18 -6
  47. data/spec/rtm/axes/string_spec.rb +7 -7
  48. data/spec/rtm/axes/strings_spec.rb +10 -10
  49. data/spec/rtm/io/tmapix_from_spec.rb +76 -0
  50. data/spec/rtm/io/tmapix_to_spec.rb +159 -0
  51. data/spec/rtm/io/to_hash_spec.rb +90 -0
  52. data/spec/rtm/io/to_rdf_spec.rb +37 -0
  53. data/spec/rtm/io/to_string_spec.rb +122 -0
  54. data/spec/rtm/io/to_yaml_spec.rb +89 -0
  55. data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +156 -1
  56. data/spec/rtm/sugar/occurrence/external_spec.rb +129 -0
  57. data/spec/rtm/sugar/reifiable/reifier_spec.rb +41 -0
  58. data/spec/rtm/sugar/role/counterparts_spec.rb +174 -172
  59. data/spec/rtm/sugar/topic/best_name_spec.rb +25 -0
  60. data/spec/rtm/sugar/topic/characteristics_spec.rb +20 -5
  61. data/spec/rtm/sugar/topic/counterparts_spec.rb +41 -1
  62. data/spec/rtm/sugar/topic/hash_access_spec.rb +1 -1
  63. data/spec/rtm/sugar/topic/scoped_spec.rb +178 -114
  64. data/spec/rtm/sugar/topic/topic_ref_spec.rb +10 -10
  65. data/spec/rtm/sugar/topic/typed_spec.rb +196 -134
  66. data/spec/rtm/sugar/topic_map/themes_spec.rb +67 -0
  67. data/spec/rtm/sugar/typed/types_spec.rb +1 -1
  68. data/spec/rtm/tmapi/core/association_spec.rb +2 -2
  69. data/spec/rtm/tmapi/core/datatype_aware_spec.rb +236 -0
  70. data/spec/rtm/tmapi/core/name_spec.rb +186 -1
  71. data/spec/rtm/tmapi/core/occurrence_spec.rb +24 -67
  72. data/spec/rtm/tmapi/core/reifiable_spec.rb +2 -2
  73. data/spec/rtm/tmapi/core/scoped_spec.rb +40 -2
  74. data/spec/rtm/tmapi/core/topic_map_spec.rb +98 -30
  75. data/spec/rtm/tmapi/core/topic_spec.rb +558 -82
  76. data/spec/rtm/tmapi/core/variant_spec.rb +3 -3
  77. data/spec/rtm_spec.rb +0 -1
  78. data/spec/spec_helper.rb +7 -2
  79. data/test/javalibs/junit-4.5.jar +0 -0
  80. data/test/javalibs/tmapi-2.0-tests.jar +0 -0
  81. data/test/tmapi_tests.rb +25 -0
  82. metadata +66 -11
  83. data/lib/rtm/io/ontopia_io.rb +0 -25
  84. data/lib/rtm/io/tmapix.rb +0 -234
  85. data/lib/rtm/sugar/occurrence/externalize.rb +0 -31
  86. data/spec/rtm/io/tmapix_spec.rb +0 -85
  87. data/test/base_unit_test.rb +0 -161
  88. data/test/base_unit_test_tmapi.rb +0 -165
@@ -0,0 +1,37 @@
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
+
6
+ module RTM::IO::ToRDF::TopicMap
7
+
8
+ describe self do
9
+ before(:each) do
10
+ @tm = get_used_tm_sys_tm
11
+ @tm.from_ctm(File.dirname(__FILE__) + "/../../resources/toyTM.ctm")
12
+ end
13
+ after(:each) do
14
+ @tm.close
15
+ end
16
+
17
+ describe "#to_rdf" do
18
+ it "should be callable on an Ontopia topic map" do
19
+ if implementation_for_spec == :ontopia
20
+ lambda{@tm.to_rdf}.should_not raise_error
21
+ @tm.to_rdf.should be_a_kind_of String
22
+ else
23
+ lambda{@tm.to_rdf}.should raise_error
24
+ end
25
+ end
26
+ end
27
+
28
+ describe "#to_rdf_ontopia" do
29
+ it "should be callable on an Ontopia topic map" do
30
+ if implementation_for_spec == :ontopia
31
+ @tm.to_rdf_ontopia.should be_a_kind_of String
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,122 @@
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
+
6
+ module RTM::IO::ToString
7
+
8
+ describe self do
9
+ before(:each) do
10
+ @tm = get_used_tm_sys_tm
11
+ @tm.reifier!
12
+ @topic = @tm.get!("a:b")
13
+ @name = @topic.create_name("name type", "name value", ["theme1", "theme2"])
14
+ @name.reifier!
15
+ @var = @name.create_variant(1234, RTM::PSI[:String], ["theme5"])
16
+ @var.reifier!
17
+ @occ = @topic.create_occurrence("occ type", "occ value", :datatype => RTM::PSI[:IRI], :scope => ["theme3", "theme4"])
18
+ @occ.reifier!
19
+ @assoc = @tm.create_association("assoc type", ["theme6", "theme7"])
20
+ @assoc.reifier!
21
+ @role = @assoc.create_role("role type", "role player")
22
+ @role.reifier!
23
+ @locator = @tm.create_locator("http://www.example.org/test this locator")
24
+ end
25
+ after(:each) do
26
+ @output.should be_a_kind_of String
27
+ @tm.close
28
+ end
29
+
30
+ describe "#to_s" do
31
+ describe "for TopicMap" do
32
+ before(:each) do
33
+ @tm.should be_a_kind_of RTM::TopicMap
34
+ end
35
+ it "should give back a String using the short version" do
36
+ @output = @tm.to_s(:short)
37
+ end
38
+ it "should give back a String using the long version" do
39
+ @output = @tm.to_s(:long)
40
+ end
41
+ end
42
+ describe "for Topic" do
43
+ before(:each) do
44
+ @topic.should be_a_kind_of RTM::Topic
45
+ end
46
+ it "should give back a String using the short version" do
47
+ @output = @topic.to_s(:short)
48
+ end
49
+ it "should give back a String using the long version" do
50
+ @output = @topic.to_s(:long)
51
+ end
52
+ end
53
+ describe "for Association" do
54
+ before(:each) do
55
+ @assoc.should be_a_kind_of RTM::Association
56
+ end
57
+ it "should give back a String using the short version" do
58
+ @output = @assoc.to_s(:short)
59
+ end
60
+ it "should give back a String using the long version" do
61
+ @output = @assoc.to_s(:long)
62
+ end
63
+ end
64
+ describe "for Role" do
65
+ before(:each) do
66
+ @role.should be_a_kind_of RTM::Role
67
+ end
68
+ it "should give back a String using the short version" do
69
+ @output = @role.to_s(:short)
70
+ end
71
+ it "should give back a String using the long version" do
72
+ @output = @role.to_s(:long)
73
+ end
74
+ end
75
+ describe "for Name" do
76
+ before(:each) do
77
+ @name.should be_a_kind_of RTM::Name
78
+ end
79
+ it "should give back a String using the short version" do
80
+ @output = @name.to_s(:short)
81
+ end
82
+ it "should give back a String using the long version" do
83
+ @output = @name.to_s(:long)
84
+ end
85
+ end
86
+ describe "for Occurrence" do
87
+ before(:each) do
88
+ @occ.should be_a_kind_of RTM::Occurrence
89
+ end
90
+ it "should give back a String using the short version" do
91
+ @output = @occ.to_s(:short)
92
+ end
93
+ it "should give back a String using the long version" do
94
+ @output = @occ.to_s(:long)
95
+ end
96
+ end
97
+ describe "for Variant" do
98
+ before(:each) do
99
+ @var.should be_a_kind_of RTM::Variant
100
+ end
101
+ it "should give back a String using the short version" do
102
+ @output = @var.to_s(:short)
103
+ end
104
+ it "should give back a String using the short version" do
105
+ @output = @var.to_s(:long)
106
+ end
107
+ end
108
+ describe "for Locator" do
109
+ before(:each) do
110
+ @locator.should be_a_kind_of RTM::Locator
111
+ end
112
+ it "should give back a String using the short version" do
113
+ @output = @locator.to_s(:short)
114
+ end
115
+ it "should give back a String using the long version" do
116
+ @output = @locator.to_s(:long)
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ end
@@ -0,0 +1,89 @@
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
+
6
+ module RTM::IO::ToYAML
7
+
8
+ describe self do
9
+ before(:each) do
10
+ @tm = get_used_tm_sys_tm
11
+ @tm.reifier!
12
+ @topic = @tm.get!("a:b")
13
+ @name = @topic.create_name("name type", "name value", ["theme1", "theme2"])
14
+ @name.reifier!
15
+ @var = @name.create_variant(1234, RTM::PSI[:String], ["theme5"])
16
+ @var.reifier!
17
+ @occ = @topic.create_occurrence("occ type", "occ value", :datatype => RTM::PSI[:IRI], :scope => ["theme3", "theme4"])
18
+ @occ.reifier!
19
+ @assoc = @tm.create_association("assoc type", ["theme6", "theme7"])
20
+ @assoc.reifier!
21
+ @role = @assoc.create_role("role type", "role player")
22
+ @role.reifier!
23
+ @locator = @tm.create_locator("http://www.example.org/test this locator")
24
+ end
25
+ after(:each) do
26
+ @output.should be_a_kind_of String
27
+ @tm.close
28
+ end
29
+
30
+ describe "#to_yaml" do
31
+ describe "for TopicMap" do
32
+ before(:each) do
33
+ @tm.should be_a_kind_of RTM::TopicMap
34
+ end
35
+ it "should give back a String" do
36
+ @output = @tm.to_yaml
37
+ end
38
+ end
39
+ describe "for Topic" do
40
+ before(:each) do
41
+ @topic.should be_a_kind_of RTM::Topic
42
+ end
43
+ it "should give back a String" do
44
+ @output = @topic.to_yaml
45
+ end
46
+ end
47
+ describe "for Association" do
48
+ before(:each) do
49
+ @assoc.should be_a_kind_of RTM::Association
50
+ end
51
+ it "should give back a String" do
52
+ @output = @assoc.to_yaml
53
+ end
54
+ end
55
+ describe "for Role" do
56
+ before(:each) do
57
+ @role.should be_a_kind_of RTM::Role
58
+ end
59
+ it "should give back a String" do
60
+ @output = @role.to_yaml
61
+ end
62
+ end
63
+ describe "for Name" do
64
+ before(:each) do
65
+ @name.should be_a_kind_of RTM::Name
66
+ end
67
+ it "should give back a String" do
68
+ @output = @name.to_yaml
69
+ end
70
+ end
71
+ describe "for Occurrence" do
72
+ before(:each) do
73
+ @occ.should be_a_kind_of RTM::Occurrence
74
+ end
75
+ it "should give back a String" do
76
+ @output = @occ.to_yaml
77
+ end
78
+ end
79
+ describe "for Variant" do
80
+ before(:each) do
81
+ @var.should be_a_kind_of RTM::Variant
82
+ end
83
+ it "should give back a String" do
84
+ @output = @var.to_yaml
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -3,14 +3,169 @@
3
3
 
4
4
  require File.dirname(__FILE__) + '/../../../spec_helper'
5
5
 
6
- module Sugar::Occurrence::DynamicValue
6
+ module RTM::Sugar::Occurrence::DynamicValue
7
7
  describe self do
8
8
  before(:each) do
9
9
  @tm = get_used_tm_sys_tm
10
+ @topic = @tm.get!("Leipzig")
10
11
  end
11
12
  after(:each) do
12
13
  @tm.close
13
14
  end
14
15
 
16
+ describe "#dynamic value" do
17
+ it "should return a Locator if the datatype is xsd:anyURI" do
18
+ @occ = @topic.create_occurrence("Website", "http://www.example.org/Leipzig", :datatype => RTM::PSI[:IRI])
19
+ @occ.datatype.reference.should == RTM::PSI[:IRI]
20
+ @occ.value.should == "http://www.example.org/Leipzig"
21
+ @occ.dynamic_value.should == @tm.create_locator("http://www.example.org/Leipzig")
22
+ ###
23
+ @occ = @topic.create_occurrence("Website", "Leipzig", :datatype => RTM::PSI[:IRI])
24
+ @occ.datatype.reference.should == RTM::PSI[:IRI]
25
+ @occ.value.should == "http://www.topicmapslab.de/Leipzig"
26
+ @occ.dynamic_value.should == @tm.create_locator("http://www.topicmapslab.de/Leipzig")
27
+ end
28
+ it "should return a String if the datatype is xsd:string" do
29
+ @occ = @topic.create_occurrence("Website", "http://www.example.org/Leipzig", :datatype => RTM::PSI[:String])
30
+ @occ.datatype.reference.should == RTM::PSI[:String]
31
+ @occ.value.should == "http://www.example.org/Leipzig"
32
+ @occ.dynamic_value.should == "http://www.example.org/Leipzig"
33
+ end
34
+ it "should return a Float if the datatype is xsd:float" do
35
+ 3.5.class.should == Float
36
+ @occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Float])
37
+ @occ.datatype.reference.should == RTM::PSI[:Float]
38
+ @occ.value.should == "3.5"
39
+ @occ.dynamic_value.should == 3.5
40
+ @occ.dynamic_value.class.should == Float
41
+ ###
42
+ @occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Float])
43
+ @occ.datatype.reference.should == RTM::PSI[:Float]
44
+ @occ.value.should == "1"
45
+ @occ.dynamic_value.should == 1.0
46
+ @occ.dynamic_value.class.should == Float
47
+ end
48
+ it "should return a Float if the datatype is xsd:double" do
49
+ 3.5.class.should == Float
50
+ @occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Double])
51
+ @occ.datatype.reference.should == RTM::PSI[:Double]
52
+ @occ.value.should == "3.5"
53
+ @occ.dynamic_value.should == 3.5
54
+ @occ.dynamic_value.class.should == Float
55
+ ###
56
+ @occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Double])
57
+ @occ.datatype.reference.should == RTM::PSI[:Double]
58
+ @occ.value.should == "1"
59
+ @occ.dynamic_value.should == 1.0
60
+ @occ.dynamic_value.class.should == Float
61
+ end
62
+ it "should return a Float if the datatype is xsd:decimal" do
63
+ 3.5.class.should == Float
64
+ @occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Decimal])
65
+ @occ.datatype.reference.should == RTM::PSI[:Decimal]
66
+ @occ.value.should == "3.5"
67
+ @occ.dynamic_value.should == 3.5
68
+ @occ.dynamic_value.class.should == Float
69
+ ###
70
+ @occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Decimal])
71
+ @occ.datatype.reference.should == RTM::PSI[:Decimal]
72
+ @occ.value.should == "1" unless implementation_for_spec == :tinytim
73
+ @occ.dynamic_value.should == 1.0
74
+ @occ.dynamic_value.class.should == Float
75
+ end
76
+ it "should return a Fixnum/Bignum if the datatype is xsd:int" do
77
+ 3.5.class.should == Float
78
+ @occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Int])
79
+ @occ.datatype.reference.should == RTM::PSI[:Int]
80
+ @occ.value.should == "3.5"
81
+ @occ.dynamic_value.should == 3
82
+ @occ.dynamic_value.class.should == Fixnum
83
+ ###
84
+ @occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Int])
85
+ @occ.datatype.reference.should == RTM::PSI[:Int]
86
+ @occ.value.should == "1"
87
+ @occ.dynamic_value.should == 1
88
+ @occ.dynamic_value.class.should == Fixnum
89
+ ####
90
+ number = 9999999999999999999
91
+ number.class.should == Bignum
92
+ @occ = @topic.create_occurrence("Number", number.to_s, :datatype => RTM::PSI[:Int])
93
+ @occ.datatype.reference.should == RTM::PSI[:Int]
94
+ @occ.value.should == number.to_s
95
+ @occ.dynamic_value.should == number
96
+ @occ.dynamic_value.class.should == Bignum
97
+ end
98
+ it "should return a Fixnum/Bignum if the datatype is xsd:integer" do
99
+ unless implementation_for_spec == :tinytim
100
+ 3.5.class.should == Float
101
+ @occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Integer])
102
+ @occ.datatype.reference.should == RTM::PSI[:Integer]
103
+ @occ.value.should == "3.5"
104
+ @occ.dynamic_value.should == 3
105
+ @occ.dynamic_value.class.should == Fixnum
106
+ end
107
+ ###
108
+ @occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Integer])
109
+ @occ.datatype.reference.should == RTM::PSI[:Integer]
110
+ @occ.value.should == "1"
111
+ @occ.dynamic_value.should == 1
112
+ @occ.dynamic_value.class.should == Fixnum
113
+ ####
114
+ number = 9999999999999999999
115
+ number.class.should == Bignum
116
+ @occ = @topic.create_occurrence("Number", number.to_s, :datatype => RTM::PSI[:Integer])
117
+ @occ.datatype.reference.should == RTM::PSI[:Integer]
118
+ @occ.value.should == number.to_s
119
+ @occ.dynamic_value.should == number
120
+ @occ.dynamic_value.class.should == Bignum
121
+ end
122
+ it "should return a Fixnum/Bignum if the datatype is xsd:integer" do
123
+ 3.5.class.should == Float
124
+ @occ = @topic.create_occurrence("Number", "3.5", :datatype => RTM::PSI[:Long])
125
+ @occ.datatype.reference.should == RTM::PSI[:Long]
126
+ @occ.value.should == "3.5"
127
+ @occ.dynamic_value.should == 3
128
+ @occ.dynamic_value.class.should == Fixnum
129
+ ###
130
+ @occ = @topic.create_occurrence("Number", "1", :datatype => RTM::PSI[:Long])
131
+ @occ.datatype.reference.should == RTM::PSI[:Long]
132
+ @occ.value.should == "1"
133
+ @occ.dynamic_value.should == 1
134
+ @occ.dynamic_value.class.should == Fixnum
135
+ ####
136
+ number = 9999999999999999999
137
+ number.class.should == Bignum
138
+ @occ = @topic.create_occurrence("Number", number.to_s, :datatype => RTM::PSI[:Long])
139
+ @occ.datatype.reference.should == RTM::PSI[:Long]
140
+ @occ.value.should == number.to_s
141
+ @occ.dynamic_value.should == number
142
+ @occ.dynamic_value.class.should == Bignum
143
+ end
144
+ it "should return a Time if the datatype is xsd:time" do
145
+ time = Time.new
146
+ @occ = @topic.create_occurrence("Number", time)
147
+ @occ.datatype.reference.should == RTM::PSI[:Time]
148
+ @occ.value.should == time.to_s
149
+ #@occ.dynamic_value.should == time # cannot be tested this way
150
+ @occ.dynamic_value.class.should == Time
151
+ end
152
+ it "should return a Date if the datatype is xsd:date" do
153
+ date = Date.new
154
+ @occ = @topic.create_occurrence("Number", date)
155
+ @occ.datatype.reference.should == RTM::PSI[:Date]
156
+ @occ.value.should == date.to_s
157
+ @occ.dynamic_value.should == date
158
+ @occ.dynamic_value.class.should == Date
159
+ end
160
+ it "should return a DateTime if the datatype is xsd:dateTime" do
161
+ dateTime = DateTime.new
162
+ @occ = @topic.create_occurrence("Number", dateTime)
163
+ @occ.datatype.reference.should == RTM::PSI[:DateTime]
164
+ @occ.value.should == dateTime.to_s
165
+ @occ.dynamic_value.should == dateTime
166
+ @occ.dynamic_value.class.should == DateTime
167
+ end
168
+ end
169
+
15
170
  end
16
171
  end
@@ -0,0 +1,129 @@
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
+
6
+ module RTM::Sugar::Occurrence::DynamicValue
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 "#externalize" do
16
+ before(:each) do
17
+ @leipzig = @tm.get!("http://en.wikipedia.org/wiki/Leipzig")
18
+ end
19
+ it "should create an association and two roles out of the occurrence if the value is of type xsd:String" do
20
+ occ = @leipzig.create_occurrence("Webpage", "http://www.leipzig.de/")
21
+ occ.value.should be_a_kind_of String
22
+ occ.value.should == "http://www.leipzig.de/"
23
+ occ.datatype.value.should == RTM::PSI[:String]
24
+ ### now create the association
25
+ association = occ.externalize
26
+ ### type must be RTM::PSI[:subject_representation]
27
+ assoc_type = @tm.get(RTM::PSI[:subject_representation])
28
+ assoc_type.should_not be_nil
29
+ association.type.should == assoc_type
30
+ ### 2 roles
31
+ association.should have(2).roles
32
+ ### one role of type RTM::PSI[:represented_subject] with player occ.parent (the topic)
33
+ association.roles(RTM::PSI[:represented_subject]).size.should == 1
34
+ role1 = association.roles(RTM::PSI[:represented_subject]).first
35
+ role1.player.should == @leipzig
36
+ ### the other role of type occ_type and player: topic with subject locator occ_value
37
+ association.roles("Webpage").size.should == 1
38
+ role2 = association.roles("Webpage").first
39
+ r2player = @tm.get("=http://www.leipzig.de/")
40
+ r2player.should_not be_nil
41
+ role2.player.should == r2player
42
+ end
43
+ it "should create an association and two roles out of the occurrence if the value is of type xsd:anyURI" do
44
+ occ = @leipzig.create_occurrence("Webpage", @tm.create_locator("http://www.leipzig.de/"))
45
+ occ.value.should be_a_kind_of String
46
+ occ.value.should == "http://www.leipzig.de/"
47
+ occ.datatype.value.should == RTM::PSI[:IRI]
48
+ ### now create the association
49
+ association = occ.externalize
50
+ ### type must be RTM::PSI[:subject_representation]
51
+ assoc_type = @tm.get(RTM::PSI[:subject_representation])
52
+ assoc_type.should_not be_nil
53
+ association.type.should == assoc_type
54
+ ### 2 roles
55
+ association.should have(2).roles
56
+ ### one role of type RTM::PSI[:represented_subject] with player occ.parent (the topic)
57
+ association.roles(RTM::PSI[:represented_subject]).size.should == 1
58
+ role1 = association.roles(RTM::PSI[:represented_subject]).first
59
+ role1.player.should == @leipzig
60
+ ### the other role of type occ_type and player: topic with subject locator occ_value
61
+ association.roles("Webpage").size.should == 1
62
+ role2 = association.roles("Webpage").first
63
+ r2player = @tm.get("=http://www.leipzig.de/")
64
+ r2player.should_not be_nil
65
+ role2.player.should == r2player
66
+ end
67
+ it "should resolve relative identifiers = occ values" do
68
+ occ = @leipzig.create_occurrence(@tm.get!("Webpage"), "foobar")
69
+ occ.value.should be_a_kind_of String
70
+ occ.value.should == "foobar"
71
+ occ.datatype.value.should == RTM::PSI[:String]
72
+ ### now create the association
73
+ association = occ.externalize
74
+ ### type must be RTM::PSI[:subject_representation]
75
+ assoc_type = @tm.get(RTM::PSI[:subject_representation])
76
+ assoc_type.should_not be_nil
77
+ association.type.should == assoc_type
78
+ ### 2 roles
79
+ association.should have(2).roles
80
+ ### one role of type RTM::PSI[:represented_subject] with player occ.parent (the topic)
81
+ association.roles(RTM::PSI[:represented_subject]).size.should == 1
82
+ role1 = association.roles(RTM::PSI[:represented_subject]).first
83
+ role1.player.should == @leipzig
84
+ ### the other role of type occ_type and player: topic with subject locator occ_value
85
+ association.roles("Webpage").size.should == 1
86
+ role2 = association.roles("Webpage").first
87
+ r2player = @tm.get("=http://www.topicmapslab.de/foobar")
88
+ r2player.should_not be_nil
89
+ role2.player.should == r2player
90
+ end
91
+ it "should perhaps be tested for other datatypes"
92
+ end
93
+
94
+ describe "#externalize!" do
95
+ before(:each) do
96
+ @leipzig = @tm.get!("http://en.wikipedia.org/wiki/Leipzig")
97
+ end
98
+ it "should remove the occurrence also" do
99
+ occ = @leipzig.create_occurrence("Webpage", "http://www.leipzig.de/", :scope => ["theme1", "theme2"])
100
+ @leipzig.should have(1).occurrences
101
+ association = occ.externalize!
102
+ @leipzig.occurrences.should be_empty
103
+ end
104
+ it "should remove the occurrence also, even if it has a reifier" do
105
+ occ = @leipzig.create_occurrence("Webpage", "http://www.leipzig.de/", :scope => ["theme1", "theme2"])
106
+ occ.reifier = "a_reifier"
107
+ occ.reifier.should_not be_nil
108
+ @leipzig.should have(1).occurrences
109
+ association = occ.externalize!
110
+ @leipzig.occurrences.should be_empty
111
+ end
112
+ end
113
+
114
+ describe "#external?" do
115
+ before(:each) do
116
+ @leipzig = @tm.get!("http://en.wikipedia.org/wiki/Leipzig")
117
+ end
118
+ it "should return true if this occurrence is an external occurrence" do
119
+ occ = @leipzig.create_occurrence("Webpage", @tm.create_locator("http://www.leipzig.de/"))
120
+ occ.external?.should be_true
121
+ end
122
+ it "should return false if this occurrence is not an external occurrence" do
123
+ occ = @leipzig.create_occurrence("Webpage", "http://www.leipzig.de/")
124
+ occ.external?.should be_false
125
+ end
126
+ end
127
+
128
+ end
129
+ end