]>
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 org
.apache
.commons
.io
.IOUtils
;
26 import org
.apache
.commons
.logging
.Log
;
27 import org
.apache
.commons
.logging
.LogFactory
;
28 import org
.argeo
.jcr
.JcrResourceAdapter
;
29 import org
.argeo
.server
.jackrabbit
.unit
.AbstractJcrTestCase
;
30 import org
.springframework
.core
.io
.ClassPathResource
;
31 import org
.springframework
.core
.io
.Resource
;
33 public class JcrResourceAdapterTest
extends AbstractJcrTestCase
{
34 private static SimpleDateFormat sdf
= new SimpleDateFormat(
35 "yyyyMMdd:hhmmss.SSS");
37 private final static Log log
= LogFactory
38 .getLog(JcrResourceAdapterTest
.class);
40 private JcrResourceAdapter jra
;
42 public void testCreate() throws Exception
{
43 String basePath
= "/test/subdir";
45 Resource res
= new ClassPathResource("org/argeo/server/jcr/dummy00.xls");
46 String filePath
= basePath
+ "/dummy.xml";
47 jra
.create(filePath
, res
, "application/vnd.ms-excel");
48 InputStream in
= jra
.retrieve(filePath
);
49 assertTrue(IOUtils
.contentEquals(res
.getInputStream(), in
));
52 public void testVersioning() throws Exception
{
53 String basePath
= "/test/versions";
55 String filePath
= basePath
+ "/dummy.xml";
56 Resource res00
= new ClassPathResource(
57 "org/argeo/server/jcr/dummy00.xls");
58 jra
.create(filePath
, res00
, "application/vnd.ms-excel");
59 Resource res01
= new ClassPathResource(
60 "org/argeo/server/jcr/dummy01.xls");
61 jra
.update(filePath
, res01
);
62 Resource res02
= new ClassPathResource(
63 "org/argeo/server/jcr/dummy02.xls");
64 jra
.update(filePath
, res02
);
66 List
<Calendar
> versions
= jra
.listVersions(filePath
);
67 log
.debug("Versions of " + filePath
);
69 for (Calendar version
: versions
) {
70 log
.debug(" " + (count
== 0 ?
"base" : count
- 1) + "\t"
71 + sdf
.format(version
.getTime()));
75 assertEquals(4, versions
.size());
77 InputStream in
= jra
.retrieve(filePath
, 1);
78 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
79 in
= jra
.retrieve(filePath
, 0);
80 assertTrue(IOUtils
.contentEquals(res00
.getInputStream(), in
));
81 in
= jra
.retrieve(filePath
, 2);
82 assertTrue(IOUtils
.contentEquals(res02
.getInputStream(), in
));
83 Resource res03
= new ClassPathResource(
84 "org/argeo/server/jcr/dummy03.xls");
85 jra
.update(filePath
, res03
);
86 in
= jra
.retrieve(filePath
, 1);
87 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
91 protected void setUp() throws Exception
{
94 jra
= new JcrResourceAdapter();
95 jra
.setSession(session());
99 protected void tearDown() throws Exception
{
100 log
.debug("TEAR DOWN");
104 protected File
getRepositoryFile() throws Exception
{
105 Resource res
= new ClassPathResource(
106 "org/argeo/server/jcr/repository.xml");
107 return res
.getFile();