1 package org
.argeo
.server
.jcr
;
4 import java
.io
.InputStream
;
5 import java
.text
.SimpleDateFormat
;
6 import java
.util
.Calendar
;
9 import junit
.framework
.TestCase
;
11 import org
.apache
.commons
.io
.FileUtils
;
12 import org
.apache
.commons
.io
.IOUtils
;
13 import org
.apache
.commons
.logging
.Log
;
14 import org
.apache
.commons
.logging
.LogFactory
;
15 import org
.apache
.jackrabbit
.core
.TransientRepository
;
16 import org
.springframework
.core
.io
.ClassPathResource
;
17 import org
.springframework
.core
.io
.Resource
;
19 public class JcrResourceAdapterTest
extends TestCase
{
20 private static SimpleDateFormat sdf
= new SimpleDateFormat(
21 "yyyyMMdd:hhmmss.SSS");
23 private final static Log log
= LogFactory
24 .getLog(JcrResourceAdapterTest
.class);
26 private JcrResourceAdapter jra
;
27 private TransientRepository repository
;
29 public void testCreate() throws Exception
{
30 String basePath
= "/test/subdir";
32 Resource res
= new ClassPathResource("org/argeo/server/jcr/dummy00.xls");
33 String filePath
= basePath
+ "/dummy.xml";
34 jra
.create(filePath
, res
, "application/vnd.ms-excel");
35 InputStream in
= jra
.retrieve(filePath
);
36 assertTrue(IOUtils
.contentEquals(res
.getInputStream(), in
));
39 public void testVersioning() throws Exception
{
40 String basePath
= "/test/versions";
42 String filePath
= basePath
+ "/dummy.xml";
43 Resource res00
= new ClassPathResource(
44 "org/argeo/server/jcr/dummy00.xls");
45 jra
.create(filePath
, res00
, "application/vnd.ms-excel");
46 Resource res01
= new ClassPathResource(
47 "org/argeo/server/jcr/dummy01.xls");
48 jra
.update(filePath
, res01
);
49 Resource res02
= new ClassPathResource(
50 "org/argeo/server/jcr/dummy02.xls");
51 jra
.update(filePath
, res02
);
53 List
<Calendar
> versions
= jra
.listVersions(filePath
);
54 for (Calendar version
: versions
)
55 log
.debug(sdf
.format(version
.getTime()));
56 assertEquals(4, versions
.size());
58 InputStream in
= jra
.retrieve(filePath
, 1);
59 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
60 in
= jra
.retrieve(filePath
, 0);
61 assertTrue(IOUtils
.contentEquals(res00
.getInputStream(), in
));
62 in
= jra
.retrieve(filePath
, 2);
63 assertTrue(IOUtils
.contentEquals(res02
.getInputStream(), in
));
64 Resource res03
= new ClassPathResource(
65 "org/argeo/server/jcr/dummy03.xls");
66 jra
.update(filePath
, res03
);
67 in
= jra
.retrieve(filePath
, 1);
68 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
72 protected void setUp() throws Exception
{
73 File homeDir
= new File(System
.getProperty("java.io.tmpdir"),
74 JcrResourceAdapterTest
.class.getSimpleName());
75 FileUtils
.deleteDirectory(homeDir
);
76 Resource res
= new ClassPathResource(
77 "org/argeo/server/jcr/repository.xml");
78 repository
= new TransientRepository(res
.getFile(), homeDir
);
80 jra
= new JcrResourceAdapter();
81 jra
.setRepository(repository
);
82 jra
.setUsername("demo");
83 jra
.setPassword("demo");
84 jra
.afterPropertiesSet();
88 protected void tearDown() throws Exception
{
90 // repository.shutdown();