001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.sail.memory;
007:
008: import java.io.File;
009:
010: import junit.framework.TestCase;
011:
012: import info.aduna.io.FileUtil;
013: import info.aduna.iteration.CloseableIteration;
014:
015: import org.openrdf.model.URI;
016: import org.openrdf.model.ValueFactory;
017: import org.openrdf.model.vocabulary.RDF;
018: import org.openrdf.query.BindingSet;
019: import org.openrdf.query.QueryEvaluationException;
020: import org.openrdf.query.QueryLanguage;
021: import org.openrdf.query.algebra.TupleExpr;
022: import org.openrdf.query.impl.EmptyBindingSet;
023: import org.openrdf.query.parser.ParsedTupleQuery;
024: import org.openrdf.query.parser.QueryParserUtil;
025: import org.openrdf.sail.SailConnection;
026:
027: public class StoreSerializationTest extends TestCase {
028:
029: /*-----------*
030: * Variables *
031: *-----------*/
032:
033: private File dataDir;
034:
035: /*---------*
036: * Methods *
037: *---------*/
038:
039: @Override
040: protected void setUp() throws Exception {
041: super .setUp();
042: dataDir = FileUtil.createTempDir("memorystore");
043: }
044:
045: @Override
046: protected void tearDown() throws Exception {
047: super .tearDown();
048: FileUtil.deleteDir(dataDir);
049: }
050:
051: public void testSerialization() throws Exception {
052: MemoryStore store = new MemoryStore(dataDir);
053: store.initialize();
054:
055: ValueFactory factory = store.getValueFactory();
056: URI foo = factory.createURI("http://www.foo.example/foo");
057: URI bar = factory.createURI("http://www.foo.example/bar");
058:
059: SailConnection con = store.getConnection();
060: con.addStatement(foo, RDF.TYPE, bar);
061: con.commit();
062:
063: ParsedTupleQuery query = QueryParserUtil.parseTupleQuery(
064: QueryLanguage.SERQL, "SELECT X, P, Y FROM {X} P {Y}",
065: null);
066: TupleExpr tupleExpr = query.getTupleExpr();
067:
068: CloseableIteration<? extends BindingSet, QueryEvaluationException> iter = con
069: .evaluate(tupleExpr, null, EmptyBindingSet
070: .getInstance(), false);
071:
072: BindingSet bindingSet = iter.next();
073:
074: assertEquals(bindingSet.getValue("X"), foo);
075: assertEquals(bindingSet.getValue("P"), RDF.TYPE);
076: assertEquals(bindingSet.getValue("Y"), bar);
077: iter.close();
078: con.close();
079:
080: store.shutDown();
081:
082: store = new MemoryStore(dataDir);
083: store.initialize();
084:
085: factory = store.getValueFactory();
086: foo = factory.createURI("http://www.foo.example/foo");
087: bar = factory.createURI("http://www.foo.example/bar");
088:
089: con = store.getConnection();
090:
091: iter = con.evaluate(tupleExpr, null, EmptyBindingSet
092: .getInstance(), false);
093:
094: bindingSet = iter.next();
095:
096: assertEquals(bindingSet.getValue("X"), foo);
097: assertEquals(bindingSet.getValue("P"), RDF.TYPE);
098: assertEquals(bindingSet.getValue("Y"), bar);
099:
100: iter.close();
101: con.close();
102: }
103: }
|