Move various CMS extensions to Argeo SLC.
[lgpl/argeo-commons.git] / org.argeo.jcr / src / org / argeo / jcr / unit / AbstractJcrTestCase.java
index 1269a3ee5730243b172896b546ff6191e3974dcc..dc2963a51e73d9ac90db61d30a5c7dcb9bfc0a73 100644 (file)
@@ -1,18 +1,3 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 package org.argeo.jcr.unit;
 
 import java.io.File;
@@ -20,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;
@@ -29,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);
 
@@ -45,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 {
@@ -75,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>() {
+                       session = Subject.doAs(lc.getSubject(), new PrivilegedAction<Session>() {
 
-                                               @Override
-                                               public Session run() {
-                                                       return login();
-                                               }
+                               @Override
+                               public Session run() {
+                                       return login();
+                               }
 
-                                       });
+                       });
                } else
                        session = login();
                this.session = session;
@@ -104,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);
                }
        }
 
@@ -125,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;
        }