]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/unit/AbstractJcrTestCase.java
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.jcr
.unit
;
21 import javax
.jcr
.Repository
;
22 import javax
.jcr
.Session
;
23 import javax
.jcr
.SimpleCredentials
;
25 import junit
.framework
.TestCase
;
27 import org
.apache
.commons
.io
.FileUtils
;
28 import org
.apache
.commons
.logging
.Log
;
29 import org
.apache
.commons
.logging
.LogFactory
;
30 import org
.argeo
.ArgeoException
;
32 public abstract class AbstractJcrTestCase
extends TestCase
{
33 private final static Log log
= LogFactory
.getLog(AbstractJcrTestCase
.class);
35 private Repository repository
;
36 private Session session
= null;
38 protected abstract File
getRepositoryFile() throws Exception
;
40 protected abstract Repository
createRepository() throws Exception
;
43 protected void setUp() throws Exception
{
44 File homeDir
= getHomeDir();
45 FileUtils
.deleteDirectory(homeDir
);
46 repository
= createRepository();
49 protected File
getHomeDir() {
50 File homeDir
= new File(System
.getProperty("java.io.tmpdir"),
51 AbstractJcrTestCase
.class.getSimpleName() + "-"
52 + System
.getProperty("user.name"));
57 protected void tearDown() throws Exception
{
58 if (session
!= null) {
60 if (log
.isDebugEnabled())
61 log
.debug("Logout session");
65 protected Session
session() {
66 if (session
== null) {
68 if (log
.isDebugEnabled())
69 log
.debug("Login session");
70 session
= getRepository().login(
71 new SimpleCredentials("demo", "demo".toCharArray()));
72 } catch (Exception e
) {
73 throw new ArgeoException("Cannot login to repository", e
);
79 protected Repository
getRepository() {