]> git.argeo.org Git - lgpl/argeo-commons.git/blob - JcrResourceAdapterTest.java
5810443ef6f709cef96b363fe7ea15c69cc15df2
[lgpl/argeo-commons.git] / JcrResourceAdapterTest.java
1 package org.argeo.server.jcr;
2
3 import java.io.File;
4 import java.io.InputStream;
5 import java.text.SimpleDateFormat;
6 import java.util.Calendar;
7 import java.util.List;
8
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;
16
17 public class JcrResourceAdapterTest extends AbstractJcrTestCase {
18 private static SimpleDateFormat sdf = new SimpleDateFormat(
19 "yyyyMMdd:hhmmss.SSS");
20
21 private final static Log log = LogFactory
22 .getLog(JcrResourceAdapterTest.class);
23
24 private JcrResourceAdapter jra;
25
26 public void testCreate() throws Exception {
27 String basePath = "/test/subdir";
28 jra.mkdirs(basePath);
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));
34 }
35
36 public void testVersioning() throws Exception {
37 String basePath = "/test/versions";
38 jra.mkdirs(basePath);
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);
49
50 List<Calendar> versions = jra.listVersions(filePath);
51 log.debug("Versions of " + filePath);
52 int count = 0;
53 for (Calendar version : versions) {
54 log.debug(" " + (count == 0 ? "base" : count - 1) + "\t"
55 + sdf.format(version.getTime()));
56 count++;
57 }
58
59 assertEquals(4, versions.size());
60
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));
72 }
73
74 @Override
75 protected void setUp() throws Exception {
76 super.setUp();
77 jra = new JcrResourceAdapter();
78 jra.setSession(session());
79 }
80
81 protected File getRepositoryFile() throws Exception {
82 Resource res = new ClassPathResource(
83 "org/argeo/server/jcr/repository.xml");
84 return res.getFile();
85 }
86
87 }