1 package org
.argeo
.cms
.tabular
;
3 import java
.io
.InputStreamReader
;
4 import java
.util
.ArrayList
;
8 import javax
.jcr
.PropertyType
;
10 import org
.apache
.commons
.logging
.Log
;
11 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.apache
.jackrabbit
.commons
.cnd
.CndImporter
;
13 import org
.argeo
.api
.tabular
.TabularColumn
;
14 import org
.argeo
.api
.tabular
.TabularRow
;
15 import org
.argeo
.api
.tabular
.TabularRowIterator
;
16 import org
.argeo
.api
.tabular
.TabularWriter
;
17 import org
.argeo
.cms
.ArgeoTypes
;
18 import org
.argeo
.jackrabbit
.unit
.AbstractJackrabbitTestCase
;
20 public class JcrTabularTest
extends AbstractJackrabbitTestCase
{
21 private final static Log log
= LogFactory
.getLog(JcrTabularTest
.class);
23 public void testWriteReadCsv() throws Exception
{
24 // session().setNamespacePrefix("argeo", ArgeoNames.ARGEO_NAMESPACE);
25 InputStreamReader reader
= new InputStreamReader(getClass().getResourceAsStream("/org/argeo/api/ldap.cnd"));
26 CndImporter
.registerNodeTypes(reader
, session());
28 reader
= new InputStreamReader(getClass().getResourceAsStream("/org/argeo/cms/argeo.cnd"));
29 CndImporter
.registerNodeTypes(reader
, session());
31 // reader = new InputStreamReader(getClass().getResourceAsStream("/org/argeo/cms/cms.cnd"));
32 // CndImporter.registerNodeTypes(reader, session());
36 Integer columnCount
= 15;
37 Long rowCount
= 1000l;
38 String stringValue
= "test, \ntest";
40 List
<TabularColumn
> header
= new ArrayList
<TabularColumn
>();
41 for (int i
= 0; i
< columnCount
; i
++) {
42 header
.add(new TabularColumn("col" + i
, PropertyType
.STRING
));
44 Node tableNode
= session().getRootNode().addNode("table", ArgeoTypes
.ARGEO_TABLE
);
45 TabularWriter writer
= new JcrTabularWriter(tableNode
, header
, ArgeoTypes
.ARGEO_CSV
);
46 for (int i
= 0; i
< rowCount
; i
++) {
47 List
<Object
> objs
= new ArrayList
<Object
>();
48 for (int j
= 0; j
< columnCount
; j
++) {
49 objs
.add(stringValue
);
51 writer
.appendRow(objs
.toArray());
56 if (log
.isDebugEnabled())
57 log
.debug("Wrote tabular content " + rowCount
+ " rows, " + columnCount
+ " columns");
59 TabularRowIterator rowIt
= new JcrTabularRowIterator(tableNode
);
61 while (rowIt
.hasNext()) {
62 TabularRow tr
= rowIt
.next();
63 assertEquals(header
.size(), tr
.size());
66 assertEquals(rowCount
, count
);
67 if (log
.isDebugEnabled())
68 log
.debug("Read tabular content " + rowCount
+ " rows, " + columnCount
+ " columns");