2 * Copyright (C) 2007-2012 Mathieu Baudier
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
.server
.jcr
;
18 import java
.io
.InputStream
;
19 import java
.text
.SimpleDateFormat
;
20 import java
.util
.Calendar
;
21 import java
.util
.List
;
23 import org
.apache
.commons
.io
.IOUtils
;
24 import org
.apache
.commons
.logging
.Log
;
25 import org
.apache
.commons
.logging
.LogFactory
;
26 import org
.argeo
.jcr
.AbstractInternalJackrabbitTestCase
;
27 import org
.argeo
.jcr
.JcrResourceAdapter
;
28 import org
.springframework
.core
.io
.ClassPathResource
;
29 import org
.springframework
.core
.io
.Resource
;
31 public class JcrResourceAdapterTest
extends AbstractInternalJackrabbitTestCase
{
32 private static SimpleDateFormat sdf
= new SimpleDateFormat(
33 "yyyyMMdd:hhmmss.SSS");
35 private final static Log log
= LogFactory
36 .getLog(JcrResourceAdapterTest
.class);
38 private JcrResourceAdapter jra
;
40 public void testCreate() throws Exception
{
41 String basePath
= "/test/subdir";
43 Resource res
= new ClassPathResource("org/argeo/server/jcr/dummy00.xls");
44 String filePath
= basePath
+ "/dummy.xml";
45 jra
.create(filePath
, res
.getInputStream(), "application/vnd.ms-excel");
46 InputStream in
= jra
.retrieve(filePath
);
47 assertTrue(IOUtils
.contentEquals(res
.getInputStream(), in
));
50 public void testVersioning() throws Exception
{
51 String basePath
= "/test/versions";
53 String filePath
= basePath
+ "/dummy.xml";
54 Resource res00
= new ClassPathResource(
55 "org/argeo/server/jcr/dummy00.xls");
56 jra
.create(filePath
, res00
.getInputStream(), "application/vnd.ms-excel");
57 Resource res01
= new ClassPathResource(
58 "org/argeo/server/jcr/dummy01.xls");
59 jra
.update(filePath
, res01
.getInputStream());
60 Resource res02
= new ClassPathResource(
61 "org/argeo/server/jcr/dummy02.xls");
62 jra
.update(filePath
, res02
.getInputStream());
64 List
<Calendar
> versions
= jra
.listVersions(filePath
);
65 log
.debug("Versions of " + filePath
);
67 for (Calendar version
: versions
) {
68 log
.debug(" " + (count
== 0 ?
"base" : count
- 1) + "\t"
69 + sdf
.format(version
.getTime()));
73 assertEquals(4, versions
.size());
75 InputStream in
= jra
.retrieve(filePath
, 1);
76 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
77 in
= jra
.retrieve(filePath
, 0);
78 assertTrue(IOUtils
.contentEquals(res00
.getInputStream(), in
));
79 in
= jra
.retrieve(filePath
, 2);
80 assertTrue(IOUtils
.contentEquals(res02
.getInputStream(), in
));
81 Resource res03
= new ClassPathResource(
82 "org/argeo/server/jcr/dummy03.xls");
83 jra
.update(filePath
, res03
.getInputStream());
84 in
= jra
.retrieve(filePath
, 1);
85 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
89 protected void setUp() throws Exception
{
92 jra
= new JcrResourceAdapter();
93 jra
.setSession(session());
97 protected void tearDown() throws Exception
{
98 log
.debug("TEAR DOWN");