# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::DatatypeAware describe self do before(:each) do @tm = get_used_tm_sys_tm end after(:each) do @tm.close end describe "#value=" do before(:each) do @topic = @tm.get!("House") end describe "for Occurrence" do it "should set the datatype to xsd:anyURI if argument datatype is xsd:anyURI" do occ = @topic.create_occurrence("street number", "1") occ.datatype.to_external_form.should == RTM::PSI[:String] occ.value = "http://www.example.org/House", RTM::PSI[:IRI] occ.datatype.to_external_form.should == RTM::PSI[:IRI] occ.value.should == "http://www.example.org/House" end it "should set the datatype to xsd:anyURI if argument datatype is xsd:anyURI and resolve the value using the base iri" do occ = @topic.create_occurrence("street number", "1") occ.datatype.to_external_form.should == RTM::PSI[:String] occ.value = "House", RTM::PSI[:IRI] occ.datatype.to_external_form.should == RTM::PSI[:IRI] occ.value.should == "http://www.topicmapslab.de/House" end it "should set the datatype to xsd:anyURI also if it was Integer before" do occ = @topic.create_occurrence("street number", "1", :datatype => RTM::PSI[:Integer]) occ.value.should == "1" occ.datatype.reference.should == RTM::PSI[:Integer] occ.value = 1, RTM::PSI[:IRI] occ.datatype.to_external_form.should == RTM::PSI[:IRI] occ.value.should == "http://www.topicmapslab.de/1" end it "should set an IRI value and the datatype to xsd:AnyURI if argument is a Locator" do occ = @topic.create_occurrence("street number", "1") occ.datatype.to_external_form.should == RTM::PSI[:String] occ.value = @tm.create_locator("http://www.example.org/House") occ.datatype.to_external_form.should == RTM::PSI[:IRI] occ.value.should == "http://www.example.org/House" # since we dont know if not */ as in case of ontopia end it "should set a String value and the datatype to xsd:String if argument is a String" do occ = @topic.create_occurrence("Webseite", @tm.create_locator("http://www.example.org/House")) 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.example.org/House")) 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.example.org/House")) 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.example.org/House")) 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 describe "for Variant" do it "should set the datatype to xsd:anyURI if argument datatype is xsd:anyURI" do var = @topic.create_name("White House").create_variant("WH", ["short form"]) var.datatype.reference.should == RTM::PSI[:String] var.value = "http://www.example.org/WhiteHouse", RTM::PSI[:IRI] var.datatype.reference.should == RTM::PSI[:IRI] var.value.should == "http://www.example.org/WhiteHouse" end it "should set the datatype to xsd:anyURI if argument datatype is xsd:anyURI and resolve the value using the base iri" do var = @topic.create_name("White House").create_variant("WH", ["short form"]) var.datatype.to_external_form.should == RTM::PSI[:String] var.value = "White-House", RTM::PSI[:IRI] var.datatype.to_external_form.should == RTM::PSI[:IRI] var.value.should == "http://www.topicmapslab.de/White-House" end it "should set the datatype to xsd:anyURI also if it was Integer before" do var = @topic.create_name("White House").create_variant("1", RTM::PSI[:Integer], ["short form"]) var.value.should == "1" var.datatype.reference.should == RTM::PSI[:Integer] var.value = 1, RTM::PSI[:IRI] var.datatype.to_external_form.should == RTM::PSI[:IRI] var.value.should == "http://www.topicmapslab.de/1" end it "should set an IRI value and the datatype to xsd:AnyURI if argument is a Locator" do var = @topic.create_name("White House").create_variant("WH", ["short form"]) var.datatype.to_external_form.should == RTM::PSI[:String] var.value = @tm.create_locator("http://www.example.org/House") var.datatype.to_external_form.should == RTM::PSI[:IRI] var.value.should == "http://www.example.org/House" # since we dont know if not */ as in case of ontopia end it "should set a String value and the datatype to xsd:String if argument is a String" do var = @topic.create_name("White House").create_variant(@tm.create_locator("WH"), ["short form"]) var.datatype.to_external_form.should == RTM::PSI[:IRI] var.value=("1") var.datatype.to_external_form.should == RTM::PSI[:String] var.value.should == "1" end it "should set a Float value and the datatype to xsd:Float if arguement is a Float" do var = @topic.create_name("White House").create_variant(@tm.create_locator("WH"), ["short form"]) var.datatype.to_external_form.should == RTM::PSI[:IRI] 0.5.class.should == Float var.value = 0.5 var.datatype.to_external_form.should == RTM::PSI[:Float] var.value.should == "0.5" end it "should set a Fixnum value and the datatype to xsd:long if arguement is a Fixnum" do var = @topic.create_name("White House").create_variant(@tm.create_locator("WH"), ["short form"]) var.datatype.to_external_form.should == RTM::PSI[:IRI] 1.class.should == Fixnum var.value = 1 var.datatype.to_external_form.should == RTM::PSI[:Long] var.value.should == "1" end it "should set a Bignum value and the datatype to xsd:integer if arguement is a Bignum" do var = @topic.create_name("White House").create_variant(@tm.create_locator("WH"), ["short form"]) var.datatype.to_external_form.should == RTM::PSI[:IRI] 9999999999999999999.class.should == Bignum var.value = 9999999999999999999 var.datatype.to_external_form.should == RTM::PSI[:Integer] var.value.should == "9999999999999999999" end end end describe "#datatype=" do before(:each) do @topic = @tm.get!("House") end describe "for Occurrence" do it "should set the datatype to xsd:anyURI even if value is a String" do occ = @topic.create_occurrence("street number", "1") occ.datatype.reference.should == RTM::PSI[:String] occ.datatype = RTM::PSI[:IRI] occ.datatype.reference.should == RTM::PSI[:IRI] end it "should set the datatype to xsd:String even if value is a Locator" do occ = @topic.create_occurrence("wesbite", @tm.create_locator("http://www.example.org/House")) occ.value.should == "http://www.example.org/House" occ.datatype.reference.should == RTM::PSI[:IRI] occ.datatype = RTM::PSI[:String] occ.value.should == "http://www.example.org/House" occ.datatype.reference.should == RTM::PSI[:String] end it "should set the datatype to xsd:anyURI even if value is a number" do occ = @topic.create_occurrence("street number", "1", :datatype => RTM::PSI[:Integer]) occ.value.should == "1" occ.datatype.reference.should == RTM::PSI[:Integer] occ.datatype = RTM::PSI[:IRI] occ.value.should == "http://www.topicmapslab.de/1" occ.datatype.reference.should == RTM::PSI[:IRI] end it "should set the datatype to xsd:Integer even if value is a String" do occ = @topic.create_occurrence("street number", "1") occ.value.should == "1" occ.datatype.reference.should == RTM::PSI[:String] occ.datatype = RTM::PSI[:Integer] occ.value.should == "1" occ.datatype.reference.should == RTM::PSI[:Integer] end it "should raise an error if datatype is no String or Locator" do occ = @topic.create_occurrence("street number", "1") occ.datatype.reference.should == RTM::PSI[:String] lambda{occ.datatype = 1}.should raise_error # don't test for symbols #lambda{occ.datatype = :test}.should raise_error lambda{occ.datatype = @tm.get!(RTM::PSI[:IRI])}.should raise_error end end describe "for Variant" do it "should set the datatype to xsd:anyURI even if value is a String" do var = @topic.create_name("White House").create_variant("WH", ["short form"]) var.value.should == "WH" var.datatype.reference.should == RTM::PSI[:String] var.datatype = RTM::PSI[:IRI] var.datatype.reference.should == RTM::PSI[:IRI] end it "should set the datatype to xsd:String even if value is a Locator" do var = @topic.create_name("White House").create_variant(@tm.create_locator("http://www.example.org/House"), ["short form"]) var.value.should == "http://www.example.org/House" var.datatype.reference.should == RTM::PSI[:IRI] var.datatype = RTM::PSI[:String] var.value.should == "http://www.example.org/House" var.datatype.reference.should == RTM::PSI[:String] end it "should set the datatype to xsd:anyURI even if value is a number" do var = @topic.create_name("White House").create_variant("1", RTM::PSI[:Integer], ["short form"]) var.value.should == "1" var.datatype.reference.should == RTM::PSI[:Integer] var.datatype = RTM::PSI[:IRI] var.value.should == "http://www.topicmapslab.de/1" var.datatype.reference.should == RTM::PSI[:IRI] end it "should set the datatype to xsd:Integer even if value is a String" do occ = @topic.create_name("White House").create_variant("1", ["short form"]) occ.value.should == "1" occ.datatype.reference.should == RTM::PSI[:String] occ.datatype = RTM::PSI[:Integer] occ.value.should == "1" occ.datatype.reference.should == RTM::PSI[:Integer] end it "should raise an error if datatype is no String or Locator" do var = @topic.create_name("White House").create_variant("1", ["short form"]) var.datatype.reference.should == RTM::PSI[:String] lambda{var.datatype = 1}.should raise_error # don't test for symbols #lambda{var.datatype = :test}.should raise_error lambda{var.datatype = @tm.get!(RTM::PSI[:IRI])}.should raise_error end end end end end