⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serqlxmltabletest.java

📁 这是外国一个开源推理机
💻 JAVA
字号:
/*  Sesame - Storage and Querying architecture for RDF and RDF Schema *  Copyright (C) 2001-2005 Aduna * *  Contact:  *  	Aduna *  	Prinses Julianaplein 14 b *  	3817 CS Amersfoort *  	The Netherlands *  	tel. +33 (0)33 465 99 87 *  	fax. +33 (0)33 465 99 87 * *  	http://aduna.biz/ *  	http://www.openrdf.org/ *   *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Lesser General Public *  License as published by the Free Software Foundation; either *  version 2.1 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Lesser General Public License for more details. * *  You should have received a copy of the GNU Lesser General Public *  License along with this library; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package org.openrdf.sesame.query.serql;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import org.xml.sax.SAXException;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;import org.openrdf.util.io.IOUtil;import org.openrdf.util.xml.XMLReaderFactory;import org.openrdf.sesame.Sesame;import org.openrdf.sesame.admin.AdminMsg;import org.openrdf.sesame.admin.AdminMsgCollector;import org.openrdf.sesame.config.AccessDeniedException;import org.openrdf.sesame.config.ConfigurationException;import org.openrdf.sesame.config.RepositoryConfig;import org.openrdf.sesame.constants.RDFFormat;import org.openrdf.sesame.constants.QueryLanguage;import org.openrdf.sesame.query.MalformedQueryException;import org.openrdf.sesame.query.QueryEvaluationException;import org.openrdf.sesame.query.QueryResultsTable;import org.openrdf.sesame.query.QueryResultsTableBuilder;import org.openrdf.sesame.query.XmlQueryResultReader;import org.openrdf.sesame.repository.local.LocalRepository;import org.openrdf.sesame.repository.local.LocalService;public class SeRQLxmlTableTest extends TestCase {/*----------+| Constants |+----------*/	public static final String TEST_DIR_PREFIX = "/files/testcases/SeRQL/XmlTable";	private static final String TESTREP_ID = "xmlTableTest";	private static final boolean USE_RDBMS = true;/*----------+| Variables |+----------*/	protected LocalRepository _repository;	protected String _inputData;	protected String _queryFile;	protected String _expectedResult;/*-------------+| Constructors |+-------------*/	/**	 * Creates a new SeRQLxmlTableTest test.	 **/	public SeRQLxmlTableTest(String name, LocalRepository repository,			String inputData, String queryFile, String expectedResult)	{		super(name);		_repository = repository;		_inputData = inputData;		_queryFile = queryFile;		_expectedResult = expectedResult;	}/*--------+| Methods |+--------*/	protected void runTest() {		try {			// Clear the repository			AdminMsgCollector adminListener = new AdminMsgCollector();			_repository.clear(adminListener);			if (adminListener.hasErrors()) {				AdminMsg errMsg = (AdminMsg)adminListener.getErrors().get(0);				fail("Unable to clear repository: " + errMsg.getMessage());			}			// Upload input data			InputStream stream = getClass().getResourceAsStream(_inputData);			_repository.addData(stream,  _inputData, RDFFormat.RDFXML, true, adminListener);			stream.close();			if (adminListener.hasErrors()) {				AdminMsg errMsg = (AdminMsg)adminListener.getErrors().get(0);				fail("Unable to add test data to repository: " + errMsg.getMessage());			}			// Read query from file			stream = getClass().getResourceAsStream(_queryFile);			String query = IOUtil.readFully(new InputStreamReader(stream, "ISO-8859-1"));			stream.close();			// Evaluate query on input data			QueryResultsTable queryResult = _repository.performTableQuery(QueryLanguage.SERQL, query);			// Read expected query result			XmlQueryResultReader queryResultReader = new XmlQueryResultReader( XMLReaderFactory.createXMLReader() );			QueryResultsTableBuilder tableBuilder = new QueryResultsTableBuilder();			stream = getClass().getResourceAsStream(_expectedResult);			queryResultReader.read(stream, tableBuilder);			stream.close();			QueryResultsTable expectedResult = tableBuilder.getQueryResultsTable();			// Compare query result to expected data			if (!queryResult.equals(expectedResult)) {				System.err.println("Expected result:");				System.err.println(expectedResult.toString());				System.err.println("Query result:");				System.err.println(queryResult.toString());				fail("Query result not equal to expected result");			}		}		catch (IOException e) {			fail("Unable to run test due to I/O error: " + e.getMessage());		}		catch (AccessDeniedException e) {			fail("Access denied: " + e.getMessage());		}		catch (MalformedQueryException e) {			fail("Malformed query: " + e.getMessage());		}		catch (QueryEvaluationException e) {			fail("Query evaluation error: " + e.getMessage());		}		catch (SAXException e) {			fail("SAX error: " + e.getMessage());		}	}/*--------------------------------------+| Test methods                          |+--------------------------------------*/	public static Test suite()		throws ConfigurationException	{		LocalService service = Sesame.getService();		LocalRepository repository = null;		if (USE_RDBMS) {			RepositoryConfig repConfig = new RepositoryConfig(TESTREP_ID);			repConfig.addSail(					new org.openrdf.sesame.sailimpl.rdbms.RdfSchemaRepositoryConfig(							"com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/testdb",							"sesame", "")					);			repConfig.setWorldReadable(true);			repConfig.setWorldWriteable(true);			repository = service.createRepository(repConfig);		}		else {			repository = service.createRepository(TESTREP_ID, true);		}		return suite(repository);	}	public static Test suite(LocalRepository repository) {		TestSuite suite = new TestSuite();		suite.addTest(_createTestCase(repository, "test001"));		suite.addTest(_createTestCase(repository, "test002"));		suite.addTest(_createTestCase(repository, "test003"));		suite.addTest(_createTestCase(repository, "test004"));		suite.addTest(_createTestCase(repository, "test005"));		suite.addTest(_createTestCase(repository, "test006"));		suite.addTest(_createTestCase(repository, "test007"));		suite.addTest(_createTestCase(repository, "test008"));		suite.addTest(_createTestCase(repository, "test009"));		// count operator not yet implemented.		//suite.addTest(_createTestCase(repository, "test010")); 		suite.addTest(_createTestCase(repository, "test011"));		return suite;	}	private static TestCase _createTestCase(LocalRepository repository, String testName) {		return new SeRQLxmlTableTest(testName, repository,				TEST_DIR_PREFIX + "/" + testName + "-in.rdf",				TEST_DIR_PREFIX + "/" + testName + "-query",				TEST_DIR_PREFIX + "/" + testName + "-out.xml");	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -