# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
# License:   Apache License, Version 2.0

require File.dirname(__FILE__) + '/../../../spec_helper'

module RTM::Typed
  describe self do
    before(:each) do
      @tm = get_used_tm_sys_tm    
    end
    after(:each) do
      @tm.close
    end
    describe "#type" do
      before(:each) do
         @topic = @tm.create_topic_by("Uni_Leipzig")
      @testname = @topic.create_name("test_type","Universität Leipzig")
      end
      it "for all instances of Typed this should give back the type" do
        @testname.type.should == @tm.get("test_type")
      end
      it "should following the TMDM give back all instances of supertypes"
    end

    describe "#type=" do
      before(:each) do
        topic = @tm.get!("child")
        @name = topic.create_name("Child")
        @name.should be_a_kind_of RTM::Name
        @occ = topic.create_occurrence("height","small")
        @occ.should be_a_kind_of RTM::Occurrence
        @assoc = @tm.create_association("mother_child")
        @assoc.should be_a_kind_of RTM::Association
        @role = @assoc.create_role("child","Hans")
        @role.should be_a_kind_of RTM::Role
      end
      it "should set the type if the Construct is a Role and identifier a String" do
        previous_type = @role.type
        @role.type = "infant"
        @role.type.should_not == previous_type
        @role.type.should == @tm.get("infant")
      end
      it "should set the type if the Construct is a Role and identifier a Locator" do
        previous_type = @role.type
        @role.type = @tm.create_locator("infant")
        @role.type.should_not == previous_type
        @role.type.should == @tm.get("infant")
      end
      it "should set the type if the Construct is a Role and identifier a Topic" do
        previous_type = @role.type
        @role.type = @tm.get!("infant")
        @role.type.should_not == previous_type
        @role.type.should == @tm.get("infant")
      end
      it "should set the type if the Construct is an Association and identifier a String" do
        previous_type = @assoc.type
        @assoc.type = "mother-infant"
        @assoc.type.should_not == previous_type
        @assoc.type.should == @tm.get("mother-infant")
      end
      it "should set the type if the Construct is an Association and identifier a Locator" do
        previous_type = @assoc.type
        @assoc.type = @tm.create_locator("mother-infant")
        @assoc.type.should_not == previous_type
        @assoc.type.should == @tm.get("mother-infant")
      end
      it "should set the type if the Construct is an Association and identifier a Topic" do
        previous_type = @assoc.type
        @assoc.type = @tm.get!("mother-infant")
        @assoc.type.should_not == previous_type
        @assoc.type.should == @tm.get("mother-infant")
      end    
      it "should set the type if the Construct is a Name and identifier a String" do
        previous_type = @name.type
        @name.type = "infant"
        @name.type.should_not == previous_type
        @name.type.should == @tm.get("infant")
      end
      it "should set the type if the Construct is a Name and identifier a Locator" do
        previous_type = @name.type
        @name.type = @tm.create_locator("infant")
        @name.type.should_not == previous_type
        @name.type.should == @tm.get("infant")
      end
      it "should set the type if the Construct is a Name and identifier a Topic" do
        previous_type = @name.type
        @name.type = @tm.get!("infant")
        @name.type.should_not == previous_type
        @name.type.should == @tm.get("infant")
      end  
      it "should set the type if the Construct is an Occurrence and identifier a String" do
        previous_type = @occ.type
        @occ.type = "size"
        @occ.type.should_not == previous_type
        @occ.type.should == @tm.get("size")
      end
      it "should set the type if the Construct is an Occurrence and identifier a Locator" do
        previous_type = @occ.type
        @occ.type = @tm.create_locator("size")
        @occ.type.should_not == previous_type
        @occ.type.should == @tm.get("size")
      end
      it "should set the type if the Construct is an Occurrence and identifier a Topic" do
        previous_type = @occ.type
        @occ.type = @tm.get!("size")
        @occ.type.should_not == previous_type
        @occ.type.should == @tm.get("size")
      end
    end

  end
end