# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::TopicMap describe self do before(:each) do @tm = get_used_tm_sys_tm @tm.should be_a_kind_of RTM::TopicMap end after(:each) do @tm.close end describe "#topics" do before(:each) do @a,@b,@c,@d,@e,@f = @tm.get!(["a","b","c","d","e","f"]) @a.add_type(@b) @d.add_type(@f) @e.add_type(@f) end it "should give back all topics in the topic map when called without type" do @tm.topics.size.should == 6 @tm.topics.should include(@a,@b,@c,@d,@e,@f) end it "should give back all topics that are instances of the specified type" do @tm.topics(@b).size.should == 1 @tm.topics("b").should include(@a) ### @tm.topics(@f).size.should == 2 @tm.topics("f").should include(@d,@e) ### @tm.topics(@c).should be_empty @tm.topics("c").should be_empty ### @tm.topics("not_existing").should be_empty end end describe "#construct_by_id" do it "should give back the topic map if the id of the topic map is given" do pending if implementation_for_spec == :tinytim @tm.construct_by_id(@tm.id).should_not be_nil @tm.construct_by_id(@tm.id).should == @tm end end describe "#add_prefix" do before(:each) do @reference_org = "http://www.example.org" @reference_com = "http://www.example.com" end it "should raise an error if the identifier or reference are not Strings" do lambda{@tm.add_prefix(1, "www.example.org")}.should raise_error lambda{@tm.add_prefix("a", 2)}.should raise_error end it "should be allowed to set a prefix" do # one prefix xsd per default @tm.prefixes.size.should == 1 @tm.prefixes["xsd"] == RTM::PREFIX[:xsd] @tm.add_prefix("a", @reference_org) @tm.prefixes.size.should == 2 @tm.prefixes["a"].should == @reference_org end it "should replace the reference if prefix already exists" do @tm.add_prefix("a", @reference_org) @tm.prefixes["a"].should == @reference_org @tm.add_prefix("a", @reference_com) @tm.prefixes["a"].should == @reference_com end it "should give back the prefixes-Hash" do @tm.add_prefix("a", @reference_com).should == @tm.prefixes @tm.add_prefix("g", @reference_org).should == @tm.prefixes end it "should raise an error if identifier equals sl, si or ii" do lambda{@tm.add_prefix("sl", @reference_org)}.should raise_error lambda{@tm.add_prefix("si", @reference_org)}.should raise_error lambda{@tm.add_prefix("ii", @reference_org)}.should raise_error end it "should raise an error if identifier or reference is empty" do lambda{@tm.add_prefix("", @reference_org)}.should raise_error lambda{@tm.add_prefix("test", "")}.should raise_error lambda{@tm.add_prefix("", "")}.should raise_error end end describe "#delete_prefix" do before(:each) do # one default prefix 'xsd' @tm.add_prefix("a", "http://www.example.org/a/") @tm.add_prefix("b", "http://www.example.org/b/") @tm.add_prefix("c", "http://www.example.org/c/") end it "should delete the right prefix" do @tm.prefixes.length.should == 4 @tm.delete_prefix("a").size.should == 3 @tm.find_prefix(:identifier => "a").should be_empty @tm.find_prefix(:identifier => "b").should_not be_empty @tm.find_prefix(:identifier => "c").should_not be_empty end it "should delete the right prefix if the reference is given" do @tm.prefixes.length.should == 4 @tm.delete_prefix("a","http://www.example.org/a/").size.should == 3 @tm.find_prefix(:identifier => "a").should be_empty @tm.find_prefix(:identifier => "b").should_not be_empty @tm.find_prefix(:identifier => "c").should_not be_empty end it "should delete nothing if identifier does not match" do @tm.prefixes.length.should == 4 @tm.delete_prefix("x").size.should == 4 @tm.find_prefix(:identifier => "a").should_not be_empty @tm.find_prefix(:identifier => "b").should_not be_empty @tm.find_prefix(:identifier => "c").should_not be_empty end it "should delete nothing if reference does not match" do @tm.prefixes.length.should == 4 @tm.delete_prefix("a","x").size.should == 4 @tm.find_prefix(:identifier => "a").should_not be_empty @tm.find_prefix(:identifier => "b").should_not be_empty @tm.find_prefix(:identifier => "c").should_not be_empty end it "should be the alias for del_prefix" do @tm.method(:del_prefix).should == @tm.method(:delete_prefix) end end describe "#find_prefix" do it "should be tested" end describe "#create_topic_by" do it "should allow creating a new topic by subject identifier" do identifier = "subject:identifier" topics = @tm.create_topic_by([identifier]) topics.should be_a_kind_of Array topics.length.should == 1 topic = topics.first topic.should be_a_kind_of RTM::Topic topic.getSubjectIdentifiers.size.should == 1 topic.getSubjectIdentifiers.map{|i| i.value }.should include(identifier) end it "should allow creating a new topic by item identifier with ^-prefix" do identifier = "item:identifier" topic = @tm.create_topic_by("^" + identifier) topic.should be_a_kind_of RTM::Topic topic.getItemIdentifiers.size.should == 1 topic.getItemIdentifiers.map{|i| i.value }.should include(identifier) end it "should allow creating a new topic by subject locator with =-prefix" do identifier = "subject:locator" topic = @tm.create_topic_by("=" + identifier) topic.should be_a_kind_of RTM::Topic topic.getSubjectLocators.size.should == 1 topic.getSubjectLocators.map{|i| i.value }.should include(identifier) end it "should allow creating a new topic by subject identifier with si:-prefix" do identifier = "subject:identifier" topic = @tm.create_topic_by("si:" + identifier) topic.should be_a_kind_of RTM::Topic topic.getSubjectIdentifiers.size.should == 1 topic.getSubjectIdentifiers.map{|i| i.value }.should include(identifier) end it "should allow creating a new topic by item identifier with ii:-prefix" do identifier = "item:identifier" topic = @tm.create_topic_by("ii:" + identifier) topic.should be_a_kind_of RTM::Topic topic.getItemIdentifiers.size.should == 1 topic.getItemIdentifiers.map{|i| i.value }.should include(identifier) end it "should allow creating new topics by an Array of identifiers" do identifier = ["subject:identifier", "^item:identifier", "subject:locator", "si:subject:identifier", "ii:item:identifier" ] identifier.should be_a_kind_of Array topic_array = @tm.create_topic_by(identifier) topic_array.should be_a_kind_of Array topic_array.size.should == identifier.length topic_array.each{|t| t.should be_a_kind_of RTM::Topic} end end describe "#get" do before(:each) do @topic1 = @tm.create_topic_by_subject_identifier("si") @tm.create_topic_by_subject_identifier("si-test") @topic2 = @tm.create_topic_by_subject_locator("sl") @tm.create_topic_by_subject_locator("sl-test") @topic3 = @tm.create_topic_by_item_identifier("ii") @tm.create_topic_by_item_identifier("ii-test") end it "should be tested with Topics" do @topic1.should be_a_kind_of RTM::Topic @topic2.should be_a_kind_of RTM::Topic @topic3.should be_a_kind_of RTM::Topic end it "should give back nil if argument is nil" do @tm.get(nil).should be_nil end it "should give back nil if argument is an empty String" do @tm.get("").should be_nil end it "should give back nil if argument equals 'si:'" do @tm.get("si:").should be_nil end it "should give back nil if argument equals '='" do @tm.get("=").should be_nil end it "should give back nil if argument equals 'sl:'" do @tm.get("sl:").should be_nil end it "should give back nil if argument equals '^'" do @tm.get("^").should be_nil end it "should give back nil if argument equals 'ii:'" do @tm.get("ii:").should be_nil end it "should give back a Topic if argument is a Topic" do @tm.get(@topic1).should == @topic1 @tm.get(@topic2).should == @topic2 @tm.get(@topic3).should == @topic3 end it "should give back a Topic if argument is a Locator and Topic has the Locator as subject identifier" do @tm.get(@tm.create_locator("si")).should == @topic1 end it "should give back a Topic if argument is a Locator and Topic has the Locator as item identifier" do @tm.get(@tm.create_locator("ii")).should == @topic3 end it "should give back nil if argument is a Locator and Topic has the Locator as subject locator" do @tm.get(@tm.create_locator("sl")).should be_nil end it "should give back a Topic if argument is a String (absolute) and Topic has String as subject identifier" do @tm.get("http://www.topicmapslab.de/si").should == @topic1 @tm.get("si:http://www.topicmapslab.de/si").should == @topic1 end it "should give back a Topic if argument is a String (absolute) and Topic has String as subject identifier" do @tm.get("sl:http://www.topicmapslab.de/sl").should == @topic2 @tm.get("=http://www.topicmapslab.de/sl").should == @topic2 end it "should give back a Topic if argument is a String (absolute) and Topic has String as subject identifier" do @tm.get("ii:http://www.topicmapslab.de/ii").should == @topic3 @tm.get("^http://www.topicmapslab.de/ii").should == @topic3 end it "should give back a Topic if argument is a String (relative) and Topic has String as subject identifier" do @tm.get("si").should == @topic1 @tm.get("si:si").should == @topic1 end it "should give back a Topic if argument is a String (relative) and Topic has String as subject identifier" do @tm.get("sl:sl").should == @topic2 @tm.get("=sl").should == @topic2 end it "should give back a Topic if argument is a String (relative) and Topic has String as subject identifier" do @tm.get("ii:ii").should == @topic3 @tm.get("^ii").should == @topic3 end it "should give back an empty Array if argument equals '[]'" do @tm.get([]).should == [] end it "should give back nil if there is no Topic which has the argument (Locator) as identifier" do @tm.get(@tm.create_locator("something")).should be_nil end it "should give back nil if there is no Topic which has the argument (String, si) as identifier" do @tm.get("something").should be_nil @tm.get("http://www.topicmapslab.de/something").should be_nil @tm.get("si:something").should be_nil @tm.get("si:http://www.topicmapslab.de/something").should be_nil end it "should give back nil if there is no Topic which has the argument (String, sl) as identifier" do @tm.get("sl:something").should be_nil @tm.get("sl:http://www.topicmapslab.de/something").should be_nil @tm.get("=something").should be_nil @tm.get("=http://www.topicmapslab.de/something").should be_nil end it "should give back nil if there is no Topic which has the argument (String, ii) as identifier" do @tm.get("ii:something").should be_nil @tm.get("ii:http://www.topicmapslab.de/something").should be_nil @tm.get("^something").should be_nil @tm.get("^http://www.topicmapslab.de/something").should be_nil end it "should give back an Array of Topics and nils if argument is Array of identifiers and nils" do array = ["si","","=sl","",nil,"something","^ii",@tm.create_locator("blub")] @tm.get(array).size.should == array.size @tm.get(array).should == array.map{|i| @tm.get(i)} end it "should give back a Multiarray of Topics and nils if argument is a Multiarray of identifiers and nils" do array = [["si","","=sl","",nil,"something"],"^ii",@tm.create_locator("blub")] @tm.get(array).size.should == array.size @tm.get(array)[0].should == @tm.get(["si","","=sl","",nil,"something"]) @tm.get(array)[1].should == @tm.get("^ii") @tm.get(array)[2].should == @tm.get(@tm.create_locator("blub")) end it "should handle identifier which are qnames (get)" do @tm.add_prefix("x","http://www.example.org/x/") @tm.add_prefix("y","http://www.example.org/y/") topic = @tm.create_topic_by_subject_identifier("http://www.example.org/x/something") @tm.get("x:something").should == topic topic2 = @tm.create_topic_by_item_identifier("http://www.example.org/y/something") @tm.get("ii:y:something").should == topic2 end end describe "#get!" do before(:each) do @tm.create_topic_by_subject_identifier("dummy_si") @tm.create_topic_by_subject_locator("dummy_sl") @tm.create_topic_by_item_identifier("dummy_ii") end it "should give back nil if the argument is nil" do @tm.get!(nil).should be_nil end it "should give back an empty Array if the argument equals []" do @tm.get!([]).should == [] end it "should give back the argument if argument is a Topic" do topic = @tm.create_topic topic.should be_a_kind_of RTM::Topic @tm.get!(topic).should == topic end it "should give back a Topic if argument is a Locator and the Topic defined by the Locator (si) already exists" do locator = @tm.create_locator("http://www.example.org/uni-leipzig") locator.should be_a_kind_of RTM::Locator topic = @tm.create_topic_by_subject_identifier(locator) topic.should be_a_kind_of RTM::Topic @tm.get!(locator).should == topic end it "should give back a Topic if argument is a Locator and the Topic defined by the Locator (ii) already exists" do locator = @tm.create_locator("http://www.example.org/uni-leipzig") locator.should be_a_kind_of RTM::Locator topic = @tm.create_topic_by_item_identifier(locator) topic.should be_a_kind_of RTM::Topic @tm.get!(locator).should == topic end it "should give back a Topic if argument is a String(absolute IRI,si) and the Topic defined by the String already exists" do string = "http://www.example.org/uni-leipzig" topic = @tm.create_topic_by_subject_identifier(@tm.create_locator(string)) @tm.get!(string).should == topic @tm.get!("si:" + string).should == topic end it "should give back a Topic if argument is a String(absolute IRI,sl) and the Topic defined by the String already exists" do string = "http://www.example.org/uni-leipzig" topic = @tm.create_topic_by_subject_locator(@tm.create_locator(string)) @tm.get!("sl:" + string).should == topic @tm.get!("=" + string).should == topic end it "should give back a Topic if argument is a String(absolute IRI,ii) and the Topic defined by the String already exists" do string = "http://www.example.org/uni-leipzig" topic = @tm.create_topic_by_item_identifier(@tm.create_locator(string)) @tm.get!("ii:" + string).should == topic @tm.get!("^" + string).should == topic end it "should give back a Topic if argument is a String(relative IRI,si) and the Topic defined by the String already exists" do string = "get-test" topic = @tm.create_topic_by_subject_identifier(@tm.create_locator(string)) @tm.get!(string).should == topic @tm.get!("si:" + string).should == topic end it "should give back a Topic if argument is a String(relative IRI,sl) and the Topic defined by the String already exists" do string = "get-test" topic = @tm.create_topic_by_subject_locator(@tm.create_locator(string)) @tm.get!("sl:" + string).should == topic @tm.get!("=" + string).should == topic end it "should give back a Topic if argument is a String(relative IRI,ii) and the Topic defined by the String already exists" do string = "get-test" topic = @tm.create_topic_by_item_identifier(@tm.create_locator(string)) @tm.get!("ii:" + string).should == topic @tm.get!("^" + string).should == topic end it "should create a Topic and give back this Topic if argument is a String (si) and no Topic has this String as subject identifier" do string = "get-test" topic = @tm.get!(string) topic.should be_a_kind_of RTM::Topic topic.item.should be_nil topic.locators.should be_empty topic.indicators.size.should == 1 topic.indicators.first.should == ("http://www.topicmapslab.de/" + string) end it "should create a Topic and give back this Topic if argument is a String (si, starting with 'si:') and no Topic has this String as subject identifier" do string = "get-test" topic = @tm.get!("si:" + string) topic.should be_a_kind_of RTM::Topic topic.item.should be_nil topic.locators.should be_empty topic.indicators.size.should == 1 topic.indicators.first.should == ("http://www.topicmapslab.de/" + string) end it "should give back a Topic if argument is a String (si) and and a Topic which has this String as item identifier already exists" do string = "get-test" topic1 = @tm.create_topic_by_subject_locator(@tm.create_locator(string)) topic2 = @tm.create_topic_by_item_identifier(@tm.create_locator(string)) @tm.get!(string).should == topic2 topic2.item.should == ("http://www.topicmapslab.de/" + string) topic2.indicators.size.should == 1 topic2.indicators.first.should == ("http://www.topicmapslab.de/" + string) topic2.locators.should be_empty end it "should give back a Topic if argument is a String (si, starting with 'si:') and and a Topic which has this String as item identifier already exists" do string = "get-test" topic1 = @tm.create_topic_by_subject_locator(@tm.create_locator(string)) topic2 = @tm.create_topic_by_item_identifier(@tm.create_locator(string)) @tm.get!("si:" + string).should == topic2 topic2.item.should == ("http://www.topicmapslab.de/" + string) topic2.indicators.size.should == 1 topic2.indicators.first.should == ("http://www.topicmapslab.de/" + string) topic2.locators.should be_empty end it "should create a Topic and give back this Topic if argument is a String (sl, starting with 'sl:') and no Topic has this String as subject locator" do string = "get-test" topic = @tm.get!("sl:" + string) topic.should be_a_kind_of RTM::Topic topic.item.should be_nil topic.locators.size.should == 1 topic.locators.first.should == ("http://www.topicmapslab.de/" + string) topic.indicators.should be_empty end it "should create a Topic and give back this Topic if argument is a String (sl, starting with '=') and no Topic has this String as subject locator" do string = "get-test" topic = @tm.get!("=" + string) topic.should be_a_kind_of RTM::Topic topic.item.should be_nil topic.locators.size.should == 1 topic.locators.first.should == ("http://www.topicmapslab.de/" + string) topic.indicators.should be_empty end it "should create a Topic and give back this Topic if argument is a String (ii, starting with 'ii:') and no Topic has this String as subject locator" do string = "get-test" topic = @tm.get!("ii:" + string) topic.should be_a_kind_of RTM::Topic topic.item.should == ("http://www.topicmapslab.de/" + string) topic.locators.should be_empty topic.indicators.should be_empty topic.indicators.should be_empty end it "should create a Topic and give back this Topic if argument is a String (ii, starting with '^') and no Topic has this String as subject locator" do string = "get-test" topic = @tm.get!("^" + string) topic.should be_a_kind_of RTM::Topic topic.item.should == ("http://www.topicmapslab.de/" + string) topic.locators.should be_empty topic.indicators.should be_empty end it "should give back a Topic if argument is a String (ii, starting with 'ii:') and and a Topic which has this String as subject identifier already exists" do string = "get-test" topic1 = @tm.create_topic_by_subject_locator(@tm.create_locator(string)) topic2 = @tm.create_topic_by_subject_identifier(@tm.create_locator(string)) @tm.get!("ii:" + string).should == topic2 topic2.item.should == ("http://www.topicmapslab.de/" + string) topic2.indicators.size.should == 1 topic2.indicators.first.should == ("http://www.topicmapslab.de/" + string) topic2.locators.should be_empty end it "should give back a Topic if argument is a String (ii, starting with '^') and and a Topic which has this String as subject identifier already exists" do string = "get-test" topic1 = @tm.create_topic_by_subject_locator(@tm.create_locator(string)) topic2 = @tm.create_topic_by_subject_identifier(@tm.create_locator(string)) @tm.get!("^" + string).should == topic2 topic2.item.should == ("http://www.topicmapslab.de/" + string) topic2.indicators.size.should == 1 topic2.indicators.first.should == ("http://www.topicmapslab.de/" + string) topic2.locators.should be_empty end it "should create a Topic (with si) if argument is a Locator and no Topic has this Locator as si or ii" do locator = @tm.create_locator("si") @tm.create_topic_by_subject_locator(locator) topic = @tm.get!(locator) topic.locators.should be_empty topic.item.should be_nil topic.indicators.size.should == 1 topic.indicators.first.should == ("http://www.topicmapslab.de/" + "si") end it "should give back a Topic (with si) if argument is a Locator and a Topic has this Locator as ii" do locator = @tm.create_locator("si") topic = @tm.create_topic_by_item_identifier(locator) @tm.get!(locator).should == topic topic.locators.should be_empty topic.item.should == ("http://www.topicmapslab.de/" + "si") topic.indicators.should be_empty end it "should allow to create/get several Topics wheras some already exist and others not" do array = ["dummy_si",@tm.create_locator("something"),"sl:Hans"] @tm.get!(array).size.should == array.size @tm.get!(array).should == array.map{|i| @tm.get!(i)} end it "should give back a Multiarray of Topics if argument is a Multiarray of identifiers and nils" do array = [["si","","=sl","",nil,"something"],"^ii",@tm.create_locator("blub")] @tm.get!(array).size.should == array.size @tm.get!(array)[0].should == @tm.get!(["si","","=sl","",nil,"something"]) @tm.get!(array)[1].should == @tm.get!("^ii") @tm.get!(array)[2].should == @tm.get!(@tm.create_locator("blub")) end it "should handle identifier which are qnames" do @tm.add_prefix("x","http://www.example.org/x/") @tm.add_prefix("y","http://www.example.org/y/") topic = @tm.get!("x:something") topic.indicators.should include("http://www.example.org/x/something") topic2 = @tm.get!("sl:y:something") topic2.locators.should include("http://www.example.org/y/something") end end describe "#createLocator" do it "should raise an error if identifier is relative" do if implementation_for_spec == :tinytim pending do lambda{@tm.createLocator("xyz")}.should raise_error end else lambda{@tm.createLocator("xyz")}.should raise_error end end end describe "#create_locator" do before(:each) do @prefix_identifier = "x" @reference = "http://www.example.org/" end it "should handle qname if localpart of a qname contains a '/'" do @tm.add_prefix(@prefix_identifier, @reference) qname = @prefix_identifier + ":" + "part/something" topic = @tm.get!(qname) topic.indicators.should include(qname) end it "should handle qnames" do @tm.add_prefix(@prefix_identifier, @reference) qname = @prefix_identifier + ":" + "something" topic = @tm.get!(qname) topic.should be_a_kind_of RTM::Topic topic.indicators.should include(@reference + "something") end it "should use the base_iri to create absolute IRIS" do @tm.create_locator("xxx").value.should == (@tm.base_iri + "xxx") end end describe "#instances" do before(:each) do @t1, @t2, @t3, @t4, @t5, @t6 = @tm.get!(["t1","t2", "t3", "t4", "t5", "t6"]) end it "should give back all instances in the topic map when called without type without duplicates" do @t1.add_types(@t2, @t3) @t4.add_type(@t5) @t6.add_types(@t1, @t4) @tm.instances.size.should == 3 @tm.instances.should include(@t1, @t4, @t6) end it "should give back all instances of the specified type" do @a,@b,@c,@d,@e,@f = @tm.get!(["a","b","c","d","e","f"]) @a.add_type(@b) @d.add_type(@f) @e.add_type(@f) @tm.instances(@b).size.should == 1 @tm.instances("b").should include(@a) ### @tm.instances(@f).size.should == 2 @tm.instances("f").should include(@d,@e) ### @tm.instances(@c).should be_empty @tm.instances("c").should be_empty ### @tm.instances("not_existing").should be_empty end end describe "#children" do it "should give back an Array of all Associations and Topics contained in the TopicMap" do topic1 = @tm.create_topic_by("topic1") topic2 = @tm.create_topic_by("topic2") assoc_type1 = @tm.create_topic_by("asso1") assoc_type2 = @tm.create_topic_by("asso2") assoc1 = @tm.create_association(assoc_type1) assoc2 = @tm.create_association(assoc_type2) topic1.should be_a_kind_of RTM::Topic topic2.should be_a_kind_of RTM::Topic assoc1.should be_a_kind_of RTM::Association assoc2.should be_a_kind_of RTM::Association @tm.children.size.should == 6 @tm.children.should include(topic1) @tm.children.should include(topic2) @tm.children.should include(assoc_type1) @tm.children.should include(assoc_type2) @tm.children.should include(assoc1) @tm.children.should include(assoc2) end end describe "#create_association" do it "should create an association (in the unconstrained scope) with given type if type is a String" do assoc = @tm.create_association("assoc_type") assoc.should be_a_kind_of RTM::Association assoc.type.should == @tm.get("assoc_type") assoc.scope.should be_empty end it "should create an association (in the unconstrained scope) with given type if type is a Locator" do locator = @tm.create_locator("assoc_type") assoc = @tm.create_association(locator) assoc.should be_a_kind_of RTM::Association assoc.type.should == @tm.get("assoc_type") assoc.scope.should be_empty end it "should create an association (in the unconstrained scope) with given type if type is a Topic" do assoc_type = @tm.get!("assoc_type") assoc = @tm.create_association(assoc_type) assoc.should be_a_kind_of RTM::Association assoc.type.should == assoc_type assoc.scope.should be_empty end it "should raise an error if if type is not a Topic or Topic-Reference" do lambda{@tm.create_association(["type"])}.should raise_error lambda{@tm.create_association(1)}.should raise_error end it "should create an association with given type and scope = empty Array" do assoc = @tm.create_association("assoc_type",[]) assoc.should be_a_kind_of RTM::Association assoc.type.should == @tm.get("assoc_type") assoc.scope.should be_empty end it "should create an association with given type and scope = Array of Topic/Topic-References" do locator = @tm.create_locator("theme3") theme = @tm.get!("theme2") assoc = @tm.create_association("assoc_type",["theme1",theme,locator]) assoc.should be_a_kind_of RTM::Association assoc.type.should == @tm.get("assoc_type") assoc.should have(3).scope assoc.scope.should include @tm.get("theme1"), @tm.get(locator),theme end it "should create an association with given type and roles" do assoc = @tm.create_association("Country-Capital","Capital" => "Berlin", "Country" => "Germany") assoc.should be_a_kind_of RTM::Association assoc.should have(2).roles assoc.type.should == @tm.get("Country-Capital") assoc.roles.map{|r| r.type}.should include @tm.get("Capital"), @tm.get("Country") assoc.roles.map{|r| r.player}.should include @tm.get("Berlin"), @tm.get("Germany") end it "should create an association with given type, scope and roles" do assoc = @tm.create_association("Country-Capital",["2008"],"Capital" => "Berlin", "Country" => "Germany") assoc.should be_a_kind_of RTM::Association assoc.should have(2).roles assoc.type.should == @tm.get("Country-Capital") assoc.should have(1).scope assoc.scope.should include @tm.get("2008") assoc.roles.map{|r| r.type}.should include @tm.get("Capital"), @tm.get("Country") assoc.roles.map{|r| r.player}.should include @tm.get("Berlin"), @tm.get("Germany") end it "should raise an error if scope is not an Array" do lambda{@tm.create_association("assoc_type","scope")}.should raise_error lambda{@tm.create_association("assoc_type","scope","roletype" => "player")}.should raise_error end it "should raise an error if roles are not in a Hash" do lambda{@tm.create_association("assoc_type","role")}.should raise_error lambda{@@tm.create_association("assoc_type",["theme1", "theme2"],"role")}.should raise_error end it "should create an association with given type and roles with same roletype" do assoc = @tm.create_association("Neighbouring_Countries","Neighbouring_Country" => ["Germany", "France"]) assoc.should be_a_kind_of RTM::Association assoc.should have(2).roles assoc.type.should == @tm.get("Neighbouring_Countries") assoc.roles.map{|r| r.type}.should include @tm.get("Neighbouring_Country") assoc.roles.map{|r| r.player}.should include @tm.get("France"), @tm.get("Germany") end end describe "#associations" do before(:each) do @assoc1 = @tm.create_association("at1") @assoc2 = @tm.create_association("at2", "rt21" => "rp21") @assoc3 = @tm.create_association("at3", "rt31" => "rp31", "rt32" => "rp32") @assoc4 = @tm.create_association("at3") @no_assoc_type = @tm.get!("no_assoc_type") end it "should give back all associations" do @tm.should have(4).associations @tm.associations.should include(@assoc1, @assoc2, @assoc3, @assoc4) end it "should give back some associations if argument type (String) is given" do @tm.associations("at1").size.should == 1 @tm.associations("at1").should include(@assoc1) @tm.associations("at3").size.should == 2 @tm.associations("at3").should include(@assoc3, @assoc4) @tm.associations("no_assoc_type").should be_empty end it "should give back some associations if argument type (Locator) is given" do at2_loc = @tm.create_locator("at2") at2_loc.should_not be_nil at3_loc = @tm.create_locator("at3") at3_loc.should_not be_nil @tm.associations(at2_loc).size.should == 1 @tm.associations(at2_loc).should include(@assoc2) @tm.associations(at3_loc).size.should == 2 @tm.associations(at3_loc).should include(@assoc3, @assoc4) @tm.associations(@tm.create_locator("no_assoc_type")).should be_empty end it "should give back some associations if argument type (Topic) is given" do at1 = @tm.get("at1") at1.should_not be_nil at3 = @tm.get("at3") at3.should_not be_nil @tm.associations(at1).size.should == 1 @tm.associations(at1).should include(@assoc1) @tm.associations(at3).size.should == 2 @tm.associations(at3).should include(@assoc3, @assoc4) @tm.associations(@no_assoc_type).should be_empty end it "should raise error if argument type is nil" do lambda{@tm.associations(nil)}.should raise_error end it "should raise error if argument type is an array" do lambda{@tm.associations(["a"])}.should raise_error end it "should give back no associations if argument type is a String but no Topic with this identifier exists" do @tm.associations("not_existing").should be_empty end it "should give back no associations if argument type is a Locator but no Topic with this identifier exists" do @tm.associations(@tm.create_locator("not_existing")).should be_empty end end describe "and statistic methods:" do before(:each) do @tm.from_xtm(File.dirname(__FILE__) + "/../../../resources/toyTM.xtm") end describe "#names" do it "should give back all names in the topic map" do @tm.should have(165).names end end describe "#occurrences" do it "should give back all names in the topic map" do @tm.should have(24).occurrences end end describe "#roles" do it "should give back all names in the topic map" do pending if implementation_for_spec == :sesametm @tm.should have(131).roles end end describe "#variants" do it "should give back all names in the topic map" do @tm.should have(44).variants end end end describe "#locator" do it "should give back a locator" do @tm.locator.should be_a_kind_of RTM::Locator @tm.getLocator.should be_a_kind_of RTM::Locator end end end # of describe self describe self do describe "#remove" do it "should remove this TopicMap from its container" do @tm = get_used_tm_sys_tm @tm.remove pending if implementation_for_spec == :sesametm lambda{@tm.close}.should raise_error end end end # of describe self end #of module