# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::Navigation::Topic describe self do before(:each) do @tms = get_used_tm_sys @tm_empty = @tms.create("http://rtm.topicmapslab.de/spec/rtm/axes/navigation/supertypes/empty") @topic1 = @tm_empty.get!("topic1") #lonely Topic @tm = @tms.create("http://rtm.topicmapslab.de/spec/rtm/axes/navigation/supertypes/tm") @t_lebewesen = @tm.get!("Lebewesen") @t_tier = @tm.get!("Tier") @t_affe = @tm.get!("Affe") @t_saeuger = @tm.get!("Saeuger") @t_mensch = @tm.get!("Mensch") @t_super_sub = @tm.get!(RTM::PSI[:supertype_subtype]) @t_super = @tm.get!(RTM::PSI[:supertype]) @t_sub = @tm.get!(RTM::PSI[:subtype]) @t_etwas = @tm.get!("etwas") @t_etwas_anderes = @tm.get!("etwas_anderes") @t_noch_anders = @tm.get!("noch_anders") @assoc1 = @tm.create_association(@t_super_sub) @assoc2 = @tm.create_association(@t_super_sub) @assoc3 = @tm.create_association(@t_super_sub) @assoc4 = @tm.create_association(@t_super_sub) @assoc5 = @tm.create_association(@t_super_sub) @assoc6 = @tm.create_association(@t_super_sub) @assoc7 = @tm.create_association(@t_super_sub) @assoc8 = @tm.create_association(@t_super_sub) @assoc1.create_role(@t_sub,@t_mensch) @assoc1.create_role(@t_super,@t_saeuger) @assoc2.create_role(@t_sub,@t_saeuger) @assoc2.create_role(@t_super,@t_tier) @assoc3.create_role(@t_sub,@t_affe) @assoc3.create_role(@t_super,@t_saeuger) @assoc4.create_role(@t_sub,@t_affe) @assoc4.create_role(@t_super,@t_tier) @assoc5.create_role(@t_sub,@t_tier) @assoc5.create_role(@t_super,@t_lebewesen) @assoc6.create_role(@t_sub,@t_lebewesen) @assoc6.create_role(@t_sub,@t_noch_anders) @assoc6.create_role(@t_super,@t_etwas) @assoc6.create_role(@t_super,@t_etwas_anderes) @assoc7.create_role(@t_sub,@t_tier) @assoc8.create_role(@t_super,@t_mensch) end after(:each) do @tm_empty.close @tm.close end describe "#direct_supertypes" do it "should give back an empty Array if Topic has no supertypes" do @topic1.direct_supertypes.should be_empty @topic1.direct_supertypes.should_not be_nil end it "should not create typing topics" do @topic1.direct_supertypes @tm_empty.get(RTM::PSI[:subtype]).should be_nil @tm_empty.get(RTM::PSI[:supertype]).should be_nil @tm_empty.get(RTM::PSI[:supertype_subtype]).should be_nil end it "should give back the direct supertypes" do @t_saeuger.should have(1).direct_supertypes @t_saeuger.direct_supertypes.should include @t_tier @t_affe.should have(2).direct_supertypes @t_affe.direct_supertypes.should include @t_saeuger, @t_tier end it "should not give back direct supertypes that are not part of a binary association" do @t_lebewesen.direct_supertypes.should be_empty end it "should handle unary associations" do @t_tier.should have(1).direct_supertypes @t_mensch.should have(1).direct_supertypes end end describe "#direct_subtypes" do it "should give back an empty Array if Topic has no subtypes" do @topic1.direct_subtypes.should be_empty @topic1.direct_subtypes.should_not be_nil end it "should not create typing topics" do @topic1.direct_subtypes @tm_empty.get(RTM::PSI[:subtype]).should be_nil @tm_empty.get(RTM::PSI[:supertype]).should be_nil @tm_empty.get(RTM::PSI[:supertype_subtype]).should be_nil end it "should give back the direct subtypes" do @t_saeuger.should have(2).direct_subtypes @t_saeuger.direct_subtypes.should include @t_affe, @t_mensch @t_affe.direct_subtypes.should be_empty @t_lebewesen.should have(1).direct_subtypes @t_lebewesen.direct_subtypes.should include @t_tier end it "should not give back direct supertypes that are not part of a binary association" do @t_etwas.direct_subtypes.should be_empty end it "should handle unary associations" do @t_tier.should have(2).direct_subtypes @t_mensch.direct_subtypes.should be_empty end end describe "#transitive_supertypes" do it "should give back an empty Array if Topic has no transitive supertypes" do @topic1.transitive_supertypes.should be_empty @topic1.transitive_supertypes.should_not be_nil @t_lebewesen.transitive_supertypes.should be_empty @t_lebewesen.transitive_supertypes.should_not be_nil end it "should not create typing topics" do @topic1.transitive_supertypes @tm_empty.get(RTM::PSI[:subtype]).should be_nil @tm_empty.get(RTM::PSI[:supertype]).should be_nil @tm_empty.get(RTM::PSI[:supertype_subtype]).should be_nil end it "should give back the transitive supertypes" do @t_mensch.should have(3).transitive_supertypes @t_mensch.transitive_supertypes.should include @t_saeuger, @t_tier, @t_lebewesen @t_saeuger.should have(2).transitive_supertypes @t_saeuger.transitive_supertypes.should include @t_tier, @t_lebewesen @t_affe.should have(3).transitive_supertypes @t_affe.transitive_supertypes.should include @t_saeuger, @t_tier, @t_lebewesen @t_tier.should have(1).transitive_supertypes @t_tier.transitive_supertypes.should include @t_lebewesen @t_lebewesen.transitive_supertypes.should be_empty end it "should not give back transitive supertypes that are not part of a binary association" do @t_noch_anders.transitive_supertypes.should be_empty end end describe "#transitive_subtypes" do it "should give back an empty Array if Topic has no transitive subtypes" do @topic1.transitive_subtypes.should be_empty @topic1.transitive_subtypes.should_not be_nil @t_mensch.transitive_subtypes.should be_empty @t_mensch.transitive_subtypes.should_not be_nil end it "should not create typing topics" do @topic1.transitive_subtypes @tm_empty.get(RTM::PSI[:subtype]).should be_nil @tm_empty.get(RTM::PSI[:supertype]).should be_nil @tm_empty.get(RTM::PSI[:supertype_subtype]).should be_nil end it "should give back the transitive subtypes" do @t_mensch.transitive_subtypes.should be_empty @t_saeuger.should have(2).transitive_subtypes @t_saeuger.transitive_subtypes.should include @t_affe, @t_mensch @t_affe.transitive_subtypes.should be_empty @t_tier.should have(3).transitive_subtypes @t_tier.transitive_subtypes.should include @t_affe, @t_saeuger, @t_mensch @t_lebewesen.should have(4).transitive_subtypes @t_lebewesen.transitive_subtypes.should include @t_tier, @t_saeuger, @t_affe, @t_mensch end it "should not give back transitive subtypes that are not part of a binary association" do @t_etwas_anderes.transitive_subtypes.should be_empty end end describe "#add_supertype" do before(:each) do @topic1.direct_supertypes.should be_empty @tm_empty.get("topic2").should be_nil @tm_empty.get(RTM::PSI[:subtype]).should be_nil @tm_empty.get(RTM::PSI[:supertype]).should be_nil @tm_empty.get(RTM::PSI[:supertype_subtype]).should be_nil @assoc = @topic1.add_supertype("topic2") end it "should create the typing topics if not present" do @tm_empty.get(RTM::PSI[:subtype]).should_not be_nil @tm_empty.get(RTM::PSI[:supertype]).should_not be_nil @tm_empty.get(RTM::PSI[:supertype_subtype]).should_not be_nil end it "should add exactly one supertype at a time" do @topic1.should have(1).direct_supertypes end it "should create the supertyping topic" do @tm_empty.get("topic2").should_not == nil @tm_empty.get("topic2").roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).size.should == 1 @tm_empty.get("topic2").roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).first.player.should == @tm_empty.get("topic2") end it "should set the Topic as subtype" do @topic1.roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).size.should == 1 @topic1.roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).first.player.should == @topic1 end it "should create a supertype_subtype association" do @topic1.roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).first.parent.type.should == @tm_empty.get(RTM::PSI[:supertype_subtype]) @assoc.type.should == @tm_empty.get(RTM::PSI[:supertype_subtype]) end it "should create a supertype_subtype association with exactly two roles" do @topic1.roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).first.parent.roles.size.should == 2 end it "should return the created supertype_subtype association" do @assoc.should be_a_kind_of RTM::Association end it "should create a second association even if a supertype is set which already _is_ a supertype of this Topic, but direct_supertypes should return unique Array" do @assoc2 = @topic1.add_supertype("topic2") @assoc2.type.should == @tm_empty.get(RTM::PSI[:supertype_subtype]) @topic1.roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).size.should == 2 @tm_empty.get("topic2").roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).size.should == 2 @topic1.should have(1).direct_supertypes end end describe "#add_subtype" do before(:each) do @topic1.direct_subtypes.should be_empty @tm_empty.get("topic0").should be_nil @tm_empty.get(RTM::PSI[:subtype]).should be_nil @tm_empty.get(RTM::PSI[:supertype]).should be_nil @tm_empty.get(RTM::PSI[:supertype_subtype]).should be_nil @assoc = @topic1.add_subtype("topic0") end it "should create the typing topics if not present" do @tm_empty.get(RTM::PSI[:subtype]).should_not be_nil @tm_empty.get(RTM::PSI[:supertype]).should_not be_nil @tm_empty.get(RTM::PSI[:supertype_subtype]).should_not be_nil end it "should add exactly one subtype at a time" do @topic1.should have(1).direct_subtypes end it "should create the subtyping topic" do @tm_empty.get("topic0").should_not == nil @tm_empty.get("topic0").roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).size.should == 1 @tm_empty.get("topic0").roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).first.player.should == @tm_empty.get("topic0") end it "should set the Topic as supertype" do @topic1.roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).size.should == 1 @topic1.roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).first.player.should == @topic1 end it "should create a supertype_subtype association" do @topic1.roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).first.parent.type.should == @tm_empty.get(RTM::PSI[:supertype_subtype]) @assoc.type.should == @tm_empty.get(RTM::PSI[:supertype_subtype]) end it "should create a supertype_subtype association with exactly two roles" do @topic1.roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).first.parent.roles.size.should == 2 end it "should return the created supertype_subtype association" do @assoc.should be_a_kind_of RTM::Association end it "should create a second association even if a subtype is set which already _is_ a subtype of this Topic, but direct_subtypes should return unique Array" do @assoc2 = @topic1.add_subtype("topic0") @assoc2.type.should == @tm_empty.get(RTM::PSI[:supertype_subtype]) @topic1.roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).size.should == 2 @tm_empty.get("topic0").roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).size.should == 2 @topic1.should have(1).direct_subtypes end end describe "#add_subtypes" do before(:each) do @topic1.direct_supertypes.should be_empty @tm_empty.get("topic2").should be_nil @tm_empty.get(RTM::PSI[:subtype]).should be_nil @tm_empty.get(RTM::PSI[:supertype]).should be_nil @tm_empty.get(RTM::PSI[:supertype_subtype]).should be_nil @resulting_assocs = @topic1.add_subtypes("topic2", "topic3") end it "should create the typing topics if not present" do @tm_empty.get(RTM::PSI[:subtype]).should_not be_nil @tm_empty.get(RTM::PSI[:supertype]).should_not be_nil @tm_empty.get(RTM::PSI[:supertype_subtype]).should_not be_nil end it "should add several subtypes" do @topic1.should have(2).direct_subtypes end it "should create the subtyping topics" do @tm_empty.get("topic2").should_not be_nil @tm_empty.get("topic2").roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).size.should == 1 @tm_empty.get("topic2").roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).first.player.should == @tm_empty.get("topic2") ### @tm_empty.get("topic3").should_not be_nil @tm_empty.get("topic3").roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).size.should == 1 @tm_empty.get("topic3").roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).first.player.should == @tm_empty.get("topic3") end it "should set the Topic as supertype" do @topic1.roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).size.should == 2 @topic1.roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).first.player.should == @topic1 end it "should create supertype_subtype associations" do @topic1.roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).first.parent.type.should == @tm_empty.get(RTM::PSI[:supertype_subtype]) @resulting_assocs.each do |assoc| assoc.type.should == @tm_empty.get(RTM::PSI[:supertype_subtype]) end end it "should create a supertype_subtype association with exactly two roles" do @topic1.roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).first.parent.roles.size.should == 2 end it "should return the created supertype_subtype association" do @resulting_assocs.should respond_to(:each) @resulting_assocs.each do |result| result.should be_a_kind_of(RTM::Association) end end it "should be tested further" end describe "#add_supertypes" do before(:each) do @topic1.direct_supertypes.should be_empty @tm_empty.get("topic2").should be_nil @tm_empty.get("topic3").should be_nil @tm_empty.get(RTM::PSI[:subtype]).should be_nil @tm_empty.get(RTM::PSI[:supertype]).should be_nil @tm_empty.get(RTM::PSI[:supertype_subtype]).should be_nil @resulting_assocs = @topic1.add_supertypes("topic2", "topic3") end it "should create the typing topics if not present" do @tm_empty.get(RTM::PSI[:subtype]).should_not be_nil @tm_empty.get(RTM::PSI[:supertype]).should_not be_nil @tm_empty.get(RTM::PSI[:supertype_subtype]).should_not be_nil end it "should add several supertypes" do @topic1.should have(2).direct_supertypes end it "should create the supertyping topics" do @tm_empty.get("topic2").should_not be_nil @tm_empty.get("topic2").roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).size.should == 1 @tm_empty.get("topic2").roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).first.player.should == @tm_empty.get("topic2") ### @tm_empty.get("topic3").should_not be_nil @tm_empty.get("topic3").roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).size.should == 1 @tm_empty.get("topic3").roles(RTM::PSI[:supertype],RTM::PSI[:supertype_subtype]).first.player.should == @tm_empty.get("topic3") end it "should set the Topic as subtype" do @topic1.roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).size.should == 2 @topic1.roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).first.player.should == @topic1 end it "should create supertype_subtype associations" do @topic1.roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).first.parent.type.should == @tm_empty.get(RTM::PSI[:supertype_subtype]) @resulting_assocs.each do |assoc| assoc.type.should == @tm_empty.get(RTM::PSI[:supertype_subtype]) end end it "should create a supertype_subtype association with exactly two roles" do @topic1.roles(RTM::PSI[:subtype],RTM::PSI[:supertype_subtype]).first.parent.roles.size.should == 2 end it "should return the created supertype_subtype association" do @resulting_assocs.should respond_to(:each) @resulting_assocs.each do |result| result.should be_a_kind_of(RTM::Association) end end it "should be tested further" end describe "#supertypes" do it "should call transitive_supertypes" do @topic1.method(:supertypes).should == @topic1.method(:transitive_supertypes) end end describe "#subtypes" do it "should call transitive_subtypes" do @topic1.method(:subtypes).should == @topic1.method(:transitive_subtypes) end end describe "#reverse_supertypes" do it "should call subtypes" do @topic1.method(:reverse_supertypes).should == @topic1.method(:subtypes) end end describe "#reverse_subtypes" do it "should call supertypes" do @topic1.method(:reverse_subtypes).should == @topic1.method(:supertypes) end end end end