# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::Scoped describe self do before(:each) do @tm = get_used_tm_sys_tm end after(:each) do @tm.close end describe "#scope" do before(:each) do @topic = @tm.get!("Hans") @name1 = @topic.create_name("Hans") @name2 = @topic.create_name("first", "Hansi", ["home"]) @occ1 = @topic.create_occurrence("birthyear","1982") @occ2 = @topic.create_occurrence("birthplace","Berlin",:scope => ["german"]) @variant1 = @name1.create_variant("Bubi",["endearment"]) @variant2 = @name2.create_variant("Bubi",["home","endearment"]) @assoc1 = @tm.create_association("birth") @assoc2 = @tm.create_association("home",["german"]) end it "should give back a empty set if no scope is set" do @name1.should have(0).scope @name1.should have(0).themes @occ1.should have(0).scope @occ1.should have(0).themes @assoc1.should have(0).scope @assoc1.should have(0).themes end it "should give back a container" do @name1.scope.should respond_to(:each) @name1.scope.should_not be_a_kind_of String @name2.scope.should respond_to(:each) @name2.scope.should_not be_a_kind_of String @occ1.scope.should respond_to(:each) @occ1.scope.should_not be_a_kind_of String @occ2.scope.should respond_to(:each) @occ2.scope.should_not be_a_kind_of String @variant1.scope.should respond_to(:each) @variant1.scope.should_not be_a_kind_of String @variant2.scope.should respond_to(:each) @variant2.scope.should_not be_a_kind_of String @assoc1.scope.should respond_to(:each) @assoc1.scope.should_not be_a_kind_of String @assoc2.scope.should respond_to(:each) @assoc2.scope.should_not be_a_kind_of String end it "should give back the topics in the scope" do @name2.should have(1).scope @occ2.should have(1).scope @variant2.should have(2).scope @assoc2.should have(1).scope @name2.should have(1).themes @occ2.should have(1).themes @variant2.should have(2).themes @assoc2.should have(1).themes end it "should give back RTM::Topics" do @name2.scope.each{|t| t.should be_a_kind_of RTM::Topic} @occ2.scope.each{|t| t.should be_a_kind_of RTM::Topic} @variant2.scope.each{|t| t.should be_a_kind_of RTM::Topic} @assoc2.scope.each{|t| t.should be_a_kind_of RTM::Topic} end it "should be told, if a theme is in the returned scope or not" do @name2.scope.include?(@tm.get("something")) @occ2.scope.include?(@tm.get("something")) @variant2.scope.include?(@tm.get("something")) @assoc2.scope.include?(@tm.get("something")) ### existing_topic = @tm.get!("existing") @name2.scope.should_not include(existing_topic) @occ2.scope.should_not include(existing_topic) @variant2.scope.should_not include(existing_topic) @assoc2.scope.should_not include(existing_topic) ### #p @name2.scope.inspect @name2.scope.should include(@tm.get("home")) @occ2.scope.should include(@tm.get("german")) @variant2.scope.should include(@tm.get("endearment")) @assoc2.scope.should include(@tm.get("german")) end end describe "#add_theme" do before(:each) do @topic = @tm.get!("Hans") @name1 = @topic.create_name("Hans") @name2 = @topic.create_name("first", "Hansi", ["home"]) @occ1 = @topic.create_occurrence("birthyear","1982") @occ2 = @topic.create_occurrence("birthplace","Berlin",:scope => ["german"]) @variant1 = @name1.create_variant("Bubi",["endearment"]) @variant2 = @name2.create_variant("Bubi",["home","endearment"]) @assoc1 = @tm.create_association("birth") @assoc2 = @tm.create_association("home",["german"]) end it "should add one Topic to the scope of a Name" do @name1.should be_a_kind_of RTM::Name @name2.should be_a_kind_of RTM::Name ### @name1.scope.should be_empty @name1.add_theme("test_scope_1") @name1.should have(1).themes @name1.add_theme(@tm.create_locator("test_scope_2")) @name1.should have(2).themes @name1.add_theme(@tm.get!("test_scope_3")) @name1.should have(3).themes @name1.scope.should include @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3") ### @name2.should have(1).themes @name2.scope.should include @tm.get("home") @name2.add_theme("test_scope_1") @name2.should have(2).themes @name2.add_theme(@tm.create_locator("test_scope_2")) @name2.should have(3).themes @name2.add_theme(@tm.get!("test_scope_3")) @name2.should have(4).themes @name2.scope.should include @tm.get("home"), @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3") end it "should add one Topic to the scope of an Occurrence" do @occ1.should be_a_kind_of RTM::Occurrence @occ2.should be_a_kind_of RTM::Occurrence ### @occ1.scope.should be_empty @occ1.add_theme("test_scope_1") @occ1.should have(1).themes @occ1.add_theme(@tm.create_locator("test_scope_2")) @occ1.should have(2).themes @occ1.add_theme(@tm.get!("test_scope_3")) @occ1.should have(3).themes @occ1.scope.should include @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3") ### @occ2.should have(1).themes @occ2.scope.should include @tm.get("german") @occ2.add_theme("test_scope_1") @occ2.should have(2).themes @occ2.add_theme(@tm.create_locator("test_scope_2")) @occ2.should have(3).themes @occ2.add_theme(@tm.get!("test_scope_3")) @occ2.should have(4).themes @occ2.scope.should include @tm.get("german"), @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3") end it "should add one Topic to the scope of a Variant" do @variant1.should be_a_kind_of RTM::Variant @variant2.should be_a_kind_of RTM::Variant ### @variant1.should have(1).themes @variant1.scope.should include @tm.get("endearment") @variant1.add_theme("test_scope_1") @variant1.should have(2).themes @variant1.add_theme(@tm.create_locator("test_scope_2")) @variant1.should have(3).themes @variant1.add_theme(@tm.get!("test_scope_3")) @variant1.should have(4).themes @variant1.scope.should include @tm.get("endearment"), @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3") ### @variant2.should have(2).themes @variant2.scope.should include @tm.get("home"), @tm.get("endearment") @variant2.add_theme("test_scope_1") @variant2.should have(3).themes @variant2.add_theme(@tm.create_locator("test_scope_2")) @variant2.should have(4).themes @variant2.add_theme(@tm.get!("test_scope_3")) @variant2.should have(5).themes @variant2.scope.should include @tm.get("home"), @tm.get("endearment"), @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3") end it "should add one Topic to the scope of an Association" do @assoc1.should be_a_kind_of RTM::Association @assoc2.should be_a_kind_of RTM::Association ### @assoc1.scope.should be_empty @assoc1.add_theme("test_scope_1") @assoc1.should have(1).themes @assoc1.add_theme(@tm.create_locator("test_scope_2")) @assoc1.should have(2).themes @assoc1.add_theme(@tm.get!("test_scope_3")) @assoc1.should have(3).themes @assoc1.scope.should include @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3") ### @assoc2.should have(1).themes @assoc2.scope.should include @tm.get("german") @assoc2.add_theme("test_scope_1") @assoc2.should have(2).themes @assoc2.add_theme(@tm.create_locator("test_scope_2")) @assoc2.should have(3).themes @assoc2.add_theme(@tm.get!("test_scope_3")) @assoc2.should have(4).themes @assoc2.scope.should include @tm.get("german"), @tm.get("test_scope_1"), @tm.get("test_scope_2"), @tm.get("test_scope_3") end it "should raise an error if identifier is not a Topic or Topic-Reference" do lambda{@name1.add_theme(["test_scope"])}.should raise_error lambda{@occ1.add_theme(["test_scope"])}.should raise_error lambda{@variant1.add_theme(["test_scope"])}.should raise_error lambda{@association1.add_theme(["test_scope"])}.should raise_error end it "should raise an error if argument consists of several identifiers" do lambda{@name1.add_theme("testscope1", "testscope2")}.should raise_error end end describe "#add_themes" do before(:each) do @topic = @tm.get!("Hans") end it "should not add a theme if no argument is given" do @name1 = @topic.create_name("Hans") @name1.should have(0).themes @name1.add_themes() @name1.should have(0).themes ### @name2 = @topic.create_name("first", "Hansi", ["home"]) @name2.should have(1).themes @name2.add_themes() @name2.should have(1).themes end it "should add one theme if one argument is given" do # adding one @name1 = @topic.create_name("Hans") @name1.should have(0).themes @name1.add_themes("home") @name1.should have(1).themes # adding another @name2 = @topic.create_name("first", "Hansi", ["home"]) @name2.should have(1).themes @name2.add_themes("mom") @name2.should have(2).themes # adding t2 again -> should still have 2 themes @name2.add_themes("home") @name2.should have(2).themes end it "should add several themes if several arguments are given" do @name1 = @topic.create_name("Hans") @name1.should have(0).themes @name1.add_themes("home", "mom") @name1.should have(2).themes end it "should add several themes if several arrays with arguments are given" do @name1 = @topic.create_name("Hans") @name1.should have(0).themes @name1.add_themes(["home", "mom"], "testscope") @name1.should have(3).themes end it "should raise an error if a hash is given" do @name1 = @topic.create_name("Hans") @name1.should have(0).themes lambda{@name1.add_themes("x" => "y")}.should raise_error end end describe "#remove_theme" do before(:each) do @topic = @tm.get!("Hans") @name = @topic.create_name("first", "Hansi", ["home","mom"]) @occ = @topic.create_occurrence("birthplace","Berlin",:scope => ["german","english"]) @variant = @name.create_variant("Bubi",["endearment"]) @assoc = @tm.create_association("home",["german","english"]) @existing_dummy = @tm.get!("existing_dummy") end it "should remove a Topic from the scope of a Name" do @name.should be_a_kind_of RTM::Name ### @name.should have(2).themes @name.scope.should include @tm.get("home"), @tm.get("mom") @name.remove_theme("home") @name.should have(1).themes @name.scope.should include @tm.get("mom") @name.remove_theme("mom") @name.scope.should be_empty @name.remove_theme("mom") @name.scope.should be_empty end it "should remove a Topic from the scope of an Occurrence" do @occ.should be_a_kind_of RTM::Occurrence ### @occ.should have(2).themes @occ.scope.should include @tm.get("german"), @tm.get("english") @occ.remove_theme("german") @occ.should have(1).themes @occ.scope.should include @tm.get("english") @occ.remove_theme("english") @occ.scope.should be_empty @occ.remove_theme("english") @occ.scope.should be_empty end it "should remove a Topic from the scope of a Variant" do @variant.should be_a_kind_of RTM::Variant ### @variant.should have(3).themes @variant.scope.should include(@tm.get("home"), @tm.get("mom"), @tm.get("endearment")) @variant.remove_theme("endearment") @variant.should have(2).themes @variant.scope.should include @tm.get("home"), @tm.get("mom") @variant.should be_a_kind_of RTM::Variant end it "should not remove a theme from the scope of an Variant is removed that occurrs in the scope of its parent Name also" do @variant.should be_a_kind_of RTM::Variant ### @variant.should have(3).themes @variant.scope.should include(@tm.get("home"), @tm.get("mom"), @tm.get("endearment")) @variant.remove_theme("home") @variant.should have(3).themes @variant.scope.should include(@tm.get("home"), @tm.get("mom"), @tm.get("endearment")) @variant.should be_a_kind_of RTM::Variant end it "should remove a Topic from the scope of an Association" do @assoc.should be_a_kind_of RTM::Association ### @assoc.should have(2).themes @assoc.scope.should include @tm.get("german"), @tm.get("english") @assoc.remove_theme("german") @assoc.should have(1).themes @assoc.scope.should include @tm.get("english") @assoc.remove_theme("english") @assoc.scope.should be_empty @assoc.remove_theme("english") @assoc.scope.should be_empty end it "should not fail if the Topic_to_be_removed is not in the scope" do @name.should have(2).themes @name.remove_theme("dummy") @name.remove_theme("existing_dummy") @name.should have(2).themes end it "should raise an error if argument consists of several identifiers" do lambda{@name.remove_theme("testscope1", "testscope2")}.should raise_error end end describe "#remove_themes" do before(:each) do @topic = @tm.get!("Hans") # @name1 = @topic.create_name("Hans") # @name2 = @topic.create_name("first", "Hansi", ["home"]) # @occ1 = @topic.create_occurrence("birthyear","1982") # @occ2 = @topic.create_occurrence("birthplace","Berlin",:scope => ["german"]) # @variant1 = @name1.create_variant("Bubi",["endearment"]) # @variant2 = @name2.create_variant("Bubi",["home","endearment"]) # @assoc1 = @tm.create_association("birth") # @assoc2 = @tm.create_association("home",["german"]) end it "should not remove a theme if no argument is given" do @name1 = @topic.create_name("Hans") @name2 = @topic.create_name("first", "Hansi", ["home"]) @name1.should have(0).themes @name1.remove_themes() @name1.should have(0).themes @name2.should have(1).themes @name2.remove_themes() @name2.should have(1).themes end it "should remove one theme if one argument is given" do @name2 = @topic.create_name("first", "Hansi", ["home"]) @variant2 = @name2.create_variant("Bubi",["home","endearment"]) # removing one @variant2.should have(2).themes @variant2.remove_themes("endearment") @variant2.should have(1).themes # removing a non existing @name2 = @topic.create_name("first", "Hansi", ["home"]) @name2.should have(1).themes @name2.remove_theme("non_existing") end it "should remove a theme that occurs in a variant also (given a Topic)" do @name2 = @topic.create_name("first", "Hansi", ["home"]) @variant2 = @name2.create_variant("Bubi",["home","endearment"]) @name2.should have(1).themes @name2.themes.should include(@tm.get("home")) @variant2.should have(2).themes @variant2.themes.should include(@tm.get("home"), @tm.get("endearment")) @name2.remove_theme(@tm.get("home")) @name2.should have(0).themes if implementation_for_spec == :tinytim @variant2.should have(2).themes elsif implementation_for_spec == :ontopia @variant2.should have(1).themes else ### ??? @variant2.should have(2).themes end end it "should remove a theme that occurs in a variant also" do @name2 = @topic.create_name("first", "Hansi", ["home"]) @variant2 = @name2.create_variant("Bubi",["home","endearment"]) @name2.should have(1).themes @name2.themes.should include(@tm.get("home")) @variant2.should have(2).themes @variant2.themes.should include(@tm.get("home"), @tm.get("endearment")) @name2.remove_theme("home") @name2.should have(0).themes if implementation_for_spec == :tinytim @variant2.should have(2).themes elsif implementation_for_spec == :ontopia @variant2.should have(1).themes else ### ??? @variant2.should have(2).themes end end it "should remove several themes if several arguments are given" do @name2 = @topic.create_name("first", "Hansi", ["home","endearment","mom"]) @name2.should have(3).themes @name2.remove_themes("home", "mom", "not_existing") @name2.should have(1).themes end it "should remove several themes if several arrays with arguments are given" do @name2 = @topic.create_name("first", "Hansi", ["home","endearment","mom"]) @name2.should have(3).themes @name2.remove_themes("home", ["mom", "not_existing"]) @name2.should have(1).themes end it "should raise an error if a hash is given" do @name2 = @topic.create_name("first", "Hansi", ["home"]) lambda{@name1.remove_themes("x" => "y")}.should raise_error end end describe "#scope=" do before(:each) do @topic = @tm.get!("Hans") @name = @topic.create_name("first", "Hansi", ["home","mom"]) @occ = @topic.create_occurrence("birthplace","Berlin",:scope => ["german","english"]) @variant = @name.create_variant("Bubi",["endearment"]) @assoc = @tm.create_association("home",["german","english"]) @existing_dummy = @tm.get!("existing_dummy") end it "should set the scope to empty upon request" do @name.should be_a_kind_of RTM::Name @name.should have(2).themes pending @name.scope = [] @name.should have(0).themes end end end end