]> git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.jcr/src/test/java/org/argeo/server/jcr/JcrResourceAdapterTest.java
Split server Jackrabbit into JCR
[lgpl/argeo-commons.git] / server / runtime / org.argeo.server.jcr / src / test / java / org / argeo / server / jcr / 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.server.jackrabbit.unit.AbstractJcrTestCase;
13 import org.springframework.core.io.ClassPathResource;
14 import org.springframework.core.io.Resource;
15
16 public class JcrResourceAdapterTest extends AbstractJcrTestCase {
17 private static SimpleDateFormat sdf = new SimpleDateFormat(
18 "yyyyMMdd:hhmmss.SSS");
19
20 private final static Log log = LogFactory
21 .getLog(JcrResourceAdapterTest.class);
22
23 private JcrResourceAdapter jra;
24
25 public void testCreate() throws Exception {
26 String basePath = "/test/subdir";
27 jra.mkdirs(basePath);
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));
33 }
34
35 public void testVersioning() throws Exception {
36 String basePath = "/test/versions";
37 jra.mkdirs(basePath);
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);
48
49 List<Calendar> versions = jra.listVersions(filePath);
50 log.debug("Versions of " + filePath);
51 int count = 0;
52 for (Calendar version : versions) {
53 log.debug(" " + (count == 0 ? "base" : count - 1) + "\t"
54 + sdf.format(version.getTime()));
55 count++;
56 }
57
58 assertEquals(4, versions.size());
59
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));
71 }
72
73 @Override
74 protected void setUp() throws Exception {
75 super.setUp();
76 jra = new JcrResourceAdapter();
77 jra.setRepository(getRepository());
78 jra.setUsername("demo");
79 jra.setPassword("demo");
80 jra.afterPropertiesSet();
81 }
82
83 @Override
84 protected void tearDown() throws Exception {
85 jra.destroy();
86 super.tearDown();
87 }
88
89 protected File getRepositoryFile() throws Exception {
90 Resource res = new ClassPathResource(
91 "org/argeo/server/jcr/repository-inMemory.xml");
92 return res.getFile();
93 }
94
95 }