RecordStoreDataAccessTest.java :  » UnTagged » otsopack » otsopack » otsoME » dataaccess » recordstore » Android Open Source

Android Open Source » UnTagged » otsopack 
otsopack » otsopack » otsoME » dataaccess » recordstore » RecordStoreDataAccessTest.java
/*
 * Copyright (C) 2008-2011 University of Deusto
 * 
 * All rights reserved.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.
 * 
 * This software consists of contributions made by many individuals, 
 * listed below:
 *
 * Author: Aitor Gmez Goiri <aitor.gomez@deusto.es>
 */
package otsopack.otsoME.dataaccess.recordstore;

import jmunit.framework.cldc11.TestCase;
import otsopack.commons.data.Graph;
import otsopack.commons.data.ISemanticFactory;
import otsopack.commons.data.ITemplate;
import otsopack.commons.data.SemanticFormat;
import otsopack.commons.data.impl.SemanticFactory;
import otsopack.commons.data.impl.microjena.MicrojenaFactory;
import otsopack.commons.data.impl.microjena.ModelImpl;
import otsopack.commons.data.impl.microjena.TripleImpl;
import otsopack.commons.exceptions.SpaceAlreadyExistsException;
import otsopack.commons.exceptions.SpaceNotExistsException;
import otsopack.commons.exceptions.TSException;
import otsopack.otsoME.dataaccess.recordstore.space.SpaceRecord;
import otsopack.otsoME.sampledata.ExampleME;

public class RecordStoreDataAccessTest extends TestCase {
  
  private MicrojenaFactory factory;
  
  public RecordStoreDataAccessTest() {
    super(12, "RecordStoreTest");
  }  
  
  public void setUp()  throws Throwable {
    super.setUp();
    factory = new MicrojenaFactory();
    SemanticFactory.initialize(factory);
  }
  
  public void tearDown() {
  }
  
  public void test(int testNumber) throws Throwable {
    switch ( testNumber ) {
      case 0: testCreateSpace();
        break;
      case 1: testJoinSpace();
        break;
      case 2: testJoinSpaceFailure();
        break;
      case 3: testLeaveSpace();
        break;
      case 4: testLeaveSpaceFailure();
        break;
      case 5: testWriteList();
        break;  
      case 6: testQuery();
        break;
      case 7: testEmptyQuery();
        break;
      case 8: testReadTemplate();
        break;
      case 9: testReadURI();
        break;
      case 10: testTakeTemplate();
        break;
      case 11: testTakeURI();
        break;
      default:
        break;  
    }
  }
  
  public void testCreateSpace() throws Exception {
    RecordStoreDataAccess memo = new RecordStoreDataAccess();
    memo.startup();
    
    try {
      memo.createSpace("ts://espacio/");
      memo.createSpace("ts://espacio2/");
    } catch(SpaceAlreadyExistsException e) {
      // They have been created in a previous execution.
    }
    
    for(int i=0; i<memo.spaces.size(); i++) {
      String storeName1 = ((SpaceRecord) memo.spaces.elementAt(i)).getRecordStoreName();
      for(int j=(i+1); j<memo.spaces.size(); j++) {
        String storeName2 = ((SpaceRecord) memo.spaces.elementAt(j)).getRecordStoreName();
        if(storeName1.equals(storeName2)) throw new Exception("The name generator has not worked");
      }
    }
    
    memo.shutdown();
  }

  public void testJoinSpace() throws TSException {
    RecordStoreDataAccess memo = new RecordStoreDataAccess();
    memo.startup();
    try {
      memo.createSpace("ts://espacio2");
    } catch(SpaceAlreadyExistsException e) {
      // They have been created in a previous execution.
    }
    memo.joinSpace("ts://espacio2");
    memo.shutdown();
  }
  
