]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - JcrResourceAdapterTest.java
5810443ef6f709cef96b363fe7ea15c69cc15df2
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
.jcr
.JcrResourceAdapter
;
13 import org
.argeo
.server
.jackrabbit
.unit
.AbstractJcrTestCase
;
14 import org
.springframework
.core
.io
.ClassPathResource
;
15 import org
.springframework
.core
.io
.Resource
;
17 public class JcrResourceAdapterTest
extends AbstractJcrTestCase
{
18 private static SimpleDateFormat sdf
= new SimpleDateFormat(
19 "yyyyMMdd:hhmmss.SSS");
21 private final static Log log
= LogFactory
22 .getLog(JcrResourceAdapterTest
.class);
24 private JcrResourceAdapter jra
;
26 public void testCreate() throws Exception
{
27 String basePath
= "/test/subdir";
29 Resource res
= new ClassPathResource("org/argeo/server/jcr/dummy00.xls");
30 String filePath
= basePath
+ "/dummy.xml";
31 jra
.create(filePath
, res
, "application/vnd.ms-excel");
32 InputStream in
= jra
.retrieve(filePath
);
33 assertTrue(IOUtils
.contentEquals(res
.getInputStream(), in
));
36 public void testVersioning() throws Exception
{
37 String basePath
= "/test/versions";
39 String filePath
= basePath
+ "/dummy.xml";
40 Resource res00
= new ClassPathResource(
41 "org/argeo/server/jcr/dummy00.xls");
42 jra
.create(filePath
, res00
, "application/vnd.ms-excel");
43 Resource res01
= new ClassPathResource(
44 "org/argeo/server/jcr/dummy01.xls");
45 jra
.update(filePath
, res01
);
46 Resource res02
= new ClassPathResource(
47 "org/argeo/server/jcr/dummy02.xls");
48 jra
.update(filePath
, res02
);
50 List
<Calendar
> versions
= jra
.listVersions(filePath
);
51 log
.debug("Versions of " + filePath
);
53 for (Calendar version
: versions
) {
54 log
.debug(" " + (count
== 0 ?
"base" : count
- 1) + "\t"
55 + sdf
.format(version
.getTime()));
59 assertEquals(4, versions
.size());
61 InputStream in
= jra
.retrieve(filePath
, 1);
62 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
63 in
= jra
.retrieve(filePath
, 0);
64 assertTrue(IOUtils
.contentEquals(res00
.getInputStream(), in
));
65 in
= jra
.retrieve(filePath
, 2);
66 assertTrue(IOUtils
.contentEquals(res02
.getInputStream(), in
));
67 Resource res03
= new ClassPathResource(
68 "org/argeo/server/jcr/dummy03.xls");
69 jra
.update(filePath
, res03
);
70 in
= jra
.retrieve(filePath
, 1);
71 assertTrue(IOUtils
.contentEquals(res01
.getInputStream(), in
));
75 protected void setUp() throws Exception
{
77 jra
= new JcrResourceAdapter();
78 jra
.setSession(session());
81 protected File
getRepositoryFile() throws Exception
{
82 Resource res
= new ClassPathResource(
83 "org/argeo/server/jcr/repository.xml");