rtm 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/DISCLAIMER +10 -33
  2. data/LICENSE +201 -0
  3. data/README +3 -3
  4. data/lib/rtm.rb +148 -74
  5. data/lib/rtm/axes.rb +295 -0
  6. data/lib/rtm/axes/association.rb +76 -0
  7. data/lib/rtm/axes/associations.rb +96 -0
  8. data/lib/rtm/axes/assocs_names_occs.rb +56 -0
  9. data/lib/rtm/axes/characteristic.rb +68 -0
  10. data/lib/rtm/axes/characteristics.rb +93 -0
  11. data/lib/rtm/axes/string.rb +76 -0
  12. data/lib/rtm/axes/strings.rb +87 -0
  13. data/lib/rtm/axes/topic.rb +233 -0
  14. data/lib/rtm/axes/topics.rb +280 -0
  15. data/lib/rtm/{backward_compatibility.rb → deprecated/index_property_set.rb} +3 -0
  16. data/lib/rtm/engine.rb +58 -0
  17. data/lib/rtm/extensions.rb +11 -1
  18. data/lib/rtm/{locator_helpers.rb → helpers/locator.rb} +15 -4
  19. data/lib/rtm/{helpers.rb → helpers/no_output.rb} +3 -0
  20. data/lib/rtm/helpers/uri.rb +13 -0
  21. data/lib/rtm/io.rb +18 -0
  22. data/lib/rtm/io/from_xtm2_libxml.rb +2 -1
  23. data/lib/rtm/io/ontopia_io.rb +25 -0
  24. data/lib/rtm/io/tmapix.rb +234 -0
  25. data/lib/rtm/io/to_hash.rb +116 -0
  26. data/lib/rtm/io/to_jtm.rb +53 -103
  27. data/lib/rtm/io/to_rdf.rb +30 -0
  28. data/lib/rtm/io/to_string.rb +8 -6
  29. data/lib/rtm/io/to_xtm1.rb +6 -4
  30. data/lib/rtm/io/to_xtm2.rb +10 -8
  31. data/lib/rtm/io/to_yaml.rb +29 -98
  32. data/lib/rtm/navigation.rb +37 -0
  33. data/lib/rtm/navigation/association/players.rb +25 -0
  34. data/lib/rtm/navigation/name/atomify.rb +19 -0
  35. data/lib/rtm/navigation/name/characteristics.rb +33 -0
  36. data/lib/rtm/navigation/occurrence/atomify.rb +19 -0
  37. data/lib/rtm/navigation/occurrence/characteristics.rb +33 -0
  38. data/lib/rtm/navigation/topic/characteristics.rb +33 -0
  39. data/lib/rtm/navigation/topic/indicators.rb +31 -0
  40. data/lib/rtm/navigation/topic/items.rb +31 -0
  41. data/lib/rtm/navigation/topic/locators.rb +31 -0
  42. data/lib/rtm/navigation/topic/players.rb +27 -0
  43. data/lib/rtm/navigation/topic/supertypes.rb +162 -0
  44. data/lib/rtm/navigation/topic/traverse.rb +51 -0
  45. data/lib/rtm/navigation/topic/types.rb +107 -0
  46. data/lib/rtm/psi.rb +33 -2
  47. data/lib/rtm/sugar.rb +34 -0
  48. data/lib/rtm/sugar/association/hash_access.rb +46 -0
  49. data/lib/rtm/sugar/occurrence/dynamic_value.rb +75 -0
  50. data/lib/rtm/{pimp_my_api.rb → sugar/occurrence/externalize.rb} +3 -0
  51. data/lib/rtm/sugar/role/counterparts.rb +133 -46
  52. data/lib/rtm/sugar/topic/characteristics.rb +126 -12
  53. data/lib/rtm/sugar/topic/counterparts.rb +130 -7
  54. data/lib/rtm/sugar/topic/hash_access.rb +140 -30
  55. data/lib/rtm/sugar/topic/scoped.rb +65 -0
  56. data/lib/rtm/sugar/topic/topic_ref.rb +35 -0
  57. data/lib/rtm/sugar/topic/typed.rb +159 -0
  58. data/lib/rtm/sugar/typed/types.rb +38 -0
  59. data/lib/rtm/validation.rb +8 -5
  60. data/lib/rtm/version.rb +18 -0
  61. data/spec/helpers/spec_exampleexamplegroup.rb +14 -0
  62. data/spec/rtm/axes/association_spec.rb +88 -0
  63. data/spec/rtm/axes/associations_spec.rb +60 -0
  64. data/spec/rtm/axes/assocs_names_occs_spec.rb +9 -0
  65. data/spec/rtm/axes/characteristic_spec.rb +90 -0
  66. data/spec/rtm/axes/characteristics_spec.rb +85 -0
  67. data/spec/rtm/axes/string_spec.rb +145 -0
  68. data/spec/rtm/axes/strings_spec.rb +168 -0
  69. data/spec/rtm/axes/topic_spec.rb +124 -0
  70. data/spec/rtm/axes/topics_spec.rb +103 -0
  71. data/spec/rtm/base_spec.rb +32 -0
  72. data/spec/rtm/io/tmapix_spec.rb +85 -0
  73. data/spec/rtm/navigation/association/players_spec.rb +58 -0
  74. data/spec/rtm/navigation/association_spec.rb +52 -0
  75. data/spec/rtm/navigation/name/atomify_spec.rb +27 -0
  76. data/spec/rtm/navigation/name/characteristics_spec.rb +34 -0
  77. data/spec/rtm/navigation/name_spec.rb +52 -0
  78. data/spec/rtm/navigation/occurrence/atomify_spec.rb +27 -0
  79. data/spec/rtm/navigation/occurrence/characteristics_spec.rb +34 -0
  80. data/spec/rtm/navigation/occurrence_spec.rb +52 -0
  81. data/spec/rtm/navigation/string_spec.rb +51 -0
  82. data/spec/rtm/navigation/topic/characteristics_spec.rb +55 -0
  83. data/spec/rtm/navigation/topic/indicators_spec.rb +43 -0
  84. data/spec/rtm/navigation/topic/items_spec.rb +44 -0
  85. data/spec/rtm/navigation/topic/locators_spec.rb +44 -0
  86. data/spec/rtm/navigation/topic/players_spec.rb +48 -0
  87. data/spec/rtm/navigation/topic/scope_spec.rb +41 -0
  88. data/spec/rtm/navigation/topic/supertypes_spec.rb +376 -0
  89. data/spec/rtm/navigation/topic/traverse_spec.rb +64 -0
  90. data/spec/rtm/navigation/topic/types_spec.rb +195 -0
  91. data/spec/rtm/navigation/topic_spec.rb +153 -0
  92. data/spec/rtm/sugar/association/hash_access_spec.rb +55 -0
  93. data/spec/rtm/sugar/occurrence/dynamic_value_spec.rb +16 -0
  94. data/spec/rtm/sugar/role/counterparts_spec.rb +191 -0
  95. data/spec/rtm/sugar/topic/characteristics_spec.rb +318 -0
  96. data/spec/rtm/sugar/topic/counterparts_spec.rb +184 -0
  97. data/spec/rtm/sugar/topic/hash_access_spec.rb +234 -0
  98. data/spec/rtm/sugar/topic/scoped_spec.rb +131 -0
  99. data/spec/rtm/sugar/topic/topic_ref_spec.rb +44 -0
  100. data/spec/rtm/sugar/topic/typed_spec.rb +155 -0
  101. data/spec/rtm/sugar/typed/types_spec.rb +24 -0
  102. data/spec/rtm/tmapi/core/association_spec.rb +169 -0
  103. data/spec/rtm/tmapi/core/construct_spec.rb +25 -0
  104. data/spec/rtm/tmapi/core/name_spec.rb +85 -0
  105. data/spec/rtm/tmapi/core/occurrence_spec.rb +96 -0
  106. data/spec/rtm/tmapi/core/reifiable_spec.rb +168 -0
  107. data/spec/rtm/tmapi/core/role_spec.rb +73 -0
  108. data/spec/rtm/tmapi/core/scoped_spec.rb +403 -0
  109. data/spec/rtm/tmapi/core/topic_map_spec.rb +648 -0
  110. data/spec/rtm/tmapi/core/topic_spec.rb +992 -0
  111. data/spec/rtm/tmapi/core/typed_spec.rb +112 -0
  112. data/spec/rtm/tmapi/core/variant_spec.rb +52 -0
  113. data/spec/rtm/tmapi/ext/java_util_set_spec.rb +34 -0
  114. data/spec/rtm/tmapi_spec.rb +44 -0
  115. data/spec/rtm/utils/sparql_spec.rb +26 -0
  116. data/spec/rtm_spec.rb +94 -0
  117. data/spec/spec_helper.rb +23 -0
  118. data/test/base_unit_test.rb +161 -0
  119. data/test/{base_test.rb → base_unit_test_tmapi.rb} +46 -43
  120. metadata +122 -66
  121. data/COPYRIGHT +0 -4
  122. data/lib/Rakefile.rb +0 -42
  123. data/lib/activetopicmaps.rb +0 -278
  124. data/lib/rtm/backend/active_record.rb +0 -58
  125. data/lib/rtm/backend/active_record/001_initial_schema.rb +0 -116
  126. data/lib/rtm/backend/active_record/association_and_role.rb +0 -33
  127. data/lib/rtm/backend/active_record/locators.rb +0 -55
  128. data/lib/rtm/backend/active_record/name_variant_occurrence.rb +0 -45
  129. data/lib/rtm/backend/active_record/quaaxtm2rtm.rb +0 -113
  130. data/lib/rtm/backend/active_record/quaaxtm2rtmviews.rb +0 -134
  131. data/lib/rtm/backend/active_record/set_wrapper.rb +0 -98
  132. data/lib/rtm/backend/active_record/tm_construct.rb +0 -62
  133. data/lib/rtm/backend/active_record/tm_delegator.rb +0 -345
  134. data/lib/rtm/backend/active_record/tm_set_delegator.rb +0 -195
  135. data/lib/rtm/backend/active_record/tmdm.rb +0 -298
  136. data/lib/rtm/backend/active_record/topic.rb +0 -87
  137. data/lib/rtm/backend/active_record/topic_map.rb +0 -314
  138. data/lib/rtm/backend/active_record/traverse_associations.rb +0 -87
  139. data/lib/rtm/base.rb +0 -92
  140. data/lib/rtm/connect.rb +0 -92
  141. data/lib/rtm/core_ext.rb +0 -6
  142. data/lib/rtm/io/from_xtm2.rb +0 -263
  143. data/lib/rtm/merging/merging.rb +0 -307
  144. data/lib/rtm/sugar/topic/identifier_direct.rb +0 -11
  145. data/lib/rtm/sugar/topic/predefined_associations.rb +0 -42
  146. data/lib/run_main_project.rb +0 -16