  public void testJoinSpaceFailure() throws TSException {
    RecordStoreDataAccess memo = new RecordStoreDataAccess();
    memo.startup();
    try {
      memo.createSpace("ts://espacio3");
    } catch(SpaceAlreadyExistsException e) {
      // They have been created in a previous execution.
    }
    
    try {
      memo.joinSpace("ts://space_that_doesnt_exist");
      assertTrue(false);
    } catch (SpaceNotExistsException e) {
      assertTrue(true);
    }
    memo.shutdown();
  }

  public void testLeaveSpace() throws TSException {
    RecordStoreDataAccess memo = new RecordStoreDataAccess();
    memo.startup();
    try {
      memo.createSpace("ts://espacio4");
    } catch(SpaceAlreadyExistsException e) {
      // They have been created in a previous execution.
    }
    memo.joinSpace("ts://espacio4");
    memo.leaveSpace("ts://espacio4");
    memo.shutdown();
  }
  
  public void testLeaveSpaceFailure() throws TSException {
    RecordStoreDataAccess memo = new RecordStoreDataAccess();
    memo.startup();
    try {
      memo.createSpace("ts://espacio5");
    } catch(SpaceAlreadyExistsException e) {
      // They have been created in a previous execution.
    }
    memo.joinSpace("ts://espacio5");
    try {
      memo.leaveSpace("ts://espacio6");
      assertTrue(false);
    } catch (Exception e) {
      //assertTrue(true);
    }
    memo.shutdown();
  }

  public void testWriteList() throws TSException {
    final String spaceURI = "ts://espacioWrite2";
    final TripleImpl[] trips = new TripleImpl[4];
    final RecordStoreDataAccess memo = new RecordStoreDataAccess();
    memo.startup();
    try {
      memo.createSpace(spaceURI);
    } catch(SpaceAlreadyExistsException e) {
      // They have been created in a previous execution.
    }
    memo.joinSpace(spaceURI);
        
    ModelImpl model = new ModelImpl();
    model.addTriple( trips[0] = new TripleImpl(ExampleME.subj1, ExampleME.prop1, ExampleME.obj1) );
    model.addTriple( trips[1] = new TripleImpl(ExampleME.subj2, ExampleME.prop2, ExampleME.obj2) );
    model.addTriple( trips[2] = new TripleImpl(ExampleME.subj3, ExampleME.prop3, ExampleME.obj3) );
    model.addTriple( trips[3] = new TripleImpl(ExampleME.subj4, ExampleME.prop4, ExampleME.obj4) );
    
    final String graphuri = memo.write(spaceURI, model.write(SemanticFormat.NTRIPLES));
    memo.leaveSpace(spaceURI);
    memo.shutdown();

    // To test persistence, we check with a different object
    final RecordStoreDataAccess memo2 = new RecordStoreDataAccess();
    memo2.startup();
    try {
      memo2.createSpace(spaceURI);
    } catch(SpaceAlreadyExistsException e) {
      e.printStackTrace();
    }
    memo2.joinSpace(spaceURI);
    SpaceRecord m = memo2.getSpace(spaceURI);
        
    assertNotNull(graphuri);
    assertTrue( m.contains(trips[1]) );
    assertTrue( m.contains(trips[2]) );
    assertTrue( m.contains(trips[3]) );
    assertTrue( m.containsGraph(graphuri) );
    
    memo2.leaveSpace(spaceURI);
    memo2.shutdown();
  }
  
