X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.jcr%2Fsrc%2Forg%2Fargeo%2Fjcr%2Funit%2FAbstractJcrTestCase.java;h=dc2963a51e73d9ac90db61d30a5c7dcb9bfc0a73;hb=215480a865603e0090c43114541441ac1586b379;hp=319ba75d615ad8a5282b868e618c885e7951b130;hpb=afd31256550ee8fe257a43558cfd07dfcf2e5c04;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.jcr/src/org/argeo/jcr/unit/AbstractJcrTestCase.java b/org.argeo.jcr/src/org/argeo/jcr/unit/AbstractJcrTestCase.java index 319ba75d6..dc2963a51 100644 --- a/org.argeo.jcr/src/org/argeo/jcr/unit/AbstractJcrTestCase.java +++ b/org.argeo.jcr/src/org/argeo/jcr/unit/AbstractJcrTestCase.java @@ -5,6 +5,7 @@ import java.security.AccessController; import java.security.PrivilegedAction; import javax.jcr.Repository; +import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.SimpleCredentials; import javax.security.auth.Subject; @@ -14,10 +15,11 @@ import javax.security.auth.login.LoginException; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.jcr.ArgeoJcrException; +import org.argeo.jcr.JcrException; import junit.framework.TestCase; +/** Base for unit tests with a JCR repository. */ public abstract class AbstractJcrTestCase extends TestCase { private final static Log log = LogFactory.getLog(AbstractJcrTestCase.class); @@ -30,8 +32,7 @@ public abstract class AbstractJcrTestCase extends TestCase { protected abstract Repository createRepository() throws Exception; - protected abstract void clearRepository(Repository repository) - throws Exception; + protected abstract void clearRepository(Repository repository) throws Exception; @Override protected void setUp() throws Exception { @@ -60,17 +61,16 @@ public abstract class AbstractJcrTestCase extends TestCase { lc = new LoginContext(getLoginContext()); lc.login(); } catch (LoginException e) { - throw new ArgeoJcrException("JAAS login failed", e); + throw new IllegalStateException("JAAS login failed", e); } - session = Subject.doAs(lc.getSubject(), - new PrivilegedAction() { + session = Subject.doAs(lc.getSubject(), new PrivilegedAction() { - @Override - public Session run() { - return login(); - } + @Override + public Session run() { + return login(); + } - }); + }); } else session = login(); this.session = session; @@ -89,10 +89,9 @@ public abstract class AbstractJcrTestCase extends TestCase { if (subject != null) return getRepository().login(); else - return getRepository().login( - new SimpleCredentials("demo", "demo".toCharArray())); - } catch (Exception e) { - throw new ArgeoJcrException("Cannot login to repository", e); + return getRepository().login(new SimpleCredentials("demo", "demo".toCharArray())); + } catch (RepositoryException e) { + throw new JcrException("Cannot login to repository", e); } } @@ -110,8 +109,7 @@ public abstract class AbstractJcrTestCase extends TestCase { protected File getHomeDir() { File homeDir = new File(System.getProperty("java.io.tmpdir"), - AbstractJcrTestCase.class.getSimpleName() + "-" - + System.getProperty("user.name")); + AbstractJcrTestCase.class.getSimpleName() + "-" + System.getProperty("user.name")); return homeDir; }