package com.ephox.wiki.jcr; import junit.framework.*; import org.apache.jackrabbit.core.*; import org.apache.jackrabbit.core.config.*; import java.io.*; import java.net.*; public abstract class JcrRepositoryTestBase extends TestCase { private static String configFileName = JcrRepositoryTestBase.class.getPackage().getName().replace('.', '/') + "/memoryRepository.xml"; private static URL resource = JcrRepositoryTestBase.class.getClassLoader().getResource(configFileName); protected File _storageDir; protected TransientRepository _repository; @Override protected void setUp() throws Exception { super.setUp(); _storageDir = new File(System.getProperty("java.io.tmpdir"), "jcr"); deleteDirectory(_storageDir); _repository = new TransientRepository(RepositoryConfig.create(resource.toURI(), _storageDir.getAbsolutePath())); } @Override protected void tearDown() throws Exception { _storageDir = null; ((TransientRepository) _repository).shutdown(); _repository = null; super.tearDown(); } public boolean deleteDirectory(File path) { if (path.exists()) { File[] files = path.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { deleteDirectory(files[i]); } else { files[i].delete(); } } } return path.delete(); } }