  public void testQuery() throws TSException {
    final ISemanticFactory sf = new SemanticFactory();
    final String spaceURI = "ts://espacioQuery/";
    final TripleImpl[] trips = new TripleImpl[3];
    final RecordStoreDataAccess memo = new RecordStoreDataAccess();
    memo.startup();
    try {
      memo.createSpace(spaceURI);
    } catch(SpaceAlreadyExistsException e) {
      // They have been created in a previous execution.
    }
    memo.joinSpace(spaceURI);
    
    final ITemplate sel = sf.createTemplate("<"+ExampleME.subj1+"> <"+ExampleME.prop1+"> ?o .");
    final ModelImpl model = new ModelImpl();
    model.addTriple( trips[0] = new TripleImpl(ExampleME.subj1, ExampleME.prop1, ExampleME.obj1) );
    model.addTriple( trips[1] = new TripleImpl(ExampleME.subj2, ExampleME.prop2, ExampleME.obj2) );
    model.addTriple( trips[2] = new TripleImpl(ExampleME.subj3, ExampleME.prop3, ExampleME.obj3) );
    
    memo.write(spaceURI, model.write(SemanticFormat.NTRIPLES));
    memo.leaveSpace(spaceURI);
    memo.shutdown();
    
    // To test persistence, we check with a different object
    final RecordStoreDataAccess memo2 = new RecordStoreDataAccess();
    memo2.startup();
    try {
      memo2.createSpace(spaceURI);
    } catch(SpaceAlreadyExistsException e) {
      e.printStackTrace();
    }
    memo2.joinSpace(spaceURI);
    final Graph ret = memo2.query(spaceURI, sel, SemanticFormat.NTRIPLES);
    memo2.leaveSpace(spaceURI);
    memo2.shutdown();
    
    assertNotNull( ret );
    assertTrue( new ModelImpl(ret).getModel().contains(trips[0].asStatement()) );
    assertFalse( new ModelImpl(ret).getModel().contains(trips[1].asStatement()) );
    assertFalse( new ModelImpl(ret).getModel().contains(trips[2].asStatement()) );
  }
  
  public void testEmptyQuery() throws TSException {
    final ISemanticFactory sf = new SemanticFactory();
    final String spaceURI = "ts://espacioQuery2/";
    final TripleImpl[] trips = new TripleImpl[3];
    final RecordStoreDataAccess memo = new RecordStoreDataAccess();
    memo.startup();
    try {
      memo.createSpace(spaceURI);
    } catch(SpaceAlreadyExistsException e) {
      // They have been created in a previous execution.
    }
    memo.joinSpace(spaceURI);
    
    final ITemplate sel = sf.createTemplate("<"+ExampleME.subj2+"> <"+ExampleME.prop1+"> ?o .");
    ModelImpl model = new ModelImpl();
    model.addTriple( trips[0] = new TripleImpl(ExampleME.subj1, ExampleME.prop1, ExampleME.obj1) );
    model.addTriple( trips[1] = new TripleImpl(ExampleME.subj2, ExampleME.prop2, ExampleME.obj2) );
    model.addTriple( trips[2] = new TripleImpl(ExampleME.subj3, ExampleME.prop3, ExampleME.obj3) );

    memo.write(spaceURI, model.write(SemanticFormat.NTRIPLES));
    final Graph ret = memo.query(spaceURI, sel, SemanticFormat.NTRIPLES);
    memo.leaveSpace(spaceURI);
    memo.shutdown();
    
    assertNull( ret );
  }
  
