# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::Topic describe self do before(:each) do @tm = get_used_tm_sys_tm end after(:each) do @tm.close end describe "#add_type" do before(:each) do @t1,@t2,@t3 = @tm.get!(["t1","t2","t3"]) end it "should not create an type-instance-association" do @t1.add_type(@t3) if implementation_for_spec == :sesametm pending "unless engine is SesameTM" do @tm.should have(0).associations end else @tm.should have(0).associations end end it "should add a type if argument is a String" do @t1.should have(0).types @t1.add_type("t2") @t1.add_type("t4") @tm.get("t4").should_not be_nil @t1.should have(2).types @t1.types.should include @t2, @tm.get("t4") end it "should add a type if argument is a Locator" do @t1.should have(0).types locator1 = @tm.create_locator("t2") locator2 = @tm.create_locator("t4") @t1.add_type(locator1) @t1.add_type(locator2) @tm.get("t4").should_not be_nil @t1.should have(2).types @t1.types.should include @t2, @tm.get("t4") end it "should add a type if argument is a Topic" do @t1.should have(0).types @t1.add_type(@t2) @t1.add_type(@t3) @t1.should have(2).types @t1.types.should include @t2, @t3 end it "should raise an error, if no argument is given" do lambda{@t1.add_type()}.should raise_error end it "should not add a type several times" do @t1.should have(0).types @t1.add_type("t2") @t1.should have(1).types @t1.types.should include @t2 @t1.add_type("t2") @t1.should have(1).types @t1.types.should include @t2 end end describe "#add_types" do before(:each) do @t1,@t2,@t3 = @tm.get!(["t1","t2","t3"]) end it "should not add a type if no argument is given" do @t1.should have(0).types @t1.add_types() @t1.should have(0).types end it "should add one type if one argument is given" do # adding one @t1.should have(0).types @t1.add_types(@t2) @t1.should have(1).types @t1.types.should include @t2 # adding another @t1.add_types("t4") @t1.should have(2).types @tm.get("t4").should_not be_nil @t1.types.should include @t2, @tm.get("t4") # adding t2 again -> should still have 2 types @t1.add_types(@t2) @t1.should have(2).types @t1.types.should include @t2, @tm.get("t4") end it "should add several types if several arguments are given" do @t1.should have(0).types @t1.add_types(@t2, "t4", @tm.create_locator("t5")) @t1.should have(3).types @tm.get("t4").should_not be_nil @tm.get("t5").should_not be_nil @t1.types.should include @t2, @tm.get("t4"), @tm.get("t5") end it "should add several types if several arrays with arguments are given" do @t1.should have(0).types @t1.add_types([@t2, "t4"], @t3) @t1.should have(3).types @tm.get("t4").should_not be_nil @t1.types.should include @t2, @tm.get("t4"), @t3 end it "should raise an error if a hash is given" do @t1.should have(0).types lambda{@t1.add_types([@t2, "t4"], "x" => "y")}.should raise_error end end describe "#add_instance" do before(:each) do @t1,@t2,@t3 = @tm.get!(["t1","t2","t3"]) end it "should not create an type-instance-association" do @t1.add_instance(@t3) if implementation_for_spec == :sesametm pending "unless engine is SesameTM" do @tm.should have(0).associations end else @tm.should have(0).associations end end it "should add an instance if argument is a String" do @t2.should have(0).types @tm.get("t4").should be_nil @t1.should have(0).instances @t1.add_instance("t2") @t1.add_instance("t4") @tm.get("t4").should_not be_nil @t1.should have(2).instances @t1.instances.should include @t2, @tm.get("t4") @t2.should have(1).types @t2.types.should include @t1 @tm.get("t4").should have(1).types @tm.get("t4").types.should include @t1 end it "should add an instance if argument is a Locator" do @t2.should have(0).types @tm.get("t4").should be_nil @t1.should have(0).instances locator1 = @tm.create_locator("t2") locator2 = @tm.create_locator("t4") @t1.add_instance(locator1) @t1.add_instance(locator2) @tm.get("t4").should_not be_nil @t1.should have(2).instances @t1.instances.should include @t2, @tm.get("t4") @t2.should have(1).types @t2.types.should include @t1 @tm.get("t4").should have(1).types @tm.get("t4").types.should include @t1 end it "should add an instance if argument is a Topic" do @t2.should have(0).types @t3.should have(0).types @t1.should have(0).instances @t1.add_instance(@t2) @t1.add_instance(@t3) @t1.should have(2).instances @t1.instances.should include @t2, @t3 @t2.should have(1).types @t2.types.should include @t1 @t3.should have(1).types @t3.types.should include @t1 end it "should raise an error, if no argument is given" do lambda{@t1.add_instance()}.should raise_error end it "should not add an instance several times" do @t1.should have(0).instances @t1.add_instance("t2") @t1.should have(1).instances @t1.instances.should include @t2 @t2.should have(1).types @t1.add_instance("t2") @t1.should have(1).instances @t1.instances.should include @t2 @t2.should have(1).types end end describe "#add_instances" do before(:each) do @t1,@t2,@t3 = @tm.get!(["t1","t2","t3"]) end it "should not add an instance if no argument is given" do @t1.should have(0).instances @t1.add_types() @t1.should have(0).instances end it "should add one instance if one argument is given" do # adding one @t1.should have(0).instances @t2.should have(0).types @t1.add_instances(@t2) @t1.should have(1).instances @t1.instances.should include @t2 @t2.should have(1).types # adding another @tm.get("t4").should be_nil @t1.add_instances("t4") @t1.should have(2).instances @tm.get("t4").should_not be_nil @t1.instances.should include @t2, @tm.get("t4") @tm.get("t4").should have(1).types # adding t2 again -> should still have 2 instances @t1.add_instances(@t2) @t1.should have(2).instances @t1.instances.should include @t2, @tm.get("t4") @tm.get("t4").should have(1).types @t2.should have(1).types end it "should add several instances if several arguments are given" do @t1.should have(0).instances @t2.should have(0).types @t1.add_instances(@t2, "t4", @tm.create_locator("t5")) @t1.should have(3).instances @tm.get("t4").should_not be_nil @tm.get("t5").should_not be_nil @t1.instances.should include @t2, @tm.get("t4"), @tm.get("t5") @t2.should have(1).types @tm.get("t4").should have(1).types @tm.get("t5").should have(1).types end it "should add several instances if several arrays with arguments are given" do @t1.should have(0).instances @t1.add_instances([@t2, "t4"], @t3) @t1.should have(3).instances @tm.get("t4").should_not be_nil @t1.instances.should include @t2, @tm.get("t4"), @t3 end it "should raise an error if a hash is given" do @t1.should have(0).instances lambda{@t1.add_instances([@t2, "t4"], "x" => "y")}.should raise_error end end describe "#remove_type" do before(:each) do @t1,@t2,@t3,@t4 = @tm.get!(["t1","t2","t3","t4"]) @t1.add_type(@t2) @t1.add_type(@t3) @t1.should have(2).types @t1.types.should include @t2, @t3 end it "should remove a type if argument is a String" do @t1.remove_type("t2") @t1.should have(1).types @t1.types.should include @t3 @t1.remove_type("t3") @t1.should have(0).types end it "should remove a type if argument is a Locator" do @t1.remove_type(@tm.create_locator("t2")) @t1.should have(1).types @t1.types.should include @t3 @t1.remove_type(@tm.create_locator("t3")) @t1.should have(0).types end it "should remove a type if argument is a Topic" do @t1.remove_type(@t2) @t1.should have(1).types @t1.types.should include @t3 @t1.remove_type(@t3) @t1.should have(0).types end it "should not remove a type if argument does not match a type of this Topic" do @t1.remove_type("t4") @t1.should have(2).types @t1.remove_type("t5") @t1.should have(2).types @t1.remove_type(@tm.create_locator("t4")) @t1.should have(2).types @t1.remove_type(@tm.create_locator("t5")) @t1.should have(2).types @t1.remove_type(@t4) @t1.should have(2).types @t1.remove_type(@t5) @t1.should have(2).types @t1.types.should include @t2, @t3 end end describe "#parent" do it "should give back the Topic Map" do topic = @tm.create_topic_by("=weihnachtsmann") topic.should be_a_kind_of RTM::Topic @tm.get("=weihnachtsmann").should be_a_kind_of RTM::Topic topic.parent.should be_a_kind_of RTM::TopicMap topic.parent.should == @tm end end describe "#names" do before(:each) do @topic = @tm.get!("person") @value1 = "Bruce" @value2 = "Bruce Smith" @value3 = "Smith" @value4 = "Bru" @name1 = @topic.create_name(@value1) @name2 = @topic.create_name(@value2) @name3 = @topic.create_name("last",@value3) @name4 = @topic.create_name("first",@value4,["friends"]) end it "should give back all names of this Topic if no identifier is given" do @topic.should have(4).names @topic.names.should include @name1, @name2, @name3, @name4 @topic.names.map{|n| n.value}.should include @value1, @value2, @value3, @value4 end it "should give back no names if the identifier does not reference a Topic" do @tm.get("dummy").should be_nil @topic.names("dummy").should be_empty @tm.get("dummy").should be_nil @topic.names(@tm.create_locator("dummy")).should be_empty @tm.get("dummy").should be_nil end it "should give back no names if the identifier is a Topic but no Name type" do dummy = @tm.get!("dummy") @topic.names("dummy").should be_empty @topic.names(dummy).should be_empty end it "should give back names of this type if an identifier is given and is a name type" do @topic.names("first").size.should == 1 @topic.names("first").should include @name4 @topic.names("last").size.should == 1 @topic.names("last").should include @name3 @topic.names(RTM::PSI[:name_type]).size.should == 2 @topic.names(RTM::PSI[:name_type]).should include @name1, @name2 end it "should give back names which have the default name type if identifier = :default" do @topic.names(:default).size.should == 2 @topic.names(:default).should include @name1, @name2 @topic.names(:default).map{|n| n.value}.should include @value1, @value2 end it "should give back names which have one of these identifiers as Name type if an identifier is an Array or an enumeration" do @topic.names(["first","last"]).size.should == 2 @topic.names(["first","last"]).should include @name3, @name4 @topic.names("first","last").size.should == 2 @topic.names("first","last").should include @name3, @name4 @topic.names("first",:default).size.should == 3 @topic.names("first",:default).should include @name1, @name2, @name4 @topic.names(:any,"last").size.should == 4 @topic.names(:any,"last").should include @name1, @name2, @name3, @name4 @topic.names("last","dummy","first").should == @topic.names(["first","last"]) end end describe "#occurrences" do before(:each) do @topic = @tm.get!("person") @value1 = "18" @value2 = "red" @value3 = @tm.create_locator("person") @value4 = "Leipzig" @occurrence1 = @topic.create_occurrence("age",@value1,:scope => ["2009"],:datatype => RTM::PSI[:Integer]) @occurrence2 = @topic.create_occurrence("favourite_colour", @value2) @occurrence3 = @topic.create_occurrence("website",@value3) @occurrence4 = @topic.create_occurrence("home",@value4) end it "should give back all occurrences of this Topic if no identifier is given" do @topic.should have(4).occurrences @topic.occurrences.should include @occurrence1, @occurrence2, @occurrence3, @occurrence4 @topic.occurrences.map{|n| n.value}.should include @value1, @value2, @value3.value, @value4 end it "should give back no occurrences if the identifier does not reference a Topic" do @tm.get("dummy").should be_nil @topic.occurrences("dummy").should be_empty @tm.get("dummy").should be_nil @topic.occurrences(@tm.create_locator("dummy")).should be_empty @tm.get("dummy").should be_nil end it "should give back no occurrences if the identifier is a Topic but no occurrence type" do dummy = @tm.get!("dummy") @topic.occurrences("dummy").should be_empty @topic.occurrences(dummy).should be_empty end it "should give back occurrences of this type if an identifier is given and is a occurrence type" do @topic.occurrences("age").size.should == 1 @topic.occurrences("age").should include @occurrence1 @topic.occurrences("website").size.should == 1 @topic.occurrences("website").should include @occurrence3 end it "should give back occurrences which have one of these identifiers as occurrence type if an identifier is an Array or an enumeration" do @topic.occurrences(["age","favourite_colour"]).size.should == 2 @topic.occurrences(["age","favourite_colour"]).should include @occurrence1, @occurrence2 @topic.occurrences("website","home").size.should == 2 @topic.occurrences("website","home").should include @occurrence3, @occurrence4 @topic.occurrences(:any,"home").size.should == 4 @topic.occurrences(:any,"home").should include @occurrence1, @occurrence2, @occurrence3, @occurrence4 @topic.occurrences("home","dummy","age").should == @topic.occurrences(["home","age"]) end end describe "#create_name" do before(:each) do @topic = @tm.get!("person") @default_name_type = @tm.get!(RTM::PSI[:name_type]) end it "should create a name if only a value is given" do value = "George" @topic.names.should be_empty name = @topic.create_name(value) @topic.should have(1).names @topic.names.should include name name.value.should == value name.scope.should be_empty name.type.should == @default_name_type @topic.names.first.value.should == value end it "should raise an error if, one argument given, this argument is not a name" do lambda{@topic.create_name(@tm.get!("George"))}.should raise_error end it "should allow to create a name with type as Topic" do value = "George" name_type = @tm.get!("first") name = @topic.create_name(name_type, value) name.value.should == value name.type.should == name_type name.scope.should be_empty end it "should allow to create a name with type as String" do value = "Smith" name_type = "last" name = @topic.create_name(name_type,value) name.value.should == value name.type.should == @tm.get(name_type) name.scope.should be_empty end it "should allow to create a name with type as Locator" do value = "Smith" name_type = @tm.create_locator("last") name = @topic.create_name(name_type,value) name.value.should == value name.type.should == @tm.get(name_type) name.scope.should be_empty end it "should raise an error if scope is not an Array" do lambda{@topic.create_name("first","Hans","deutsch")}.should raise_error end it "should allow to create a name with value and scope-Array with on theme (String)" do value = "Hans" theme = "german" name = @topic.create_name(value,[theme]) name.value.should == value name.scope.size.should == 1 name.scope.should include(@tm.get(theme)) end it "should allow to create a name with value and scope-Array with on theme (Topic)" do value = "Hans" theme = @tm.get!("deutsch") name = @topic.create_name(value,[theme]) name.value.should == value name.scope.size.should == 1 name.scope.should include(theme) end it "should allow to create a name with value and scope-Array with on theme (Locator)" do value = "Hans" theme = @tm.create_locator("deutsch") name = @topic.create_name(value,[theme]) name.value.should == value name.scope.size.should == 1 name.scope.should include(@tm.get!(theme)) end it "should allow to create a name with value and scope-Array with several themes (Strings)" do value = "Hans" theme1 = "deutsch1" theme2 = @tm.get!("deutsch2") theme3 = @tm.create_locator("deutsch3") name = @topic.create_name(value,[theme1,theme2,theme3]) name.value.should == value name.scope.size.should == 3 name.scope.should include(@tm.get(theme1), theme2, @tm.get(theme3)) end it "should not create a name if type is an Array" do lambda{@topic.create_name(["first","last"],"Hans")}.should raise_error end it "should create a name if scope is an empty Array" do value = "Hans" type = "first" name1 = @topic.create_name(type,value,[]) name1.value.should == value name1.type.should == @tm.get(type) name1.scope.should be_empty end end describe "#children" do it "should give back all Names and Occurrences parented by a Topic" do topic = @tm.create_topic_by("Uni_Leipzig") name1 = topic.create_name("Universitaet Leipzig") name2 = topic.create_name("University of Leipzig") occ1 = topic.create_occurrence("Gruendungsjahr", "1409") occ2 = topic.create_occurrence("Webseite", "http://www.uni-leipzig.de") topic.should have(4).children topic.children.should include(name1, name2, occ1, occ2) end end describe "#roles" do before(:each) do @t1,@t2,@t3,@t4,@t5 = @tm.get!(["t1","t2","t3","t4","t5"]) @t_a1,@t_a2 = @tm.get!(["t_a1","t_a2"]) @t_r1,@t_r2,@t_r3,@t_r4,@t_r5 = @tm.get!(["t_r1","t_r2","t_r3","t_r4","t_r5"]) @a1 = @tm.create_association(@t_a1) @a2 = @tm.create_association(@t_a2) @a3 = @tm.create_association(@t_a1) @r1 = @a1.create_role(@t_r1, @t1) @r2 = @a1.create_role(@t_r2, @t2) @r3 = @a1.create_role(@t_r1, @t4) @r4 = @a2.create_role(@t_r1, @t1) @r5 = @a2.create_role(@t_r3, @t3) @r6 = @a3.create_role(@t_r4, @t1) @r7 = @a3.create_role(@t_r5, @t5) end it "should give back all roles when no arguments are given" do @t1.roles.size.should == 3 @t1.roles.should include(@r1, @r4, @r6) @t2.should have(1).roles @t3.should have(1).roles @t4.should have(1).roles @t5.should have(1).roles @t1.roles(:any).should == @t1.roles end it "should give back some roles if the roletype is given" do @t1.roles(@t_r1).size.should == 2 @t1.roles(@t_r1).should include(@r1, @r4) end it "should give back some roles if several roletypes are given" do @t1.roles([@t_r1,@t_r4]).size.should == 3 @t1.roles([@t_r1,@t_r4]).should include(@r1, @r4, @r6) end it "should give back some roles if several roletypes and one assoctype are given" do @t1.roles([@t_r1, @t_r4], @t_a1).size.should == 2 @t1.roles([@t_r1, @t_r4], @t_a1).should include(@r1, @r6) @t1.roles([@t_r1, @t_r1, @t_r4], @t_a1).size.should == 2 end it "should give back some roles if several assoctypes and one rolytype are given" do @t1.roles(@t_r4,[@t_a1,@t_a2]).size.should == 1 @t1.roles(@t_r4,[@t_a1,@t_a2]).should include(@r6) @t1.roles(@t_r1,[@t_a1,@t_a2]).size.should == 2 @t1.roles(@t_r1,[@t_a1,@t_a2]).should include(@r1, @r4) @t1.roles(@t_r1,[@t_a1,@t_a2]).should == @t1.roles([@t_r1],[@t_a1,@t_a2]) end it "should handle Arrays of Arrays" do @t1.roles(@t_r1).should == @t1.roles([@t_r1]) @t1.roles(@t_r1).should == @t1.roles([[@t_r1]]) @t1.roles(@t_r4,[@t_a1,@t_a2]).should == @t1.roles(@t_r4,[@t_a1,[@t_a2]]) end it "should give back some roles if several assoctypes and one rolytype are given" do @t1.roles(@t_r4,[@t_a1,@t_a2]).size.should == 1 @t1.roles(@t_r4,[@t_a1,@t_a2]).should include(@r6) @t1.roles(@t_r1,[@t_a1,@t_a2]).size.should == 2 @t1.roles(@t_r1,[@t_a1,@t_a2]).should include(@r1, @r4) @t1.roles(@t_r1,[@t_a1,@t_a2]).should == @t1.roles([@t_r1],[@t_a1,@t_a2]) end it "should give back some roles if several roletypes and several assoctype are given" do @t1.roles([@t_r4,@t_r1],[@t_a1,@t_a2]).size.should == 3 @t1.roles([@t_r4,@t_r1],[@t_a1,@t_a2]).should include(@r1, @r4, @r6) end it "should handle Locators" do @t1.roles(@tm.create_locator("t_r1")).should == @t1.roles(@t_r1) end it "should handle IRIs" do @t1.roles("t_r1").should == @t1.roles(@t_r1) @t1.roles("t_r2").should be_empty @t1.roles("t_r").should be_empty @t1.roles(["t_r1","t_r4"]).should == @t1.roles([@t_r1,@t_r4]) @t1.roles(["t_r1", @t_r4], "t_a1").should == @t1.roles([@t_r1, @t_r4], @t_a1) @t1.roles("t_r4",[@t_a1,@t_a2]).should == @t1.roles(@t_r4,[@t_a1,@t_a2]) @t1.roles(["t_r4",@t_r1],["t_a1",@t_a2]).should == @t1.roles([@t_r4,@t_r1],[@t_a1,@t_a2]) end it "should give back an empty Set of Roles" do @t1.roles(@t_r2).should be_empty @t1.roles(@t_a2).should be_empty end it "should set roles to roles_played" do @t1.roles.should == @t1.roles_played end end #of describe "#roles" describe "#create_occurrence" do before(:each) do @topic = @tm.get!("person") end it "should create an occurrence if only type and value=string is given" do occ = @topic.create_occurrence("Geburtsort","Leipzig") occ.should be_a_kind_of(RTM::Occurrence) @tm.get("Geburtsort").should be_a_kind_of(RTM::Topic) occ.type.should == @tm.get("Geburtsort") occ.value.should == "Leipzig" occ.scope.should respond_to(:each) occ.scope.should be_empty end it "should create an occurrence if only type and value=URI(Locator) is given" do t = @tm.get!("Webseite") occ = @topic.create_occurrence(t,@tm.create_locator("http://www.uni-leipzig.de/")) occ.should be_a_kind_of(RTM::Occurrence) occ.type.should == t occ.datatype.to_external_form.should == RTM::PSI[:IRI] occ.value.should == "http://www.uni-leipzig.de/" occ.scope.should respond_to(:each) occ.scope.should be_empty end it "should create an occurrence if only type and value=string and a scope is given" do occ = @topic.create_occurrence("Geburtsort","Leipzig",{:scope => ["deutsch"]}) occ.should be_a_kind_of(RTM::Occurrence) @tm.get("Geburtsort").should be_a_kind_of(RTM::Topic) occ.type.should == @tm.get("Geburtsort") occ.value.should == "Leipzig" occ.scope.should respond_to(:each) occ.scope.should include(@tm.get("deutsch")) occ.datatype.to_external_form.should_not == RTM::PSI[:IRI] end it "should create an occurrence if several scope-items are given" do occ = @topic.create_occurrence("Geburtsort","Leipzig",{:scope => ["deutsch","test"]}) occ.should be_a_kind_of(RTM::Occurrence) @tm.get("Geburtsort").should be_a_kind_of(RTM::Topic) occ.type.should == @tm.get("Geburtsort") occ.value.should == "Leipzig" occ.scope.should respond_to(:each) occ.scope.size.should == 2 occ.scope.should include(@tm.get("deutsch"), @tm.get("test")) end it "should create an occurrence if only type and value=string and a datatype is given" do occ = @topic.create_occurrence("Alter","26",{:datatype => @tm.create_locator(RTM::PSI[:anyType])}) occ.should be_a_kind_of(RTM::Occurrence) @tm.get("Alter").should be_a_kind_of(RTM::Topic) occ.type.should == @tm.get("Alter") occ.value.should == "26" occ.datatype.should == @tm.create_locator(RTM::PSI[:anyType]) occ.datatype.to_external_form.should ==RTM::PSI[:anyType] occ.scope.should respond_to(:each) occ.scope.should be_empty end it "should create an occurrence if type, value=string, datatype and scope is given" do occ = @topic.create_occurrence("Heimat","Sachsen",{:datatype => RTM::PSI[:String], :scope => ["deutsch"]}) occ.should be_a_kind_of(RTM::Occurrence) @tm.get("Heimat").should be_a_kind_of(RTM::Topic) occ.type.should == @tm.get("Heimat") occ.value.should == "Sachsen" occ.datatype.should == @tm.create_locator(RTM::PSI[:String]) occ.datatype.to_external_form.should == RTM::PSI[:String] occ.scope.should respond_to(:each) occ.scope.should include(@tm.get("deutsch")) end end #of describe "#create_occurrences" describe "#add_subject_identifier" do before(:each) do @ii_1 = "http://www.specs.de/ii_1" @ii_2 = "http://www.specs.de/ii_2" @si_1 = "http://www.specs.de/si_1" @si_2 = "http://www.specs.de/si_2" @sl_1 = "http://www.specs.de/sl_1" @sl_2 = "http://www.specs.de/sl_2" end it "should add an identifier as subject identifier if the topic already has another si" do topic = @tm.get!("si:" + @si_1) topic.add_subject_identifier(@si_2) topic.items.should be_empty topic.indicators.size.should == 2 topic.indicators.should include @si_1, @si_2 topic.locators.should be_empty end it "should add an identifier as subject identifier if the topic already has another ii" do topic = @tm.get!("ii:" + @ii_1) topic.add_subject_identifier(@si_2) topic.items.size.should == 1 topic.items.should include @ii_1 topic.indicators.size.should == 1 topic.indicators.should include @si_2 topic.locators.should be_empty end it "should add an identifier as subject identifier if the topic already has another sl" do topic = @tm.get!("sl:" + @sl_1) topic.add_subject_identifier(@si_2) topic.items.should be_empty topic.indicators.size.should == 1 topic.indicators.should include @si_2 topic.locators.size.should == 1 topic.locators.should include @sl_1 end it "should not add an identifier as subject identifier if the topic already this identifier as si" do topic = @tm.get!("si:" + @si_2) topic.add_subject_identifier(@si_2) topic.items.should be_empty topic.indicators.size.should == 1 topic.indicators.should include @si_2 topic.locators.should be_empty end it "should add an identifier as subject identifier if the topic already has this identifier as ii" do topic = @tm.get!("ii:" + @si_2) # puts "ii: #{topic.item_identifiers.to_s}" # puts "si: #{topic.subject_identifiers.to_s}" topic.add_subject_identifier(@si_2) # puts "ii: #{topic.item_identifiers.to_s}" # puts "si: #{topic.subject_identifiers.to_s}" topic.items.size.should == 1 topic.items.should include @si_2 topic.indicators.size.should == 1 topic.indicators.should include @si_2 topic.locators.should be_empty end it "should do what? if the topic already has this identifier as sl" it "should merge the topic A with another topic B that has the same identifier as ii or si when adding this identifier to A, but throws an exception" do topic_a = @tm.get!("ii:" + @ii_1) topic_b = @tm.get!("ii:" + @ii_2) lambda{topic_a.add_subject_identifier(@ii_2)}.should raise_error end end # of describe add_subject_indentifier describe "#add_item_identifier" do before(:each) do @ii_1 = "http://www.specs.de/ii_1" @ii_2 = "http://www.specs.de/ii_2" @si_1 = "http://www.specs.de/si_1" @si_2 = "http://www.specs.de/si_2" @sl_1 = "http://www.specs.de/sl_1" @sl_2 = "http://www.specs.de/sl_2" end it "should be tested" end #of describe add_item_identifier describe "#add_subject_locator" do before(:each) do @ii_1 = "http://www.specs.de/ii_1" @ii_2 = "http://www.specs.de/ii_2" @si_1 = "http://www.specs.de/si_1" @si_2 = "http://www.specs.de/si_2" @sl_1 = "http://www.specs.de/sl_1" @sl_2 = "http://www.specs.de/sl_2" end it "should be tested" end # of describe add_subject_locator describe "#remove_subject_identifier" do before(:each) do @topic = @tm.get!("si:http://www.example.org/topic1/si_1") @topic.add_subject_identifier("http://www.example.org/topic1/si_2") @topic.add_item_identifier("http://www.example.org/topic1/ii_1") @topic.add_item_identifier("http://www.example.org/topic1/ii_2") @topic.add_subject_locator("http://www.example.org/topic1/sl_1") @topic.add_subject_locator("http://www.example.org/topic1/sl_2") @topic_wo_si = @tm.get!("ii:http://www.example.org/topic2/ii") @topic_wo_si.add_subject_locator("http://www.example.org/topic2/sl") @topic.should have(2).indicators @topic.should have(2).items @topic.should have(2).locators end it "should remove an existing subject identifier if argument is a String" do @topic.remove_subject_identifier("http://www.example.org/topic1/si_1") @topic.should have(1).indicators @topic.indicators.should include "http://www.example.org/topic1/si_2" @topic.remove_subject_identifier("http://www.example.org/topic1/si_2") @topic.should have(0).indicators @topic.should have(2).items @topic.should have(2).locators end it "should remove an existing subject identifier if argument is a Locator" do locator1 = @tm.create_locator("http://www.example.org/topic1/si_1") locator2 = @tm.create_locator("http://www.example.org/topic1/si_2") @topic.remove_subject_identifier(locator1) @topic.should have(1).indicators @topic.indicators.should include "http://www.example.org/topic1/si_2" @topic.remove_subject_identifier(locator2) @topic.should have(0).indicators @topic.should have(2).items @topic.should have(2).locators end it "should not remove a subject identifier if argument does not refer to an existing si" do @topic.remove_subject_identifier("http://www.example.org/topic1/something") @topic.should have(2).indicators @topic.should have(2).items @topic.should have(2).locators @topic.remove_subject_identifier(@tm.create_locator("http://www.example.org/topic1/something")) @topic.should have(2).indicators @topic.should have(2).items @topic.should have(2).locators end it "should not remove a subject identifier if the identifier exists as ii or sl" do @topic_wo_si.remove_subject_identifier("http://www.example.org/topic2/ii") @topic_wo_si.remove_subject_identifier("http://www.example.org/topic2/sl") @topic_wo_si.should have(0).indicators @topic_wo_si.should have(1).items @topic_wo_si.should have(1).locators end end #of describe remove_subject_identifier describe "#remove_item_identifier" do before(:each) do @topic = @tm.get!("si:http://www.example.org/topic1/si_1") @topic.add_subject_identifier("http://www.example.org/topic1/si_2") @topic.add_item_identifier("http://www.example.org/topic1/ii_1") @topic.add_item_identifier("http://www.example.org/topic1/ii_2") @topic.add_subject_locator("http://www.example.org/topic1/sl_1") @topic.add_subject_locator("http://www.example.org/topic1/sl_2") @topic_wo_ii = @tm.get!("si:http://www.example.org/topic2/si") @topic_wo_ii.add_subject_locator("http://www.example.org/topic2/sl") @topic.should have(2).indicators @topic.should have(2).items @topic.should have(2).locators end it "should remove an existing item identifier if argument is a String" do @topic.remove_item_identifier("http://www.example.org/topic1/ii_1") @topic.should have(1).items @topic.items.should include "http://www.example.org/topic1/ii_2" @topic.remove_item_identifier("http://www.example.org/topic1/ii_2") @topic.should have(2).indicators @topic.should have(0).items @topic.should have(2).locators end it "should remove an existing item identifier if argument is a Locator" do locator1 = @tm.create_locator("http://www.example.org/topic1/ii_1") locator2 = @tm.create_locator("http://www.example.org/topic1/ii_2") @topic.remove_item_identifier(locator1) @topic.should have(1).items @topic.items.should include "http://www.example.org/topic1/ii_2" @topic.remove_item_identifier(locator2) @topic.should have(2).indicators @topic.should have(0).items @topic.should have(2).locators end it "should not remove an item identifier if argument does not refer to an existing ii" do @topic.remove_item_identifier("http://www.example.org/topic1/something") @topic.should have(2).indicators @topic.should have(2).items @topic.should have(2).locators @topic.remove_item_identifier(@tm.create_locator("http://www.example.org/topic1/something")) @topic.should have(2).indicators @topic.should have(2).items @topic.should have(2).locators end it "should not remove an item identifier if the identifier exists as si or sl" do @topic_wo_ii.remove_item_identifier("http://www.example.org/topic2/si") @topic_wo_ii.remove_item_identifier("http://www.example.org/topic2/sl") @topic_wo_ii.should have(1).indicators @topic_wo_ii.should have(0).items @topic_wo_ii.should have(1).locators end end #of describe remove_item_identifier describe "#remove_subject_locator" do before(:each) do @topic = @tm.get!("si:http://www.example.org/topic1/si_1") @topic.add_subject_identifier("http://www.example.org/topic1/si_2") @topic.add_item_identifier("http://www.example.org/topic1/ii_1") @topic.add_item_identifier("http://www.example.org/topic1/ii_2") @topic.add_subject_locator("http://www.example.org/topic1/sl_1") @topic.add_subject_locator("http://www.example.org/topic1/sl_2") @topic_wo_sl = @tm.get!("ii:http://www.example.org/topic2/ii") @topic_wo_sl.add_subject_identifier("http://www.example.org/topic2/si") @topic.should have(2).indicators @topic.should have(2).items @topic.should have(2).locators end it "should remove an existing subject locator if argument is a String" do @topic.remove_subject_locator("http://www.example.org/topic1/sl_1") @topic.should have(1).locators @topic.locators.should include "http://www.example.org/topic1/sl_2" @topic.remove_subject_locator("http://www.example.org/topic1/sl_2") @topic.should have(2).indicators @topic.should have(2).items @topic.should have(0).locators end it "should remove an existing subject locator if argument is a Locator" do locator1 = @tm.create_locator("http://www.example.org/topic1/sl_1") locator2 = @tm.create_locator("http://www.example.org/topic1/sl_2") @topic.remove_subject_locator(locator1) @topic.should have(1).locators @topic.locators.should include "http://www.example.org/topic1/sl_2" @topic.remove_subject_locator(locator2) @topic.should have(2).indicators @topic.should have(2).items @topic.should have(0).locators end it "should not remove a subject locator if argument does not refer to an existing sl" do @topic.remove_subject_locator("http://www.example.org/topic1/something") @topic.should have(2).indicators @topic.should have(2).items @topic.should have(2).locators @topic.remove_subject_locator(@tm.create_locator("http://www.example.org/topic1/something")) @topic.should have(2).indicators @topic.should have(2).items @topic.should have(2).locators end it "should not remove a subject locator if the identifier exists as ii or si" do @topic_wo_sl.remove_subject_locator("http://www.example.org/topic2/ii") @topic_wo_sl.remove_subject_locator("http://www.example.org/topic2/si") @topic_wo_sl.should have(1).indicators @topic_wo_sl.should have(1).items @topic_wo_sl.should have(0).locators end end #of describe remove_subject_locator describe "#reified" do before(:each) do end it "should be tested ..." end describe "#reified=" do before(:each) do @topic = @tm.get!("Hans") @name = @topic.create_name("firstname","Hans") @occ = @topic.create_occurrence("birthyear","2000") @variant = @name.create_variant("Hansi",["home"]) @assoc = @tm.create_association("mother-child") @role = @assoc.create_role("child","Hans") @a_reifier = @tm.get!("test_reifier") end it "should set self as reifier for the identifier (a Name)" do @name.reifier.should be_nil @a_reifier.reified = @name @name.reifier.should == @a_reifier end it "should set self as reifier for the identifier (a Variant)" do @variant.reifier.should be_nil @a_reifier.reified = @variant @variant.reifier.should == @a_reifier end it "should set self as reifier for the identifier (an Occurrence)" do @occ.reifier.should be_nil @a_reifier.reified = @occ @occ.reifier.should == @a_reifier end it "should set self as reifier for the identifier (an Association)" do @assoc.reifier.should be_nil @a_reifier.reified = @assoc @assoc.reifier.should == @a_reifier end it "should set self as reifier for the identifier (a Role)" do @role.reifier.should be_nil @a_reifier.reified = @role @role.reifier.should == @a_reifier end it "should set self as reifier for the identifier (a TopicMap)" do @tm.reifier.should be_nil @a_reifier.reified = @tm @tm.reifier.should == @a_reifier end it "should overwrite a previous reifier if identifier already had a reifier" do @name.reifier = "dummy_reifier" @name.reifier.should == @tm.get("dummy_reifier") @a_reifier.reified = @name @name.reifier.should == @a_reifier end it "should raise an error if this Topic already refies a Reifiable Construct" do @name.reifier = @a_reifier lambda{@a_reifier.reified = @occ} end it "should raise an error if the identifier is not a Reifiable" do lambda{@a_reifier.reified = "test"}.should raise_error end end describe "#remove" do before(:each) do @topic1 = @tm.get!("topic1") @topic2 = @tm.get!("topic2") @name = @topic1.create_name("firstname","Hans") @occurrence = @topic1.create_occurrence("birthyear","2000") @tm.should have(4).topics end it "should remove this topic from the container (topic map)" do @tm.literal_index.getOccurrences("2000").size.should == 1 @tm.literal_index.getNames("Hans").size.should == 1 @topic1.remove @tm.should have(3).topics @topic2.remove @tm.should have(2).topics @tm.literal_index.getOccurrences("2000").size.should == 0 @tm.literal_index.getNames("Hans").size.should == 0 end end end # of describe self end # of module