# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../../spec_helper' module RTM::Name describe self do before(:each) do @tm = get_used_tm_sys_tm @topic = @tm.create_topic_by("Uni_Leipzig") @testname = @topic.create_name("Universitaet Leipzig") end after(:each) do @tm.close end describe "#parent" do it "should give back the Topic the Name belongs to" do #puts "ancestors:" #puts @testname.java_class #puts @testname.class.ancestors @testname.should be_a_kind_of RTM::Name @testname.parent.should == @topic end end describe "#atomify" do it "should give back the value of the Name" do @testname.should be_a_kind_of RTM::Name @testname.atomify.should == "Universitaet Leipzig" end end describe "#children" do it "should return all Variants defined for this Name" do topic = @tm.create_topic_by("Uni_Leipzig") name = topic.create_name("Universitaet Leipzig") scope1 = @tm.create_topic_by("englisch") scope2 = @tm.create_topic_by("umgangssprachlich") variant1 = name.create_variant("University of Leipzig", [scope1]) variant2 = name.create_variant("Universiaet Leipzsch", [scope2]) #puts "ancestors:" #puts variant1.java_class #puts variant1.class.ancestors.inspect variant1.should be_a_kind_of RTM::Variant variant2.should be_a_kind_of RTM::Variant name.children.size.should == 2 name.children.should include(variant1) name.children.should include(variant2) end end describe "#create_variant" do describe "in tmapi notation" do describe "(errors)" do it "should raise an error if the value's datatype is not supported" do lambda{@testname.create_variant({:a => :b}, ["scope"])}.should raise_error end it "should not raise an error if a datatype is given, the value's datatype is not supported but the value may be converted to string" do lambda{:a.to_s}.should_not raise_error lambda{@testname.create_variant(:a, RTM::PSI[:String], ["scope"])}.should_not raise_error end it "should raise an error if no scope is given" do lambda{@testname.create_variant("Uni Leipzig")}.should raise_error end it "should raise an error if the scope is an empty array" do lambda{@testname.create_variant("Uni Leipzig", [])}.should raise_error end end describe "given value and scope" do after(:each) do @var.should be_a_kind_of RTM::Variant @var.scope.should_not be_empty end it "should create a variant with datatype xsd:string if value is a String" do @var = @testname.create_variant("Uni Leipzig", ["short_form"]) @var.value.should == "Uni Leipzig" @var.datatype.reference.should == RTM::PSI[:String] @var.scope.size.should == 1 @var.scope.should include(@tm.get("short_form")) end it "should create a variant with datatype xsd:anyURI if value is a Locator" do @var = @testname.create_variant(@tm.create_locator("http://example.org/testvariant"), [@tm.create_locator("short form")]) @var.value.should == "http://example.org/testvariant" @var.datatype.reference.should == RTM::PSI[:IRI] @var.scope.size.should == 1 @var.scope.should include(@tm.get("short form")) end it "should create a variant with datatype xsd:float if value is a Float" do @var = @testname.create_variant(0.5, [@tm.get!("theme1"), "theme2"]) @var.value.should == "0.5" @var.datatype.reference.should == RTM::PSI[:Float] @var.scope.size.should == 2 @var.scope.should include(@tm.get("theme1"), @tm.get("theme2")) end it "should create a variant with datatype xsd:long if value is a Fixnum" do @var = @testname.create_variant(5, [@tm.get!("theme1"), @tm.create_locator("theme2")]) @var.value.should == "5" @var.datatype.reference.should == RTM::PSI[:Long] @var.scope.size.should == 2 @var.scope.should include(@tm.get("theme1"), @tm.get("theme2")) end it "should create a variant with datatype xsd:integer if value is a Bignum" do number = 9999999999999999999 number.class.should == Bignum @var = @testname.create_variant(number, [@tm.get!("theme1"), "theme2"]) @var.value.should == number.to_s @var.datatype.reference.should == RTM::PSI[:Integer] @var.scope.size.should == 2 @var.scope.should include(@tm.get("theme1"), @tm.get("theme2")) end describe "given a parent name with scope" do it "should create a variant" do @name = @topic.create_name("University of Leipzig", ["en", "official"]) @name.scope.size.should == 2 @name.scope.should include(@tm.get("en"), @tm.get("official")) @var = @name.create_variant("U o L", ["short form"]) @var.scope.size.should == 3 @var.scope.should include(@tm.get("en"), @tm.get("official"), @tm.get("short form")) @var.datatype.reference.should == RTM::PSI[:String] end end end describe "given value, datatype and scope" do after(:each) do if @var @var.should be_a_kind_of RTM::Variant @var.scope.should_not be_empty end end describe "and value is a String" do after(:each) do if @var @var.scope.size.should == 1 @var.scope.should include(@tm.get("short_form")) end end it "should create a variant if datatye is xsd:string" do @var = @testname.create_variant("Uni Leipzig", RTM::PSI[:String], ["short_form"]) @var.value.should == "Uni Leipzig" @var.datatype.reference.should == RTM::PSI[:String] end it "should create a variant if datatye is xsd:anyURI" do @var = @testname.create_variant("Uni Leipzig", RTM::PSI[:IRI], ["short_form"]) @var.value.should == "http://www.topicmapslab.de/Uni Leipzig" @var.datatype.reference.should == RTM::PSI[:IRI] end it "should create a variant if datatye is xsd:float" do @var = @testname.create_variant("0.5", RTM::PSI[:Float], ["short_form"]) @var.value.should == "0.5" @var.datatype.reference.should == RTM::PSI[:Float] end it "should create a variant if datatye is xsd:long" do @var = @testname.create_variant("5", RTM::PSI[:Long], ["short_form"]) @var.value.should == "5" @var.datatype.reference.should == RTM::PSI[:Long] end it "should create a variant if datatye is xsd:integer" do number = 9999999999999999999 number.class.should == Bignum @var = @testname.create_variant(number.to_s, RTM::PSI[:Integer], ["short_form"]) @var.value.should == number.to_s @var.datatype.reference.should == RTM::PSI[:Integer] end describe "but value is not a number" do it "should create a variant if datatye is xsd:float" do @var = @testname.create_variant("no number", RTM::PSI[:Float], ["short_form"]) @var.value.should == "no number" @var.datatype.reference.should == RTM::PSI[:Float] end it "should create a variant if datatye is xsd:long" do @var = @testname.create_variant("no number", RTM::PSI[:Long], ["short_form"]) @var.value.should == "no number" @var.datatype.reference.should == RTM::PSI[:Long] end it "should create a variant if datatye is xsd:integer" do if implementation_for_spec == :tinytim lambda{@testname.create_variant("no number", RTM::PSI[:Integer], ["short_form"])}.should raise_error else @var = @testname.create_variant("no number", RTM::PSI[:Integer], ["short_form"]) @var.value.should == "no number" @var.datatype.reference.should == RTM::PSI[:Integer] end end end end describe "and value is a Locator" do it "should create a variant if value is a Number and datatype is xsd:string" it "should create a variant if value is a Number and datatype is xsd:anyURI" it "should create a variant if value is a Number and datatype is xsd:float" it "should create a variant if value is a Number and datatype is xsd:long" it "should create a variant if value is a Number and datatype is xsd:integer" describe "but value is not a number" do it "should create a variant if datatye is xsd:float" it "should create a variant if datatye is xsd:long" it "should create a variant if datatye is xsd:integer" end end describe "and value is a Number" do it "should create a variant if value is a Number and datatype is xsd:string" it "should create a variant if value is a Number and datatype is xsd:anyURI" it "should create a variant if value is a Number and datatype is xsd:float" it "should create a variant if value is a Number and datatype is xsd:long" it "should create a variant if value is a Number and datatype is xsd:integer" it "should be tested further" end describe "given a parent name with scope" do it "should create a variant" do @name = @topic.create_name("University of Leipzig", ["en", "official"]) @name.scope.size.should == 2 @name.scope.should include(@tm.get("en"), @tm.get("official")) @var = @name.create_variant("U o L", RTM::PSI[:IRI], ["short form"]) @var.scope.size.should == 3 @var.scope.should include(@tm.get("en"), @tm.get("official"), @tm.get("short form")) @var.datatype.reference.should == RTM::PSI[:IRI] end end end end describe "in hash notation" do describe "given value and scope" do it "should create a variant with datatype xsd:string if value is a String" it "should create a variant with datatype xsd:anyURI if value is a Locator" it "should create a variant with datatype xsd:float if value is a Float" it "should create a variant with datatype xsd:long if value is a Fixnum" it "should create a variant with datatype xsd:integer if value is a Bignum" it "should create a variant if scope is an empty array" it "should raise an error if value's datatype is not supported" end describe "given value, datatype and scope" do it "should be implemented and tested" end 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") @name = @topic1.create_name("firstname","Hans") @name.create_variant("Hansi",["Spitzname"]) @topic2.create_name("firstname","Peter") @topic1.should have(1).names @topic1.names.should include @name end after(:each) do @tm.close end it "should remove this name from the container (topic)" do @tm.literal_index.getNames("Hans").size.should == 1 @name.remove @tm.literal_index.getNames("Hans").size.should == 0 @tm.literal_index.getNames("Peter").size.should == 1 @topic1.should have(0).names end end end # of describe self end # of module