]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.jcr/src/test/java/org/argeo/server/jcr/JcrResourceAdapterTest.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
.server
.jcr
;
20 import java
.io
.InputStream
;
21 import java
.text
.SimpleDateFormat
;
22 import java
.util
.Calendar
;
23 import java
.util
.List
;
25 import javax
.jcr
.Repository
;
27 import org
.apache
.commons
.io
.IOUtils
;
28 import org
.apache
.commons
.logging
.Log
;
29 import org
.apache
.commons
.logging
.LogFactory
;
30 import org
.apache
.jackrabbit
.core
.TransientRepository
;
31 import org
.argeo
.jcr
.JcrResourceAdapter
;
32 import org
.argeo
.jcr
.unit
.AbstractJcrTestCase
;
33 import org
.springframework
.core
.io
.ClassPathResource
;
34 import org
.springframework
.core
.io
.Resource
;
36 public class JcrResourceAdapterTest
extends AbstractJcrTestCase
{
37 private static SimpleDateFormat sdf
= new SimpleDateFormat(
38 "yyyyMMdd:hhmmss.SSS");
40 private final static Log log
= LogFactory
41 .getLog(JcrResourceAdapterTest
.class);
43 private JcrResourceAdapter jra
;
45 public void testCreate() throws Exception
{
46 String basePath
= "/test/subdir";
48 Resource res
= new ClassPathResource("org/argeo/server/jcr/dummy00.xls");
49 String filePath
= basePath
+ "/dummy.xml";
50 jra
.create(filePath
, res
, "application/vnd.ms-excel");
51 InputStream in
= jra
.retrieve(filePath
);
52 assertTrue(IOUtils
.contentEquals(res
.getInputStream(), in
));
55 public void testVersioning() throws Exception
{
56 String basePath
= "/test/versions";
58 String filePath
= basePath
+ "/dummy.xml";
59 Resource res00
= new ClassPathResource(
60 "org/argeo/server/jcr/dummy00.xls");
61 jra
.create(filePath
, res00
, "application/vnd.ms-excel");
62 Resource res01
= new ClassPathResource(
63 "org/argeo/server/jcr/dummy01.xls");
64 jra
.update(filePath
, res01
);
65 Resource res02
= new ClassPathResource(
66 "org/argeo/server/jcr/dummy02.xls");
67 jra
.update(filePath
, res02
);
69 List
<Calendar
> versions
= jra
.listVersions(filePath
);
70 log
.debug("Versions of " + filePath
);
72 for (Calendar version
: versions
) {
73 log
.debug(" " + (count
== 0 ?
"base" : count
- 1) + "\t"
74 + sdf
.format(version
.getTime()));
78 assertEquals(4, versions
.size());
80 InputStream in
= jra
.retrieve(filePath
, 1);
81 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
82 in
= jra
.retrieve(filePath
, 0);
83 assertTrue(IOUtils
.contentEquals(res00
.getInputStream(), in
));
84 in
= jra
.retrieve(filePath
, 2);
85 assertTrue(IOUtils
.contentEquals(res02
.getInputStream(), in
));
86 Resource res03
= new ClassPathResource(
87 "org/argeo/server/jcr/dummy03.xls");
88 jra
.update(filePath
, res03
);
89 in
= jra
.retrieve(filePath
, 1);
90 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
94 protected void setUp() throws Exception
{
97 jra
= new JcrResourceAdapter();
98 jra
.setSession(session());
102 protected void tearDown() throws Exception
{
103 log
.debug("TEAR DOWN");
107 protected File
getRepositoryFile() throws Exception
{
108 Resource res
= new ClassPathResource(
109 "org/argeo/server/jcr/repository.xml");
110 return res
.getFile();
113 protected Repository
createRepository() throws Exception
{
114 Repository repository
= new TransientRepository(getRepositoryFile(),