# Copyright 2011 Till Schulte-Coerne (innoQ Deutschland GmbH) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'test/test_helper' class XmlTest < Test::Unit::TestCase def test_basic_xml_output document = IqRdf::Document.new('http://www.test.de/', :lang => :de) document.namespaces :foaf => 'http://xmlns.com/foaf/0.1/' document << IqRdf::testemann do |t| t.Foaf::knows(IqRdf::testefrau) t.Foaf.nick("Testy") t.Foaf.lastname("Testemann", :lang => :none) end assert_equal(< Testy Testemann rdf end def test_full_uri_subject_xml_output document = IqRdf::Document.new('http://www.test.de/') assert_raise RuntimeError do IqRdf::build_full_uri_subject("bla") end document << IqRdf::build_full_uri_subject(URI.parse('http://www.xyz.de/#test'), IqRdf::build_uri('SomeType')) do |t| t.test("testvalue") end assert_equal(< testvalue rdf end def test_complex_features document = IqRdf::Document.new('http://www.umweltprobenbank.de/', :lang => :de) document.namespaces :skos => 'http://www.w3.org/2008/05/skos#', :foaf => 'http://xmlns.com/foaf/0.1/', :upb => 'http://www.upb.de/' document << IqRdf::testemann.myCustomNote("This is an example", :lang => :en) # :testemann :myCustomNote "This is an example"@en. document << IqRdf::testemann(IqRdf::Foaf::build_uri("Person")).Foaf::name("Heinz Peter Testemann", :lang => :none) # :testemann a foaf:Person; foaf:name "Heinz Peter Testemann" . document << IqRdf::testemann.Foaf::knows(IqRdf::testefrau) # :testemann foaf:knows :testefrau . document << IqRdf::testemann.Foaf::nick("Crash test dummy") # :testemann foaf:nick "Crash test dummy"@de . document << IqRdf::testemann.testIt([IqRdf::hello, "bla"]) # :testIt (:hallo :goodbye "bla"@de), "blubb"@de; # XML: rdf:list ["u1023", "xkfkrl"].each do |id| document << IqRdf::Upb::build_uri(id, IqRdf::Skos::build_uri(:Concept)) do |doc| # upb:#{id} a skos:Concept; doc.Skos::prefLabel("Test", :lang => :en) # skos:prefLabel "Test"@en; doc.Skos::related(IqRdf::Rdf.anotherThing) # skos:related test:another_thing; doc.test1("bla") # :test1 "bla"@de; doc.testIt(:hello, :goodbye, "bla") # :testIt :hallo, :goodbye, "bla"@de; doc.anotherTest(URI.parse("http://www.test.de/foo")) # :anotherTest ; end # . end document << IqRdf::Skos::testnode.test32 do |blank_node| # Blank nodes # skos:testnode :test32 [ blank_node.title("dies ist ein test") # :title "dies ist ein test"@de; blank_node.sub do |subnode| # sub [ subnode.title("blubb") # title "blubb" end # ] end # ] assert_equal(< This is an example Heinz Peter Testemann Crash test dummy bla Test bla bla Test bla bla dies ist ein test blubb rdf =begin skos:testnode :test32 [ :title "dies ist ein test"@de; :sub [ :title "blubb"@de ] ]. =end end def test_literals document = IqRdf::Document.new('http://www.test.de/', :lang => :de) document.namespaces :foaf => 'http://xmlns.com/foaf/0.1/' document << IqRdf::testemann do |t| t.Foaf::knows(:testefrau) t.Foaf.nick("Testy") t.Foaf.lastname("Testemann", :lang => :none) t.age(32) t.married(false) t.weight(65.8) t.quotes("\"I'm \\quoted\"") t.line_breaks("I'm written\nover two lines") t.some_literal(IqRdf::Literal.new("text", :de)) end assert_equal(< Testy Testemann 32 false 65.8 "I'm \\quoted" I'm written over two lines text rdf end end