@@ -0,0 +1,112 @@
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::Typed
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
+ describe "#type" do
15
+ before(:each) do
16
+ @topic = @tm.create_topic_by("Uni_Leipzig")
17
+ @testname = @topic.create_name("test_type","Universität Leipzig")
18
+ end
19
+ it "for all instances of Typed this should give back the type" do
20
+ @testname.type.should == @tm.get("test_type")
21
+ end
22
+ it "should following the TMDM give back all instances of supertypes"
23
+ end
24
+
25
+ describe "#type=" do
26
+ before(:each) do
27
+ topic = @tm.get!("child")
28
+ @name = topic.create_name("Child")
29
+ @name.should be_a_kind_of RTM::Name
30
+ @occ = topic.create_occurrence("height","small")
31
+ @occ.should be_a_kind_of RTM::Occurrence
32
+ @assoc = @tm.create_association("mother_child")
33
+ @assoc.should be_a_kind_of RTM::Association
34
+ @role = @assoc.create_role("child","Hans")
35
+ @role.should be_a_kind_of RTM::Role
36
+ end
37
+ it "should set the type if the Construct is a Role and identifier a String" do
38
+ previous_type = @role.type
39
+ @role.type = "infant"
40
+ @role.type.should_not == previous_type
41
+ @role.type.should == @tm.get("infant")
42
+ end
43
+ it "should set the type if the Construct is a Role and identifier a Locator" do
44
+ previous_type = @role.type
45
+ @role.type = @tm.create_locator("infant")
46
+ @role.type.should_not == previous_type
47
+ @role.type.should == @tm.get("infant")
48
+ end
49
+ it "should set the type if the Construct is a Role and identifier a Topic" do
50
+ previous_type = @role.type
51
+ @role.type = @tm.get!("infant")
52
+ @role.type.should_not == previous_type
53
+ @role.type.should == @tm.get("infant")
54
+ end
55
+ it "should set the type if the Construct is an Association and identifier a String" do
56
+ previous_type = @assoc.type
57
+ @assoc.type = "mother-infant"
58
+ @assoc.type.should_not == previous_type
59
+ @assoc.type.should == @tm.get("mother-infant")
60
+ end
61
+ it "should set the type if the Construct is an Association and identifier a Locator" do
62
+ previous_type = @assoc.type
63
+ @assoc.type = @tm.create_locator("mother-infant")
64
+ @assoc.type.should_not == previous_type
65
+ @assoc.type.should == @tm.get("mother-infant")
66
+ end
67
+ it "should set the type if the Construct is an Association and identifier a Topic" do
68
+ previous_type = @assoc.type
69
+ @assoc.type = @tm.get!("mother-infant")
70
+ @assoc.type.should_not == previous_type
71
+ @assoc.type.should == @tm.get("mother-infant")
72
+ end
73
+ it "should set the type if the Construct is a Name and identifier a String" do
74
+ previous_type = @name.type
75
+ @name.type = "infant"
76
+ @name.type.should_not == previous_type
77
+ @name.type.should == @tm.get("infant")
78
+ end
79
+ it "should set the type if the Construct is a Name and identifier a Locator" do
80
+ previous_type = @name.type
81
+ @name.type = @tm.create_locator("infant")
82
+ @name.type.should_not == previous_type
83
+ @name.type.should == @tm.get("infant")
84
+ end
85
+ it "should set the type if the Construct is a Name and identifier a Topic" do
86
+ previous_type = @name.type
87
+ @name.type = @tm.get!("infant")
88
+ @name.type.should_not == previous_type
89
+ @name.type.should == @tm.get("infant")
90
+ end
91
+ it "should set the type if the Construct is an Occurrence and identifier a String" do
92
+ previous_type = @occ.type
93
+ @occ.type = "size"
94
+ @occ.type.should_not == previous_type
95
+ @occ.type.should == @tm.get("size")
96
+ end
97
+ it "should set the type if the Construct is an Occurrence and identifier a Locator" do
98
+ previous_type = @occ.type
99
+ @occ.type = @tm.create_locator("size")
100
+ @occ.type.should_not == previous_type
101
+ @occ.type.should == @tm.get("size")
102
+ end
103
+ it "should set the type if the Construct is an Occurrence and identifier a Topic" do
104
+ previous_type = @occ.type
105
+ @occ.type = @tm.get!("size")
106
+ @occ.type.should_not == previous_type
107
+ @occ.type.should == @tm.get("size")
108
+ end
109
+ end
110
+
111
+ end
112
+ end
@@ -0,0 +1,52 @@
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::Variant
7
+
8
+ describe self do
9
+ before(:each) do
10
+ @tm = get_used_tm_sys_tm
11
+ end
12
+ after(:each) do
13
+ @tm.close
14
+ end
15
+
16
+ describe "#parent" do
17
+ it "should give back Name to which the Variant belongs" do
18
+ topic = @tm.create_topic_by("sub:ident")
19
+ topic.should be_a_kind_of RTM::Topic
20
+ @tm.get("sub:ident").should be_a_kind_of RTM::Topic
21
+
22
+ scope = @tm.create_topic_by("englisch")
23
+ scope.should be_a_kind_of RTM::Topic
24
+ @tm.get("englisch").should be_a_kind_of RTM::Topic
25
+
26
+ testname = topic.create_name("Deutschland")
27
+ testname.should be_a_kind_of RTM::Name
28
+ testvariant = testname.create_variant("Germany", [scope])
29
+ testvariant.should be_a_kind_of RTM::Variant
30
+ testvariant.parent.should == testname
31
+ end
32
+ end
33
+
34
+ describe "#remove" do
35
+ before(:each) do
36
+ @topic1 = @tm.get!("topic1")
37
+ @name1 = @topic1.create_name("firstname","Hans")
38
+ @name2 = @topic1.create_name("lastname","Meier")
39
+ @variant1 = @name1.create_variant("Hansi",["alias"])
40
+ @variant2 = @name1.create_variant("Bubi",["endearment"])
41
+ end
42
+ it "should remove this Variant from the container (Name)" do
43
+ @name1.should have(2).children
44
+ @variant1.remove
45
+ @name1.should have(1).children
46
+ @variant2.remove
47
+ @name1.should have(0).children
48
+ end
49
+ end
50
+
51
+ end # of describe self
52
+ end # of module
@@ -0,0 +1,34 @@
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
+ if RUBY_PLATFORM =~ /java/
7
+ module Java::JavaLang::Iterable
8
+ describe self do
9
+ before(:each) do
10
+ @tm = get_used_tm_sys_tm
11
+ end
12
+ it "should respond to :first" do
13
+ java.util.HashSet.new.should respond_to(:first)
14
+ end
15
+ describe "#first" do
16
+ it "should give back one containee of the Iterable" do
17
+ topic = @tm.get!("Person")
18
+ names = [topic.create_name("Name1"), topic.create_name("Name2"), topic.create_name("Name3")]
19
+ topic.names.should be_a_kind_of Enumerable
20
+ lambda{topic.names.first}.should_not raise_error
21
+ names.should include topic.names.first
22
+ end
23
+ it "should give back nil if the Set is empty" do
24
+ topic = @tm.get!("Person")
25
+ set = topic.occurrences
26
+ set.should be_empty
27
+ set.should be_a_kind_of(Enumerable)
28
+ set.first.should be_nil
29
+ end
30
+
31
+ end
32
+ end # of describe self
33
+ end
34
+ end
@@ -0,0 +1,44 @@
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
7
+ class TMAPI
8
+ describe self do
9
+
10
+ describe "#create" do
11
+ before(:all) do
12
+ @connection = RTM.connect(:implementation => implementation_for_spec)
13
+ end
14
+ it "should create a topic map given a base locator (String)" do
15
+ tm = @connection.create("a:b")
16
+ tm.should be_a_kind_of RTM::TopicMap
17
+ end
18
+ it "should create a topic map given a base locator (Locator)" do
19
+ loc = @connection.create_locator("a:b")
20
+ tm = @connection.create(loc)
21
+ tm.should be_a_kind_of RTM::TopicMap
22
+ end
23
+ it "should be allowed to call create_topic_map also" do
24
+ @connection.method(:create).should == @connection.method(:create_topic_map)
25
+ end
26
+ it "should be allowed to call createTopicMap also" do
27
+ @connection.method(:create).should == @connection.method(:createTopicMap)
28
+ end
29
+ end
30
+
31
+ describe "#create_locator" do
32
+ before(:all) do
33
+ @connection = RTM.connect(:implementation => implementation_for_spec)
34
+ end
35
+ it "should create a locator given a String reference" do
36
+ locator = @connection.create_locator("a:b")
37
+ locator.should be_a_kind_of RTM::Locator
38
+ locator.reference.should == "a:b"
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,26 @@
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
+ # if implementation_for_spec == :sesametm
7
+ #
8
+ # module RTM::TopicMap
9
+ # describe self do
10
+ # before(:each) do
11
+ # @tm = get_used_tm_sys_tm
12
+ # end
13
+ # after(:each) do
14
+ # @tm.close
15
+ # end
16
+ # describe "#input" do
17
+ # it "should be called" do
18
+ # @tm.should respond_to(:input)
19
+ # @tm.input("")
20
+ # end
21
+ # end
22
+ #
23
+ # end
24
+ # end
25
+ #
26
+ # end
data/spec/rtm_spec.rb ADDED
@@ -0,0 +1,94 @@
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
+ describe RTM do
7
+ # describe "#[]" do
8
+ # it "should be empty if no TopicMapSystems are created" do
9
+ # RTM[].should be_empty
10
+ # end Fails since already reated tms are found
11
+ # end
12
+ describe "#connect" do
13
+ it "should have a TMAPI engine as default backend" do
14
+ tms_tmapi = RTM.connect(:implementation => implementation_for_spec)
15
+ tms_tmapi.should be_a_kind_of RTM::TopicMapSystem
16
+ tms_tmapi.should be_a_kind_of RTM::JavaTMAPI
17
+ tms_tmapi.should be_a_kind_of org.tmapi.core.TopicMapSystem
18
+ end
19
+ it "should allow multiple backends of the same kind in case of TMAPI" do
20
+ if RTM[implementation_for_spec]
21
+ number_of_already_existing_connections = RTM[implementation_for_spec].length
22
+ else
23
+ number_of_already_existing_connections = 0
24
+ end
25
+ tms1 = RTM.connect(:implementation => implementation_for_spec)
26
+ tms2 = RTM.connect(:implementation => implementation_for_spec)
27
+ tms1.should_not == tms2
28
+ number_of_already_existing_connections.should == RTM[implementation_for_spec].length - 2
29
+ end
30
+ # if ar_available?
31
+ # it "should allow only one classic RTM Active Record connection" do
32
+ # pending "extract active record specs to be run only by activerecord"
33
+ # false.should be true # early exit
34
+ # tmsar1 = RTM.connect :implementation => :activerecord
35
+ # RTM[:activerecord].size.should == 1
36
+ # tmsar2 = RTM.connect :implementation => :activerecord
37
+ # pending
38
+ # RTM[:activerecord].size.should == 1
39
+ # tmsar2.should == tmsar1
40
+ # tmsar1.should be_a_kind_of RTM::TopicMapSystem
41
+ # tmsar1.should_not be_a_kind_of RTM::JavaTMAPI
42
+ # tmsar1.should_not be_a_kind_of org.tmapi.core.TopicMapSystem
43
+ # end
44
+ # end
45
+ end
46
+
47
+ describe "#connections" do
48
+ it "should give back a Hash containing all connections if some exist" do
49
+ connections = RTM.connections
50
+ connections.should be_a_kind_of Hash
51
+ #TODO how to test this?
52
+ end
53
+ end
54
+
55
+ describe "#[]" do
56
+ # TODO
57
+ end
58
+
59
+ end
60
+
61
+ # if ar_available?
62
+ # describe RTM::AR do
63
+ # require File.dirname(__FILE__) + '/../test/base_unit_test.rb'
64
+ # require 'test/unit/ui/console/testrunner'
65
+ #
66
+ # it "should run the UNIT base_test without errors" do
67
+ # test_connect = BaseTest.new "test_connect"
68
+ # res1 = Test::Unit::UI::Console::TestRunner.run test_connect
69
+ # res1.error_count.should == 0
70
+ # res1.failure_count.should == 0
71
+ # test_sugar_hash_access = BaseTest.new "test_sugar_hash_access"
72
+ # res2 = Test::Unit::UI::Console::TestRunner.run test_sugar_hash_access
73
+ # res2.error_count.should == 0
74
+ # res2.failure_count.should == 0
75
+ # end
76
+ # end
77
+ # end
78
+
79
+ # describe "TMAPI with old base_test" do
80
+ # require "spec/old_base_unit_test_tmapi.rb"
81
+ # require 'test/unit/ui/console/testrunner'
82
+ # it "should run the UNIT base_test without errors for the TMAPI, too" do
83
+ # pending "first is not supported for Java::GnuTrove::THashSet" do
84
+ # test_connect = BaseTest.new "test_connect"
85
+ # res1 = Test::Unit::UI::Console::TestRunner.run test_connect
86
+ # res1.error_count.should == 0
87
+ # res1.failure_count.should == 0
88
+ # test_sugar_hash_access = BaseTest.new "test_sugar_hash_access"
89
+ # res2 = Test::Unit::UI::Console::TestRunner.run test_sugar_hash_access
90
+ # res2.error_count.should == 0
91
+ # res2.failure_count.should == 0
92
+ # end
93
+ # end
94
+ # end
@@ -0,0 +1,23 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+
4
+ $: << File.join(File.dirname(__FILE__), "/../lib")
5
+
6
+ require 'spec'
7
+ require 'rtm'
8
+
9
+ def implementation_for_spec
10
+ engine = ENV['RTM_IMPLEMENTATION'] && ENV['RTM_IMPLEMENTATION'].to_sym || :ontopia # if env is nil, the "normal progress will go on" # TODO: remove ontopia, as it should be chosen by connect by default
11
+ end
12
+ def get_used_tm_sys
13
+ RTM.connect(:implementation => implementation_for_spec)
14
+ end
15
+
16
+ def get_used_tm_sys_tm
17
+ @basis = get_used_tm_sys
18
+ @basis.create("http://www.topicmapslab.de/")
19
+ end
20
+
21
+ def ar_available?
22
+ !Gem.source_index.find_name('activerecord').empty?
23
+ end
@@ -0,0 +1,161 @@
1
+ # Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
2
+ # License: Apache License, Version 2.0
3
+ #
4
+ # Some basic tests for the Active Reckord Backend, more to be added into the RSpecs:)
5
+
6
+ $: << File.join(File.dirname(__FILE__), "/../lib")
7
+
8
+ require 'rubygems'
9
+ require 'test/unit'
10
+ require 'rtm'
11
+
12
+ class BaseTest < Test::Unit::TestCase
13
+ # There are a bunch of global assertions in here so it cannot be parallelized
14
+ # with other tests, that's why it is all in one. What can we do about that?
15
+ def test_connect
16
+ base = RTM.connect(:implementation => :activerecord)
17
+ assert base, "Connection to memory backend failed"
18
+ assert_equal 0, base[].size, "There should be no topic maps in a newly created environment."
19
+ base_locator = "http://rtm.rubyforge.org/tests/base_test"
20
+ m = base.create base_locator
21
+ assert_equal 1, base[].size, "After creation of a topic map, there should be one."
22
+ assert_kind_of RTM::TopicMap, m, "RTM.create should create something which includes RTM::TopicMap"
23
+ assert_equal base_locator, m.base_locator, "The base_locator should be initialized properly."
24
+ assert m.respond_to?(:topics), "The topic map should respond to :topics"
25
+ assert m.respond_to?(:associations), "The topic map should respond to :topics"
26
+ assert_equal 0, m.topics.size, "A new topic map should have no topics."
27
+ assert_equal 0, m.associations.size, "A new topic map should have no associations."
28
+ assert m.reifier.nil?, "A new topic map should not be reified yet."
29
+ assert_equal 0, m.item_identifiers.size, "A new topic map should "
30
+ # assigning a reifier
31
+ m.reifier = "a_topic_which_reifies_the_topic_map"
32
+ assert_equal 1, m.topics.size, "A topic should have been created to reify the topic map."
33
+ assert_kind_of RTM::Topic, m.reifier, "A reifier should be a Topic."
34
+ assert_equal m, m.topics.first.reified, "The only topic out there should reify the map (not generally, but here)."
35
+ assert_equal m.base_locator, m.topics.first.reified.base_locator, "The only topic out there should reify the map. Check base locator."
36
+ assert_equal m.__getobj__, m.topics.first.reified.__getobj__, "The only topic out there should reify the map. Look inside."
37
+ t = m.create_topic
38
+ assert_equal 2, m.topics.size, "There should be 2 topics after creating the second one."
39
+ assert_kind_of RTM::Topic, t, "The created topic should really be one."
40
+ assert_kind_of RTM::TopicMap, m
41
+ assert_equal m, t.parent, "The Topic Map should be the parent of our new topic."
42
+ # The next tests may look a bit unneeded, but they at least also test the properties be available and initialized somehow.
43
+ assert_equal 0, t.item_identifiers.size, "New topic has no item_identifiers."
44
+
45
+ assert_equal 0, t.subject_identifiers.size, "New topic has no subject_identifiers."
46
+ assert_equal 0, t.subject_locators.size, "New topic has no subject_locators."
47
+ assert !t.valid?, "Without item identifiers nor subject identifiers the topic must not be valid."
48
+ assert_equal 0, t.names.size, "New topic has no names."
49
+ assert_equal 0, t.occurrences.size, "New topic has no occurrences."
50
+ assert_equal 0, t.roles_played.size, "New topic plays no roles."
51
+ assert_nil t.reified, "New topic does not reify a statement."
52
+ n = t.create_name "bla"
53
+ assert_equal 1, t.names.size, "The topic should have one name now."
54
+ assert_kind_of RTM::Name, n
55
+ assert_kind_of RTM::Topic, n.parent, "You won't believe but this should be a Topic and right now it not..."
56
+ # TODO the following assertion does not work - it crashes pp... but why?
57
+ # assert_equal t, n.parent, "The parent of the name should be the topic on which it was created."
58
+ assert_equal 0, n.item_identifiers.size, "I wonder if someone will ever read that."
59
+ assert_kind_of RTM::Name, n, "The topic name shoud be a TopicName... makes sence, he?"
60
+ assert_equal 0, n.variants.size, "According to Lars Heuer and Robert Barta that should always be 0, not only now."
61
+ #assert_nil n.value, "We haven't set a value yet, where should it come from."
62
+ assert_equal "bla", n.value
63
+ #assert_nil n.type, "I am really tired of writing this stuff."
64
+ assert_equal m.get(RTM::PSI[:name_type]), n.type
65
+ assert_equal 0, n.scope.size, "Should I really be more serious with this stuff?"
66
+ assert_nil n.reifier, "No, I guess not... who could ever stand that."
67
+ v = n.create_variant "v1", ["v1-scope"]
68
+ assert_equal 1, n.variants.size, "The topic should have one name now."
69
+ assert_kind_of RTM::Variant, v
70
+ assert_kind_of RTM::Name, v.parent, "You won't believe but this should be a Topic and right now it not..."
71
+ # TODO the following assertion does not work - it crashes pp... but why?
72
+ # assert_equal t, v.parent, "The parent of the name should be the topic on which it was created."
73
+ assert_equal 0, v.item_identifiers.size, "I wonder if someone will ever read that."
74
+ assert_kind_of RTM::Variant, v, "The variant should be a Variant... makes sence, he?"
75
+ #assert_nil v.value, "We haven't set a value yet, where should it come from."
76
+ assert_equal "v1", v.value
77
+
78
+ assert_nil v.datatype, "No datatype set, yet."
79
+
80
+ assert_equal 1, v.scope.size, "Should I really be more serious with this stuff?"
81
+ assert_nil v.reifier, "No, I guess not... who could ever stand that."
82
+ #assert !v.valid?
83
+ o = t.create_occurrence "otype", "val"
84
+ assert_equal 1, t.occurrences.size, "The topic should have one name now."
85
+ assert_kind_of RTM::Occurrence, o
86
+ assert_kind_of RTM::Topic, o.parent, "You won't believe but this should be a Topic and right now it not..."
87
+ # TODO the following assertion does not work - it crashes pp... but why?
88
+ # assert_equal t, o.parent, "The parent of the name should be the topic on which it was created."
89
+ assert_equal 0, o.item_identifiers.size, "I wonder if someone will ever read that."
90
+ assert_kind_of RTM::Occurrence, o, "The occurrence shoud be a Occurrence... makes sence, he?"
91
+ #assert_nil o.value, "We haven't set a value yet, where should it come from."
92
+ #assert_nil o.type, "I am really tired of writing this stuff."
93
+ assert_nil o.datatype
94
+ assert_equal 0, n.scope.size, "Should I really be more serious with this stuff?"
95
+ assert_nil n.reifier, "No, I guess not... who could ever stand that."
96
+ a = m.create_association "atype"
97
+ #assert_nil a.type
98
+ assert_equal 0, a.roles.size
99
+ assert_kind_of RTM::Association, a
100
+ assert_kind_of RTM::TopicMap, a.parent
101
+ assert_equal m, a.parent
102
+ assert_equal 0, a.scope.size
103
+ #assert !a.valid?
104
+ #r1 = a.create_role
105
+ #assert_nil r1.type
106
+ #assert_nil r1.player
107
+
108
+ #assert_kind_of RTM::Role, r1
109
+ #assert_kind_of RTM::Association, r1.parent
110
+ #assert_equal 1, a.roles.size
111
+ t.item_identifiers << "nr1"
112
+ assert_equal 1, t.item_identifiers.size
113
+ fii = t.item_identifiers.first
114
+ assert_equal "http://rtm.rubyforge.org/tests/base_test#nr1", fii.to_s
115
+ assert_kind_of RTM::Locator, fii
116
+ assert_kind_of RTM::ItemIdentifier, fii #needed?
117
+ # TODO: invalidate cache/reload value somehow
118
+ #assert_equal 1, m.item_identifiers.size, "If you see this, it is probably because TopicMap#item_identifiers.size is cached which is wrong in this case."
119
+
120
+ t.subject_identifiers << "si1"
121
+ fsi = t.subject_identifiers.first
122
+ assert_equal "si1", fsi.to_s
123
+ assert_kind_of RTM::Locator, fsi
124
+ assert_kind_of RTM::SubjectIdentifier, fsi #needed?
125
+
126
+ t.subject_locators << "sl1"
127
+ fsl = t.subject_locators.first
128
+ assert_equal "sl1", fsl.to_s
129
+ assert_kind_of RTM::Locator, fsl
130
+ assert_kind_of RTM::SubjectLocator, fsl #needed?
131
+
132
+ # to be in associations_test later:
133
+ tm = base.create "urn:/associations_test"
134
+ a1 = tm.create_association "urn:/assoc_type_with_absolute_uri"
135
+ assert_not_nil a1.type
136
+ assert_equal a1.type, tm.get("urn:/assoc_type_with_absolute_uri")
137
+ a2 = tm.create_association "urn:/assoc_type_with_absolute_uri_using_hash"
138
+ assert_not_nil a2.type
139
+ assert_equal a2.type, tm.get("urn:/assoc_type_with_absolute_uri_using_hash")
140
+
141
+ a3 = tm.create_association "relative_type"
142
+ assert_not_nil a3.type
143
+ assert_equal a3.type, tm.get("relative_type")
144
+
145
+ end
146
+ def test_sugar_hash_access
147
+ base = RTM.connect(:implementation => :activerecord)
148
+ tm = base.create "a:b"
149
+ bla = tm.get!("bla")
150
+ bla["-name"] = "test"
151
+ n = bla["-name"].first
152
+ assert_equal "test", n.value
153
+ blau = tm.get!("blau")
154
+ blau["hex"] = "#0000ff"
155
+ assert_equal "#0000ff", blau["hex"].first.value
156
+ blau["hex @short"] = "#00f"
157
+ assert_equal "#0000ff", blau["hex"].first.value
158
+ assert_equal "#00f", blau["hex @short"].first.value
159
+ end
160
+
161
+ end