Code Search for Developers
 
 
  

RDFEntityRemoverTest.java from Texai at Krugle


Show RDFEntityRemoverTest.java syntax highlighted

/*
 * RDFEntityRemoverTest.java
 *
 * Created on August 16, 2007, 10:14 AM
 *
 * Description: .
 *
 * Copyright (C) August 16, 2007 Stephen L. Reed.
 *
 * This program is free software; you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package org.texai.kb.persistence;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import junit.framework.TestCase;
import net.sf.ehcache.CacheManager;
import org.openrdf.model.URI;
import org.openrdf.model.ValueFactory;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.sail.nativerdf.NativeStore;
import org.texai.kb.CacheInitializer;
import org.texai.kb.Constants;
import org.texai.kb.persistence.benchmark.RDFTestEntity;

/**
 *
 * @author reed
 */
public class RDFEntityRemoverTest  extends TestCase {
  
  /** the Sesame repository */
  static Repository repository = null;
  
  /** the Sesame repository connection */
  static RepositoryConnection repositoryConnection = null;
  
  /** the Sesame value factory */
  static ValueFactory valueFactory = null;
  
  /** the RDF utility */
  static RDFUtility rdfUtility = null;
  
  /** the RDF entity loader pool */
  static RDFEntityLoaderPool rdfEntityLoaderPool = null;
  
  public RDFEntityRemoverTest(String testName) {
    super(testName);
  }
  
  protected void setUp() throws Exception {
    if (repository == null) {
      System.out.println("oneTimeSetup");
      try {
        getClass().getClassLoader().setDefaultAssertionStatus(true);
        CacheInitializer.initializeCaches();
        final File dataDirectory = new File("/data-b/sesame/test/");
        System.out.println("accessing Sesame2 repository in " + dataDirectory.toString());
        final String indices = "spoc,posc";
        repository = new SailRepository(new NativeStore(dataDirectory, indices));
        repository.initialize();
        System.out.println("clearing Sesame2 repository");
        repositoryConnection = repository.getConnection();
        repositoryConnection.clear();
        valueFactory = repository.getValueFactory();
        rdfUtility = new RDFUtility(repositoryConnection, valueFactory);
        rdfEntityLoaderPool = new RDFEntityLoaderPool(new RDFEntityLoaderFactory(repository), Constants.RDF_ENTITY_LOADER_POOL_MAX_ACTIVE);
      } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
      }
    }
  }
  
  protected void tearDown() throws Exception {
  }
  
  
  /**
   * Test of persist method, of class org.texai.kb.persistence.RDFEntityPersister.
   */
  public void testRemove() {
    System.out.println("remove");
    
    final RDFTestEntity rdfTestEntity1 = new RDFTestEntity();
    final RDFTestEntity rdfTestEntity2 = new RDFTestEntity();
    rdfTestEntity1.setDontCareField("do not care");
    rdfTestEntity1.setFavoriteTestRDFEntityPeer(rdfTestEntity2);
    rdfTestEntity1.setMaxNbrOfScooterRiders(2);
    List<RDFTestEntity> myPeers = new ArrayList<RDFTestEntity>(1);
    myPeers.add(rdfTestEntity2);
    rdfTestEntity1.setMyPeers(myPeers);
    rdfTestEntity1.setName("TestDomainEntity 1");
    rdfTestEntity1.setNumberOfCrew(1);
    final String[] comments1 = {"comment 1", "comment 2"};
    rdfTestEntity1.setComment(comments1);
    Set<String> cyclistNotes = new HashSet<String>();
    cyclistNotes.add("note 1");
    cyclistNotes.add("note 2");
    rdfTestEntity2.setDontCareField("do not care");
    rdfTestEntity2.setFavoriteTestRDFEntityPeer(rdfTestEntity2);
    rdfTestEntity2.setMaxNbrOfScooterRiders(2);
    myPeers = new ArrayList<RDFTestEntity>(1);
    myPeers.add(rdfTestEntity1);
    rdfTestEntity2.setMyPeers(myPeers);
    List<Double> myPeersStrengths = new ArrayList<Double>();
    myPeersStrengths.add(Double.valueOf(0.5d));
    rdfTestEntity2.setName("TestDomainEntity 2");
    rdfTestEntity2.setNumberOfCrew(1);
    final String[] comments2 = {"comment 1", "comment 2"};
    rdfTestEntity2.setComment(comments2);
    
    RDFEntityPersister rdfEntityPersister = new RDFEntityPersister(repositoryConnection, valueFactory);
    rdfEntityPersister.persist(rdfTestEntity1);
    assertNotNull(rdfTestEntity1.getRDFEntityId());
    
    RDFEntityLoader rdfEntityLoader = new RDFEntityLoader(repositoryConnection, valueFactory);
    rdfEntityLoader.setRDFEntityLoaderPool(rdfEntityLoaderPool);
    URI uri1 = valueFactory.createURI(rdfTestEntity1.getRDFEntityId());
    Object result = rdfEntityLoader.find(RDFTestEntity.class, uri1);
    assertNotNull(result);
    
    RDFEntityRemover instance = new RDFEntityRemover(repositoryConnection, valueFactory);
    instance.remove(rdfTestEntity1);
    assertNotNull(rdfTestEntity1.getRDFEntityId());
    
    result = rdfEntityLoader.find(RDFTestEntity.class, uri1);
    assertNull(result);
    
    System.out.println("  remove OK");
  }
  
  /** Performs one time tear down of test harness. This must be the last test method. */
  public void testOneTimeTearDown() {
    System.out.println("oneTimeTearDown");
    CacheManager.getInstance().shutdown();
    try {
      repositoryConnection.close();
      assertNotNull(repository);
      repository.shutDown();
    } catch (RepositoryException ex) {
      ex.printStackTrace();
    }
  }
}




See more files for this project here

Texai

Texai is an chatbot that intelligently seeks to acquire knowledge and friendly behaviors.

Project homepage: http://sourceforge.net/projects/texai
Programming language(s): Java,Shell Script,XML
License: other

  LoadAFriendTest.java
  PersistANewFriendTest.java
  RDFEntityLoaderTest.java
  RDFEntityManagerTest.java
  RDFEntityPersisterTest.java
  RDFEntityRemoverTest.java
  RDFUtilityTest.java
  RemoveAFriendTest.java
  UpdateAFriendTest.java