# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::Occurrence describe self do before(:each) do @tm = get_used_tm_sys_tm end after(:each) do @tm.close end describe "#parent" do it "should give back the Topic the Occurrence belongs to" do topic = @tm.create_topic_by("Haus") topic.should be_a_kind_of RTM::Topic @tm.get("Haus").should be_a_kind_of RTM::Topic testocc = topic.create_occurrence("Hausnummer", "1") testocc.should be_a_kind_of RTM::Occurrence testocc.parent.should == topic end end describe "#value=" do before(:each) do @topic = @tm.create_topic_by("Haus") end it "should set an IRI value and the datatype to xsd:AnyURI if arguement is a Locator" do occ= @topic.create_occurrence("Hausnummer", "1") occ.datatype.to_external_form.should == RTM::PSI[:String] occ.value=(@tm.create_locator("http://www.haus.de")) occ.datatype.to_external_form.should == RTM::PSI[:IRI] occ.value.should include "http://www.haus.de" # since we dont know if not */ as in case of ontopia end it "should set an String value and the datatype to xsd:String if arguement is a String" do occ= @topic.create_occurrence("Webseite", @tm.create_locator("http://www.haus.de")) occ.datatype.to_external_form.should == RTM::PSI[:IRI] occ.value=("1") occ.datatype.to_external_form.should == RTM::PSI[:String] occ.value.should == "1" end it "should set a Float value and the datatype to xsd:Float if arguement is a Float" do occ= @topic.create_occurrence("Webseite", @tm.create_locator("http://www.haus.de")) occ.datatype.to_external_form.should == RTM::PSI[:IRI] 0.5.class.should == Float occ.value=(0.5) occ.datatype.to_external_form.should == RTM::PSI[:Float] occ.value.should == "0.5" end it "should set a Fixnum value and the datatype to xsd:long if arguement is a Fixnum" do occ= @topic.create_occurrence("Webseite", @tm.create_locator("http://www.haus.de")) occ.datatype.to_external_form.should == RTM::PSI[:IRI] 1.class.should == Fixnum occ.value=(1) occ.datatype.to_external_form.should == RTM::PSI[:Long] occ.value.should == "1" end it "should set a Bignum value and the datatype to xsd:integer if arguement is a Bignum" do occ= @topic.create_occurrence("Webseite", @tm.create_locator("http://www.haus.de")) occ.datatype.to_external_form.should == RTM::PSI[:IRI] 9999999999999999999.class.should == Bignum occ.value=(9999999999999999999) occ.datatype.to_external_form.should == RTM::PSI[:Integer] occ.value.should == "9999999999999999999" end end end # of describe self describe self do describe "#remove" do before(:each) do @tm = get_used_tm_sys_tm @topic1 = @tm.get!("topic1") @topic2 = @tm.get!("topic2") @occ = @topic1.create_occurrence("birthyear","2000") @topic2.create_occurrence("birthyear","1980") @topic1.should have(1).occurrences @topic1.occurrences.should include @occ end after(:each) do @tm.close end it "should remove this name from the container (topic)" do @tm.literal_index.getOccurrences("2000").size.should == 1 @occ.remove @tm.literal_index.getOccurrences("2000").size.should == 0 @tm.literal_index.getOccurrences("1980").size.should == 1 @topic1.should have(0).occurrences end end end # of describe self end # of module