]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.server.jcr/ext/test/org/argeo/server/jcr/JcrResourceAdapterTest.java
Move security model to CMS
[lgpl/argeo-commons.git] / org.argeo.server.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.jcr.AbstractInternalJackrabbitTestCase;
27 import org.argeo.jcr.JcrResourceAdapter;
28 import org.springframework.core.io.ClassPathResource;
29 import org.springframework.core.io.Resource;
30
31 public class JcrResourceAdapterTest extends AbstractInternalJackrabbitTestCase {
32 private static SimpleDateFormat sdf = new SimpleDateFormat(
33 "yyyyMMdd:hhmmss.SSS");
34
35 private final static Log log = LogFactory
36 .getLog(JcrResourceAdapterTest.class);
37
38 private JcrResourceAdapter jra;
39
40 public void testCreate() throws Exception {
41 String basePath = "/test/subdir";
42 jra.mkdirs(basePath);
43 Resource res = new ClassPathResource("org/argeo/server/jcr/dummy00.xls");
44 String filePath = basePath + "/dummy.xml";
45 jra.create(filePath, res.getInputStream(), "application/vnd.ms-excel");
46 InputStream in = jra.retrieve(filePath);
47 assertTrue(IOUtils.contentEquals(res.getInputStream(), in));
48 }
49
50 public void testVersioning() throws Exception {
51 String basePath = "/test/versions";
52 jra.mkdirs(basePath);
53 String filePath = basePath + "/dummy.xml";
54 Resource res00 = new ClassPathResource(
55 "org/argeo/server/jcr/dummy00.xls");
56 jra.create(filePath, res00.getInputStream(), "application/vnd.ms-excel");
57 Resource res01 = new ClassPathResource(
58 "org/argeo/server/jcr/dummy01.xls");
59 jra.update(filePath, res01.getInputStream());
60 Resource res02 = new ClassPathResource(
61 "org/argeo/server/jcr/dummy02.xls");
62 jra.update(filePath, res02.getInputStream());
63
64 List<Calendar> versions = jra.listVersions(filePath);
65 log.debug("Versions of " + filePath);
66 int count = 0;
67 for (Calendar version : versions) {
68 log.debug(" " + (count == 0 ? "base" : count - 1) + "\t"
69 + sdf.format(version.getTime()));
70 count++;
71 }
72
73 assertEquals(4, versions.size());
74
75 InputStream in = jra.retrieve(filePath, 1);
76 assertTrue(IOUtils.contentEquals(res01.getInputStream(), in));
77 in = jra.retrieve(filePath, 0);
78 assertTrue(IOUtils.contentEquals(res00.getInputStream(), in));
79 in = jra.retrieve(filePath, 2);
80 assertTrue(IOUtils.contentEquals(res02.getInputStream(), in));
81 Resource res03 = new ClassPathResource(
82 "org/argeo/server/jcr/dummy03.xls");
83 jra.update(filePath, res03.getInputStream());
84 in = jra.retrieve(filePath, 1);
85 assertTrue(IOUtils.contentEquals(res01.getInputStream(), in));
86 }
87
88 @Override
89 protected void setUp() throws Exception {
90 log.debug("SET UP");
91 super.setUp();
92 jra = new JcrResourceAdapter();
93 jra.setSession(session());
94 }
95
96 @Override
97 protected void tearDown() throws Exception {
98 log.debug("TEAR DOWN");
99 super.tearDown();
100 }
101 }