]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.server.jcr/src/org/argeo/jcr/unit/AbstractJcrTestCase.java
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.jcr
.unit
;
20 import javax
.jcr
.Repository
;
21 import javax
.jcr
.Session
;
22 import javax
.jcr
.SimpleCredentials
;
24 import junit
.framework
.TestCase
;
26 import org
.apache
.commons
.io
.FileUtils
;
27 import org
.apache
.commons
.logging
.Log
;
28 import org
.apache
.commons
.logging
.LogFactory
;
29 import org
.argeo
.ArgeoException
;
31 public abstract class AbstractJcrTestCase
extends TestCase
{
32 private final static Log log
= LogFactory
.getLog(AbstractJcrTestCase
.class);
34 private Repository repository
;
35 private Session session
= null;
37 // protected abstract File getRepositoryFile() throws Exception;
39 protected abstract Repository
createRepository() throws Exception
;
41 protected abstract void clearRepository(Repository repository
)
45 protected void setUp() throws Exception
{
46 File homeDir
= getHomeDir();
47 FileUtils
.deleteDirectory(homeDir
);
48 repository
= createRepository();
52 protected void tearDown() throws Exception
{
53 if (session
!= null) {
55 if (log
.isTraceEnabled())
56 log
.trace("Logout session");
58 clearRepository(repository
);
61 protected Session
session() {
62 if (session
== null || !session
.isLive()) {
64 if (log
.isTraceEnabled())
65 log
.trace("Login session");
66 session
= getRepository().login(
67 new SimpleCredentials("demo", "demo".toCharArray()));
68 } catch (Exception e
) {
69 throw new ArgeoException("Cannot login to repository", e
);
75 protected Repository
getRepository() {
80 * enables children class to set an existing repository in case it is not
81 * deleted on startup, to test migration by instance
83 public void setRepository(Repository repository
) {
84 this.repository
= repository
;
87 // public void logout() {
88 // if (session != null && session.isLive())
89 // JcrUtils.logoutQuietly(session);
92 // protected static TestSuite defaultTestSuite(Class<? extends TestCase>
94 // String testSuiteClassName =
95 // "org.argeo.jackrabbit.unit.JackrabbitTestSuite";
97 // Class<?> testSuiteClass = AbstractJcrTestCase.class
98 // .getClassLoader().loadClass(testSuiteClassName);
99 // if (clss == null) {
100 // return (TestSuite) testSuiteClass.newInstance();
102 // return (TestSuite) testSuiteClass.getConstructor(Class.class)
103 // .newInstance(clss);
105 // } catch (Exception e) {
106 // throw new ArgeoException("Cannot find default test suite "
107 // + testSuiteClassName, e);
111 protected File
getHomeDir() {
112 File homeDir
= new File(System
.getProperty("java.io.tmpdir"),
113 AbstractJcrTestCase
.class.getSimpleName() + "-"
114 + System
.getProperty("user.name"));