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
.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
.jackrabbit
.unit
.AbstractJackrabbitTestCase
;
27 import org
.argeo
.jcr
.JcrResourceAdapter
;
28 import org
.springframework
.core
.io
.ClassPathResource
;
29 import org
.springframework
.core
.io
.Resource
;
32 public class JcrResourceAdapterTest
extends AbstractJackrabbitTestCase
{
33 private static SimpleDateFormat sdf
= new SimpleDateFormat(
34 "yyyyMMdd:hhmmss.SSS");
36 private final static Log log
= LogFactory
37 .getLog(JcrResourceAdapterTest
.class);
39 private JcrResourceAdapter jra
;
41 public void testCreate() throws Exception
{
42 String basePath
= "/test/subdir";
44 Resource res
= new ClassPathResource("org/argeo/server/jcr/dummy00.xls");
45 String filePath
= basePath
+ "/dummy.xml";
46 jra
.create(filePath
, res
.getInputStream(), "application/vnd.ms-excel");
47 InputStream in
= jra
.retrieve(filePath
);
48 assertTrue(IOUtils
.contentEquals(res
.getInputStream(), in
));
51 public void testVersioning() throws Exception
{
52 String basePath
= "/test/versions";
54 String filePath
= basePath
+ "/dummy.xml";
55 Resource res00
= new ClassPathResource(
56 "org/argeo/server/jcr/dummy00.xls");
57 jra
.create(filePath
, res00
.getInputStream(), "application/vnd.ms-excel");
58 Resource res01
= new ClassPathResource(
59 "org/argeo/server/jcr/dummy01.xls");
60 jra
.update(filePath
, res01
.getInputStream());
61 Resource res02
= new ClassPathResource(
62 "org/argeo/server/jcr/dummy02.xls");
63 jra
.update(filePath
, res02
.getInputStream());
65 List
<Calendar
> versions
= jra
.listVersions(filePath
);
66 log
.debug("Versions of " + filePath
);
68 for (Calendar version
: versions
) {
69 log
.debug(" " + (count
== 0 ?
"base" : count
- 1) + "\t"
70 + sdf
.format(version
.getTime()));
74 assertEquals(4, versions
.size());
76 InputStream in
= jra
.retrieve(filePath
, 1);
77 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
78 in
= jra
.retrieve(filePath
, 0);
79 assertTrue(IOUtils
.contentEquals(res00
.getInputStream(), in
));
80 in
= jra
.retrieve(filePath
, 2);
81 assertTrue(IOUtils
.contentEquals(res02
.getInputStream(), in
));
82 Resource res03
= new ClassPathResource(
83 "org/argeo/server/jcr/dummy03.xls");
84 jra
.update(filePath
, res03
.getInputStream());
85 in
= jra
.retrieve(filePath
, 1);
86 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
90 protected void setUp() throws Exception
{
93 jra
= new JcrResourceAdapter();
94 jra
.setSession(session());
98 protected void tearDown() throws Exception
{
99 log
.debug("TEAR DOWN");