  public void testReadTemplate() throws TSException {
    final ISemanticFactory sf = new SemanticFactory();
    final String spaceURI = "ts://espacioRead1/";
    final TripleImpl[] trips = new TripleImpl[6];
    final RecordStoreDataAccess memo = new RecordStoreDataAccess();
    memo.startup();
    try {
      memo.createSpace(spaceURI);
    } catch(SpaceAlreadyExistsException e) {
      // They have been created in a previous execution.
    }
    memo.joinSpace(spaceURI);
        
    ModelImpl model = new ModelImpl();
    model.addTriple( trips[0] = new TripleImpl(ExampleME.subj1, ExampleME.prop1, ExampleME.obj1) );
    model.addTriple( trips[1] = new TripleImpl(ExampleME.subj2, ExampleME.prop2, ExampleME.obj2) );
    model.addTriple( trips[2] = new TripleImpl(ExampleME.subj3, ExampleME.prop3, ExampleME.obj3) );
    memo.write(spaceURI, model.write(SemanticFormat.NTRIPLES));
    
    model = new ModelImpl();
    model.addTriple( trips[3] = new TripleImpl(ExampleME.subj4, ExampleME.prop1, ExampleME.obj1) );
    model.addTriple( trips[4] = new TripleImpl(ExampleME.subj5, ExampleME.prop2, ExampleME.obj2) );
    model.addTriple( trips[5] = new TripleImpl(ExampleME.subj6, ExampleME.prop3, ExampleME.obj3) );
    memo.write(spaceURI, model.write(SemanticFormat.NTRIPLES));
    
    final ITemplate sel = sf.createTemplate("<"+ExampleME.subj1+"> ?p ?o .");
    final ITemplate sel2 = sf.createTemplate("<"+ExampleME.subj5+"> <"+ExampleME.prop2+"> ?o .");
    final Graph ret = memo.read(spaceURI, sel, SemanticFormat.NTRIPLES);
    final Graph ret2 = memo.read(spaceURI, sel2, SemanticFormat.NTRIPLES);
    final Graph ret3 = memo.read(spaceURI, sel, SemanticFormat.NTRIPLES);
  
    // We check if the first read has returned the correct model
    assertTrue( new ModelImpl(ret).getModel().contains(trips[0].asStatement()) );
    assertTrue( new ModelImpl(ret).getModel().contains(trips[1].asStatement()) );
    assertTrue( new ModelImpl(ret).getModel().contains(trips[2].asStatement()) );
    assertFalse( new ModelImpl(ret).getModel().contains(trips[3].asStatement()) );
    assertFalse( new ModelImpl(ret).getModel().contains(trips[4].asStatement()) );
    assertFalse( new ModelImpl(ret).getModel().contains(trips[5].asStatement()) );
      
    // We check if the second read has returned the correct model
    assertFalse( new ModelImpl(ret2).getModel().contains(trips[0].asStatement()) );
    assertFalse( new ModelImpl(ret2).getModel().contains(trips[1].asStatement()) );
    assertFalse( new ModelImpl(ret2).getModel().contains(trips[2].asStatement()) );
    assertTrue( new ModelImpl(ret2).getModel().contains(trips[3].asStatement()) );
    assertTrue( new ModelImpl(ret2).getModel().contains(trips[4].asStatement()) );
    assertTrue( new ModelImpl(ret2).getModel().contains(trips[5].asStatement()) );
    
    // If we do the same query again, same result
    assertTrue( new ModelImpl(ret3).getModel().contains(trips[0].asStatement()) );
    assertTrue( new ModelImpl(ret3).getModel().contains(trips[1].asStatement()) );
    assertTrue( new ModelImpl(ret3).getModel().contains(trips[2].asStatement()) );
    assertFalse( new ModelImpl(ret3).getModel().contains(trips[3].asStatement()) );
    assertFalse( new ModelImpl(ret3).getModel().contains(trips[4].asStatement()) );
    assertFalse( new ModelImpl(ret3).getModel().contains(trips[5].asStatement()) );
    
    // We check if model remain in the space
    SpaceRecord m = memo.getSpace(spaceURI);
    assertTrue( m.contains(trips[0]) );
    assertTrue( m.contains(trips[1]) );
    assertTrue( m.contains(trips[2]) );
    assertTrue( m.contains(trips[3]) );
    assertTrue( m.contains(trips[4]) );
    assertTrue( m.contains(trips[5]) );
    
    memo.leaveSpace(spaceURI);
    memo.shutdown();
  }
  
