#!/usr/bin/env ruby

# Test our basic RDF API for work with RDF containers.
#
# Dan Brickley <danbri@w3.org>
# $Id: tc_containers.rb,v 1.3 2003/04/21 19:54:54 danbri Exp $

# DONE:
# - basic load and read of rdf:Bag data
#
# TODO:
# - syntactic variants
# - Seq, Alt
# - leaking of rdf:li into model
# - rdf:member perhaps?
# - what about the rdf:List stuff?

$LOAD_PATH.unshift '../../lib/'

require 'basicrdf'
require 'test/unit'
require 'RDF4R/pastiche'

include RDF4R::Pastiche::SWAP #hmm

class TC_Containers < Test::Unit::TestCase

  FOAF='http://xmlns.com/foaf/0.1/'
  DC='http://purl.org/dc/elements/1.1'
  RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  attr_accessor :db, :verbose

  def setup
   t1='http://www.w3.org/2001/12/rubyrdf/pack/tests/containers/bag1.rdf'
   @db=Loader.get_rdf_from_uri t1
   verbose=false
  end

  def test_got_db
    assert(@db != nil, "We need a database to test.")
  end

  def test_got_triples
    assert @db.statements.size>1, "Expected >1 triple."
  end

  def test_got_Bag

    bags=@db.ask(Statement.new(nil,RDF+'type',RDF+'Bag')).subjects
    assert bags.size==1, "Only expect one bag."
    bag=bags.shift.to_s
    items=@db.ask(Statement.new(bag, nil, nil)).statements
    puts items.inspect if verbose

    profiles=Formula.new @db
     
    items=[]

    profiles.statementsMatching('subj'=>bag) do |s|
      items.push s.object.to_s if s.predicate.to_s =~ /#{RDF}_/
    end
    assert items.size==4, "Bag had: #{items.size} items, expected 4."
  end

  def teardown
   @db=nil
  end

end

