# 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 Topic < ItemProxy
    describe self do
      before(:all) do
        @tm = get_used_tm_sys_tm
        @topic = @tm.get!("person")
        @name = @topic.create_name("Hans")
        @occ = @topic.create_occurrence("Age", "18")
        @proxy = @topic.axes
      end
      after(:all) do
       @tm.close
      end
    it "should be allowed to call #tmapi and #result on a RTM::Axes::Topic" do
      @proxy.methods.should include("tmapi")
      @proxy.methods.should include("result")
    end
    it "should be allowed to call #characteristics on a RTM::Axes::Topic" do
      @proxy.methods.should include("characteristics")
    end
    it "should be allowed to call #indicators on a RTM::Axes::Topic" do
      @proxy.methods.should include("indicators")
    end
    it "should be allowed to call #item on a RTM::Axes::Topic" do
      @proxy.methods.should include("item")
    end
    it "should be allowed to call #locators on a RTM::Axes::Topic" do
      @proxy.methods.should include("locators")
    end
    it "should be allowed to call #reverse_players on a RTM::Axes::Topic" do
      @proxy.methods.should include("reverse_players")
    end
    it "should be allowed to call #reifier on a RTM::Axes::Topic" do
      @proxy.methods.should include("reifier")
    end
    it "should be allowed to call #reverse_roles on a RTM::Axes::Topic" do
      @proxy.methods.should include("reverse_roles")
    end
    it "should be allowed to call #reverse_scope on a RTM::Axes::Topic" do
      @proxy.methods.should include("reverse_scope")
    end
    it "should be allowed to call #supertypes on a RTM::Axes::Topic" do
      @proxy.methods.should include("supertypes")
    end
    it "should be allowed to call #subtypes on a RTM::Axes::Topic" do
      @proxy.methods.should include("subtypes")
    end
    it "should not be allowed to call #reverse_subtypes on a RTM::Axes::Topic" do
      @proxy.methods.should_not include("reverse_subtypes")
    end
    it "should not be allowed to call #reverse_supertypes on a RTM::Axes::Topic" do
      @proxy.methods.should_not include("reverse_supertypes")
    end
    it "should be allowed to call #traverse on a RTM::Axes::Topic" do
      @proxy.methods.should include("traverse")
    end
    it "should be allowed to call #reverse_traverse on a RTM::Axes::Topic" do
      @proxy.methods.should include("reverse_traverse")
    end
    it "should be allowed to call #types on a RTM::Axes::Topic" do
      @proxy.methods.should include("types")
    end
    it "should be allowed to call #instances on a RTM::Axes::Topic" do
      @proxy.methods.should include("instances")
    end
    it "should be allowed to call #reverse_types on a RTM::Axes::Topic" do
      @proxy.methods.should include("reverse_types")
    end
    it "should be allowed to call #reverse_instances on a RTM::Axes::Topic" do
      @proxy.methods.should include("reverse_instances")
    end
      
    describe "#new" do
      it "should raise an error if the underlying construct is not a Topic" do
        lambda{RTM::Axes::Topic.new(1,@tm)}.should raise_error 
      end
      it "should not raise an error if the underlying construct is a Topic" do
        lambda{RTM::Axes::Topic.new(@topic,@tm)}.should_not raise_error 
      end
    end
      
    describe "#characteristics" do
      it "should give back an Array" do
        @proxy.characteristics.should be_a_kind_of Array
      end
      it "should give back an Array consisting of RTM::Axes::Characteristic" do
        @proxy.characteristics.first.should be_a_kind_of RTM::Axes::Characteristic
      end
      it "should give back a RTM::Axes::Characteristics" do
        @proxy.characteristics.should be_a_kind_of RTM::Axes::Characteristics
      end
      it "should give back all Names and Occurrences of this Topic" do
        @proxy.characteristics.size.should == 2
        @proxy.characteristics.map{|c| c.construct}.should include(@name)
        @proxy.characteristics.map{|c| c.construct}.should include(@occ)
      end     
    end
      

    #      it "should give back an empty set it the topic types no role" do
#        @topic.reverse_roles.should be_empty
#      end
#      it "should give back a set of associations where that topic is the role type" do
#        a_asso = @tm.create_association("asso_type")
#        a_asso[@topic] = "to_a_noter_topic"
#        @topic.reverse_roles.length.should == 1
#        @topic.reverse_roles.include?(a_asso).should be_true
#      end
#      it "shuld give back multiple associations if the topic is used multipe times as roll tpye in one association" do
#        a_asso = @tm.create_association("asso_type")
#        a_asso[@topic] = "to_a_noter_topic"
#        a_asso[@topic] = "to_a_noter_topic_2"
#        @topic.reverse_roles.length.should == 2
#        @topic.reverse_roles.select {|a| a == a_asso }.size.should == 2
#      end

    end
  end
end