]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.jcr/ext/test/org/argeo/server/jcr/JcrResourceAdapterTest.java
[maven-release-plugin] prepare release argeo-commons-2.1.71
[lgpl/argeo-commons.git] / org.argeo.jcr / ext / test / org / argeo / server / jcr / JcrResourceAdapterTest.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.server.jcr;
17
18 import java.io.InputStream;
19 import java.text.SimpleDateFormat;
20 import java.util.Calendar;
21 import java.util.List;
22
23 import org.apache.commons.io.IOUtils;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.argeo.jackrabbit.unit.AbstractJackrabbitTestCase;
27 import org.argeo.jcr.JcrResourceAdapter;
28 import org.springframework.core.io.ClassPathResource;
29 import org.springframework.core.io.Resource;
30
31 @Deprecated
32 public class JcrResourceAdapterTest extends AbstractJackrabbitTestCase {
33 private static SimpleDateFormat sdf = new SimpleDateFormat(
34 "yyyyMMdd:hhmmss.SSS");
35
36 private final static Log log = LogFactory
37 .getLog(JcrResourceAdapterTest.class);
38
39 private JcrResourceAdapter jra;
40
41 public void testCreate() throws Exception {
42 String basePath = "/test/subdir";
43 jra.mkdirs(basePath);
44 Resource res = new ClassPathResource("org/argeo/server/jcr/dummy00.xls");
45 String filePath = basePath + "/dummy.xml";
46 jra.create(filePath, res.getInputStream(), "application/vnd.ms-excel");
47 InputStream in = jra.retrieve(filePath);
48 assertTrue(IOUtils.contentEquals(res.getInputStream(), in));
49 }
50
51 public void testVersioning() throws Exception {
52 String basePath = "/test/versions";
53 jra.mkdirs(basePath);
54 String filePath = basePath + "/dummy.xml";
55 Resource res00 = new ClassPathResource(
56 "org/argeo/server/jcr/dummy00.xls");
57 jra.create(filePath, res00.getInputStream(), "application/vnd.ms-excel");
58 Resource res01 = new ClassPathResource(
59 "org/argeo/server/jcr/dummy01.xls");
60 jra.update(filePath, res01.getInputStream());
61 Resource res02 = new ClassPathResource(
62 "org/argeo/server/jcr/dummy02.xls");
63 jra.update(filePath, res02.getInputStream());
64
65 List<Calendar> versions = jra.listVersions(filePath);
66 log.debug("Versions of " + filePath);
67 int count = 0;
68 for (Calendar version : versions) {
69 log.debug(" " + (count == 0 ? "base" : count - 1) + "\t"
70 + sdf.format(version.getTime()));
71 count++;
72 }
73
74 assertEquals(4, versions.size());
75
76 InputStream in = jra.retrieve(filePath, 1);
77 assertTrue(IOUtils.contentEquals(res01.getInputStream(), in));
78 in = jra.retrieve(filePath, 0);
79 assertTrue(IOUtils.contentEquals(res00.getInputStream(), in));
80 in = jra.retrieve(filePath, 2);
81 assertTrue(IOUtils.contentEquals(res02.getInputStream(), in));
82 Resource res03 = new ClassPathResource(
83 "org/argeo/server/jcr/dummy03.xls");
84 jra.update(filePath, res03.getInputStream());
85 in = jra.retrieve(filePath, 1);
86 assertTrue(IOUtils.contentEquals(res01.getInputStream(), in));
87 }
88
89 @Override
90 protected void setUp() throws Exception {
91 log.debug("SET UP");
92 super.setUp();
93 jra = new JcrResourceAdapter();
94 jra.setSession(session());
95 }
96
97 @Override
98 protected void tearDown() throws Exception {
99 log.debug("TEAR DOWN");
100 super.tearDown();
101 }
102 }