# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 require File.dirname(__FILE__) + '/../../spec_helper' module RTM::Axes module Strings describe self do before(:all) do @tm = get_used_tm_sys_tm @proxy = ["string1".axes(@tm),"string2".axes(@tm)].extend(Strings) end after(:all) do @tm.close end it "should be allowed to call #tmapi and #result on a Strings-Array" do @proxy.methods.should include("tmapi") @proxy.methods.should include("result") end it "should be allowed to call #reverse_atomify on a Strings-Array" do @proxy.methods.should include("reverse_atomify") end it "should not be allowed to call #reverse_indicators on a Strings-Array" do @proxy.methods.should include("reverse_indicators") end it "should not be allowed to call #reverse_item on a Strings-Array" do @proxy.methods.should include("reverse_item") end it "should not be allowed to call #reverse_locators on a Strings-Array" do @proxy.methods.should include("reverse_locators") 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("Frien", "Hans") @variant1 = @name2.create_variant("Hans",[@tm.get!("Alias")]) @proxies = ["Hans".axes(@tm),"18".axes(@tm)].extend(Strings) end it "should give back an Array" do @proxies.reverse_atomify.should be_a_kind_of Array end it "should give back an Array consisting of RTM::Axes::Characteristic" do @proxies.reverse_atomify.first.should be_a_kind_of RTM::Axes::Characteristic end it "should give back a Characteristics" do @proxies.reverse_atomify.should be_a_kind_of RTM::Axes::Characteristics end it "should give back all Names and Occurrences which have these Strings as value (including Variant values)" do @proxies.reverse_atomify.size.should == 6 @proxies.reverse_atomify.map{|res| res.construct}.should include(@name1) @proxies.reverse_atomify.map{|res| res.construct}.should include(@name3) @proxies.reverse_atomify.map{|res| res.construct}.should include(@occ3) @proxies.reverse_atomify.map{|res| res.construct}.should include(@name2) @proxies.reverse_atomify.map{|res| res.construct}.should include(@occ1) @proxies.reverse_atomify.map{|res| res.construct}.should include(@occ2) end it "should give back nothing if String in Array does not occur in a Name or Occurrence" do ["nothing".axes(@tm)].extend(Strings).reverse_atomify.should be_empty end end describe "reverse identifier methods" do before(:all) do @value = "http://www.example.org/anything" @si_value1 = "http://www.example.org/test_si_1" @ii_value1 = "http://www.example.org/test_ii_1" @sl_value1 = "http://www.example.org/test_sl_1" @si_value2 = "http://www.example.org/test_si_2" @ii_value2 = "http://www.example.org/test_ii_2" @sl_value2 = "http://www.example.org/test_sl_2" @si_topic1 = @tm.get!("si:" + @si_value1) @ii_topic1 = @tm.get!("ii:" + @ii_value1) @sl_topic1 = @tm.get!("=" + @sl_value1) @si_topic2 = @tm.get!("si:" + @si_value2) @ii_topic2 = @tm.get!("ii:" + @ii_value2) @sl_topic2 = @tm.get!("=" + @sl_value2) @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) @proxies = [@si_value1.axes(@tm),@ii_value1.axes(@tm),@sl_value1.axes(@tm),@si_value2.axes(@tm),@ii_value2.axes(@tm),@sl_value2.axes(@tm),@all_si_value.axes(@tm),@all_ii_value.axes(@tm),@all_sl_value.axes(@tm)].extend(Strings) end describe "#reverse_indicators" do it "should give back an Array" do @proxies.reverse_indicators.should be_a_kind_of Array end it "should give back an Array consisting of RTM::Axes::Topic" do @proxies.reverse_indicators.first.should be_a_kind_of(RTM::Axes::Topic) end it "should give back a Topics" do @proxies.reverse_indicators.should be_a_kind_of RTM::Axes::Topics end it "should give back all Topics which have these Strings as indicators" do @proxies.reverse_indicators.size.should == 3 @proxies.reverse_indicators.map{|res| res.construct}.should include(@si_topic1) @proxies.reverse_indicators.map{|res| res.construct}.should include(@si_topic2) @proxies.reverse_indicators.map{|res| res.construct}.should include(@all_topic) end it "should give back nothing if no Topic has one of these Strings as indicator" do [@value.axes(@tm)].extend(Strings).reverse_indicators.should be_empty end it "should give back the same Topics several times" do [@si_value1.axes(@tm),@si_value1.axes(@tm)].extend(Strings).reverse_indicators.size.should == 2 end end describe "#reverse_item" do it "should give back an Array" do @proxies.reverse_item.should be_a_kind_of Array end it "should give back an Array consisting of RTM::Axes::Topic" do @proxies.reverse_item.first.should be_a_kind_of(RTM::Axes::Topic) end it "should give back a Topics" do @proxies.reverse_item.should be_a_kind_of RTM::Axes::Topics end it "should give back all Topics which have these Strings as item identifier" do @proxies.reverse_item.size.should == 3 @proxies.reverse_item.map{|res| res.construct}.should include(@ii_topic1) @proxies.reverse_item.map{|res| res.construct}.should include(@ii_topic2) @proxies.reverse_item.map{|res| res.construct}.should include(@all_topic) end it "should give back nothing if no Topic has one of these Strings as item identifier" do [@value.axes(@tm)].extend(Strings).reverse_item.should be_empty end it "should give back the same Topics several times" do [@ii_value1.axes(@tm),@ii_value1.axes(@tm)].extend(Strings).reverse_item.size.should == 2 end end describe "#reverse_locators" do it "should give back an Array" do @proxies.reverse_locators.should be_a_kind_of Array end it "should give back an Array consisting of RTM::Axes::Topic" do @proxies.reverse_locators.first.should be_a_kind_of(RTM::Axes::Topic) end it "should give back a Topics" do @proxies.reverse_locators.should be_a_kind_of RTM::Axes::Topics end it "should give back all Topics which have these Strings as subject locator" do @proxies.reverse_locators.size.should == 3 @proxies.reverse_locators.map{|res| res.construct}.should include(@sl_topic1) @proxies.reverse_locators.map{|res| res.construct}.should include(@sl_topic2) @proxies.reverse_locators.map{|res| res.construct}.should include(@all_topic) end it "should give back nothing if no Topic has one of these Strings as subject locator" do [@value.axes(@tm)].extend(Strings).reverse_locators.should be_empty end it "should give back the same Topics several times" do [@sl_value1.axes(@tm),@sl_value1.axes(@tm)].extend(Strings).reverse_locators.size.should == 2 end end end end end end