1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package complex.unoxml; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import helper.StreamSimulator; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 33*cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 34*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 35*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 36*cdf0e10cSrcweir import com.sun.star.lang.IllegalArgumentException; 37*cdf0e10cSrcweir import com.sun.star.lang.WrappedTargetException; 38*cdf0e10cSrcweir import com.sun.star.lang.WrappedTargetRuntimeException; 39*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 40*cdf0e10cSrcweir import com.sun.star.beans.Pair; 41*cdf0e10cSrcweir import com.sun.star.beans.StringPair; 42*cdf0e10cSrcweir import com.sun.star.container.XEnumeration; 43*cdf0e10cSrcweir import com.sun.star.container.ElementExistException; 44*cdf0e10cSrcweir import com.sun.star.container.NoSuchElementException; 45*cdf0e10cSrcweir import com.sun.star.io.XInputStream; 46*cdf0e10cSrcweir import com.sun.star.io.XOutputStream; 47*cdf0e10cSrcweir import com.sun.star.text.XTextRange; 48*cdf0e10cSrcweir import com.sun.star.text.XText; 49*cdf0e10cSrcweir import com.sun.star.rdf.*; 50*cdf0e10cSrcweir import lib.TestParameters; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir import org.junit.After; 53*cdf0e10cSrcweir import org.junit.AfterClass; 54*cdf0e10cSrcweir import org.junit.Before; 55*cdf0e10cSrcweir import org.junit.BeforeClass; 56*cdf0e10cSrcweir import org.junit.Test; 57*cdf0e10cSrcweir import org.openoffice.test.OfficeConnection; 58*cdf0e10cSrcweir import static org.junit.Assert.*; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir /** 61*cdf0e10cSrcweir * Test case for service com.sun.star.rdf.Repository 62*cdf0e10cSrcweir * Currently, this service is implemented in 63*cdf0e10cSrcweir * unoxml/source/rdf/librdf_repository.cxx 64*cdf0e10cSrcweir * 65*cdf0e10cSrcweir * @author mst 66*cdf0e10cSrcweir */ 67*cdf0e10cSrcweir public class RDFRepositoryTest 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir XComponentContext xContext; 70*cdf0e10cSrcweir String tempDir; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir XDocumentRepository xRep; 73*cdf0e10cSrcweir XURI foo; 74*cdf0e10cSrcweir XURI bar; 75*cdf0e10cSrcweir XURI baz; 76*cdf0e10cSrcweir XURI uint; 77*cdf0e10cSrcweir XURI rdfslabel; 78*cdf0e10cSrcweir XURI manifest; 79*cdf0e10cSrcweir XURI uuid; 80*cdf0e10cSrcweir XURI base; 81*cdf0e10cSrcweir XBlankNode blank; 82*cdf0e10cSrcweir XLiteral lit; 83*cdf0e10cSrcweir XLiteral litlang; 84*cdf0e10cSrcweir XLiteral littype; 85*cdf0e10cSrcweir String rdfs = "http://www.w3.org/2000/01/rdf-schema#"; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir /** 88*cdf0e10cSrcweir * The test parameters 89*cdf0e10cSrcweir */ 90*cdf0e10cSrcweir private static TestParameters param = null; 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir // public String[] getTestMethodNames () 93*cdf0e10cSrcweir // { 94*cdf0e10cSrcweir // return new String[] { "check", "checkSPARQL", "checkRDFa" }; 95*cdf0e10cSrcweir // } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir @Before public void before() 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir try { 100*cdf0e10cSrcweir XMultiServiceFactory xMSF = getMSF(); 101*cdf0e10cSrcweir param = new TestParameters(); 102*cdf0e10cSrcweir param.put("ServiceFactory", xMSF); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir assertNotNull("could not create MultiServiceFactory.", xMSF); 105*cdf0e10cSrcweir XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xMSF); 106*cdf0e10cSrcweir Object defaultCtx = xPropertySet.getPropertyValue("DefaultContext"); 107*cdf0e10cSrcweir xContext = UnoRuntime.queryInterface(XComponentContext.class, defaultCtx); 108*cdf0e10cSrcweir assertNotNull("could not get component context.", xContext); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir tempDir = util.utils.getOfficeTemp/*Dir*/(xMSF); 111*cdf0e10cSrcweir System.out.println("tempdir: " + tempDir); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir foo = URI.create(xContext, "uri:foo"); 114*cdf0e10cSrcweir assertNotNull("foo", foo); 115*cdf0e10cSrcweir bar = URI.create(xContext, "uri:bar"); 116*cdf0e10cSrcweir assertNotNull("bar", bar); 117*cdf0e10cSrcweir baz = URI.create(xContext, "uri:baz"); 118*cdf0e10cSrcweir assertNotNull("baz", baz); 119*cdf0e10cSrcweir uint = URI.create(xContext, "uri:int"); 120*cdf0e10cSrcweir assertNotNull("uint", uint); 121*cdf0e10cSrcweir blank = BlankNode.create(xContext, "_:uno"); 122*cdf0e10cSrcweir assertNotNull("blank", blank); 123*cdf0e10cSrcweir lit = Literal.create(xContext, "i am the literal"); 124*cdf0e10cSrcweir assertNotNull("lit", lit); 125*cdf0e10cSrcweir litlang = Literal.createWithLanguage(xContext, 126*cdf0e10cSrcweir "i am the literal", "en"); 127*cdf0e10cSrcweir assertNotNull("litlang", litlang); 128*cdf0e10cSrcweir littype = Literal.createWithType(xContext, "42", uint); 129*cdf0e10cSrcweir assertNotNull("littype", littype); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir rdfslabel = URI.create(xContext, rdfs + "label"); 132*cdf0e10cSrcweir assertNotNull("rdfslabel", rdfslabel); 133*cdf0e10cSrcweir manifest = URI.create(xContext, "manifest:manifest"); //FIXME 134*cdf0e10cSrcweir assertNotNull("manifest", manifest); 135*cdf0e10cSrcweir uuid = URI.create(xContext, 136*cdf0e10cSrcweir "urn:uuid:224ab023-77b8-4396-a75a-8cecd85b81e3"); 137*cdf0e10cSrcweir assertNotNull("uuid", uuid); 138*cdf0e10cSrcweir base = URI.create(xContext, "base-uri:"); //FIXME 139*cdf0e10cSrcweir assertNotNull("base", base); 140*cdf0e10cSrcweir } catch (Exception e) { 141*cdf0e10cSrcweir report(e); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir //FIXME: ? 144*cdf0e10cSrcweir // xRep = Repository.create(xContext); 145*cdf0e10cSrcweir System.out.println("Creating service Repository..."); 146*cdf0e10cSrcweir xRep = UnoRuntime.queryInterface(XDocumentRepository.class, Repository.create(xContext)); 147*cdf0e10cSrcweir assertNotNull("null", xRep); 148*cdf0e10cSrcweir System.out.println("...done"); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir @After public void after() 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir xRep = null; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir @Test public void check() 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir try { 159*cdf0e10cSrcweir System.out.println("Checking that new repository is really empty..."); 160*cdf0e10cSrcweir assertTrue("empty: graphs", 0 == xRep.getGraphNames().length); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir XEnumeration stmts; 163*cdf0e10cSrcweir stmts = xRep.getStatements(null, null, null); 164*cdf0e10cSrcweir assertTrue("empty: stmts", !stmts.hasMoreElements()); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir System.out.println("...done"); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir System.out.println("Checking graph creation..."); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir XNamedGraph xFooGraph = xRep.createGraph(foo); 171*cdf0e10cSrcweir assertNotNull("foo graph", xFooGraph); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir try { 174*cdf0e10cSrcweir xRep.createGraph(foo); 175*cdf0e10cSrcweir fail("creating duplicate graph was allowed"); 176*cdf0e10cSrcweir } catch (ElementExistException e) { 177*cdf0e10cSrcweir // ignore 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir try { 181*cdf0e10cSrcweir xRep.createGraph(null); 182*cdf0e10cSrcweir fail("invalid graph name was allowed"); 183*cdf0e10cSrcweir } catch (IllegalArgumentException e) { 184*cdf0e10cSrcweir // ignore 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir XURI[] names = xRep.getGraphNames(); 188*cdf0e10cSrcweir assertTrue("no foo graph in getGraphNames", 189*cdf0e10cSrcweir 1 == names.length && eq(names[0], foo)); 190*cdf0e10cSrcweir assertNotNull("no foo graph", xRep.getGraph(foo)); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir stmts = xFooGraph.getStatements(null, null, null); 193*cdf0e10cSrcweir assertTrue("stmts in foo graph", !stmts.hasMoreElements()); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir XOutputStream xFooOut = 196*cdf0e10cSrcweir new StreamSimulator(tempDir + "empty.rdf", false, param); 197*cdf0e10cSrcweir xRep.exportGraph(FileFormat.RDF_XML, xFooOut, foo, base); 198*cdf0e10cSrcweir xFooOut.closeOutput(); 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir XInputStream xFooIn = 201*cdf0e10cSrcweir new StreamSimulator(tempDir + "empty.rdf", true, param); 202*cdf0e10cSrcweir xRep.importGraph(FileFormat.RDF_XML, xFooIn, bar, base); 203*cdf0e10cSrcweir assertNotNull("no bar graph", xRep.getGraph(bar)); 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir System.out.println("...done"); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir System.out.println("Checking graph manipulation..."); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir XEnumeration xFooEnum; 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir Statement xFoo_FooBarBaz = new Statement(foo, bar, baz, foo); 212*cdf0e10cSrcweir xFooGraph.addStatement(foo, bar, baz); 213*cdf0e10cSrcweir xFooEnum = xFooGraph.getStatements(null, null, null); 214*cdf0e10cSrcweir assertTrue("addStatement(foo,bar,baz)", 215*cdf0e10cSrcweir eq(xFooEnum, new Statement[] { xFoo_FooBarBaz })); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir Statement xFoo_FooBarBlank = new Statement(foo, bar, blank, foo); 218*cdf0e10cSrcweir xFooGraph.addStatement(foo, bar, blank); 219*cdf0e10cSrcweir xFooEnum = xFooGraph.getStatements(null, null, null); 220*cdf0e10cSrcweir assertTrue("addStatement(foo,bar,blank)", 221*cdf0e10cSrcweir eq(xFooEnum, 222*cdf0e10cSrcweir new Statement[] { xFoo_FooBarBaz, xFoo_FooBarBlank })); 223*cdf0e10cSrcweir xFooEnum = xRep.getStatements(null, null, null); 224*cdf0e10cSrcweir assertTrue("addStatement(foo,bar,blank) (global)", 225*cdf0e10cSrcweir eq(xFooEnum, 226*cdf0e10cSrcweir new Statement[] { xFoo_FooBarBaz, xFoo_FooBarBlank })); 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir Statement xFoo_BazBarLit = new Statement(baz, bar, lit, foo); 229*cdf0e10cSrcweir xFooGraph.addStatement(baz, bar, lit); 230*cdf0e10cSrcweir xFooEnum = xFooGraph.getStatements(null, null, null); 231*cdf0e10cSrcweir assertTrue("addStatement(baz,bar,lit)", 232*cdf0e10cSrcweir eq(xFooEnum, new Statement[] { 233*cdf0e10cSrcweir xFoo_FooBarBaz, xFoo_FooBarBlank, xFoo_BazBarLit })); 234*cdf0e10cSrcweir xFooEnum = xFooGraph.getStatements(baz, bar, null); 235*cdf0e10cSrcweir assertTrue("addStatement(baz,bar,lit) (baz,bar)", 236*cdf0e10cSrcweir eq(xFooEnum, new Statement[] { xFoo_BazBarLit })); 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir Statement xFoo_BazBarLitlang = 239*cdf0e10cSrcweir new Statement(baz, bar, litlang, foo); 240*cdf0e10cSrcweir xFooGraph.addStatement(baz, bar, litlang); 241*cdf0e10cSrcweir xFooEnum = xFooGraph.getStatements(null, null, null); 242*cdf0e10cSrcweir assertTrue("addStatement(baz,bar,litlang)", 243*cdf0e10cSrcweir eq(xFooEnum, new Statement[] { 244*cdf0e10cSrcweir xFoo_FooBarBaz, xFoo_FooBarBlank, xFoo_BazBarLit, 245*cdf0e10cSrcweir xFoo_BazBarLitlang })); 246*cdf0e10cSrcweir xFooEnum = xFooGraph.getStatements(null, null, baz); 247*cdf0e10cSrcweir assertTrue("addStatement(baz,bar,litlang) (baz)", 248*cdf0e10cSrcweir eq(xFooEnum, new Statement[] { xFoo_FooBarBaz })); 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir Statement xFoo_BazBarLittype = 251*cdf0e10cSrcweir new Statement(baz, bar, littype, foo); 252*cdf0e10cSrcweir xFooGraph.addStatement(baz, bar, littype); 253*cdf0e10cSrcweir xFooEnum = xFooGraph.getStatements(null, null, null); 254*cdf0e10cSrcweir assertTrue("addStatement(baz,bar,littype)", 255*cdf0e10cSrcweir eq(xFooEnum, new Statement[] { xFoo_FooBarBaz, xFoo_FooBarBlank, 256*cdf0e10cSrcweir xFoo_BazBarLit, xFoo_BazBarLitlang, xFoo_BazBarLittype })); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir xFooGraph.removeStatements(baz, bar, litlang); 259*cdf0e10cSrcweir xFooEnum = xFooGraph.getStatements(null, null, null); 260*cdf0e10cSrcweir assertTrue("removeStatement(baz,bar,litlang)", 261*cdf0e10cSrcweir eq(xFooEnum, new Statement[] { xFoo_FooBarBaz, xFoo_FooBarBlank, 262*cdf0e10cSrcweir xFoo_BazBarLit, xFoo_BazBarLittype })); 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir xFooGraph.removeStatements(foo, bar, null); 265*cdf0e10cSrcweir xFooEnum = xFooGraph.getStatements(null, null, null); 266*cdf0e10cSrcweir assertTrue("removeStatement(foo,bar,null)", 267*cdf0e10cSrcweir eq(xFooEnum, new Statement[] { 268*cdf0e10cSrcweir xFoo_BazBarLit, xFoo_BazBarLittype })); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir xFooGraph.addStatement(foo, bar, baz); 271*cdf0e10cSrcweir xFooEnum = xFooGraph.getStatements(null, null, null); 272*cdf0e10cSrcweir assertTrue("addStatement(foo,bar,baz) (re-add)", 273*cdf0e10cSrcweir eq(xFooEnum, new Statement[] { xFoo_FooBarBaz, 274*cdf0e10cSrcweir xFoo_BazBarLit, xFoo_BazBarLittype })); 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir xFooGraph.addStatement(foo, bar, baz); 277*cdf0e10cSrcweir xFooEnum = xFooGraph.getStatements(null, null, null); 278*cdf0e10cSrcweir assertTrue("addStatement(foo,bar,baz) (duplicate)", 279*cdf0e10cSrcweir eq(xFooEnum, new Statement[] { xFoo_FooBarBaz, 280*cdf0e10cSrcweir xFoo_BazBarLit, xFoo_BazBarLittype })); 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir xFooGraph.addStatement(xFooGraph, bar, baz); 283*cdf0e10cSrcweir xFooEnum = xFooGraph.getStatements(null, null, null); 284*cdf0e10cSrcweir assertTrue("addStatement(foo,bar,baz) (triplicate, as graph)", 285*cdf0e10cSrcweir eq(xFooEnum, new Statement[] { xFoo_FooBarBaz, 286*cdf0e10cSrcweir xFoo_BazBarLit, xFoo_BazBarLittype })); 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir System.out.println("...done"); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir System.out.println("Checking graph import/export..."); 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir xFooOut = new StreamSimulator(tempDir + "foo.rdf", false, param); 293*cdf0e10cSrcweir xRep.exportGraph(FileFormat.RDF_XML, xFooOut, foo, base); 294*cdf0e10cSrcweir xFooOut.closeOutput(); 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir xFooIn = new StreamSimulator(tempDir + "foo.rdf", true, param); 297*cdf0e10cSrcweir try { 298*cdf0e10cSrcweir xRep.importGraph(FileFormat.RDF_XML, xFooIn, bar, base); 299*cdf0e10cSrcweir fail("importing existing graph did not fail"); 300*cdf0e10cSrcweir } catch (ElementExistException e) { 301*cdf0e10cSrcweir // ignore 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir xFooIn = new StreamSimulator(tempDir + "foo.rdf", true, param); 305*cdf0e10cSrcweir xRep.importGraph(FileFormat.RDF_XML, xFooIn, baz, base); 306*cdf0e10cSrcweir XNamedGraph xBazGraph = xRep.getGraph(baz); 307*cdf0e10cSrcweir assertNotNull("no baz graph", xBazGraph); 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir Statement xBaz_FooBarBaz = new Statement(foo, bar, baz, baz); 310*cdf0e10cSrcweir Statement xBaz_BazBarLit = new Statement(baz, bar, lit, baz); 311*cdf0e10cSrcweir Statement xBaz_BazBarLittype = 312*cdf0e10cSrcweir new Statement(baz, bar, littype, baz); 313*cdf0e10cSrcweir XEnumeration xBazEnum = xBazGraph.getStatements(null, null, null); 314*cdf0e10cSrcweir assertTrue("importing exported graph", 315*cdf0e10cSrcweir eq(xBazEnum, new Statement[] { 316*cdf0e10cSrcweir xBaz_FooBarBaz, xBaz_BazBarLit, xBaz_BazBarLittype })); 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir System.out.println("...done"); 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir System.out.println("Checking graph deletion..."); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir xFooGraph.clear(); 323*cdf0e10cSrcweir xFooEnum = xFooGraph.getStatements(null, null, null); 324*cdf0e10cSrcweir assertTrue("clear", eq(xFooEnum, new Statement[] { })); 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir xRep.destroyGraph(baz); 327*cdf0e10cSrcweir assertNull("baz graph zombie", xRep.getGraph(baz)); 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir try { 330*cdf0e10cSrcweir xBazGraph.clear(); 331*cdf0e10cSrcweir fail("deleted graph not invalid (clear)"); 332*cdf0e10cSrcweir } catch (NoSuchElementException e) { 333*cdf0e10cSrcweir // ignore 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir try { 337*cdf0e10cSrcweir xBazGraph.addStatement(foo, foo, foo); 338*cdf0e10cSrcweir fail("deleted graph not invalid (add)"); 339*cdf0e10cSrcweir } catch (NoSuchElementException e) { 340*cdf0e10cSrcweir // ignore 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir try { 344*cdf0e10cSrcweir xBazGraph.removeStatements(null, null, null); 345*cdf0e10cSrcweir fail("deleted graph not invalid (remove)"); 346*cdf0e10cSrcweir } catch (NoSuchElementException e) { 347*cdf0e10cSrcweir // ignore 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir try { 351*cdf0e10cSrcweir xBazGraph.getStatements(null, null, null); 352*cdf0e10cSrcweir fail("deleted graph not invalid (get)"); 353*cdf0e10cSrcweir } catch (NoSuchElementException e) { 354*cdf0e10cSrcweir // ignore 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir System.out.println("...done"); 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir } catch (Exception e) { 360*cdf0e10cSrcweir report(e); 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir @Test public void checkSPARQL() 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir try { 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir System.out.println("Checking SPARQL queries..."); 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir XInputStream xIn = new StreamSimulator(TestDocument.getUrl("example.rdf"), true, param); 371*cdf0e10cSrcweir // util.utils.getFullTestDocName("example.rdf"), true, param); 372*cdf0e10cSrcweir xRep.importGraph(FileFormat.RDF_XML, xIn, manifest, base); 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir String query; 375*cdf0e10cSrcweir query = "SELECT ?p WHERE { ?p rdf:type pkg:Package . }"; 376*cdf0e10cSrcweir XQuerySelectResult result = xRep.querySelect(mkNss() + query); 377*cdf0e10cSrcweir assertTrue("query: package-id\n" + query, 378*cdf0e10cSrcweir eq(result, new String[] { "p" }, 379*cdf0e10cSrcweir new XNode[][] { { uuid } })); 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir query = "SELECT ?part ?path FROM <" + manifest + 382*cdf0e10cSrcweir "> WHERE { ?pkg rdf:type pkg:Package . ?pkg pkg:hasPart ?part ." 383*cdf0e10cSrcweir + " ?part pkg:path ?path . ?part rdf:type odf:ContentFile. }"; 384*cdf0e10cSrcweir result = xRep.querySelect(mkNss() + query); 385*cdf0e10cSrcweir assertTrue("query: contentfile", 386*cdf0e10cSrcweir eq(result, new String[] { "part", "path" }, 387*cdf0e10cSrcweir new XNode[][] { { BlankNode.create(xContext, "whatever"), 388*cdf0e10cSrcweir Literal.create(xContext, "content.xml") } })); 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir query = "SELECT ?pkg ?path FROM <" + toS(manifest) + "> WHERE { " 391*cdf0e10cSrcweir + "?pkg rdf:type pkg:Package . ?pkg pkg:hasPart ?part . " 392*cdf0e10cSrcweir + "?part pkg:path ?path . ?part rdf:type odf:ContentFile. }"; 393*cdf0e10cSrcweir result = xRep.querySelect(mkNss() + query); 394*cdf0e10cSrcweir assertTrue("query: contentfile\n" + query, 395*cdf0e10cSrcweir eq(result, new String[] { "pkg", "path" }, 396*cdf0e10cSrcweir new XNode[][] { { uuid , 397*cdf0e10cSrcweir Literal.create(xContext, "content.xml") } })); 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir query = "SELECT ?part ?path FROM <" + toS(manifest) + "> WHERE { " 400*cdf0e10cSrcweir + "?pkg rdf:type pkg:Package . ?pkg pkg:hasPart ?part . " 401*cdf0e10cSrcweir + "?part pkg:path ?path . ?part rdf:type odf:StylesFile. }"; 402*cdf0e10cSrcweir result = xRep.querySelect(mkNss() + query); 403*cdf0e10cSrcweir assertTrue("query: stylesfile\n" + query, 404*cdf0e10cSrcweir eq(result, new String[] { "part", "path" }, 405*cdf0e10cSrcweir new XNode[][] { })); 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir query = "SELECT ?part ?path FROM <" + toS(manifest) + "> WHERE { " 408*cdf0e10cSrcweir + "?pkg rdf:type pkg:Package . ?pkg pkg:hasPart ?part . " 409*cdf0e10cSrcweir + "?part pkg:path ?path . ?part rdf:type odf:MetadataFile. }"; 410*cdf0e10cSrcweir result = xRep.querySelect(mkNss() + query); 411*cdf0e10cSrcweir assertTrue("query: metadatafile\n" + query, 412*cdf0e10cSrcweir eq(result, new String[] { "part", "path" }, 413*cdf0e10cSrcweir new XNode[][] { { 414*cdf0e10cSrcweir URI.create(xContext, "http://hospital-employee/doctor"), 415*cdf0e10cSrcweir Literal.create(xContext, 416*cdf0e10cSrcweir "meta/hospital/doctor.rdf") } })); 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir //FIXME redland BUG 419*cdf0e10cSrcweir String uri = "uri:example-element-2"; 420*cdf0e10cSrcweir query = "SELECT ?path ?idref FROM <" + toS(manifest) + "> WHERE { " 421*cdf0e10cSrcweir // + "<" + toS(uuid) + "> rdf:type pkg:Package ; " 422*cdf0e10cSrcweir // + " pkg:hasPart ?part . " 423*cdf0e10cSrcweir + "<" + toS(uuid) + "> pkg:hasPart ?part . " 424*cdf0e10cSrcweir + "?part pkg:path ?path ; " 425*cdf0e10cSrcweir + " rdf:type ?type ; " 426*cdf0e10cSrcweir + " pkg:hasPart <" + uri + "> . " 427*cdf0e10cSrcweir // + "<" + uri + "> rdf:type odf:Element ; " 428*cdf0e10cSrcweir + "<" + uri + "> " 429*cdf0e10cSrcweir + " pkg:idref ?idref . " 430*cdf0e10cSrcweir + " FILTER (?type = odf:ContentFile || ?type = odf:StylesFile)" 431*cdf0e10cSrcweir + " }"; 432*cdf0e10cSrcweir //System.out.println(query); 433*cdf0e10cSrcweir result = xRep.querySelect(mkNss() + query); 434*cdf0e10cSrcweir assertTrue("query: example-element-2\n" + query, 435*cdf0e10cSrcweir eq(result, new String[] { "path", "idref" }, 436*cdf0e10cSrcweir new XNode[][] { { 437*cdf0e10cSrcweir Literal.create(xContext, "content.xml"), 438*cdf0e10cSrcweir Literal.create(xContext, "ID_B") } })); 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir // CONSTRUCT result triples have no graph! 441*cdf0e10cSrcweir Statement x_PkgFooLit = new Statement(uuid, foo, lit, null); 442*cdf0e10cSrcweir query = "CONSTRUCT { ?pkg <" + toS(foo) + "> \"" + 443*cdf0e10cSrcweir lit.getStringValue() + "\" } FROM <" + toS(manifest) + 444*cdf0e10cSrcweir "> WHERE { ?pkg rdf:type pkg:Package . } "; 445*cdf0e10cSrcweir XEnumeration xResultEnum = xRep.queryConstruct(mkNss() + query); 446*cdf0e10cSrcweir assertTrue("query: construct\n" + query, 447*cdf0e10cSrcweir eq(xResultEnum, new Statement[] { x_PkgFooLit })); 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir query = "ASK { ?pkg rdf:type pkg:Package . }"; 450*cdf0e10cSrcweir boolean bResult = xRep.queryAsk(mkNss() + query); 451*cdf0e10cSrcweir assertTrue("query: ask\n" + query, bResult); 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir System.out.println("...done"); 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir } catch (Exception e) { 456*cdf0e10cSrcweir report(e); 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir @Test public void checkRDFa() 461*cdf0e10cSrcweir { 462*cdf0e10cSrcweir try { 463*cdf0e10cSrcweir System.out.println("Checking RDFa gunk..."); 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir String content = "behold, for i am the content."; 466*cdf0e10cSrcweir XTextRange xTR = new TestRange(content); 467*cdf0e10cSrcweir XMetadatable xM = (XMetadatable) xTR; 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir Pair<Statement[], Boolean> result = 470*cdf0e10cSrcweir xRep.getStatementRDFa((XMetadatable)xTR); 471*cdf0e10cSrcweir assertTrue("RDFa: get: not empty (initial)", 472*cdf0e10cSrcweir 0 == result.First.length); 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir try { 475*cdf0e10cSrcweir xRep.setStatementRDFa(foo, new XURI[] {}, xM, "", null); 476*cdf0e10cSrcweir fail("RDFa: set: no predicate"); 477*cdf0e10cSrcweir } catch (IllegalArgumentException e) { 478*cdf0e10cSrcweir // ignore 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir try { 482*cdf0e10cSrcweir xRep.setStatementRDFa(foo, new XURI[] {bar}, null, "", null); 483*cdf0e10cSrcweir fail("RDFa: set: null"); 484*cdf0e10cSrcweir } catch (IllegalArgumentException e) { 485*cdf0e10cSrcweir // ignore 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir XLiteral trlit = Literal.create(xContext, content); 489*cdf0e10cSrcweir Statement x_FooBarTRLit = new Statement(foo, bar, trlit, null); 490*cdf0e10cSrcweir xRep.setStatementRDFa(foo, new XURI[] { bar }, xM, "", null); 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir result = xRep.getStatementRDFa((XMetadatable)xTR); 493*cdf0e10cSrcweir assertTrue("RDFa: get: without content", 494*cdf0e10cSrcweir !result.Second && (1 == result.First.length) 495*cdf0e10cSrcweir && eq(result.First[0], x_FooBarTRLit)); 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir //FIXME: do this? 498*cdf0e10cSrcweir xTR.setString(lit.getStringValue()); 499*cdf0e10cSrcweir /* 500*cdf0e10cSrcweir Statement xFooBarLit = new Statement(foo, bar, lit, null); 501*cdf0e10cSrcweir result = xRep.getStatementRDFa((XMetadatable)xTR); 502*cdf0e10cSrcweir assertTrue("RDFa: get: change", 503*cdf0e10cSrcweir eq((Statement)result.First, xFooBarLit) && null == result.Second); 504*cdf0e10cSrcweir */ 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir Statement x_FooBarLittype = new Statement(foo, bar, littype, null); 507*cdf0e10cSrcweir xRep.setStatementRDFa(foo, new XURI[] { bar }, xM, "42", uint); 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir result = xRep.getStatementRDFa((XMetadatable)xTR); 510*cdf0e10cSrcweir assertTrue("RDFa: get: with content", 511*cdf0e10cSrcweir result.Second && 512*cdf0e10cSrcweir (1 == result.First.length) && 513*cdf0e10cSrcweir eq(result.First[0], x_FooBarLittype)); 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir //FIXME: do this? 516*cdf0e10cSrcweir xTR.setString(content); 517*cdf0e10cSrcweir /* 518*cdf0e10cSrcweir Statement xFooLabelTRLit = new Statement(foo, rdfslabel, trlit, null); 519*cdf0e10cSrcweir result = xRep.getStatementRDFa((XMetadatable)xTR); 520*cdf0e10cSrcweir assertTrue("RDFa: get: change (label)", 521*cdf0e10cSrcweir eq((Statement)result.First, xFooBarLittype) && 522*cdf0e10cSrcweir eq((Statement)result.Second, xFooLabelTRLit)); 523*cdf0e10cSrcweir */ 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir xRep.removeStatementRDFa((XMetadatable)xTR); 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir result = xRep.getStatementRDFa((XMetadatable)xTR); 528*cdf0e10cSrcweir assertTrue("RDFa: get: not empty (removed)", 529*cdf0e10cSrcweir 0 == result.First.length); 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir xRep.setStatementRDFa(foo, new XURI[] { foo, bar, baz }, xM, 532*cdf0e10cSrcweir "", null); 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir Statement x_FooFooTRLit = new Statement(foo, foo, trlit, null); 535*cdf0e10cSrcweir Statement x_FooBazTRLit = new Statement(foo, baz, trlit, null); 536*cdf0e10cSrcweir result = xRep.getStatementRDFa((XMetadatable) xTR); 537*cdf0e10cSrcweir assertTrue("RDFa: get: without content (multiple predicates, reinsert)", 538*cdf0e10cSrcweir !result.Second && 539*cdf0e10cSrcweir eq(result.First, new Statement[] { 540*cdf0e10cSrcweir x_FooFooTRLit, x_FooBarTRLit, x_FooBazTRLit })); 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir xRep.removeStatementRDFa((XMetadatable)xTR); 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir result = xRep.getStatementRDFa((XMetadatable) xTR); 545*cdf0e10cSrcweir assertTrue("RDFa: get: not empty (re-removed)", 546*cdf0e10cSrcweir 0 == result.First.length); 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir System.out.println("...done"); 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir } catch (Exception e) { 551*cdf0e10cSrcweir report(e); 552*cdf0e10cSrcweir } 553*cdf0e10cSrcweir } 554*cdf0e10cSrcweir 555*cdf0e10cSrcweir // utilities ------------------------------------------------------------- 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir public void report2(Exception e) 558*cdf0e10cSrcweir { 559*cdf0e10cSrcweir if (e instanceof WrappedTargetException) 560*cdf0e10cSrcweir { 561*cdf0e10cSrcweir System.out.println("Cause:"); 562*cdf0e10cSrcweir Exception cause = (Exception) 563*cdf0e10cSrcweir (((WrappedTargetException)e).TargetException); 564*cdf0e10cSrcweir System.out.println(cause.toString()); 565*cdf0e10cSrcweir report2(cause); 566*cdf0e10cSrcweir } else if (e instanceof WrappedTargetRuntimeException) { 567*cdf0e10cSrcweir System.out.println("Cause:"); 568*cdf0e10cSrcweir Exception cause = (Exception) 569*cdf0e10cSrcweir (((WrappedTargetRuntimeException)e).TargetException); 570*cdf0e10cSrcweir System.out.println(cause.toString()); 571*cdf0e10cSrcweir report2(cause); 572*cdf0e10cSrcweir } 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir public void report(Exception e) { 576*cdf0e10cSrcweir System.out.println("Exception occurred:"); 577*cdf0e10cSrcweir e.printStackTrace(); 578*cdf0e10cSrcweir report2(e); 579*cdf0e10cSrcweir fail(); 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir public static String toS(XNode n) { 583*cdf0e10cSrcweir if (null == n) 584*cdf0e10cSrcweir { 585*cdf0e10cSrcweir return "< null >"; 586*cdf0e10cSrcweir } 587*cdf0e10cSrcweir return n.getStringValue(); 588*cdf0e10cSrcweir } 589*cdf0e10cSrcweir 590*cdf0e10cSrcweir static boolean isBlank(XNode i_node) 591*cdf0e10cSrcweir { 592*cdf0e10cSrcweir XBlankNode blank = UnoRuntime.queryInterface(XBlankNode.class, i_node); 593*cdf0e10cSrcweir return blank != null; 594*cdf0e10cSrcweir } 595*cdf0e10cSrcweir 596*cdf0e10cSrcweir /* 597*cdf0e10cSrcweir static class Statement implements XStatement 598*cdf0e10cSrcweir { 599*cdf0e10cSrcweir XResource m_Subject; 600*cdf0e10cSrcweir XResource m_Predicate; 601*cdf0e10cSrcweir XNode m_Object; 602*cdf0e10cSrcweir XURI m_Graph; 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir Statement(XResource i_Subject, XResource i_Predicate, XNode i_Object, 605*cdf0e10cSrcweir XURI i_Graph) 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir m_Subject = i_Subject; 608*cdf0e10cSrcweir m_Predicate = i_Predicate; 609*cdf0e10cSrcweir m_Object = i_Object; 610*cdf0e10cSrcweir m_Graph = i_Graph; 611*cdf0e10cSrcweir } 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir public XResource getSubject() { return m_Subject; } 614*cdf0e10cSrcweir public XResource getPredicate() { return m_Predicate; } 615*cdf0e10cSrcweir public XNode getObject() { return m_Object; } 616*cdf0e10cSrcweir public XURI getGraph() { return m_Graph; } 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir */ 619*cdf0e10cSrcweir 620*cdf0e10cSrcweir static Statement[] toSeq(XEnumeration i_Enum) throws Exception 621*cdf0e10cSrcweir { 622*cdf0e10cSrcweir java.util.Collection c = new java.util.Vector(); 623*cdf0e10cSrcweir while (i_Enum.hasMoreElements()) { 624*cdf0e10cSrcweir Statement s = (Statement) i_Enum.nextElement(); 625*cdf0e10cSrcweir //System.out.println("toSeq: " + s.getSubject().getStringValue() + " " + s.getPredicate().getStringValue() + " " + s.getObject().getStringValue() + "."); 626*cdf0e10cSrcweir c.add(s); 627*cdf0e10cSrcweir } 628*cdf0e10cSrcweir // return (Statement[]) c.toArray(); 629*cdf0e10cSrcweir // java sucks 630*cdf0e10cSrcweir Object[] arr = c.toArray(); 631*cdf0e10cSrcweir Statement[] ret = new Statement[arr.length]; 632*cdf0e10cSrcweir for (int i = 0; i < arr.length; ++i) { 633*cdf0e10cSrcweir ret[i] = (Statement) arr[i]; 634*cdf0e10cSrcweir } 635*cdf0e10cSrcweir return ret; 636*cdf0e10cSrcweir } 637*cdf0e10cSrcweir 638*cdf0e10cSrcweir static XNode[][] toSeqs(XEnumeration i_Enum) throws Exception 639*cdf0e10cSrcweir { 640*cdf0e10cSrcweir java.util.Collection c = new java.util.Vector(); 641*cdf0e10cSrcweir while (i_Enum.hasMoreElements()) { 642*cdf0e10cSrcweir XNode[] s = (XNode[]) i_Enum.nextElement(); 643*cdf0e10cSrcweir c.add(s); 644*cdf0e10cSrcweir } 645*cdf0e10cSrcweir // return (XNode[][]) c.toArray(); 646*cdf0e10cSrcweir Object[] arr = c.toArray(); 647*cdf0e10cSrcweir XNode[][] ret = new XNode[arr.length][]; 648*cdf0e10cSrcweir for (int i = 0; i < arr.length; ++i) { 649*cdf0e10cSrcweir ret[i] = (XNode[]) arr[i]; 650*cdf0e10cSrcweir } 651*cdf0e10cSrcweir return ret; 652*cdf0e10cSrcweir } 653*cdf0e10cSrcweir 654*cdf0e10cSrcweir static class BindingComp implements java.util.Comparator 655*cdf0e10cSrcweir { 656*cdf0e10cSrcweir public int compare(Object i_Left, Object i_Right) 657*cdf0e10cSrcweir { 658*cdf0e10cSrcweir XNode[] left = (XNode[]) i_Left; 659*cdf0e10cSrcweir XNode[] right = (XNode[]) i_Right; 660*cdf0e10cSrcweir if (left.length != right.length) 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir throw new RuntimeException(); 663*cdf0e10cSrcweir } 664*cdf0e10cSrcweir for (int i = 0; i < left.length; ++i) { 665*cdf0e10cSrcweir int eq = (left[i].getStringValue().compareTo( 666*cdf0e10cSrcweir right[i].getStringValue())); 667*cdf0e10cSrcweir if (eq != 0) return eq; 668*cdf0e10cSrcweir } 669*cdf0e10cSrcweir return 0; 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir } 672*cdf0e10cSrcweir 673*cdf0e10cSrcweir static class StmtComp implements java.util.Comparator 674*cdf0e10cSrcweir { 675*cdf0e10cSrcweir public int compare(Object i_Left, Object i_Right) 676*cdf0e10cSrcweir { 677*cdf0e10cSrcweir int eq; 678*cdf0e10cSrcweir Statement left = (Statement) i_Left; 679*cdf0e10cSrcweir Statement right = (Statement) i_Right; 680*cdf0e10cSrcweir if ((eq = cmp(left.Graph, right.Graph )) != 0) 681*cdf0e10cSrcweir { 682*cdf0e10cSrcweir return eq; 683*cdf0e10cSrcweir } 684*cdf0e10cSrcweir if ((eq = cmp(left.Subject, right.Subject )) != 0) 685*cdf0e10cSrcweir { 686*cdf0e10cSrcweir return eq; 687*cdf0e10cSrcweir } 688*cdf0e10cSrcweir if ((eq = cmp(left.Predicate, right.Predicate)) != 0) 689*cdf0e10cSrcweir { 690*cdf0e10cSrcweir return eq; 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir if ((eq = cmp(left.Object, right.Object )) != 0) 693*cdf0e10cSrcweir { 694*cdf0e10cSrcweir return eq; 695*cdf0e10cSrcweir } 696*cdf0e10cSrcweir return 0; 697*cdf0e10cSrcweir } 698*cdf0e10cSrcweir 699*cdf0e10cSrcweir public int cmp(XNode i_Left, XNode i_Right) 700*cdf0e10cSrcweir { 701*cdf0e10cSrcweir if (isBlank(i_Left)) { 702*cdf0e10cSrcweir return isBlank(i_Right) ? 0 : 1; 703*cdf0e10cSrcweir } else { 704*cdf0e10cSrcweir if (isBlank(i_Right)) { 705*cdf0e10cSrcweir return -1; 706*cdf0e10cSrcweir } else { 707*cdf0e10cSrcweir return toS(i_Left).compareTo(toS(i_Right)); 708*cdf0e10cSrcweir } 709*cdf0e10cSrcweir } 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir } 712*cdf0e10cSrcweir 713*cdf0e10cSrcweir static boolean eq(Statement i_Left, Statement i_Right) 714*cdf0e10cSrcweir { 715*cdf0e10cSrcweir XURI lG = i_Left.Graph; 716*cdf0e10cSrcweir XURI rG = i_Right.Graph; 717*cdf0e10cSrcweir if (!eq(lG, rG)) { 718*cdf0e10cSrcweir System.out.println("Graphs differ: " + toS(lG) + " != " + toS(rG)); 719*cdf0e10cSrcweir return false; 720*cdf0e10cSrcweir } 721*cdf0e10cSrcweir if (!eq(i_Left.Subject, i_Right.Subject)) { 722*cdf0e10cSrcweir System.out.println("Subjects differ: " + 723*cdf0e10cSrcweir i_Left.Subject.getStringValue() + " != " + 724*cdf0e10cSrcweir i_Right.Subject.getStringValue()); 725*cdf0e10cSrcweir return false; 726*cdf0e10cSrcweir } 727*cdf0e10cSrcweir if (!eq(i_Left.Predicate, i_Right.Predicate)) { 728*cdf0e10cSrcweir System.out.println("Predicates differ: " + 729*cdf0e10cSrcweir i_Left.Predicate.getStringValue() + " != " + 730*cdf0e10cSrcweir i_Right.Predicate.getStringValue()); 731*cdf0e10cSrcweir return false; 732*cdf0e10cSrcweir } 733*cdf0e10cSrcweir if (!eq(i_Left.Object, i_Right.Object)) { 734*cdf0e10cSrcweir System.out.println("Objects differ: " + 735*cdf0e10cSrcweir i_Left.Object.getStringValue() + " != " + 736*cdf0e10cSrcweir i_Right.Object.getStringValue()); 737*cdf0e10cSrcweir return false; 738*cdf0e10cSrcweir } 739*cdf0e10cSrcweir return true; 740*cdf0e10cSrcweir } 741*cdf0e10cSrcweir 742*cdf0e10cSrcweir static boolean eq(Statement[] i_Result, Statement[] i_Expected) 743*cdf0e10cSrcweir { 744*cdf0e10cSrcweir if (i_Result.length != i_Expected.length) { 745*cdf0e10cSrcweir System.out.println("eq: different lengths: " + i_Result.length + " " + 746*cdf0e10cSrcweir i_Expected.length); 747*cdf0e10cSrcweir return false; 748*cdf0e10cSrcweir } 749*cdf0e10cSrcweir Statement[] expected = (Statement[]) 750*cdf0e10cSrcweir java.util.Arrays.asList(i_Expected).toArray(); 751*cdf0e10cSrcweir java.util.Arrays.sort(i_Result, new StmtComp()); 752*cdf0e10cSrcweir java.util.Arrays.sort(expected, new StmtComp()); 753*cdf0e10cSrcweir for (int i = 0; i < expected.length; ++i) { 754*cdf0e10cSrcweir if (!eq(i_Result[i], expected[i])) 755*cdf0e10cSrcweir { 756*cdf0e10cSrcweir return false; 757*cdf0e10cSrcweir } 758*cdf0e10cSrcweir } 759*cdf0e10cSrcweir return true; 760*cdf0e10cSrcweir } 761*cdf0e10cSrcweir 762*cdf0e10cSrcweir static boolean eq(XEnumeration i_Enum, Statement[] i_Expected) 763*cdf0e10cSrcweir throws Exception 764*cdf0e10cSrcweir { 765*cdf0e10cSrcweir Statement[] current = toSeq(i_Enum); 766*cdf0e10cSrcweir return eq(current, i_Expected); 767*cdf0e10cSrcweir } 768*cdf0e10cSrcweir 769*cdf0e10cSrcweir static boolean eq(XNode i_Left, XNode i_Right) 770*cdf0e10cSrcweir { 771*cdf0e10cSrcweir if (i_Left == null) { 772*cdf0e10cSrcweir return (i_Right == null); 773*cdf0e10cSrcweir } else { 774*cdf0e10cSrcweir return (i_Right != null) && 775*cdf0e10cSrcweir (i_Left.getStringValue().equals(i_Right.getStringValue()) 776*cdf0e10cSrcweir // FIXME: hack: blank nodes considered equal 777*cdf0e10cSrcweir || (isBlank(i_Left) && isBlank(i_Right))); 778*cdf0e10cSrcweir } 779*cdf0e10cSrcweir } 780*cdf0e10cSrcweir 781*cdf0e10cSrcweir static boolean eq(XQuerySelectResult i_Result, 782*cdf0e10cSrcweir String[] i_Vars, XNode[][] i_Bindings) throws Exception 783*cdf0e10cSrcweir { 784*cdf0e10cSrcweir String[] vars = (String[]) i_Result.getBindingNames(); 785*cdf0e10cSrcweir XEnumeration iter = (XEnumeration) i_Result; 786*cdf0e10cSrcweir XNode[][] bindings = toSeqs(iter); 787*cdf0e10cSrcweir if (vars.length != i_Vars.length) { 788*cdf0e10cSrcweir System.out.println("var lengths differ"); 789*cdf0e10cSrcweir return false; 790*cdf0e10cSrcweir } 791*cdf0e10cSrcweir if (bindings.length != i_Bindings.length) { 792*cdf0e10cSrcweir System.out.println("binding lengths differ: " + i_Bindings.length + 793*cdf0e10cSrcweir " vs " + bindings.length ); 794*cdf0e10cSrcweir return false; 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir java.util.Arrays.sort(bindings, new BindingComp()); 797*cdf0e10cSrcweir java.util.Arrays.sort(i_Bindings, new BindingComp()); 798*cdf0e10cSrcweir for (int i = 0; i < i_Bindings.length; ++i) { 799*cdf0e10cSrcweir if (i_Bindings[i].length != i_Vars.length) { 800*cdf0e10cSrcweir System.out.println("TEST ERROR!"); 801*cdf0e10cSrcweir throw new Exception(); 802*cdf0e10cSrcweir } 803*cdf0e10cSrcweir if (bindings[i].length != i_Vars.length) { 804*cdf0e10cSrcweir System.out.println("binding length and var length differ"); 805*cdf0e10cSrcweir return false; 806*cdf0e10cSrcweir } 807*cdf0e10cSrcweir for (int j = 0; j < i_Vars.length; ++j) { 808*cdf0e10cSrcweir if (!eq(bindings[i][j], i_Bindings[i][j])) { 809*cdf0e10cSrcweir System.out.println("bindings differ: " + 810*cdf0e10cSrcweir toS(bindings[i][j]) + " != " + toS(i_Bindings[i][j])); 811*cdf0e10cSrcweir return false; 812*cdf0e10cSrcweir } 813*cdf0e10cSrcweir } 814*cdf0e10cSrcweir } 815*cdf0e10cSrcweir for (int i = 0; i < i_Vars.length; ++i) { 816*cdf0e10cSrcweir if (!vars[i].equals(i_Vars[i])) { 817*cdf0e10cSrcweir System.out.println("variable names differ: " + 818*cdf0e10cSrcweir vars[i] + " != " + i_Vars[i]); 819*cdf0e10cSrcweir return false; 820*cdf0e10cSrcweir } 821*cdf0e10cSrcweir } 822*cdf0e10cSrcweir return true; 823*cdf0e10cSrcweir } 824*cdf0e10cSrcweir 825*cdf0e10cSrcweir static String mkNamespace(String i_prefix, String i_namespace) 826*cdf0e10cSrcweir { 827*cdf0e10cSrcweir return "PREFIX " + i_prefix + ": <" + i_namespace + ">\n"; 828*cdf0e10cSrcweir } 829*cdf0e10cSrcweir 830*cdf0e10cSrcweir static String mkNss() 831*cdf0e10cSrcweir { 832*cdf0e10cSrcweir String namespaces = mkNamespace("rdf", 833*cdf0e10cSrcweir "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); 834*cdf0e10cSrcweir namespaces += mkNamespace("pkg", 835*cdf0e10cSrcweir "http://docs.oasis-open.org/opendocument/meta/package/common#"); 836*cdf0e10cSrcweir namespaces += mkNamespace("odf", 837*cdf0e10cSrcweir "http://docs.oasis-open.org/opendocument/meta/package/odf#"); 838*cdf0e10cSrcweir return namespaces; 839*cdf0e10cSrcweir } 840*cdf0e10cSrcweir 841*cdf0e10cSrcweir class TestRange implements XTextRange, XMetadatable, XServiceInfo 842*cdf0e10cSrcweir { 843*cdf0e10cSrcweir String m_Stream; 844*cdf0e10cSrcweir String m_XmlId; 845*cdf0e10cSrcweir String m_Text; 846*cdf0e10cSrcweir TestRange(String i_Str) { m_Text = i_Str; } 847*cdf0e10cSrcweir 848*cdf0e10cSrcweir public String getStringValue() { return ""; } 849*cdf0e10cSrcweir public String getNamespace() { return ""; } 850*cdf0e10cSrcweir public String getLocalName() { return ""; } 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir public StringPair getMetadataReference() 853*cdf0e10cSrcweir { return new StringPair(m_Stream, m_XmlId); } 854*cdf0e10cSrcweir public void setMetadataReference(StringPair i_Ref) 855*cdf0e10cSrcweir throws IllegalArgumentException 856*cdf0e10cSrcweir { m_Stream = i_Ref.First; m_XmlId = i_Ref.Second; } 857*cdf0e10cSrcweir public void ensureMetadataReference() 858*cdf0e10cSrcweir { m_Stream = "content.xml"; m_XmlId = "42"; } 859*cdf0e10cSrcweir 860*cdf0e10cSrcweir public String getImplementationName() { return null; } 861*cdf0e10cSrcweir public String[] getSupportedServiceNames() { return null; } 862*cdf0e10cSrcweir public boolean supportsService(String i_Svc) 863*cdf0e10cSrcweir { return i_Svc.equals("com.sun.star.text.Paragraph"); } 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir public XText getText() { return null; } 866*cdf0e10cSrcweir public XTextRange getStart() { return null; } 867*cdf0e10cSrcweir public XTextRange getEnd() { return null; } 868*cdf0e10cSrcweir public String getString() { return m_Text; } 869*cdf0e10cSrcweir public void setString(String i_Str) { m_Text = i_Str; } 870*cdf0e10cSrcweir } 871*cdf0e10cSrcweir 872*cdf0e10cSrcweir private XMultiServiceFactory getMSF() 873*cdf0e10cSrcweir { 874*cdf0e10cSrcweir final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); 875*cdf0e10cSrcweir return xMSF1; 876*cdf0e10cSrcweir } 877*cdf0e10cSrcweir 878*cdf0e10cSrcweir // setup and close connections 879*cdf0e10cSrcweir @BeforeClass public static void setUpConnection() throws Exception { 880*cdf0e10cSrcweir System.out.println("setUpConnection()"); 881*cdf0e10cSrcweir connection.setUp(); 882*cdf0e10cSrcweir } 883*cdf0e10cSrcweir 884*cdf0e10cSrcweir @AfterClass public static void tearDownConnection() 885*cdf0e10cSrcweir throws InterruptedException, com.sun.star.uno.Exception 886*cdf0e10cSrcweir { 887*cdf0e10cSrcweir System.out.println("tearDownConnection()"); 888*cdf0e10cSrcweir connection.tearDown(); 889*cdf0e10cSrcweir } 890*cdf0e10cSrcweir 891*cdf0e10cSrcweir private static final OfficeConnection connection = new OfficeConnection(); 892*cdf0e10cSrcweir } 893*cdf0e10cSrcweir 894