#!/usr/bin/env ruby

$:.unshift '../lib/' 		
$:.unshift '../../lib/' 		

# Testing load and query of remote rdf while setting baseuri
# Dan Brickley <danbri@w3.org>
# $Id: tc_baseuri.rb,v 1.3 2003/04/06 15:15:39 danbri Exp $

# This tests the base URI facilities of basicrdf, which 
# at the time of writing, are hosed.
#
# recent changes:
# $Log: tc_baseuri.rb,v $
# Revision 1.3  2003/04/06 15:15:39  danbri
# Fixed so it workie.
#
# Revision 1.2  2003/04/06 14:48:16  danbri
# working on base uri problem
#


require 'test/unit'
require 'basicrdf'

class TC_BaseFetchRDF < Test::Unit::TestCase

  attr_accessor :data, :s1, :b1



  def setup
    s1='http://www.w3.org/2001/12/rubyrdf/pack/tests/net/b1.rdf'
    b1='http://www.w3.org/2001/12/rubyrdf/pack/tests/'
    puts "Loading remote RDF from: #{s1}"
    @data = Loader.get_rdf_from_uri s1, b1
  end

  def test_base
    foaf='http://xmlns.com/foaf/0.1/'


    puts "Test that we got a graph"   
    assert (@data != nil, "Should have got a graph during setup")

    pages=data.ask(Statement.new(nil, foaf+'topic', nil)).subjects

    # Make sure it parsed OK(ish):
    puts "Test that it has plausible contents."
    assert(pages.size==1, "doc should contain just one page that has a foaf:topic, we found: '#{pages.size}'")

    page=pages.shift.to_s 
    ok=true
    nt=data.toNtriples.to_s
    local='file://local.rdf/test/relative/uri/here'

    # look for old broken behaviour

    puts "Test that it doesn't contain relative URIs indicating locally parsed tmp file's location."
    assert !(nt =~ /(file:\/\/local.*uri\/here)/), 
	"Shouldn't find this local uri in b1.rdf's ntriples: #{$1} <- rough test"

    # sniff for shiny new behaviour
    puts "Test that the graph contains our base URI."
    assert(nt =~ /#{b1}/, "ntriples should contain our base uri, #{b1}")

    # did the URI turn out correct?
    puts "Test URI label on specific node in the graph."
    assert page == 'http://www.w3.org/2001/12/rubyrdf/pack/tests/test/relative/uri/here',
	"The absolutised URI of the resource with a foaf:topic should be \
	'http://www.w3.org/2001/12/rubyrdf/pack/tests/test/relative/uri/here'; actual: #{page}"


    # TODO: let's try some ../../ stuff, see if that works!

  end

end

