package org.neo4j.meta.input.rdfs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Collection; import org.junit.AfterClass; import org.junit.BeforeClass; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.kernel.EmbeddedGraphDatabase; import org.neo4j.meta.model.MetaModelRelTypes; import org.neo4j.util.EntireGraphDeletor; /** * Base class for tests. */ public abstract class MetaTestCase { private static GraphDatabaseService graphDb; @BeforeClass public static void setUpDb() throws Exception { graphDb = new EmbeddedGraphDatabase( "target/var/db" ); } @AfterClass public static void tearDownDb() throws Exception { graphDb.shutdown(); } protected static GraphDatabaseService graphDb() { return graphDb; } protected <T> String join( String delimiter, T... items ) { StringBuffer buffer = new StringBuffer(); for ( T item : items ) { if ( buffer.length() > 0 ) { buffer.append( delimiter ); } buffer.append( item.toString() ); } return buffer.toString(); } protected <T> void assertCollection( Collection<T> collection, T... items ) { String collectionString = join( ", ", collection.toArray() ); assertEquals( collectionString, items.length, collection.size() ); for ( T item : items ) { assertTrue( collection.contains( item ) ); } } protected void deleteMetaModel() { Relationship rel = graphDb().getReferenceNode().getSingleRelationship( MetaModelRelTypes.REF_TO_META_SUBREF, Direction.OUTGOING ); Node node = rel.getEndNode(); rel.delete(); new EntireGraphDeletor().delete( node ); } }