rtm-majortom 0.3.1-java

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.
@@ -0,0 +1,10 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Majortom; end
5
+
6
+ module RTM::Majortom::Sugar;end
7
+
8
+ require File.join(File.dirname(__FILE__), '/sugar/topic_map')
9
+
10
+ RTM::TopicMap.register_extension(RTM::Majortom::Sugar::TopicMap)
@@ -0,0 +1,74 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Majortom::Sugar
5
+ module TopicMap
6
+
7
+ def latest_revision_id
8
+ raise("not supported") if self.read_only?
9
+ return 0 unless last_revision = revision_index.last_revision
10
+ last_revision.getId
11
+ end
12
+
13
+ # Returns all revisions in the revision_index starting with the last one
14
+ def all_revisions
15
+ all_revisions = []
16
+ revision = self.revision_index.last_revision
17
+ if revision
18
+ all_revisions << revision
19
+ while revision = revision.past
20
+ all_revisions << revision
21
+ end
22
+ end
23
+ return all_revisions
24
+ end
25
+
26
+ # Calls and loads the RevisionIndex managed by MaJorToM.
27
+ def revision_index
28
+ index = getIndex(Java::DeTopicmapslabMajortomModelIndex::IRevisionIndex.java_class)
29
+ index.open unless index.is_open
30
+ return index
31
+ end
32
+
33
+ # Calls and loads the SupertypeSubtypeIndex managed by MaJorToM.
34
+ def supertype_subtype_index
35
+ index = getIndex(Java::DeTopicmapslabMajortomModelIndex::ISupertypeSubtypeIndex.java_class)
36
+ index.open unless index.is_open
37
+ return index
38
+ end
39
+
40
+ # Calls and loads the TransitiveTypeInstanceIndex managed by MaJorToM.
41
+ def transitive_type_instance_index
42
+ index = getIndex(Java::DeTopicmapslabMajortomModelIndex::ITransitiveTypeInstanceIndex.java_class)
43
+ index.open unless index.is_open
44
+ return index
45
+ end
46
+
47
+ def register_tmql_environment_map(topic_map)
48
+ raise("topic_map must be a topic map") unless topic_map.is_a?(RTM::TopicMap)
49
+ if self.store.is_read_only
50
+ self.store.registerTMQLEnvironmentMap(topic_map)
51
+ else
52
+ raise("Method only working on read-only topic maps.")
53
+ end
54
+ end
55
+ alias :registerTMQLEnvironmentMap :register_tmql_environment_map
56
+
57
+ def tmql_environment_map
58
+ if self.store.is_read_only
59
+ self.store.getTMQLEnvironmentMap
60
+ else
61
+ raise("Method only working on read-only topic maps.")
62
+ end
63
+ end
64
+ alias :getTMQLEnvironmentMap :tmql_environment_map
65
+
66
+ def enable_revision_management
67
+ self.store.enable_revision_management(true)
68
+ end
69
+
70
+ def disable_revision_management
71
+ self.store.enable_revision_management(false)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,168 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ module RTM::Revision
5
+ Type = Java::DeTopicmapslabMajortomModelEvent::TopicMapEventType
6
+
7
+ def self.specify_event(type)
8
+ return (
9
+ case type
10
+ when Type::ASSOCIATION_ADDED
11
+ :creation
12
+ when Type::ASSOCIATION_REMOVED
13
+ :deletion
14
+ when Type::DATATYPE_SET
15
+ :update
16
+ when Type::ID_MODIFIED
17
+ :update
18
+ when Type::ITEM_IDENTIFIER_ADDED
19
+ :update
20
+ when Type::ITEM_IDENTIFIER_REMOVED
21
+ :update
22
+ when Type::MERGE
23
+ :update
24
+ when Type::NAME_ADDED
25
+ :update
26
+ when Type::NAME_REMOVED
27
+ :update
28
+ when Type::OCCURRENCE_ADDED
29
+ :update
30
+ when Type::OCCURRENCE_REMOVED
31
+ :update
32
+ when Type::PLAYER_MODIFIED
33
+ :update
34
+ when Type::REIFIER_SET
35
+ :update
36
+ when Type::REMOVE_DUPLICATES
37
+ :update
38
+ when Type::ROLE_ADDED
39
+ :update
40
+ when Type::ROLE_REMOVED
41
+ :update
42
+ when Type::SCOPE_MODIFIED
43
+ :update
44
+ when Type::SUBJECT_IDENTIFIER_ADDED
45
+ :update
46
+ when Type::SUBJECT_IDENTIFIER_REMOVED
47
+ :update
48
+ when Type::SUBJECT_LOCATOR_ADDED
49
+ :update
50
+ when Type::SUBJECT_LOCATOR_REMOVED
51
+ :update
52
+ when Type::TOPIC_ADDED
53
+ :creation
54
+ when Type::TOPIC_REMOVED
55
+ :deletion
56
+ when Type::TYPE_ADDED
57
+ :update
58
+ when Type::TYPE_REMOVED
59
+ :update
60
+ when Type::TYPE_SET
61
+ :update
62
+ when Type::VALUE_MODIFIED
63
+ :update
64
+ when Type::VARIANT_ADDED
65
+ :update
66
+ when Type::VARIANT_REMOVED
67
+ :update
68
+ else
69
+ nil
70
+ end )
71
+ end
72
+
73
+ def self.topic_or_association_context(revision)
74
+ # TODO not finished yet, test it also in the history_spec
75
+ type = revision.changeset_type
76
+ changeset = revision.changeset
77
+
78
+ case type
79
+ when Type::ASSOCIATION_ADDED
80
+ context = changeset.first.new_value # association
81
+ when Type::ASSOCIATION_REMOVED
82
+ context = changeset.last.old_value # association
83
+ when Type::DATATYPE_SET
84
+ datatype_aware = changeset.first.context
85
+ if datatype_aware.is_a?(RTM::Occurrence)
86
+ context = datatype_aware.parent # topic
87
+ else
88
+ context = datatype_aware.parent.parent # topic
89
+ end
90
+ when Type::ID_MODIFIED
91
+ return nil
92
+ when Type::ITEM_IDENTIFIER_ADDED
93
+ context = changeset.first.context # topic
94
+ when Type::ITEM_IDENTIFIER_REMOVED
95
+ context = changeset.first.context # topic
96
+ when Type::MERGE
97
+ return nil
98
+ when Type::NAME_ADDED
99
+ context = changeset.first.context # topic
100
+ when Type::NAME_REMOVED
101
+ context = changeset.last.context # topic
102
+ when Type::OCCURRENCE_ADDED
103
+ context = changeset.first.context # topic
104
+ when Type::OCCURRENCE_REMOVED
105
+ context = changeset.last.context # topic
106
+ when Type::PLAYER_MODIFIED
107
+ context = changeset.first.context.parent # association
108
+ when Type::REIFIER_SET
109
+ return nil
110
+ when Type::REMOVE_DUPLICATES
111
+ return nil
112
+ when Type::ROLE_ADDED
113
+ context = changeset.first.context # association
114
+ when Type::ROLE_REMOVED
115
+ context = changeset.last.context # association
116
+ when Type::SCOPE_MODIFIED
117
+ typed = changeset.first.context
118
+ if typed.is_a?(RTM::Variant)
119
+ context = typed.parent.parent # topic
120
+ elsif typed.is_a?(RTM::Occurrence)
121
+ context = typed.parent # topic
122
+ elsif typed.is_a?(RTM::Name)
123
+ context = typed.parent # topic
124
+ else
125
+ context = typed # association
126
+ end
127
+ when Type::SUBJECT_IDENTIFIER_ADDED
128
+ context = changeset.first.context # topic
129
+ when Type::SUBJECT_IDENTIFIER_REMOVED
130
+ context = changeset.first.context # topic
131
+ when Type::SUBJECT_LOCATOR_ADDED
132
+ context = changeset.first.context # topic
133
+ when Type::SUBJECT_LOCATOR_REMOVED
134
+ context = changeset.first.context # topic
135
+ when Type::TOPIC_ADDED
136
+ context = changeset.first.new_value # topic
137
+ when Type::TOPIC_REMOVED
138
+ context = changeset.last.old_value # topic
139
+ when Type::TYPE_ADDED
140
+ context = changeset.first.context # topic
141
+ when Type::TYPE_REMOVED
142
+ context = changeset.first.context # topic
143
+ when Type::TYPE_SET
144
+ typed = changeset.first.context
145
+ if typed.is_a?(RTM::Role)
146
+ context = typed.parent # association
147
+ elsif typed.is_a?(RTM::Association)
148
+ context = typed # association
149
+ else
150
+ context = typed.parent # topic
151
+ end
152
+ when Type::VALUE_MODIFIED
153
+ valued = changeset.first.context
154
+ if valued.is_a?(RTM::Variant)
155
+ context = valued.parent.parent #topic
156
+ else
157
+ context = valued.parent # topic
158
+ end
159
+ when Type::VARIANT_ADDED
160
+ context = changeset.first.context.parent # topic
161
+ when Type::VARIANT_REMOVED
162
+ context = changeset.last.context.parent # topic
163
+ else
164
+ return nil
165
+ end
166
+ return context
167
+ end
168
+ end
@@ -0,0 +1,149 @@
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::Majortom::Sugar::Topic
7
+ describe self do
8
+ before(:each) do
9
+ @tm = get_used_tm_sys_tm
10
+ @tm.clear
11
+ end
12
+ after(:each) do
13
+ @tm.close
14
+ end
15
+
16
+ describe "#best_label with special examples" do
17
+ it "should give back an identifier if the name is empty" do
18
+ topic = @tm.get!("Leipzig")
19
+ topic.create_name("")
20
+ topic.best_label.should == "http://www.topicmapslab.de/Leipzig"
21
+ end
22
+ it "should give back the shorter value" do
23
+ topic = @tm.get!("Leipzig")
24
+ topic.create_name("Le ipzig in Sachsen", ["long"])
25
+ topic.create_name("Short", ["short"])
26
+ topic.best_label.should == "Short"
27
+ end
28
+ it "should give back the shorter value" do
29
+ topic = @tm.get!("Leipzig")
30
+ topic.create_name("Le ipzig in Sachsen", ["long", "theme"])
31
+ topic.create_name("Short", ["short", "theme"])
32
+ topic.best_label("theme").should == "Short"
33
+ end
34
+ it "should handle Berlin in the totTM" do
35
+ @tm.clear
36
+ @tm.from_xtm(File.join(File.dirname(__FILE__), "/../../../rtm/spec/resources/toyTM.xtm"))
37
+ berlin = @tm.get("http://en.wikipedia.org/wiki/Berlin")
38
+ berlin.should_not be_nil
39
+ berlin.best_label.should == "Berlin"
40
+ end
41
+ describe "should handle topic with only a" do
42
+ it "item identifier" do
43
+ t = @tm.get!("ii:an_item_identifier")
44
+ t.best_label.should == "http://www.topicmapslab.de/an_item_identifier"
45
+ t.best_label("theme").should == "http://www.topicmapslab.de/an_item_identifier"
46
+ @tm.get!("theme")
47
+ t.best_label("theme").should == "http://www.topicmapslab.de/an_item_identifier"
48
+ end
49
+ it "subject identifier" do
50
+ t = @tm.get!("si:a_subject_identifier")
51
+ t.best_label.should == "http://www.topicmapslab.de/a_subject_identifier"
52
+ t.best_label("theme").should == "http://www.topicmapslab.de/a_subject_identifier"
53
+ @tm.get!("theme")
54
+ t.best_label("theme").should == "http://www.topicmapslab.de/a_subject_identifier"
55
+ end
56
+ it "subject locator" do
57
+ t = @tm.get!("sl:a_subject_locator")
58
+ t.best_label.should == "http://www.topicmapslab.de/a_subject_locator"
59
+ t.best_label("theme").should == "http://www.topicmapslab.de/a_subject_locator"
60
+ @tm.get!("theme")
61
+ t.best_label("theme").should == "http://www.topicmapslab.de/a_subject_locator"
62
+ end
63
+ end
64
+ describe "should handle the toyTM including michael jackson" do
65
+ it "should give back the best_label of all topics" do
66
+ @tm.clear
67
+ @tm.from_xtm(File.join(File.dirname(__FILE__), "/../../../rtm/spec/resources/toyTM_MJ.xtm"))
68
+
69
+ creator = @tm.get!("http://en.wikipedia.org/wiki/Creator")
70
+ lit = @tm.get!("http://en.wikipedia.org/wiki/Lithuania")
71
+
72
+ creator.best_label(lit).should == "Creator"
73
+
74
+ # @tm.topics.each do |t|
75
+ # puts "++++++++++"
76
+ # t.best_label
77
+ # @tm.topics.each do |theme|
78
+ # begin
79
+ # t.best_label(theme)
80
+ # rescue
81
+ # puts t.reference
82
+ # #puts t.names.first
83
+ # puts theme.reference
84
+ #
85
+ # end
86
+ # end
87
+ # end
88
+ end
89
+ end
90
+ end
91
+
92
+ describe "#best_label" do
93
+ before(:each) do
94
+ @topic = @tm.get!("Leipzig")
95
+ @topic.add_si("LE")
96
+ @topic.add_ii("http://example.org/id-10")
97
+ @topic.add_ii("1")
98
+ end
99
+ after(:each) do
100
+ @topic.best_label.should be_a_kind_of String
101
+ end
102
+ it "should return an identfier if the topic has no name, resolved" do
103
+ @topic.best_label.should == "http://www.topicmapslab.de/LE"
104
+ end
105
+ it "should give back the name if the topic has one name" do
106
+ @topic["-city-name"] = "Leipzig"
107
+ @topic.best_label.should == "Leipzig"
108
+ end
109
+ it "should give back the default name if the topic has several names" do
110
+ @topic["-city-name"] = "Leipzig"
111
+ @topic["-"] = "Leipzisch"
112
+ @topic.best_label.should == "Leipzisch"
113
+ end
114
+ it "should give back the default name with the smallest value if the topic has several names" do
115
+ @topic["-city-name"] = "Leipzig"
116
+ @topic["-"] = "LE"
117
+ @topic["-"] = "Leipzisch"
118
+ @topic["-"] = "A Schone Stadt"
119
+ @topic.best_label.should == "LE"
120
+ end
121
+ it "should give back the default name with the smallest value sorted alphabetically if the topic has several names" do
122
+ @topic["-city-name"] = "Leipzig"
123
+ @topic["-"] = "LE"
124
+ @topic["-"] = "Leipzisch"
125
+ @topic["-"] = "LA"
126
+ @topic.best_label.should == "LA"
127
+ end
128
+ it "should give back the name with the given theme" do
129
+ @topic["-city-name name @test_theme"] = "Leipzig"
130
+ @topic["-"] = "LE"
131
+ @topic["-"] = "Leipzisch"
132
+ @topic["-"] = "LA"
133
+ test_theme = @tm.get("test_theme")
134
+ test_theme.should_not be_nil
135
+ @topic.best_label(test_theme).should == "Leipzig"
136
+ end
137
+ it "should give back the name with the given theme preferring default names" do
138
+ @topic["-city-name name @test_theme"] = "Leipzig"
139
+ @topic["-"] = "LE"
140
+ @topic["- @test_theme"] = "Leipzisch"
141
+ @topic["- @test_theme_other"] = "LA"
142
+ test_theme = @tm.get("test_theme")
143
+ test_theme.should_not be_nil
144
+ @topic.best_label(test_theme).should == "Leipzisch"
145
+ end
146
+ end
147
+
148
+ end
149
+ end
@@ -0,0 +1,936 @@
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::TopicMap
7
+ describe self do
8
+ before(:each) do
9
+ @tm = get_used_tm_sys_tm
10
+ @tm.should be_a_kind_of RTM::TopicMap
11
+ @tm.clear
12
+ @tm.revision_index.first_revision.should be_nil
13
+ end
14
+ after(:each) do
15
+ if implementation_for_spec == :majortom_db
16
+ @tm.remove
17
+ else
18
+ @tm.close
19
+ end
20
+ end
21
+
22
+ describe "the id of a revision" do
23
+ it "should not be 0" do
24
+ @tm.revision_index.last_revision.should be_nil
25
+ @tm.get!("topic")
26
+ @tm.revision_index.last_revision.should_not be_nil
27
+ @tm.revision_index.last_revision.getId.should_not == 0
28
+ pending "not working for db" do
29
+ @tm.revision_index.last_revision.getId.should == 1
30
+ end if implementation_for_spec == :majortom_db
31
+ end
32
+ it "should be return via latest_revision_id" do
33
+ @tm.revision_index.last_revision.should be_nil
34
+ @tm.latest_revision_id.should == 0
35
+ @tm.get!("topic")
36
+ @tm.revision_index.last_revision.should_not be_nil
37
+ pending "not working for db" do
38
+ @tm.latest_revision_id.should == 1
39
+ end if implementation_for_spec == :majortom_db
40
+ end
41
+ end
42
+
43
+ describe "#all_revisions" do
44
+ it "should be callable on an empty topic map" do
45
+ @tm.all_revisions.should be_empty
46
+ end
47
+ it "should give back all revisions in the revision index" do
48
+
49
+ # ... will be filled
50
+ end
51
+ end
52
+
53
+ describe "Revisions" do
54
+ describe "should work properly" do
55
+ it "when adding a topic with si" do
56
+ @tm.topics.should be_empty
57
+ @tm.revision_index.last_revision.should be_nil
58
+ topic1 = @tm.get!("topic1")
59
+ @tm.should have(1).all_revisions
60
+ last_revision = @tm.revision_index.last_revision
61
+ last_revision.should_not be_nil
62
+ last_revision.changeset_type.to_s.should == "TOPIC_ADDED"
63
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
64
+ changeset = last_revision.changeset
65
+ changeset.size.should == 2
66
+ change1 = changeset.first
67
+ change1.type.to_s.should == "TOPIC_ADDED"
68
+ change1.context.should == @tm
69
+ change2 = changeset.last
70
+ change2.type.to_s.should == "SUBJECT_IDENTIFIER_ADDED"
71
+ change2.context.should == topic1
72
+ end
73
+ it "when adding a topic with sl" do
74
+ @tm.topics.should be_empty
75
+ @tm.revision_index.last_revision.should be_nil
76
+ topic1 = @tm.get!("sl:topic1")
77
+ @tm.should have(1).all_revisions
78
+ last_revision = @tm.revision_index.last_revision
79
+ last_revision.should_not be_nil
80
+ last_revision.changeset_type.to_s.should == "TOPIC_ADDED"
81
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
82
+ changeset = last_revision.changeset
83
+ changeset.size.should == 2
84
+ change1 = changeset.first
85
+ change1.type.to_s.should == "TOPIC_ADDED"
86
+ change1.context.should == @tm
87
+ change2 = changeset.last
88
+ change2.type.to_s.should == "SUBJECT_LOCATOR_ADDED"
89
+ change2.context.should == topic1
90
+ end
91
+ it "when adding a topic with ii" do
92
+ @tm.topics.should be_empty
93
+ @tm.revision_index.last_revision.should be_nil
94
+ topic1 = @tm.get!("ii:topic1")
95
+ @tm.should have(1).all_revisions
96
+ last_revision = @tm.revision_index.last_revision
97
+ last_revision.should_not be_nil
98
+ last_revision.changeset_type.to_s.should == "TOPIC_ADDED"
99
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
100
+ changeset = last_revision.changeset
101
+ changeset.size.should == 2
102
+ change1 = changeset.first
103
+ change1.type.to_s.should == "TOPIC_ADDED"
104
+ change1.context.should == @tm
105
+ change2 = changeset.last
106
+ change2.type.to_s.should == "ITEM_IDENTIFIER_ADDED"
107
+ change2.context.should == topic1
108
+ end
109
+ it "when adding a topic with nothing" do
110
+ @tm.topics.should be_empty
111
+ @tm.revision_index.last_revision.should be_nil
112
+ topic1 = @tm.create_topic
113
+ @tm.should have(1).all_revisions
114
+ last_revision = @tm.revision_index.last_revision
115
+ last_revision.should_not be_nil
116
+ last_revision.changeset_type.to_s.should == "TOPIC_ADDED"
117
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
118
+ changeset = last_revision.changeset
119
+ changeset.size.should == 2
120
+ change1 = changeset.first
121
+ change1.type.to_s.should == "TOPIC_ADDED"
122
+ change1.context.should == @tm
123
+ change2 = changeset.last
124
+ change2.type.to_s.should == "ITEM_IDENTIFIER_ADDED"
125
+ change2.context.should == topic1
126
+ end
127
+ it "when adding an association" do
128
+ @tm.topics.should be_empty
129
+ @tm.revision_index.last_revision.should be_nil
130
+ @tm.disable_revision_management
131
+ @tm.get!("assoc_type")
132
+ @tm.enable_revision_management
133
+ @tm.revision_index.last_revision.should be_nil
134
+ assoc = @tm.create_association("assoc_type")
135
+ @tm.should have(1).all_revisions
136
+ last_revision = @tm.revision_index.last_revision
137
+ last_revision.should_not be_nil
138
+ last_revision.changeset_type.to_s.should == "ASSOCIATION_ADDED"
139
+ RTM::Revision.topic_or_association_context(last_revision).should == assoc
140
+ changeset = last_revision.changeset
141
+ changeset.size.should == 3
142
+ change1 = changeset.first
143
+ change1.type.to_s.should == "ASSOCIATION_ADDED"
144
+ change1.context.should == @tm
145
+ change2 = changeset.get(1)
146
+ change2.type.to_s.should == "TYPE_SET"
147
+ change2.context.should == assoc
148
+ change3 = changeset.last
149
+ change3.type.to_s.should == "SCOPE_MODIFIED"
150
+ change3.context.should == assoc
151
+ end
152
+ it "when adding a role to an association" do
153
+ @tm.topics.should be_empty
154
+ @tm.revision_index.last_revision.should be_nil
155
+ @tm.disable_revision_management
156
+ @tm.get!("assoc_type")
157
+ @tm.get!("role_type")
158
+ @tm.get!("role_player")
159
+ assoc = @tm.create_association("assoc_type")
160
+ @tm.enable_revision_management
161
+ @tm.revision_index.last_revision.should be_nil
162
+ role = assoc.create_role("role_type", "role_player")
163
+ @tm.should have(1).all_revisions
164
+ last_revision = @tm.revision_index.last_revision
165
+ last_revision.should_not be_nil
166
+ last_revision.changeset_type.to_s.should == "ROLE_ADDED"
167
+ RTM::Revision.topic_or_association_context(last_revision).should == assoc
168
+ changeset = last_revision.changeset
169
+ changeset.size.should == 3
170
+ change1 = changeset.first
171
+ change1.type.to_s.should == "ROLE_ADDED"
172
+ change1.context.should == assoc
173
+ change2 = changeset.get(1)
174
+ change2.type.to_s.should == "TYPE_SET"
175
+ change2.context.should == role
176
+ change3 = changeset.last
177
+ change3.type.to_s.should == "PLAYER_MODIFIED"
178
+ change3.context.should == role
179
+ end
180
+ it "when adding a type to a topic" do
181
+ @tm.topics.should be_empty
182
+ @tm.revision_index.last_revision.should be_nil
183
+ @tm.disable_revision_management
184
+ topic = @tm.get!("topic")
185
+ type = @tm.get!("type")
186
+ @tm.enable_revision_management
187
+ @tm.revision_index.last_revision.should be_nil
188
+ topic.add_type("type")
189
+ @tm.should have(1).all_revisions
190
+ last_revision = @tm.revision_index.last_revision
191
+ last_revision.should_not be_nil
192
+ last_revision.changeset_type.to_s.should == "TYPE_ADDED"
193
+ RTM::Revision.topic_or_association_context(last_revision).should == topic
194
+ changeset = last_revision.changeset
195
+ changeset.size.should == 1
196
+ change = changeset.first
197
+ change.type.to_s.should == "TYPE_ADDED"
198
+ change.context.should == topic
199
+ end
200
+ it "when removing a type from a topic" do
201
+ @tm.topics.should be_empty
202
+ @tm.revision_index.last_revision.should be_nil
203
+ @tm.disable_revision_management
204
+ topic = @tm.get!("topic")
205
+ type = @tm.get!("type")
206
+ topic.add_type("type")
207
+ @tm.enable_revision_management
208
+ @tm.revision_index.last_revision.should be_nil
209
+ topic.remove_type("type")
210
+ @tm.should have(1).all_revisions
211
+ last_revision = @tm.revision_index.last_revision
212
+ last_revision.should_not be_nil
213
+ last_revision.changeset_type.to_s.should == "TYPE_REMOVED"
214
+ RTM::Revision.topic_or_association_context(last_revision).should == topic
215
+ changeset = last_revision.changeset
216
+ changeset.size.should == 1
217
+ change = changeset.first
218
+ change.type.to_s.should == "TYPE_REMOVED"
219
+ change.context.should == topic
220
+ end
221
+ it "when adding a name to a topic" do
222
+ @tm.topics.should be_empty
223
+ @tm.revision_index.last_revision.should be_nil
224
+ @tm.disable_revision_management
225
+ topic = @tm.get!("topic")
226
+ nametype = @tm.get!("nametype")
227
+ @tm.enable_revision_management
228
+ @tm.revision_index.last_revision.should be_nil
229
+ name = topic.create_name(nametype, "a Name")
230
+ @tm.should have(1).all_revisions
231
+ last_revision = @tm.revision_index.last_revision
232
+ last_revision.should_not be_nil
233
+ last_revision.changeset_type.to_s.should == "NAME_ADDED"
234
+ RTM::Revision.topic_or_association_context(last_revision).should == topic
235
+ changeset = last_revision.changeset
236
+ changeset.size.should == 4
237
+ change1 = changeset.first
238
+ change1.type.to_s.should == "NAME_ADDED"
239
+ change1.context.should == topic
240
+ change2 = changeset.get(1)
241
+ change2.type.to_s.should == "TYPE_SET"
242
+ change2.context.should == name
243
+ change3 = changeset.get(2)
244
+ change3.type.to_s.should == "VALUE_MODIFIED"
245
+ change3.context.should == name
246
+ change4 = changeset.last
247
+ change4.type.to_s.should == "SCOPE_MODIFIED"
248
+ change4.context.should == name
249
+ end
250
+ it "when adding a variant to a name" do
251
+ @tm.topics.should be_empty
252
+ @tm.revision_index.last_revision.should be_nil
253
+ @tm.disable_revision_management
254
+ topic = @tm.get!("topic")
255
+ nametype = @tm.get!("nametype")
256
+ name = topic.create_name(nametype, "a Name")
257
+ @tm.get!("theme")
258
+ @tm.enable_revision_management
259
+ @tm.revision_index.last_revision.should be_nil
260
+ variant = name.create_variant("a Variant", ["theme"])
261
+ @tm.should have(1).all_revisions
262
+ last_revision = @tm.revision_index.last_revision
263
+ last_revision.should_not be_nil
264
+ last_revision.changeset_type.to_s.should == "VARIANT_ADDED"
265
+ RTM::Revision.topic_or_association_context(last_revision).should == topic
266
+ changeset = last_revision.changeset
267
+ changeset.size.should == 4
268
+ change1 = changeset.first
269
+ change1.type.to_s.should == "VARIANT_ADDED"
270
+ change1.context.should == name
271
+ change2 = changeset.get(1)
272
+ change2.type.to_s.should == "VALUE_MODIFIED"
273
+ change2.context.should == variant
274
+ change3 = changeset.get(2)
275
+ change3.type.to_s.should == "DATATYPE_SET"
276
+ change3.context.should == variant
277
+ change4 = changeset.last
278
+ change4.type.to_s.should == "SCOPE_MODIFIED"
279
+ change4.context.should == variant
280
+ end
281
+ it "when adding a occurrence to a topic" do
282
+ @tm.topics.should be_empty
283
+ @tm.revision_index.last_revision.should be_nil
284
+ @tm.disable_revision_management
285
+ topic = @tm.get!("topic")
286
+ occtype = @tm.get!("occtype")
287
+ @tm.enable_revision_management
288
+ @tm.revision_index.last_revision.should be_nil
289
+ occ = topic.create_occurrence(occtype, "a Name")
290
+ @tm.should have(1).all_revisions
291
+ last_revision = @tm.revision_index.last_revision
292
+ last_revision.should_not be_nil
293
+ last_revision.changeset_type.to_s.should == "OCCURRENCE_ADDED"
294
+ RTM::Revision.topic_or_association_context(last_revision).should == topic
295
+ changeset = last_revision.changeset
296
+ changeset.size.should == 5
297
+ change1 = changeset.first
298
+ change1.type.to_s.should == "OCCURRENCE_ADDED"
299
+ change1.context.should == topic
300
+ change2 = changeset.get(1)
301
+ change2.type.to_s.should == "TYPE_SET"
302
+ change2.context.should == occ
303
+ change3 = changeset.get(2)
304
+ change3.type.to_s.should == "VALUE_MODIFIED"
305
+ change3.context.should == occ
306
+ change4 = changeset.get(3)
307
+ change4.type.to_s.should == "DATATYPE_SET"
308
+ change4.context.should == occ
309
+ change5 = changeset.last
310
+ change5.type.to_s.should == "SCOPE_MODIFIED"
311
+ change5.context.should == occ
312
+ end
313
+ it "when removing a si from a topic" do
314
+ @tm.topics.should be_empty
315
+ @tm.revision_index.last_revision.should be_nil
316
+ @tm.disable_revision_management
317
+ topic1 = @tm.get!("topic1")
318
+ @tm.enable_revision_management
319
+ @tm.revision_index.last_revision.should be_nil
320
+ topic1.remove_si("topic1")
321
+ topic1.references.should be_empty
322
+ @tm.should have(1).all_revisions
323
+ last_revision = @tm.revision_index.last_revision
324
+ last_revision.should_not be_nil
325
+ last_revision.changeset_type.to_s.should == "SUBJECT_IDENTIFIER_REMOVED"
326
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
327
+ changeset = last_revision.changeset
328
+ changeset.size.should == 1
329
+ change1 = changeset.first
330
+ change1.type.to_s.should == "SUBJECT_IDENTIFIER_REMOVED"
331
+ change1.context.should == topic1
332
+ end
333
+ it "when removing an ii from a topic" do
334
+ @tm.topics.should be_empty
335
+ @tm.revision_index.last_revision.should be_nil
336
+ @tm.disable_revision_management
337
+ topic1 = @tm.get!("ii:topic1")
338
+ @tm.enable_revision_management
339
+ @tm.revision_index.last_revision.should be_nil
340
+ topic1.remove_ii("topic1")
341
+ topic1.references.should be_empty
342
+ @tm.should have(1).all_revisions
343
+ last_revision = @tm.revision_index.last_revision
344
+ last_revision.should_not be_nil
345
+ last_revision.changeset_type.to_s.should == "ITEM_IDENTIFIER_REMOVED"
346
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
347
+ changeset = last_revision.changeset
348
+ changeset.size.should == 1
349
+ change1 = changeset.first
350
+ change1.type.to_s.should == "ITEM_IDENTIFIER_REMOVED"
351
+ change1.context.should == topic1
352
+ last_revision.changeset.first.context.should be_a_kind_of RTM::Topic
353
+ end
354
+ it "when removing a sl from a topic" do
355
+ @tm.topics.should be_empty
356
+ @tm.revision_index.last_revision.should be_nil
357
+ @tm.disable_revision_management
358
+ topic1 = @tm.get!("sl:topic1")
359
+ @tm.enable_revision_management
360
+ @tm.revision_index.last_revision.should be_nil
361
+ topic1.remove_sl("topic1")
362
+ topic1.references.should be_empty
363
+ @tm.should have(1).all_revisions
364
+ last_revision = @tm.revision_index.last_revision
365
+ last_revision.should_not be_nil
366
+ last_revision.changeset_type.to_s.should == "SUBJECT_LOCATOR_REMOVED"
367
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
368
+ changeset = last_revision.changeset
369
+ changeset.size.should == 1
370
+ change1 = changeset.first
371
+ change1.type.to_s.should == "SUBJECT_LOCATOR_REMOVED"
372
+ change1.context.should == topic1
373
+ end
374
+ it "when adding a si from a topic" do
375
+ @tm.topics.should be_empty
376
+ @tm.revision_index.last_revision.should be_nil
377
+ @tm.disable_revision_management
378
+ topic1 = @tm.get!("topic1")
379
+ @tm.enable_revision_management
380
+ @tm.revision_index.last_revision.should be_nil
381
+ topic1.add_si("topic_identifier2")
382
+ topic1.should have(2).references
383
+ @tm.should have(1).all_revisions
384
+ last_revision = @tm.revision_index.last_revision
385
+ last_revision.should_not be_nil
386
+ last_revision.changeset_type.to_s.should == "SUBJECT_IDENTIFIER_ADDED"
387
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
388
+ changeset = last_revision.changeset
389
+ changeset.size.should == 1
390
+ change1 = changeset.first
391
+ change1.type.to_s.should == "SUBJECT_IDENTIFIER_ADDED"
392
+ change1.context.should == topic1
393
+ end
394
+ it "when adding an ii from a topic" do
395
+ @tm.topics.should be_empty
396
+ @tm.revision_index.last_revision.should be_nil
397
+ @tm.disable_revision_management
398
+ topic1 = @tm.get!("ii:topic1")
399
+ @tm.enable_revision_management
400
+ @tm.revision_index.last_revision.should be_nil
401
+ topic1.add_ii("topic_identifier2")
402
+ topic1.should have(2).references
403
+ @tm.should have(1).all_revisions
404
+ last_revision = @tm.revision_index.last_revision
405
+ last_revision.should_not be_nil
406
+ last_revision.changeset_type.to_s.should == "ITEM_IDENTIFIER_ADDED"
407
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
408
+ changeset = last_revision.changeset
409
+ changeset.size.should == 1
410
+ change1 = changeset.first
411
+ change1.type.to_s.should == "ITEM_IDENTIFIER_ADDED"
412
+ change1.context.should == topic1
413
+ last_revision.changeset.first.context.should be_a_kind_of RTM::Topic
414
+ end
415
+ it "when adding a sl from a topic" do
416
+ @tm.topics.should be_empty
417
+ @tm.revision_index.last_revision.should be_nil
418
+ @tm.disable_revision_management
419
+ topic1 = @tm.get!("sl:topic1")
420
+ @tm.enable_revision_management
421
+ @tm.revision_index.last_revision.should be_nil
422
+ topic1.add_sl("topic_identifier2")
423
+ topic1.should have(2).references
424
+ @tm.should have(1).all_revisions
425
+ last_revision = @tm.revision_index.last_revision
426
+ last_revision.should_not be_nil
427
+ last_revision.changeset_type.to_s.should == "SUBJECT_LOCATOR_ADDED"
428
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
429
+ changeset = last_revision.changeset
430
+ changeset.size.should == 1
431
+ change1 = changeset.first
432
+ change1.type.to_s.should == "SUBJECT_LOCATOR_ADDED"
433
+ change1.context.should == topic1
434
+ end
435
+ it "when removing a topic" do
436
+ @tm.topics.should be_empty
437
+ @tm.revision_index.last_revision.should be_nil
438
+ @tm.disable_revision_management
439
+ topic1 = @tm.get!("topic1")
440
+ name = topic1.create_name("name")
441
+ name.create_variant("var", ["theme"])
442
+ occ = topic1.create_occurrence("occ_type", "occ")
443
+ @tm.enable_revision_management
444
+ @tm.revision_index.last_revision.should be_nil
445
+ topic1.remove
446
+ @tm.should have(1).all_revisions
447
+ last_revision = @tm.revision_index.last_revision
448
+ last_revision.should_not be_nil
449
+ last_revision.changeset_type.to_s.should == "TOPIC_REMOVED"
450
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
451
+ changeset = last_revision.changeset
452
+ changeset.size.should == 4
453
+ change1 = changeset.first
454
+ ["VARIANT_REMOVED", "OCCURRENCE_REMOVED"].should include change1.type.to_s
455
+ [name, topic1].should include change1.context
456
+ change2 = changeset.get(1)
457
+ ["VARIANT_REMOVED", "OCCURRENCE_REMOVED", "NAME_REMOVED"].should include change2.type.to_s
458
+ [name, topic1].should include change2.context
459
+ change3 = changeset.get(2)
460
+ ["OCCURRENCE_REMOVED", "NAME_REMOVED"].should include change3.type.to_s
461
+ [topic1].should include change3.context
462
+ change4 = changeset.last
463
+ change4.type.to_s.should == "TOPIC_REMOVED"
464
+ change4.context.should == @tm
465
+ end
466
+ it "when removing a name" do
467
+ @tm.topics.should be_empty
468
+ @tm.revision_index.last_revision.should be_nil
469
+ @tm.disable_revision_management
470
+ topic1 = @tm.get!("topic1")
471
+ name = topic1.create_name("name")
472
+ name.create_variant("var", ["theme"])
473
+ @tm.enable_revision_management
474
+ @tm.revision_index.last_revision.should be_nil
475
+ name.remove
476
+ @tm.should have(1).all_revisions
477
+ last_revision = @tm.revision_index.last_revision
478
+ last_revision.should_not be_nil
479
+ last_revision.changeset_type.to_s.should == "NAME_REMOVED"
480
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
481
+ changeset = last_revision.changeset
482
+ changeset.size.should == 2
483
+ change1 = changeset.first
484
+ ["VARIANT_REMOVED"].should include change1.type.to_s
485
+ [name].should include change1.context
486
+ change2 = changeset.last
487
+ ["NAME_REMOVED"].should include change2.type.to_s
488
+ [topic1].should include change2.context
489
+ end
490
+ it "when removing a variant" do
491
+ @tm.topics.should be_empty
492
+ @tm.revision_index.last_revision.should be_nil
493
+ @tm.disable_revision_management
494
+ topic1 = @tm.get!("topic1")
495
+ name = topic1.create_name("name")
496
+ variant = name.create_variant("var", ["theme"])
497
+ @tm.enable_revision_management
498
+ @tm.revision_index.last_revision.should be_nil
499
+ variant.remove
500
+ @tm.should have(1).all_revisions
501
+ last_revision = @tm.revision_index.last_revision
502
+ last_revision.should_not be_nil
503
+ last_revision.changeset_type.to_s.should == "VARIANT_REMOVED"
504
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
505
+ changeset = last_revision.changeset
506
+ changeset.size.should == 1
507
+ change1 = changeset.first
508
+ ["VARIANT_REMOVED"].should include change1.type.to_s
509
+ [name].should include change1.context
510
+ end
511
+ it "when removing an occurrence" do
512
+ @tm.topics.should be_empty
513
+ @tm.revision_index.last_revision.should be_nil
514
+ @tm.disable_revision_management
515
+ topic1 = @tm.get!("topic1")
516
+ occ = topic1.create_occurrence("occ_type", "occ", :scope => ["theme"])
517
+ @tm.enable_revision_management
518
+ @tm.revision_index.last_revision.should be_nil
519
+ occ.remove
520
+ @tm.should have(1).all_revisions
521
+ last_revision = @tm.revision_index.last_revision
522
+ last_revision.should_not be_nil
523
+ last_revision.changeset_type.to_s.should == "OCCURRENCE_REMOVED"
524
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
525
+ changeset = last_revision.changeset
526
+ changeset.size.should == 1
527
+ change1 = changeset.first
528
+ ["OCCURRENCE_REMOVED"].should include change1.type.to_s
529
+ [topic1].should include change1.context
530
+ end
531
+ it "when removing an association without roles" do
532
+ @tm.topics.should be_empty
533
+ @tm.revision_index.last_revision.should be_nil
534
+ @tm.disable_revision_management
535
+ assoc = @tm.create_association("assoc_type")
536
+ @tm.enable_revision_management
537
+ @tm.revision_index.last_revision.should be_nil
538
+ assoc.remove
539
+ @tm.should have(1).all_revisions
540
+ last_revision = @tm.revision_index.last_revision
541
+ last_revision.should_not be_nil
542
+ last_revision.changeset_type.to_s.should == "ASSOCIATION_REMOVED"
543
+ RTM::Revision.topic_or_association_context(last_revision).should == assoc
544
+ changeset = last_revision.changeset
545
+ changeset.size.should == 1
546
+ change1 = changeset.first
547
+ change1.type.to_s.should == "ASSOCIATION_REMOVED"
548
+ change1.context.should == @tm
549
+ end
550
+ it "when removing an association with roles" do
551
+ @tm.topics.should be_empty
552
+ @tm.revision_index.last_revision.should be_nil
553
+ @tm.disable_revision_management
554
+ assoc = @tm.create_association("assoc_type", "role_type1" => "role_player1", "role_type2" => "role_player2")
555
+ @tm.enable_revision_management
556
+ @tm.revision_index.last_revision.should be_nil
557
+ assoc.remove
558
+ @tm.should have(1).all_revisions
559
+ last_revision = @tm.revision_index.last_revision
560
+ last_revision.should_not be_nil
561
+ last_revision.changeset_type.to_s.should == "ASSOCIATION_REMOVED"
562
+ RTM::Revision.topic_or_association_context(last_revision).should == assoc
563
+ changeset = last_revision.changeset
564
+ changeset.size.should == 3
565
+ change1 = changeset.first
566
+ change1.type.to_s.should == "ROLE_REMOVED"
567
+ change1.context.should == assoc
568
+ change2 = changeset.get(1)
569
+ change2.type.to_s.should == "ROLE_REMOVED"
570
+ change2.context.should == assoc
571
+ change3 = changeset.last
572
+ change3.type.to_s.should == "ASSOCIATION_REMOVED"
573
+ change3.context.should == @tm
574
+ number_of_roles_removed = changeset.size - 1
575
+ number_of_roles_removed.times do |i|
576
+ puts i
577
+ changeset[i].old_value.player.reference.should include "role_player"
578
+ end
579
+ end
580
+ it "when removing a role from an association" do
581
+ @tm.topics.should be_empty
582
+ @tm.revision_index.last_revision.should be_nil
583
+ @tm.disable_revision_management
584
+ assoc = @tm.create_association("assoc_type", "role_type1" => "role_player1")
585
+ role = assoc.create_role("role_type2", "role_player2")
586
+ @tm.enable_revision_management
587
+ @tm.revision_index.last_revision.should be_nil
588
+ role.remove
589
+ @tm.should have(1).all_revisions
590
+ last_revision = @tm.revision_index.last_revision
591
+ last_revision.should_not be_nil
592
+ last_revision.changeset_type.to_s.should == "ROLE_REMOVED"
593
+ RTM::Revision.topic_or_association_context(last_revision).should == assoc
594
+ changeset = last_revision.changeset
595
+ changeset.size.should == 1
596
+ change1 = changeset.first
597
+ change1.type.to_s.should == "ROLE_REMOVED"
598
+ change1.context.should == assoc
599
+ end
600
+ it "when setting a value of a name" do
601
+ @tm.topics.should be_empty
602
+ @tm.revision_index.last_revision.should be_nil
603
+ @tm.disable_revision_management
604
+ topic1 = @tm.get!("topic1")
605
+ name = topic1.create_name("name")
606
+ @tm.enable_revision_management
607
+ @tm.revision_index.last_revision.should be_nil
608
+ name.set_value("other name")
609
+ @tm.should have(1).all_revisions
610
+ last_revision = @tm.revision_index.last_revision
611
+ last_revision.should_not be_nil
612
+ last_revision.changeset_type.to_s.should == "VALUE_MODIFIED"
613
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
614
+ changeset = last_revision.changeset
615
+ changeset.size.should == 1
616
+ change1 = changeset.first
617
+ change1.type.to_s.should == "VALUE_MODIFIED"
618
+ change1.context.should == name
619
+ end
620
+ it "when setting a value of an occurrence" do
621
+ @tm.topics.should be_empty
622
+ @tm.revision_index.last_revision.should be_nil
623
+ @tm.disable_revision_management
624
+ topic1 = @tm.get!("topic1")
625
+ occ = topic1.create_occurrence("occ_type", "occ")
626
+ @tm.enable_revision_management
627
+ @tm.revision_index.last_revision.should be_nil
628
+ occ.set_value(@tm.create_locator("other occ"))
629
+ @tm.should have(1).all_revisions
630
+ last_revision = @tm.revision_index.last_revision
631
+ last_revision.should_not be_nil
632
+ last_revision.changeset_type.to_s.should == "VALUE_MODIFIED"
633
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
634
+ changeset = last_revision.changeset
635
+ changeset.size.should == 2
636
+ change1 = changeset.first
637
+ change1.type.to_s.should == "VALUE_MODIFIED"
638
+ change1.context.should == occ
639
+ change1 = changeset.last
640
+ change1.type.to_s.should == "DATATYPE_SET"
641
+ change1.context.should == occ
642
+ end
643
+ it "when setting a value of a variant" do
644
+ @tm.topics.should be_empty
645
+ @tm.revision_index.last_revision.should be_nil
646
+ @tm.disable_revision_management
647
+ topic1 = @tm.get!("topic1")
648
+ name = topic1.create_name("name")
649
+ variant = name.create_variant("var", ["theme"])
650
+ @tm.enable_revision_management
651
+ @tm.revision_index.last_revision.should be_nil
652
+ variant.set_value(@tm.create_locator("other val"))
653
+ @tm.should have(1).all_revisions
654
+ last_revision = @tm.revision_index.last_revision
655
+ last_revision.should_not be_nil
656
+ last_revision.changeset_type.to_s.should == "VALUE_MODIFIED"
657
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
658
+ changeset = last_revision.changeset
659
+ changeset.size.should == 2
660
+ change1 = changeset.first
661
+ change1.type.to_s.should == "VALUE_MODIFIED"
662
+ change1.context.should == variant
663
+ change1 = changeset.last
664
+ change1.type.to_s.should == "DATATYPE_SET"
665
+ change1.context.should == variant
666
+ end
667
+ it "when adding a theme to a scoped (name)" do
668
+ @tm.topics.should be_empty
669
+ @tm.revision_index.last_revision.should be_nil
670
+ @tm.disable_revision_management
671
+ topic1 = @tm.get!("topic1")
672
+ name = topic1.create_name("name")
673
+ @tm.get!("theme")
674
+ @tm.enable_revision_management
675
+ @tm.revision_index.last_revision.should be_nil
676
+ name.add_theme("theme")
677
+ @tm.should have(1).all_revisions
678
+ last_revision = @tm.revision_index.last_revision
679
+ last_revision.should_not be_nil
680
+ last_revision.changeset_type.to_s.should == "SCOPE_MODIFIED"
681
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
682
+ changeset = last_revision.changeset
683
+ changeset.size.should == 1
684
+ change1 = changeset.first
685
+ change1.type.to_s.should == "SCOPE_MODIFIED"
686
+ change1.context.should == name
687
+ end
688
+ it "when adding a theme to a scoped (association)" do
689
+ @tm.topics.should be_empty
690
+ @tm.revision_index.last_revision.should be_nil
691
+ @tm.disable_revision_management
692
+ topic1 = @tm.get!("topic1")
693
+ assoc = @tm.create_association("assoc_type", "role_type1" => "role_player1", "role_type2" => "role_player2")
694
+ @tm.get!("theme")
695
+ @tm.enable_revision_management
696
+ @tm.revision_index.last_revision.should be_nil
697
+ assoc.add_theme("theme")
698
+ @tm.should have(1).all_revisions
699
+ last_revision = @tm.revision_index.last_revision
700
+ last_revision.should_not be_nil
701
+ last_revision.changeset_type.to_s.should == "SCOPE_MODIFIED"
702
+ RTM::Revision.topic_or_association_context(last_revision).should == assoc
703
+ changeset = last_revision.changeset
704
+ changeset.size.should == 1
705
+ change1 = changeset.first
706
+ change1.type.to_s.should == "SCOPE_MODIFIED"
707
+ change1.context.should == assoc
708
+ end
709
+ it "when removing a theme from a scoped (name)" do
710
+ @tm.topics.should be_empty
711
+ @tm.revision_index.last_revision.should be_nil
712
+ @tm.disable_revision_management
713
+ topic1 = @tm.get!("topic1")
714
+ name = topic1.create_name("name", ["theme"])
715
+ @tm.enable_revision_management
716
+ @tm.revision_index.last_revision.should be_nil
717
+ name.remove_theme("theme")
718
+ @tm.should have(1).all_revisions
719
+ last_revision = @tm.revision_index.last_revision
720
+ last_revision.should_not be_nil
721
+ last_revision.changeset_type.to_s.should == "SCOPE_MODIFIED"
722
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
723
+ changeset = last_revision.changeset
724
+ changeset.size.should == 1
725
+ change1 = changeset.first
726
+ change1.type.to_s.should == "SCOPE_MODIFIED"
727
+ change1.context.should == name
728
+ end
729
+ it "when removing a theme to a scoped (association)" do
730
+ @tm.topics.should be_empty
731
+ @tm.revision_index.last_revision.should be_nil
732
+ @tm.disable_revision_management
733
+ topic1 = @tm.get!("topic1")
734
+ assoc = @tm.create_association("assoc_type", "role_type1" => "role_player1", "role_type2" => "role_player2")
735
+ assoc.add_theme("theme")
736
+ @tm.enable_revision_management
737
+ @tm.revision_index.last_revision.should be_nil
738
+ assoc.remove_theme("theme")
739
+ @tm.should have(1).all_revisions
740
+ last_revision = @tm.revision_index.last_revision
741
+ last_revision.should_not be_nil
742
+ last_revision.changeset_type.to_s.should == "SCOPE_MODIFIED"
743
+ RTM::Revision.topic_or_association_context(last_revision).should == assoc
744
+ changeset = last_revision.changeset
745
+ changeset.size.should == 1
746
+ change1 = changeset.first
747
+ change1.type.to_s.should == "SCOPE_MODIFIED"
748
+ change1.context.should == assoc
749
+ end
750
+ it "when setting a type of a typed (occurrence)" do
751
+ @tm.topics.should be_empty
752
+ @tm.revision_index.last_revision.should be_nil
753
+ @tm.disable_revision_management
754
+ topic1 = @tm.get!("topic1")
755
+ occ = topic1.create_occurrence("occ_type", "occ")
756
+ @tm.get!("other_type")
757
+ @tm.enable_revision_management
758
+ @tm.revision_index.last_revision.should be_nil
759
+ occ.type = "other_type"
760
+ @tm.should have(1).all_revisions
761
+ last_revision = @tm.revision_index.last_revision
762
+ last_revision.should_not be_nil
763
+ last_revision.changeset_type.to_s.should == "TYPE_SET"
764
+ RTM::Revision.topic_or_association_context(last_revision).should == topic1
765
+ changeset = last_revision.changeset
766
+ changeset.size.should == 1
767
+ change1 = changeset.first
768
+ change1.type.to_s.should == "TYPE_SET"
769
+ change1.context.should == occ
770
+ end
771
+ it "when setting a type of a typed (role)" do
772
+ @tm.topics.should be_empty
773
+ @tm.revision_index.last_revision.should be_nil
774
+ @tm.disable_revision_management
775
+ topic1 = @tm.get!("topic1")
776
+ assoc = @tm.create_association("assoc_type", "role_type1" => "role_player1")
777
+ role = assoc.create_role("role_type2", "role_player2")
778
+ @tm.get!("role_type3")
779
+ @tm.enable_revision_management
780
+ @tm.revision_index.last_revision.should be_nil
781
+ role.type = "role_type3"
782
+ @tm.should have(1).all_revisions
783
+ last_revision = @tm.revision_index.last_revision
784
+ last_revision.should_not be_nil
785
+ last_revision.changeset_type.to_s.should == "TYPE_SET"
786
+ RTM::Revision.topic_or_association_context(last_revision).should == assoc
787
+ changeset = last_revision.changeset
788
+ changeset.size.should == 1
789
+ change1 = changeset.first
790
+ change1.type.to_s.should == "TYPE_SET"
791
+ change1.context.should == role
792
+ end
793
+ it "when setting the player of a role" do
794
+ @tm.topics.should be_empty
795
+ @tm.revision_index.last_revision.should be_nil
796
+ @tm.disable_revision_management
797
+ topic1 = @tm.get!("topic1")
798
+ assoc = @tm.create_association("assoc_type", "role_type1" => "role_player1")
799
+ role = assoc.create_role("role_type2", "role_player2")
800
+ @tm.get!("role_player3")
801
+ @tm.enable_revision_management
802
+ @tm.revision_index.last_revision.should be_nil
803
+ role.player = "role_player3"
804
+ @tm.should have(1).all_revisions
805
+ last_revision = @tm.revision_index.first_revision
806
+ last_revision.should_not be_nil
807
+ last_revision.changeset_type.to_s.should == "PLAYER_MODIFIED"
808
+ RTM::Revision.topic_or_association_context(last_revision).should == assoc
809
+ changeset = last_revision.changeset
810
+ changeset.size.should == 1
811
+ change1 = changeset.first
812
+ change1.type.to_s.should == "PLAYER_MODIFIED"
813
+ change1.context.should == role
814
+ end
815
+ it "when setting a reifier of a reifier (role)" do
816
+ @tm.topics.should be_empty
817
+ @tm.revision_index.last_revision.should be_nil
818
+ @tm.disable_revision_management
819
+ topic1 = @tm.get!("topic1")
820
+ assoc = @tm.create_association("assoc_type", "role_type1" => "role_player1")
821
+ role = assoc.create_role("role_type2", "role_player2")
822
+ @tm.get!("reifier")
823
+ @tm.enable_revision_management
824
+ @tm.revision_index.last_revision.should be_nil
825
+ role.reifier = "reifier"
826
+ @tm.should have(1).all_revisions
827
+ last_revision = @tm.revision_index.first_revision
828
+ last_revision.should_not be_nil
829
+ last_revision.changeset_type.to_s.should == "REIFIER_SET"
830
+ changeset = last_revision.changeset
831
+ changeset.size.should == 1
832
+ change1 = changeset.first
833
+ change1.type.to_s.should == "REIFIER_SET"
834
+ change1.context.should == role
835
+ end
836
+ it "when de-setting a reifier of a reifier (role) " do
837
+ @tm.topics.should be_empty
838
+ @tm.revision_index.last_revision.should be_nil
839
+ @tm.disable_revision_management
840
+ topic1 = @tm.get!("topic1")
841
+ assoc = @tm.create_association("assoc_type", "role_type1" => "role_player1")
842
+ role = assoc.create_role("role_type2", "role_player2")
843
+ role.reifier = "reifier"
844
+ role.reifier.should_not be_nil
845
+ @tm.enable_revision_management
846
+ @tm.revision_index.last_revision.should be_nil
847
+ role.reifier = nil
848
+ role.reifier.should be_nil
849
+ @tm.should have(1).all_revisions
850
+ last_revision = @tm.revision_index.first_revision
851
+ last_revision.should_not be_nil
852
+ last_revision.changeset_type.to_s.should == "REIFIER_SET"
853
+ changeset = last_revision.changeset
854
+ changeset.size.should == 1
855
+ change1 = changeset.first
856
+ change1.type.to_s.should == "REIFIER_SET"
857
+ change1.context.should == role
858
+ end
859
+ it "when calling merge_in " do
860
+ @tm.topics.should be_empty
861
+ @tm.revision_index.last_revision.should be_nil
862
+ @tm.disable_revision_management
863
+ topic1 = @tm.get!("topic1")
864
+ topic1.create_name("name")
865
+ topic1.create_occurrence("occ_type", "occ")
866
+ assoc = @tm.create_association("assoc_type", "role_type1" => "role_player1", "role_type2" => "role_player2")
867
+ tm = get_used_tm_sys.create("http://example.org/merging_map/")
868
+ topic2 = tm.get!("topic1")
869
+ topic2.create_name("name")
870
+ topic2.create_occurrence("occ_type", "occ")
871
+ assoc = tm.create_association("assoc_type", "role_type1" => "role_player1", "role_type2" => "role_player2")
872
+ @tm.enable_revision_management
873
+ @tm.revision_index.last_revision.should be_nil
874
+ @tm.merge_in(tm)
875
+ if implementation_for_spec == :majortom_db
876
+ pending "not working" do
877
+ @tm.should have(1).all_revisions
878
+ last_revision = @tm.revision_index.first_revision
879
+ last_revision.should_not be_nil
880
+ last_revision.changeset_type.to_s.should == "MERGE"
881
+ changeset = last_revision.changeset
882
+ changeset.size.should == 32
883
+ end
884
+ else
885
+ @tm.should have(1).all_revisions
886
+ last_revision = @tm.revision_index.first_revision
887
+ last_revision.should_not be_nil
888
+ last_revision.changeset_type.to_s.should == "MERGE"
889
+ changeset = last_revision.changeset
890
+ changeset.size.should == 32
891
+ end
892
+ end
893
+ it "when calling remove_duplicates" do
894
+ @tm.topics.should be_empty
895
+ @tm.revision_index.last_revision.should be_nil
896
+ @tm.disable_revision_management
897
+ topic1 = @tm.get!("topic1")
898
+ topic1.create_name("name")
899
+ topic1.create_name("name")
900
+ @tm.enable_revision_management
901
+ @tm.revision_index.last_revision.should be_nil
902
+ @tm.remove_duplicates
903
+ @tm.should have(1).all_revisions
904
+ last_revision = @tm.revision_index.first_revision
905
+ last_revision.should_not be_nil
906
+ if implementation_for_spec == :majortom_db
907
+ pending "not working" do
908
+ last_revision.changeset_type.to_s.should == "REMOVE_DUPLICATES"
909
+ changeset = last_revision.changeset
910
+ changeset.size.should == 1
911
+ end
912
+ else
913
+ last_revision.changeset_type.to_s.should == "REMOVE_DUPLICATES"
914
+ changeset = last_revision.changeset
915
+ changeset.size.should == 1
916
+ end
917
+ end
918
+ end
919
+ end
920
+
921
+ describe "Changes in the topic map" do
922
+ it "should handle creating and deleting a topic" do
923
+ @tm.topics.should be_empty
924
+ @tm.revision_index.last_revision.should be_nil
925
+ @tm.enable_revision_management
926
+ topic = @tm.get!("topic")
927
+ topic.remove
928
+ @tm.should have(2).all_revisions
929
+ first_revision = @tm.revision_index.first_revision
930
+ first_revision.changeset_type.should == RTM::Revision::Type::TOPIC_ADDED
931
+ first_revision.changeset.first.new_value.read_only?.should be_true
932
+ end
933
+ end
934
+
935
+ end # of describe self
936
+ end