# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::Association describe self do before(:each) do @tm = get_used_tm_sys_tm @asso = @tm.create_association("a_type") end after(:each) do @tm.close end describe "#role_types" do it "should give back all types of the roles on a association" do @asso.create_role("a_type_1","a_player") @asso.role_types.include?(@tm.get("a_type_1")).should be_true end end describe "#create_role" do it "should allow to create a role using a String-reference" do asso = @tm.create_association("a_type") role1 = asso.create_role("type1", "player1") type2 = @tm.get!("type2") player2 = @tm.get!("player2") role2 = asso.create_role("type2", "player2") role1.should be_a_kind_of RTM::Role role2.should be_a_kind_of RTM::Role @tm.get("type1").should be_a_kind_of RTM::Topic @tm.get("player1").should be_a_kind_of RTM::Topic @tm.get("player1").roles(@tm.get("type1")).size.should == 1 player2.roles(type2).size.should == 1 asso.roles.size.should == 2 asso.roles(@tm.get("type1")).size.should == 1 asso.roles(type2).size.should == 1 end it "should allow to create a role using Topics" do asso = @tm.create_association("a_type") type = @tm.get!("type") player = @tm.get!("player") type.should be_a_kind_of RTM::Topic player.should be_a_kind_of RTM::Topic role = asso.create_role(type, player) role.should be_a_kind_of RTM::Role player.roles(type).size.should == 1 asso.roles.size.should == 1 asso.roles(type).size.should == 1 asso.roles(type).should include(role) player.roles(type).size.should == 1 end it "should allow to create a role using Locators" do asso = @tm.create_association("a_type") loc1 = @tm.create_locator("type") loc2 = @tm.create_locator("player") loc1.should be_a_kind_of RTM::Locator loc2.should be_a_kind_of RTM::Locator role = asso.create_role(loc1,loc2) role.should be_a_kind_of RTM::Role asso.roles.size.should == 1 asso.roles(@tm.get(loc1)).size.should == 1 asso.roles(@tm.get(loc1)).should include(role) @tm.get(loc2).roles(@tm.get(loc1)).size.should == 1 @tm.get(loc2).roles(@tm.get(loc1)).should include(role) end end describe "#parent" do it "should give back the TopicMap the Association belongs to" do testassoc = @tm.create_association("Haus-Nummer-Beziehung") testassoc.should be_a_kind_of RTM::Association testassoc.parent.should == @tm end end describe "#children" do it "should return all Roles belonging to an Association" do topic = @tm.create_topic_by("Haus") topic_instance = @tm.create_topic_by("Weisses_Haus") topic_instance2 = @tm.create_topic_by("Anderes_Haus") testassoc = @tm.create_association("Haus-Nummer-Beziehung") testrole = testassoc.create_role(topic, topic_instance) #TMAPI function testrole2 = testassoc.create_role(topic, topic_instance2) #TMAPI function testassoc.should be_a_kind_of RTM::Association testrole.should be_a_kind_of RTM::Role testrole2.should be_a_kind_of RTM::Role testassoc.children.size.should == 2 testassoc.children.should include(testrole) testassoc.children.should include(testrole2) end end describe "#roles" do it "should return an empty Set if the Association has no Roles" do @asso.roles.should be_empty @asso.roles.should_not be_nil end it "should return an empty Array if type is no Roletype of a Role in this Association" do @asso.create_role("type1","player1") @asso.create_role("type1","player2") @asso.create_role("type2","player3") other_asso = @tm.create_association("a_type") other_asso.create_role("type3","player4") @asso.roles("typex").should be_empty @asso.roles(nil).should be_empty @asso.roles("type3").should be_empty end it "should return the right Roles, also if type is a Topic, String-Reference or Locator" do t_type1,t_type2,t_type3 = @tm.get!(["type1","type2","type3"]) t_player1,t_player2,t_player3,t_player4 = @tm.get!(["player1","player2","player3","player4"]) role1 = @asso.create_role(t_type1,t_player1) role2 = @asso.create_role(t_type1,t_player2) role3 = @asso.create_role(t_type2,t_player3) other_asso = @tm.create_association("a_type") role4 = other_asso.create_role(t_type3,t_player4) @asso.roles.size.should == 3 @asso.roles.should include(role1) @asso.roles.should include(role2) @asso.roles.should include(role3) other_asso.roles.size.should == 1 other_asso.roles.should include(role4) @asso.roles("type1").size.should == 2 @asso.roles("type1").should include(role1) @asso.roles("type1").should include(role2) @asso.roles(t_type2).size.should == 1 @asso.roles(t_type2).should include(role3) other_asso.roles(t_type3.references_as_locators.first).size.should == 1 other_asso.roles(t_type3.references_as_locators.first).should include(role4) end end end # of describe self describe self do describe "#remove" do before(:each) do @tm = get_used_tm_sys_tm @assoc1 = @tm.create_association("assoc1") @assoc2 = @tm.create_association("assoc2") @assoc3 = @tm.create_association("assoc1") @assoc1.create_role("r1","topic1") @assoc1.create_role("r2","topic2") @tm.should have(3).associations end after(:each) do @tm.close end it "should remove this assocition from the container (topic map)" do @assoc1.remove @tm.should have(2).associations @tm.associations.should include @assoc2, @assoc3 @assoc2.remove @tm.should have(1).associations @tm.associations.should include @assoc3 @assoc3.remove @tm.should have(0).associations end end end # of describe self end #of module