  public void testReadURI() throws TSException {
    final String spaceURI = "ts://espacioRead2/";
    final TripleImpl[] trips = new TripleImpl[6];
    final String[] graphsuri = new String[2];
    final RecordStoreDataAccess memo = new RecordStoreDataAccess();
    memo.startup();
    try {
      memo.createSpace(spaceURI);
    } catch(SpaceAlreadyExistsException e) {
      // They have been created in a previous execution.
    }
    memo.joinSpace(spaceURI);
        
    ModelImpl model = new ModelImpl();
    model.addTriple( trips[0] = new TripleImpl(ExampleME.subj1, ExampleME.prop1, ExampleME.obj1) );
    model.addTriple( trips[1] = new TripleImpl(ExampleME.subj2, ExampleME.prop2, ExampleME.obj2) );
    model.addTriple( trips[2] = new TripleImpl(ExampleME.subj3, ExampleME.prop3, ExampleME.obj3) );
    graphsuri[0] = memo.write(spaceURI, model.write(SemanticFormat.NTRIPLES));
    
    model = new ModelImpl();
    model.addTriple( trips[3] = new TripleImpl(ExampleME.subj4, ExampleME.prop1, ExampleME.obj1) );
    model.addTriple( trips[4] = new TripleImpl(ExampleME.subj5, ExampleME.prop2, ExampleME.obj2) );
    model.addTriple( trips[5] = new TripleImpl(ExampleME.subj6, ExampleME.prop3, ExampleME.obj3) );
    graphsuri[1] = memo.write(spaceURI, model.write(SemanticFormat.NTRIPLES));
    
    final Graph ret = memo.read(spaceURI, graphsuri[1], SemanticFormat.NTRIPLES);
    final Graph ret2 = memo.read(spaceURI, graphsuri[0], SemanticFormat.NTRIPLES);
    final Graph ret3 = memo.read(spaceURI, graphsuri[1], SemanticFormat.NTRIPLES);
  
    // We check if the first read has returned the correct model
    assertFalse( new ModelImpl(ret).getModel().contains(trips[0].asStatement()) );
    assertFalse( new ModelImpl(ret).getModel().contains(trips[1].asStatement()) );
    assertFalse( new ModelImpl(ret).getModel().contains(trips[2].asStatement()) );
    assertTrue( new ModelImpl(ret).getModel().contains(trips[3].asStatement()) );
    assertTrue( new ModelImpl(ret).getModel().contains(trips[4].asStatement()) );
    assertTrue( new ModelImpl(ret).getModel().contains(trips[5].asStatement()) );
      
    // We check if the second read has returned the correct model
    assertTrue( new ModelImpl(ret2).getModel().contains(trips[0].asStatement()) );
    assertTrue( new ModelImpl(ret2).getModel().contains(trips[1].asStatement()) );
    assertTrue( new ModelImpl(ret2).getModel().contains(trips[2].asStatement()) );
    assertFalse( new ModelImpl(ret2).getModel().contains(trips[3].asStatement()) );
    assertFalse( new ModelImpl(ret2).getModel().contains(trips[4].asStatement()) );
    assertFalse( new ModelImpl(ret2).getModel().contains(trips[5].asStatement()) );
    
    // If we do the same query again, same result
    assertFalse( new ModelImpl(ret3).getModel().contains(trips[0].asStatement()) );
    assertFalse( new ModelImpl(ret3).getModel().contains(trips[1].asStatement()) );
    assertFalse( new ModelImpl(ret3).getModel().contains(trips[2].asStatement()) );
    assertTrue( new ModelImpl(ret3).getModel().contains(trips[3].asStatement()) );
    assertTrue( new ModelImpl(ret3).getModel().contains(trips[4].asStatement()) );
    assertTrue( new ModelImpl(ret3).getModel().contains(trips[5].asStatement()) );
    
    // We check if model remain in the space
    SpaceRecord m = memo.getSpace(spaceURI);
    assertTrue( m.contains(trips[0]) );
    assertTrue( m.contains(trips[1]) );
    assertTrue( m.contains(trips[2]) );
    assertTrue( m.contains(trips[3]) );
    assertTrue( m.contains(trips[4]) );
    assertTrue( m.contains(trips[5]) );
    
    memo.leaveSpace(spaceURI);
    memo.shutdown();
  }
  
