]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.jcr/src/test/java/org/argeo/server/jcr/JcrResourceAdapterTest.java
1 package org
.argeo
.server
.jcr
;
4 import java
.io
.InputStream
;
5 import java
.text
.SimpleDateFormat
;
6 import java
.util
.Calendar
;
9 import org
.apache
.commons
.io
.IOUtils
;
10 import org
.apache
.commons
.logging
.Log
;
11 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.argeo
.server
.jackrabbit
.unit
.AbstractJcrTestCase
;
13 import org
.springframework
.core
.io
.ClassPathResource
;
14 import org
.springframework
.core
.io
.Resource
;
16 public class JcrResourceAdapterTest
extends AbstractJcrTestCase
{
17 private static SimpleDateFormat sdf
= new SimpleDateFormat(
18 "yyyyMMdd:hhmmss.SSS");
20 private final static Log log
= LogFactory
21 .getLog(JcrResourceAdapterTest
.class);
23 private JcrResourceAdapter jra
;
25 public void testCreate() throws Exception
{
26 String basePath
= "/test/subdir";
28 Resource res
= new ClassPathResource("org/argeo/server/jcr/dummy00.xls");
29 String filePath
= basePath
+ "/dummy.xml";
30 jra
.create(filePath
, res
, "application/vnd.ms-excel");
31 InputStream in
= jra
.retrieve(filePath
);
32 assertTrue(IOUtils
.contentEquals(res
.getInputStream(), in
));
35 public void testVersioning() throws Exception
{
36 String basePath
= "/test/versions";
38 String filePath
= basePath
+ "/dummy.xml";
39 Resource res00
= new ClassPathResource(
40 "org/argeo/server/jcr/dummy00.xls");
41 jra
.create(filePath
, res00
, "application/vnd.ms-excel");
42 Resource res01
= new ClassPathResource(
43 "org/argeo/server/jcr/dummy01.xls");
44 jra
.update(filePath
, res01
);
45 Resource res02
= new ClassPathResource(
46 "org/argeo/server/jcr/dummy02.xls");
47 jra
.update(filePath
, res02
);
49 List
<Calendar
> versions
= jra
.listVersions(filePath
);
50 log
.debug("Versions of " + filePath
);
52 for (Calendar version
: versions
) {
53 log
.debug(" " + (count
== 0 ?
"base" : count
- 1) + "\t"
54 + sdf
.format(version
.getTime()));
58 assertEquals(4, versions
.size());
60 InputStream in
= jra
.retrieve(filePath
, 1);
61 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
62 in
= jra
.retrieve(filePath
, 0);
63 assertTrue(IOUtils
.contentEquals(res00
.getInputStream(), in
));
64 in
= jra
.retrieve(filePath
, 2);
65 assertTrue(IOUtils
.contentEquals(res02
.getInputStream(), in
));
66 Resource res03
= new ClassPathResource(
67 "org/argeo/server/jcr/dummy03.xls");
68 jra
.update(filePath
, res03
);
69 in
= jra
.retrieve(filePath
, 1);
70 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
74 protected void setUp() throws Exception
{
76 jra
= new JcrResourceAdapter();
77 jra
.setRepository(getRepository());
78 jra
.setUsername("demo");
79 jra
.setPassword("demo");
80 jra
.afterPropertiesSet();
84 protected void tearDown() throws Exception
{
89 protected File
getRepositoryFile() throws Exception
{
90 Resource res
= new ClassPathResource(
91 "org/argeo/server/jcr/repository-inMemory.xml");