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

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

module RTM::IO::TmapiXFrom::TopicMap

  describe self do
    before(:each) do
      @tm = get_used_tm_sys_tm
      @tm.topics.should be_empty
      @tm.associations.should be_empty
      @tm.names.should be_empty
      @tm.occurrences.should be_empty
      @tm.variants.should be_empty
      @tm.roles.should be_empty
      @test_size = false
    end
    after(:each) do
      if @test_size
        # This is just for testing if approx. everything was imported
        @tm.topics.size.should >= 117
        @tm.associations.size.should >= 58
        @tm.names.size.should >= 169
        @tm.occurrences.size.should == 28
        @tm.variants.size.should == 44
        @tm.roles.size.should >= 131
      end
      @tm.close
    end

    describe "#from_ltm" do
      it "should import into an empty topic map" do
        @tm.from_ltm(File.dirname(__FILE__) + "/../../resources/toyTM.ltm")
#        @tm.occurrences.each do |o|
#          puts "Occurrence:"
#          puts "Type: " + o.type.reference
#          puts "Parent: " + o.parent.reference
#        end
        #@test_size = true
      end
      it "should load the pokemon.ltm map" do
        @tm.from_ltm(File.dirname(__FILE__) + "/../../resources/pokemon.ltm")
      end
    end

    describe "#from_ctm" do
      it "should import into an empty topic map" do
        @tm.from_ctm(File.dirname(__FILE__) + "/../../resources/toyTM.ctm")
        @test_size = true
      end
    end

    describe "#from_jtm" do
      it "should import into an empty topic map" do
        @tm.from_jtm(File.dirname(__FILE__) + "/../../resources/toyTM.jtm")
        @test_size = true
      end
    end

    describe "#from_tmxml" do
      it "should import into an empty topic map" do
        pending "not working" do
          @tm.from_tmxml(File.dirname(__FILE__) + "/../../resources/toyTM.tmxml")
        end
      end
    end

    describe "#from_xtm10" do
      it "should import into an empty topic map" do
        @tm.from_xtm10(File.dirname(__FILE__) + "/../../resources/toyTM_xtm10.xtm")
        @test_size = true
      end
      it "should provide an alias for from_xtm1" do
        @tm.method(:from_xtm1).should == @tm.method(:from_xtm10)
      end
    end

    describe "#from_xtm20" do
      it "should import into an empty topic map" do
        @tm.from_xtm20(File.dirname(__FILE__) + "/../../resources/toyTM_xtm20.xtm")
        @test_size = true
      end
      it "should provide an alias for from_xtm2" do
        @tm.method(:from_xtm2).should == @tm.method(:from_xtm20)
      end
    end

    describe "#from_xtm21" do
      it "should import into an empty topic map from xtm v2.1" do
        @tm.from_xtm21(File.dirname(__FILE__) + "/../../resources/toyTM.xtm")
        @test_size = true
      end
      it "should provide an alias for from_xtm2" do
        @tm.method(:from_xtm).should == @tm.method(:from_xtm20)
      end
    end

    describe "#from_n3" do
      it "should be tested"
    end

    describe "#from_rdfxml" do
      it "should be tested"
    end

  end
end