# 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 @tm = get_used_tm_sys_tm end after(:each) do @tm.close end describe "#traverse" do before(:each) do @topic = @tm.get!("person") @topic.add_supertype(@tm.get!("mensch")) @topic.add_supertype(@tm.get!("wasanderes")) @topic.add_subtype(@tm.get!("noch_wasanderes")) asso = @tm.create_association("http://psi.topicmaps.org/smeasso") asso["role1"] = @topic asso["role2"] = @tm.get!("player2") @tm.get!("something") end it "should give back an empty set if the Topic plays no Role in an Association" do @tm.get!("something").traverse.should be_empty end it "should give back all the players of all Associations in which this Topic plays a Role" do @topic.traverse.size.should == 4 #self deducted once for each association @topic.traverse.should include(@tm.get("mensch")) @topic.traverse.should include(@tm.get("wasanderes")) @topic.traverse.should include(@tm.get("noch_wasanderes")) @topic.traverse.should include(@tm.get("player2")) end it "should be constrainable with the optional item" do @topic.traverse(RTM::PSI[:supertype_subtype]).size.should == 3 @topic.traverse(RTM::PSI[:supertype_subtype]).should include(@tm.get("mensch")) @topic.traverse(RTM::PSI[:supertype_subtype]).should include(@tm.get("wasanderes")) @topic.traverse(RTM::PSI[:supertype_subtype]).should include(@tm.get("noch_wasanderes")) @topic.traverse("http://psi.topicmaps.org/wrong_type").should be_empty @topic.traverse("http://psi.topicmaps.org/smeasso").size.should == 1 @topic.traverse("http://psi.topicmaps.org/smeasso").should include(@tm.get("player2")) end it "should give back an empty Array if the optional item is not included as Topic in the TopicMap" do @tm.get("nothing").should be_nil @topic.traverse("nothing").should be_empty end it "should give back an empty Array if the optional item exists as Topic in the TopicMap but is not an Association type" do @tm.get("something").should be_a_kind_of RTM::Topic @topic.traverse("something").should be_empty end describe "#reverse_traverse" do it "should always give back an empty set" do @tm.get!("nikolaus").add_supertype(@tm.get!("mensch")) @tm.get!("nikolaus").add_supertype(@tm.get!("wasanderes")) @tm.get!("nikolaus").add_subtype(@tm.get!("noch_wasanderes")) @tm.get("nikolaus").reverse_traverse.should be_empty end end end end end