# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../spec_helper' module RTM::Axes class String < ItemProxy describe self do before(:all) do @tm = get_used_tm_sys_tm @proxy = "string".axes(@tm) end after(:all) do @tm.close end it "should be allowed to call #tmapi and #result on a RTM::TQML::String" do @proxy.methods.should include("tmapi") @proxy.methods.should include("result") end it "should be allowed to call #reverse_atomify on a RTM::TQML::String" do @proxy.methods.should include("reverse_atomify") end it "should be allowed to call #reverse_indicators on a RTM::TQML::String" do @proxy.methods.should include("reverse_indicators") end it "should be allowed to call #reverse_item on a RTM::TQML::String" do @proxy.methods.should include("reverse_item") end it "should be allowed to call #reverse_locators on a RTM::TQML::String" do @proxy.methods.should include("reverse_locators") end describe "#new" do it "should raise an error if the underlying construct is not a String" do lambda{RTM::Axes::String.new(1,@tm)}.should raise_error end it "should not raise an error if the underlying construct is a String" do lambda{RTM::Axes::String.new("string",@tm)}.should_not raise_error end end describe "#reverse_atomify" do before(:all) do @topic1 = @tm.get!("Hans") @topic2 = @tm.get!("Peter") @topic3 = @tm.get!("Hans2") @name1 = @topic1.create_name("Hans") @name2 = @topic2.create_name("Peter") @name3 = @topic3.create_name("Hans") @occ1 = @topic1.create_occurrence("Number","18") @occ2 = @topic2.create_occurrence("Age", "18") @occ3 = @topic3.create_occurrence("Friend", "Hans") @variant1 = @name2.create_variant("Hans",[@tm.get!("Alias")]) end it "should give back an Array" do "Hans".axes(@tm).reverse_atomify.should be_a_kind_of Array "nothing".axes(@tm).reverse_atomify.should be_a_kind_of Array end it "should give back an Array consisting of RTM::Axes::Characteristic" do "Hans".axes(@tm).reverse_atomify.first.should be_a_kind_of RTM::Axes::Characteristic end it "should give back a RTM::Axes::Characteristics" do "Hans".axes(@tm).reverse_atomify.should be_a_kind_of RTM::Axes::Characteristics end it "should give back all Names and Occurrences which have this String as value (including Variant values)" do value1 = "Hans" value2 = "18" value1.axes(@tm).reverse_atomify.size.should == 4 value2.axes(@tm).reverse_atomify.size.should == 2 value1.axes(@tm).reverse_atomify.map{|res| res.construct}.should include(@name1) value1.axes(@tm).reverse_atomify.map{|res| res.construct}.should include(@name3) value1.axes(@tm).reverse_atomify.map{|res| res.construct}.should include(@occ3) value1.axes(@tm).reverse_atomify.map{|res| res.construct}.should include(@name2) value2.axes(@tm).reverse_atomify.map{|res| res.construct}.should include(@occ1) value2.axes(@tm).reverse_atomify.map{|res| res.construct}.should include(@occ2) end it "should give back nil if String does not occur in a Name or Occurrence" do "nothing".axes(@tm).reverse_atomify.should be_empty end end describe "reverse identifier methods" do before(:all) do @value = "http://www.example.org/anything" @si_value = "http://www.example.org/test_si" @ii_value = "http://www.example.org/test_ii" @sl_value = "http://www.example.org/test_sl" @si_topic = @tm.get!("si:" + @si_value) @ii_topic = @tm.get!("ii:" + @ii_value) @sl_topic = @tm.get!("=" + @sl_value) @all_topic = @tm.create_topic @all_si_value = "http://www.example.org/all_si" @all_ii_value = "http://www.example.org/all_ii" @all_sl_value = "http://www.example.org/all_sl" @all_topic.add_subject_identifier(@all_si_value) @all_topic.add_item_identifier(@all_ii_value) @all_topic.add_subject_locator(@all_sl_value) end describe "#reverse_indicators" do it "should give back a RTM::Axes::Topic if a Topic is found" do @si_value.axes(@tm).reverse_indicators.should be_a_kind_of(RTM::Axes::Topic) @all_si_value.axes(@tm).reverse_indicators.should be_a_kind_of(RTM::Axes::Topic) end it "should give back nil if no Topic is found" do @value.axes(@tm).reverse_indicators.should be_nil end it "should give back the right Topic" do @si_value.axes(@tm).reverse_indicators.construct.should == @si_topic @all_si_value.axes(@tm).reverse_indicators.construct.should == @all_topic end end describe "#reverse_item" do it "should give back a RTM::Axes::Topic if a Topic is found" do @ii_value.axes(@tm).reverse_item.should be_a_kind_of(RTM::Axes::Topic) @all_ii_value.axes(@tm).reverse_item.should be_a_kind_of(RTM::Axes::Topic) end it "should give back nil if no Topic is found" do @value.axes(@tm).reverse_item.should be_nil end it "should give back the right Topic" do @ii_value.axes(@tm).reverse_item.construct.should == @ii_topic @all_ii_value.axes(@tm).reverse_item.construct.should == @all_topic end end describe "#reverse_locators" do it "should give back a RTM::Axes::Topic if a Topic is found" do @sl_value.axes(@tm).reverse_locators.should be_a_kind_of(RTM::Axes::Topic) @all_sl_value.axes(@tm).reverse_locators.should be_a_kind_of(RTM::Axes::Topic) end it "should give back nil if no Topic is found" do @value.axes(@tm).reverse_locators.should be_nil end it "should give back the right Topic" do @sl_value.axes(@tm).reverse_locators.construct.should == @sl_topic @all_sl_value.axes(@tm).reverse_locators.construct.should == @all_topic end end end end #of describe self end end