1 package org
.argeo
.jcr
.docbook
;
3 import java
.io
.ByteArrayInputStream
;
4 import java
.io
.ByteArrayOutputStream
;
5 import java
.io
.InputStream
;
6 import java
.io
.InputStreamReader
;
8 import javax
.jcr
.RepositoryException
;
10 import org
.apache
.commons
.io
.IOUtils
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.apache
.jackrabbit
.commons
.cnd
.CndImporter
;
14 import org
.argeo
.jackrabbit
.unit
.AbstractJackrabbitTestCase
;
15 import org
.argeo
.jcr
.JcrUtils
;
17 public class DocBookModelTest
extends AbstractJackrabbitTestCase
{
18 private final static Log log
= LogFactory
.getLog(DocBookModelTest
.class);
20 public void testLoadWikipediaSample() throws Exception
{
21 importXml("WikipediaSample.dbk.xml");
24 public void XXXtestLoadHowTo() throws Exception
{
25 importXml("howto.xml", false);
28 protected void importXml(String res
) throws Exception
{
32 protected void importXml(String res
, Boolean mini
) throws Exception
{
34 try (InputStream in
= getClass().getResourceAsStream(res
)) {
35 bytes
= IOUtils
.toByteArray(in
);
39 long begin
= System
.currentTimeMillis();
41 InputStreamReader reader
= new InputStreamReader(getClass()
43 "/org/argeo/jcr/docbook/docbook.cnd"));
44 CndImporter
.registerNodeTypes(reader
, session());
47 InputStreamReader reader
= new InputStreamReader(getClass()
49 "/org/argeo/jcr/docbook/docbook-full.cnd"));
50 CndImporter
.registerNodeTypes(reader
, session());
53 long duration
= System
.currentTimeMillis() - begin
;
54 if (log
.isDebugEnabled())
55 log
.debug(" CND loaded in " + duration
+ " ms");
58 String testPath
= "/" + res
;
60 JcrUtils
.mkdirs(session(), testPath
, "dbk:set");
62 // JcrUtils.mkdirs(session(), testPath, "dbk:book");
64 DocBookModel model
= new DocBookModel(session());
65 try (InputStream in
= new ByteArrayInputStream(bytes
)) {
66 long begin
= System
.currentTimeMillis();
67 model
.importXml(testPath
, in
);
68 long duration
= System
.currentTimeMillis() - begin
;
69 if (log
.isDebugEnabled())
70 log
.debug("Imported " + res
+ " " + (bytes
.length
/ 1024l)
71 + " kB in " + duration
+ " ms ("
72 + (bytes
.length
/ duration
) + " B/ms)");
76 // JcrUtils.debug(session().getRootNode());
78 try (ByteArrayOutputStream out
= new ByteArrayOutputStream()) {
80 model
.exportXml(testPath
+ "/dbk:book", out
);
81 } catch (Exception e
) {
82 model
.exportXml(testPath
+ "/dbk:article", out
);
84 bytes
= out
.toByteArray();
87 model
.setSession(session());
89 // log.debug(new String(bytes));
90 try (InputStream in
= new ByteArrayInputStream(bytes
)) {
91 long begin
= System
.currentTimeMillis();
92 model
.importXml(testPath
, in
);
93 long duration
= System
.currentTimeMillis() - begin
;
94 if (log
.isDebugEnabled())
95 log
.debug("Re-imported " + res
+ " "
96 + (bytes
.length
/ 1024l) + " kB in " + duration
97 + " ms (" + (bytes
.length
/ duration
) + " B/ms)");
103 protected void saveSession() throws RepositoryException
{
104 long begin
= System
.currentTimeMillis();
106 long duration
= System
.currentTimeMillis() - begin
;
107 if (log
.isDebugEnabled())
108 log
.debug(" Session save took " + duration
+ " ms");
111 // public static Test suite() {
112 // return defaultTestSuite(DocBookModelTest.class);