  public void testTakeTemplate() throws TSException {
    final ISemanticFactory sf = new SemanticFactory();
    final String spaceURI = "ts://espacioTake/";
    final TripleImpl[] trips = new TripleImpl[6];
    final RecordStoreDataAccess memo = new RecordStoreDataAccess();
    memo.startup();
    try {
      memo.createSpace(spaceURI);
    } catch(SpaceAlreadyExistsException e) {
      // They have been created in a previous execution.
    }
    memo.joinSpace(spaceURI);
        
    ModelImpl model = new ModelImpl();
    model.addTriple( trips[0] = new TripleImpl(ExampleME.subj1, ExampleME.prop1, ExampleME.obj1) );
    model.addTriple( trips[1] = new TripleImpl(ExampleME.subj2, ExampleME.prop2, ExampleME.obj2) );
    model.addTriple( trips[2] = new TripleImpl(ExampleME.subj3, ExampleME.prop3, ExampleME.obj3) );
    memo.write(spaceURI, model.write(SemanticFormat.NTRIPLES));
    
    model = new ModelImpl();
    model.addTriple( trips[3] = new TripleImpl(ExampleME.subj4, ExampleME.prop1, ExampleME.obj1) );
    model.addTriple( trips[4] = new TripleImpl(ExampleME.subj5, ExampleME.prop2, ExampleME.obj2) );
    model.addTriple( trips[5] = new TripleImpl(ExampleME.subj6, ExampleME.prop3, ExampleME.obj3) );
    memo.write(spaceURI, model.write(SemanticFormat.NTRIPLES));
    
    final ITemplate sel = sf.createTemplate("<"+ExampleME.subj1+"> ?p ?o .");
    final ITemplate sel2 = sf.createTemplate("<"+ExampleME.subj5+"> <"+ExampleME.prop2+"> ?o .");
    final Graph ret = memo.take(spaceURI, sel, SemanticFormat.NTRIPLES);
    final Graph ret2 = memo.take(spaceURI, sel2, SemanticFormat.NTRIPLES);
    final Graph ret3 = memo.take(spaceURI, sel, SemanticFormat.NTRIPLES);
  
    // We check if the first read has returned the correct model
    assertTrue( new ModelImpl(ret).getModel().contains(trips[0].asStatement()) );
    assertTrue( new ModelImpl(ret).getModel().contains(trips[1].asStatement()) );
    assertTrue( new ModelImpl(ret).getModel().contains(trips[2].asStatement()) );
    assertFalse( new ModelImpl(ret).getModel().contains(trips[3].asStatement()) );
    assertFalse( new ModelImpl(ret).getModel().contains(trips[4].asStatement()) );
    assertFalse( new ModelImpl(ret).getModel().contains(trips[5].asStatement()) );
      
    // We check if the second read has returned the correct model
    assertFalse( new ModelImpl(ret2).getModel().contains(trips[0].asStatement()) );
    assertFalse( new ModelImpl(ret2).getModel().contains(trips[1].asStatement()) );
    assertFalse( new ModelImpl(ret2).getModel().contains(trips[2].asStatement()) );
    assertTrue( new ModelImpl(ret2).getModel().contains(trips[3].asStatement()) );
    assertTrue( new ModelImpl(ret2).getModel().contains(trips[4].asStatement()) );
    assertTrue( new ModelImpl(ret2).getModel().contains(trips[5].asStatement()) );
    
    // If we do the same query again, the model shouldn't be in the space because of the "take"
    assertNull( ret3 );
    
    // We check if model remain in the space
    SpaceRecord m = memo.getSpace(spaceURI);
    assertFalse( m.contains(trips[0]) );
    assertFalse( m.contains(trips[1]) );
    assertFalse( m.contains(trips[2]) );
    assertFalse( m.contains(trips[3]) );
    assertFalse( m.contains(trips[4]) );
    assertFalse( m.contains(trips[5]) );
    
    memo.leaveSpace(spaceURI);
    memo.shutdown();
  }
  
