]>
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
;
42 protected void setUp() throws Exception
{
43 File homeDir
= getHomeDir();
44 FileUtils
.deleteDirectory(homeDir
);
45 repository
= createRepository();
48 protected File
getHomeDir() {
49 File homeDir
= new File(System
.getProperty("java.io.tmpdir"),
50 AbstractJcrTestCase
.class.getSimpleName() + "-"
51 + System
.getProperty("user.name"));
56 protected void tearDown() throws Exception
{
57 if (session
!= null) {
59 if (log
.isDebugEnabled())
60 log
.debug("Logout session");
64 protected Session
session() {
65 if (session
== null) {
67 if (log
.isDebugEnabled())
68 log
.debug("Login session");
69 session
= getRepository().login(
70 new SimpleCredentials("demo", "demo".toCharArray()));
71 } catch (Exception e
) {
72 throw new ArgeoException("Cannot login to repository", e
);
78 protected Repository
getRepository() {
83 * enables children class to set an existing repository in case it is not
84 * deleted on startup, to test migration by instance
86 protected void setRepository(Repository repository
) {
87 this.repository
= repository
;