# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::Sugar::Occurrence::DynamicValue describe self do before(:each) do @tm = get_used_tm_sys_tm end after(:each) do @tm.close end describe "#externalize" do before(:each) do @leipzig = @tm.get!("http://en.wikipedia.org/wiki/Leipzig") end it "should create an association and two roles out of the occurrence if the value is of type xsd:String" do occ = @leipzig.create_occurrence("Webpage", "http://www.leipzig.de/") occ.value.should be_a_kind_of String occ.value.should == "http://www.leipzig.de/" occ.datatype.value.should == RTM::PSI[:String] ### now create the association association = occ.externalize ### type must be RTM::PSI[:subject_representation] assoc_type = @tm.get(RTM::PSI[:subject_representation]) assoc_type.should_not be_nil association.type.should == assoc_type ### 2 roles association.should have(2).roles ### one role of type RTM::PSI[:represented_subject] with player occ.parent (the topic) association.roles(RTM::PSI[:represented_subject]).size.should == 1 role1 = association.roles(RTM::PSI[:represented_subject]).first role1.player.should == @leipzig ### the other role of type occ_type and player: topic with subject locator occ_value association.roles("Webpage").size.should == 1 role2 = association.roles("Webpage").first r2player = @tm.get("=http://www.leipzig.de/") r2player.should_not be_nil role2.player.should == r2player end it "should create an association and two roles out of the occurrence if the value is of type xsd:anyURI" do occ = @leipzig.create_occurrence("Webpage", @tm.create_locator("http://www.leipzig.de/")) occ.value.should be_a_kind_of String occ.value.should == "http://www.leipzig.de/" occ.datatype.value.should == RTM::PSI[:IRI] ### now create the association association = occ.externalize ### type must be RTM::PSI[:subject_representation] assoc_type = @tm.get(RTM::PSI[:subject_representation]) assoc_type.should_not be_nil association.type.should == assoc_type ### 2 roles association.should have(2).roles ### one role of type RTM::PSI[:represented_subject] with player occ.parent (the topic) association.roles(RTM::PSI[:represented_subject]).size.should == 1 role1 = association.roles(RTM::PSI[:represented_subject]).first role1.player.should == @leipzig ### the other role of type occ_type and player: topic with subject locator occ_value association.roles("Webpage").size.should == 1 role2 = association.roles("Webpage").first r2player = @tm.get("=http://www.leipzig.de/") r2player.should_not be_nil role2.player.should == r2player end it "should resolve relative identifiers = occ values" do occ = @leipzig.create_occurrence(@tm.get!("Webpage"), "foobar") occ.value.should be_a_kind_of String occ.value.should == "foobar" occ.datatype.value.should == RTM::PSI[:String] ### now create the association association = occ.externalize ### type must be RTM::PSI[:subject_representation] assoc_type = @tm.get(RTM::PSI[:subject_representation]) assoc_type.should_not be_nil association.type.should == assoc_type ### 2 roles association.should have(2).roles ### one role of type RTM::PSI[:represented_subject] with player occ.parent (the topic) association.roles(RTM::PSI[:represented_subject]).size.should == 1 role1 = association.roles(RTM::PSI[:represented_subject]).first role1.player.should == @leipzig ### the other role of type occ_type and player: topic with subject locator occ_value association.roles("Webpage").size.should == 1 role2 = association.roles("Webpage").first r2player = @tm.get("=http://www.topicmapslab.de/foobar") r2player.should_not be_nil role2.player.should == r2player end it "should perhaps be tested for other datatypes" end describe "#externalize!" do before(:each) do @leipzig = @tm.get!("http://en.wikipedia.org/wiki/Leipzig") end it "should remove the occurrence also" do occ = @leipzig.create_occurrence("Webpage", "http://www.leipzig.de/", :scope => ["theme1", "theme2"]) @leipzig.should have(1).occurrences association = occ.externalize! @leipzig.occurrences.should be_empty end it "should remove the occurrence also, even if it has a reifier" do occ = @leipzig.create_occurrence("Webpage", "http://www.leipzig.de/", :scope => ["theme1", "theme2"]) occ.reifier = "a_reifier" occ.reifier.should_not be_nil @leipzig.should have(1).occurrences association = occ.externalize! @leipzig.occurrences.should be_empty end end describe "#external?" do before(:each) do @leipzig = @tm.get!("http://en.wikipedia.org/wiki/Leipzig") end it "should return true if this occurrence is an external occurrence" do occ = @leipzig.create_occurrence("Webpage", @tm.create_locator("http://www.leipzig.de/")) occ.external?.should be_true end it "should return false if this occurrence is not an external occurrence" do occ = @leipzig.create_occurrence("Webpage", "http://www.leipzig.de/") occ.external?.should be_false end end end end