  public void testTakeURI() throws TSException {
    final String spaceURI = "ts://espacioRead2/";
    final TripleImpl[] trips = new TripleImpl[6];
    final String[] graphsuri = new String[2];
    RecordStoreDataAccess memo = new RecordStoreDataAccess();
    memo.startup();
    try {
      memo.createSpace(spaceURI);
    } catch(SpaceAlreadyExistsException e) {
      // They have been created in a previous execution
    }
    memo.joinSpace(spaceURI);
        
    ModelImpl model = new ModelImpl();
    model.addTriple( trips[0] = new TripleImpl(ExampleME.subj1, ExampleME.prop1, ExampleME.obj1) );
    model.addTriple( trips[1] = new TripleImpl(ExampleME.subj2, ExampleME.prop2, ExampleME.obj2) );
    model.addTriple( trips[2] = new TripleImpl(ExampleME.subj3, ExampleME.prop3, ExampleME.obj3) );
    graphsuri[0] = memo.write(spaceURI, model.write(SemanticFormat.NTRIPLES));
    
    model = new ModelImpl();
    model.addTriple( trips[3] = new TripleImpl(ExampleME.subj4, ExampleME.prop1, ExampleME.obj1) );
    model.addTriple( trips[4] = new TripleImpl(ExampleME.subj5, ExampleME.prop2, ExampleME.obj2) );
    model.addTriple( trips[5] = new TripleImpl(ExampleME.subj6, ExampleME.prop3, ExampleME.obj3) );
    graphsuri[1] = memo.write(spaceURI, model.write(SemanticFormat.NTRIPLES));
    
    memo.leaveSpace(spaceURI);
    memo.shutdown();
    
    //different StoreManager object, to check if storage works
    RecordStoreDataAccess memo2 = new RecordStoreDataAccess();
    memo2.startup();
    try {
      memo2.createSpace(spaceURI);
    } catch(SpaceAlreadyExistsException e) {
      // They have been created in a previous execution
    }
    memo2.joinSpace(spaceURI);
    
    final Graph ret = memo2.take(spaceURI, graphsuri[1], SemanticFormat.NTRIPLES);
    final Graph ret2 = memo2.take(spaceURI, graphsuri[0], SemanticFormat.NTRIPLES);
    final Graph ret3 = memo2.take(spaceURI, graphsuri[1], SemanticFormat.NTRIPLES);
  
    // We check if the first read has returned the correct model
    assertFalse( new ModelImpl(ret).getModel().contains(trips[0].asStatement()) );
    assertFalse( new ModelImpl(ret).getModel().contains(trips[1].asStatement()) );
    assertFalse( new ModelImpl(ret).getModel().contains(trips[2].asStatement()) );
    assertTrue( new ModelImpl(ret).getModel().contains(trips[3].asStatement()) );
    assertTrue( new ModelImpl(ret).getModel().contains(trips[4].asStatement()) );
    assertTrue( new ModelImpl(ret).getModel().contains(trips[5].asStatement()) );
      
    // We check if the second read has returned the correct model
    assertTrue( new ModelImpl(ret2).getModel().contains(trips[0].asStatement()) );
    assertTrue( new ModelImpl(ret2).getModel().contains(trips[1].asStatement()) );
    assertTrue( new ModelImpl(ret2).getModel().contains(trips[2].asStatement()) );
    assertFalse( new ModelImpl(ret2).getModel().contains(trips[3].asStatement()) );
    assertFalse( new ModelImpl(ret2).getModel().contains(trips[4].asStatement()) );
    assertFalse( new ModelImpl(ret2).getModel().contains(trips[5].asStatement()) );
    
    // If we do the same query again, the model shouldn't be in the space because of the "take"
    assertNull( ret3 );
    
    // We check if model remain in the space
    SpaceRecord m = memo.getSpace(spaceURI);
    assertFalse( m.contains(trips[0]) );
    assertFalse( m.contains(trips[1]) );
    assertFalse( m.contains(trips[2]) );
    assertFalse( m.contains(trips[3]) );
    assertFalse( m.contains(trips[4]) );
    assertFalse( m.contains(trips[5]) );
    
    memo2.leaveSpace(spaceURI);
    memo2.shutdown();
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.