Project

General

Profile

« Previous | Next » 

Revision 47752

[maven-release-plugin] copy for tag cnr-xmldb-2.0.1

View differences:

modules/cnr-xmldb/tags/cnr-xmldb-2.0.1/cnr-xmldb.iml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
4
    <output url="file://$MODULE_DIR$/target/classes" />
5
    <output-test url="file://$MODULE_DIR$/target/test-classes" />
6
    <content url="file://$MODULE_DIR$">
7
      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
9
      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
10
      <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
11
      <excludeFolder url="file://$MODULE_DIR$/target" />
12
    </content>
13
    <orderEntry type="inheritedJdk" />
14
    <orderEntry type="sourceFolder" forTests="false" />
15
    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.9" level="project" />
16
    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
17
    <orderEntry type="library" scope="PROVIDED" name="Maven: xerces:xercesImpl:2.11.0" level="project" />
18
    <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
19
    <orderEntry type="library" name="Maven: org.springframework:spring-context:4.2.5.RELEASE" level="project" />
20
    <orderEntry type="library" name="Maven: org.springframework:spring-aop:4.2.5.RELEASE" level="project" />
21
    <orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" />
22
    <orderEntry type="library" name="Maven: org.springframework:spring-beans:4.2.5.RELEASE" level="project" />
23
    <orderEntry type="library" name="Maven: org.springframework:spring-core:4.2.5.RELEASE" level="project" />
24
    <orderEntry type="library" name="Maven: org.springframework:spring-expression:4.2.5.RELEASE" level="project" />
25
    <orderEntry type="library" name="Maven: org.exist-db:exist-core:3.0.RC1" level="project" />
26
    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.5.0" level="project" />
27
    <orderEntry type="library" name="Maven: com.github.krukow:clj-ds:0.0.4" level="project" />
28
    <orderEntry type="library" name="Maven: com.siemens.ct.exi:exificient:0.9.3" level="project" />
29
    <orderEntry type="library" name="Maven: org.exist-db.thirdparty.net.sf.sunxacml:sunxacml:1.2" level="project" />
30
    <orderEntry type="library" name="Maven: com.thaiopensource:jing:20091111" level="project" />
31
    <orderEntry type="library" name="Maven: isorelax:isorelax:20030108" level="project" />
32
    <orderEntry type="library" name="Maven: org.gnu:gnu-crypto:2.0.1" level="project" />
33
    <orderEntry type="library" name="Maven: org.exist-db.thirdparty.javax.xml.xquery:xqjapi:1.0-fr" level="project" />
34
    <orderEntry type="library" name="Maven: jline:jline:0.9.94" level="project" />
35
    <orderEntry type="library" name="Maven: cglib:cglib:2.2.2" level="project" />
36
    <orderEntry type="library" name="Maven: excalibur-cli:excalibur-cli:1.0" level="project" />
37
    <orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
38
    <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.1" level="project" />
39
    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
40
    <orderEntry type="library" name="Maven: commons-pool:commons-pool:1.6" level="project" />
41
    <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.3" level="project" />
42
    <orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.logging.log4j:log4j-core:2.3" level="project" />
43
    <orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.logging.log4j:log4j-jul:2.3" level="project" />
44
    <orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.logging.log4j:log4j-slf4j-impl:2.3" level="project" />
45
    <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.12" level="project" />
46
    <orderEntry type="library" name="Maven: xml-resolver:xml-resolver:1.2" level="project" />
47
    <orderEntry type="library" name="Maven: xalan:xalan:2.7.2" level="project" />
48
    <orderEntry type="library" name="Maven: xalan:serializer:2.7.2" level="project" />
49
    <orderEntry type="library" name="Maven: org.apache.xmlrpc:xmlrpc-common:3.1.3" level="project" />
50
    <orderEntry type="library" name="Maven: org.apache.ws.commons.util:ws-commons-util:1.0.2" level="project" />
51
    <orderEntry type="library" name="Maven: org.apache.xmlrpc:xmlrpc-client:3.1.3" level="project" />
52
    <orderEntry type="library" name="Maven: org.apache.xmlrpc:xmlrpc-server:3.1.3" level="project" />
53
    <orderEntry type="library" name="Maven: org.exist-db.thirdparty.org.expath:pkg-repo:0.6.0-patched" level="project" />
54
    <orderEntry type="library" name="Maven: com.fifesoft:rsyntaxtextarea:2.5.6" level="project" />
55
    <orderEntry type="library" name="Maven: org.quartz-scheduler:quartz:2.2.1" level="project" />
56
    <orderEntry type="library" name="Maven: c3p0:c3p0:0.9.1.1" level="project" />
57
    <orderEntry type="library" name="Maven: org.exist-db.thirdparty.org.xmldb:xmldb-api:1.0-patched" level="project" />
58
    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
59
    <orderEntry type="library" name="Maven: org.exist-db:exist-start:3.0.RC1" level="project" />
60
    <orderEntry type="library" name="Maven: org.aspectj:aspectjrt:1.8.9" level="project" />
61
    <orderEntry type="module" module-name="cnr-misc-utils" />
62
    <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
63
    <orderEntry type="library" name="Maven: dom4j:dom4j:1.6.1" level="project" />
64
    <orderEntry type="library" name="Maven: jaxen:jaxen:1.1.6" level="project" />
65
    <orderEntry type="library" name="Maven: saxonica:saxon:9.1.0.8" level="project" />
66
    <orderEntry type="library" name="Maven: saxonica:saxon-dom:9.1.0.8" level="project" />
67
    <orderEntry type="library" name="Maven: jgrapht:jgrapht:0.7.2" level="project" />
68
    <orderEntry type="library" name="Maven: net.sf.ehcache:ehcache:2.8.0" level="project" />
69
    <orderEntry type="library" name="Maven: org.springframework:spring-test:4.2.5.RELEASE" level="project" />
70
    <orderEntry type="module" module-name="cnr-service-common" />
71
    <orderEntry type="library" name="Maven: org.antlr:stringtemplate:3.2" level="project" />
72
    <orderEntry type="library" name="Maven: org.antlr:antlr:2.7.7" level="project" />
73
    <orderEntry type="library" name="Maven: org.springframework:spring-tx:4.2.5.RELEASE" level="project" />
74
    <orderEntry type="module" module-name="cnr-service-utils" />
75
    <orderEntry type="library" name="Maven: apache:oro:2.0.8" level="project" />
76
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-frontend-jaxws:3.1.5" level="project" />
77
    <orderEntry type="library" name="Maven: org.ow2.asm:asm:5.0.4" level="project" />
78
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-bindings-soap:3.1.5" level="project" />
79
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-wsdl:3.1.5" level="project" />
80
    <orderEntry type="library" name="Maven: wsdl4j:wsdl4j:1.6.3" level="project" />
81
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-databinding-jaxb:3.1.5" level="project" />
82
    <orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-impl:2.2.11" level="project" />
83
    <orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-core:2.2.11" level="project" />
84
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-bindings-xml:3.1.5" level="project" />
85
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-frontend-simple:3.1.5" level="project" />
86
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-ws-addr:3.1.5" level="project" />
87
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-ws-policy:3.1.5" level="project" />
88
    <orderEntry type="library" name="Maven: org.apache.neethi:neethi:3.0.3" level="project" />
89
    <orderEntry type="module" module-name="cnr-rmi-api" />
90
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-core:3.1.5" level="project" />
91
    <orderEntry type="library" name="Maven: org.codehaus.woodstox:woodstox-core-asl:4.4.1" level="project" />
92
    <orderEntry type="library" name="Maven: org.codehaus.woodstox:stax2-api:3.1.4" level="project" />
93
    <orderEntry type="library" name="Maven: org.apache.ws.xmlschema:xmlschema-core:2.2.1" level="project" />
94
    <orderEntry type="module" module-name="cnr-spring-utils" />
95
    <orderEntry type="library" name="Maven: org.springframework:spring-web:4.2.5.RELEASE" level="project" />
96
    <orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.2.5.RELEASE" level="project" />
97
    <orderEntry type="library" name="Maven: jparsec:jparsec:2.0" level="project" />
98
    <orderEntry type="library" name="Maven: runcc:runcc:0.7" level="project" />
99
    <orderEntry type="library" name="Maven: com.google.guava:guava:18.0" level="project" />
100
    <orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
101
  </component>
102
</module>
modules/cnr-xmldb/tags/cnr-xmldb-2.0.1/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/cnr-xmldb/trunk/", "deploy_repository": "dnet45-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "cnr-xmldb"}
modules/cnr-xmldb/tags/cnr-xmldb-2.0.1/src/test/java/eu/dnetlib/xml/database/exist/TestExistTrigger.java
1
package eu.dnetlib.xml.database.exist;
2

  
3
import javax.xml.xpath.XPathExpression;
4
import javax.xml.xpath.XPathExpressionException;
5
import javax.xml.xpath.XPathFactory;
6

  
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9
import org.exist.collections.triggers.SAXTrigger;
10
import org.exist.collections.triggers.TriggerException;
11
import org.exist.dom.persistent.DocumentImpl;
12
import org.exist.storage.DBBroker;
13
import org.exist.storage.txn.Txn;
14
import org.exist.xmldb.XmldbURI;
15

  
16
/**
17
 * simple test trigger.
18
 *
19
 * @author marko
20
 *
21
 */
22
public class TestExistTrigger extends SAXTrigger {
23
	/**
24
	 * logger.
25
	 */
26
	private static final Log log = LogFactory.getLog(TestExistTrigger.class); // NOPMD by marko on 11/24/08 5:02 PM
27
	/**
28
	 * expression.
29
	 */
30
	private transient XPathExpression expr;
31

  
32
	/**
33
	 * useless.
34
	 */
35
	public TestExistTrigger() {
36
		super();
37

  
38
		try {
39
			expr = XPathFactory.newInstance().newXPath().compile("//hello");
40
		} catch (XPathExpressionException e) {
41
			log.fatal("cannot parse xpath", e);
42
		}
43
	}
44

  
45

  
46

  
47
	@Override
48
	public void beforeCreateDocument(final DBBroker dbBroker, final Txn txn, final XmldbURI xmldbURI) throws TriggerException {
49

  
50
	}
51

  
52
	@Override
53
	public void afterCreateDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
54
		try {
55
			log.debug("created new document: " + expr.evaluate(document));
56
		} catch (XPathExpressionException e) {
57
			log.fatal("xpatthing", e);
58
		}
59
	}
60

  
61
	@Override
62
	public void beforeUpdateDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
63
		try {
64
			log.info("old value: " + expr.evaluate(document));
65

  
66
		} catch (XPathExpressionException e) {
67
			log.fatal("xpatthing", e);
68
		}
69
	}
70

  
71
	@Override
72
	public void afterUpdateDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
73

  
74
		try {
75
			log.info("new value: " + expr.evaluate(document));
76
		} catch (XPathExpressionException e) {
77
			log.fatal("xpatthing", e);
78
		}
79

  
80
	}
81

  
82
	@Override
83
	public void beforeUpdateDocumentMetadata(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
84

  
85
	}
86

  
87
	@Override
88
	public void afterUpdateDocumentMetadata(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
89

  
90
	}
91

  
92
	@Override
93
	public void beforeCopyDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document, final XmldbURI xmldbURI) throws TriggerException {
94

  
95
	}
96

  
97
	@Override
98
	public void afterCopyDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document, final XmldbURI xmldbURI) throws TriggerException {
99

  
100
	}
101

  
102
	@Override
103
	public void beforeMoveDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document, final XmldbURI xmldbURI) throws TriggerException {
104

  
105
	}
106

  
107
	@Override
108
	public void afterMoveDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document, final XmldbURI xmldbURI) throws TriggerException {
109

  
110
	}
111

  
112
	@Override
113
	public void beforeDeleteDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
114
		try {
115
			log.debug("deleted document: " + expr.evaluate(document));
116
		} catch (XPathExpressionException e) {
117
			log.fatal("xpatthing", e);
118
		}
119

  
120
	}
121

  
122
	@Override
123
	public void afterDeleteDocument(final DBBroker dbBroker, final Txn txn, final XmldbURI xmldbURI) throws TriggerException {
124

  
125
	}
126
}
modules/cnr-xmldb/tags/cnr-xmldb-2.0.1/src/test/java/eu/dnetlib/xml/database/exist/ExistDatabaseTest.java
1
package eu.dnetlib.xml.database.exist;
2

  
3
import java.io.IOException;
4
import java.util.*;
5

  
6
import eu.dnetlib.xml.database.XMLDatabase;
7
import org.apache.commons.logging.Log;
8
import org.apache.commons.logging.LogFactory;
9
import org.junit.After;
10
import org.junit.Before;
11
import org.junit.Ignore;
12
import org.junit.Test;
13
import org.xmldb.api.base.XMLDBException;
14

  
15
import static org.junit.Assert.*;
16

  
17
/**
18
 * Test the exist wrapper.
19
 *
20
 * @author marko
21
 *
22
 */
23
public class ExistDatabaseTest { // NOPMD by marko on 11/24/08 5:01 PM
24
	/**
25
	 * number of values in stress test profile.
26
	 */
27
	private static final int STRESS_VALUES = 100;
28

  
29
	/**
30
	 * number of times the values are repeated in the stress test.
31
	 */
32
	private static final int STRESS_PROF_LEN = 100;
33

  
34
	/**
35
	 * number of profile writes in stress test.
36
	 */
37
	private static final int STRESS_TIMES = 2000000;
38

  
39
	/**
40
	 * number of collections for stress test.
41
	 */
42
	private static final int STRESS_COLLS = 40;
43

  
44
	/**
45
	 * number of profiles in stress test.
46
	 */
47
	private static final int STRESS_PROFILES = 1000;
48

  
49
	/**
50
	 * parallel tuning.
51
	 */
52
	private static final int VALUE_SCATTER = 7;
53

  
54
	/**
55
	 * parallel tuning.
56
	 */
57
	private static final int QUERY_SCATTER = 5;
58

  
59
	/**
60
	 * test trigger name.
61
	 */
62
	private static final String TEST_TRIGGER = "testTrigger";
63

  
64
	/**
65
	 * number of collections for parallel test.
66
	 */
67
	private static final int PAR_COLLS = 20;
68

  
69
	/**
70
	 * iterations per thread.
71
	 */
72
	private static final int PAR_ITERATIONS = 100;
73

  
74
	/**
75
	 * parallel job executions.
76
	 */
77
	private static final int PAR_TIMES = 100;
78

  
79
	/**
80
	 * logger.
81
	 */
82
	public static final Log log = LogFactory.getLog(ExistDatabaseTest.class); // NOPMD by marko on 11/24/08 5:01 PM
83

  
84
	/**
85
	 * test xml string.
86
	 */
87
	private static final String HELLO_XML = "<hello/>";
88

  
89
	/**
90
	 * test xml content.
91
	 */
92
	private static final String HELLO_XML_CONTENT = "<hello>content</hello>";
93

  
94
	/**
95
	 * test file name.
96
	 */
97
	private static final String EXAMPLE = "example";
98

  
99
	/**
100
	 * trigger test file name.
101
	 */
102
	private static final String TRIGGER_TEST_FILE = "shouldTrigger";
103

  
104
	/**
105
	 * root collection prefix.
106
	 */
107
	private static final String DB_ROOT = "/db";
108

  
109
	/**
110
	 * test collection name.
111
	 */
112
	private static final String DB_TEST = "/db/testCollection";
113

  
114
	/**
115
	 * test other collection name.
116
	 */
117
	private static final String DB_OTHER = "/db/otherCollection";
118

  
119
	/**
120
	 * test sub collection.
121
	 */
122
	private static final String DB_SUB = DB_TEST + "/sub";
123

  
124
	/**
125
	 * xml database under test.
126
	 */
127
	private transient XMLDatabase database;
128

  
129
	/**
130
	 * eXist database under test, viewed only in setUp and tearDown.
131
	 */
132
	private transient ExistDatabase edb;
133

  
134
	/**
135
	 * prepares the database.
136
	 *
137
	 * @throws Exception
138
	 *             exist error
139
	 */
140
	@Before
141
	public void setUp() throws Exception {
142
		edb = new TemporaryExistDatabase();
143
		edb.start();
144
		database = edb;
145
	}
146

  
147
	/**
148
	 * shuts down the database.
149
	 *
150
	 * @throws IOException
151
	 *             happens
152
	 */
153
	@After
154
	public void tearDown() throws IOException {
155
		if (edb != null)
156
			edb.stop();
157
	}
158

  
159
	/**
160
	 * test create.
161
	 *
162
	 * @throws XMLDBException
163
	 *             happens
164
	 */
165
	@Test
166
	public void create() throws XMLDBException {
167
		database.create(EXAMPLE, DB_ROOT, HELLO_XML);
168
		assertEquals("database resource created", true, true);
169
	}
170

  
171
	/**
172
	 * correct behavior is to throw exception on empty file name, because otherwise the file is invisible but the data
173
	 * is inserted in the xml db.
174
	 *
175
	 * @throws XMLDBException
176
	 *             expected
177
	 */
178
	@Test(expected = XMLDBException.class)
179
	public void createEmptyName() throws XMLDBException {
180
		database.create("", DB_ROOT, "<shouldnt_exist/>");
181

  
182
		// code to repeat the bug, shouldn't be executed because of the expected exception
183
		final Iterator<String> res = database.xquery("collection('')/shouldnt_exist");
184

  
185
		assertTrue("shouldn't exist, but it exists",  res.hasNext());
186
		log.info(database.list(DB_ROOT));
187
		assertEquals("file should be listed, with empty file name", 1, database.list(DB_ROOT).size());
188
		assertEquals("file should be listed, with empty file name", "", database.list(DB_ROOT).get(0));
189

  
190
		assertEquals("the file can be retrieved", "<shouldnt_exist/>", database.read("", DB_ROOT));
191
	}
192

  
193
	/**
194
	 * test read.
195
	 *
196
	 * @throws XMLDBException
197
	 *             shouldn't happen
198
	 */
199
	@Test
200
	public void read() throws XMLDBException {
201
		create();
202
		final String res = database.read(EXAMPLE, DB_ROOT);
203
		assertEquals("simple reading", HELLO_XML, res);
204
	}
205

  
206
	/**
207
	 * test read of non existing file.
208
	 *
209
	 * @throws XMLDBException
210
	 *             shouldn't throw exception
211
	 */
212
	@Test
213
	public void readError() throws XMLDBException {
214
		final String res = database.read("nonExisting", DB_ROOT);
215
		assertEquals("expecting null on unexisting", null, res);
216
	}
217

  
218
	/**
219
	 * test remove.
220
	 *
221
	 * @throws XMLDBException
222
	 *             shouldn't throw exception
223
	 */
224
	@Test
225
	public void remove() throws XMLDBException {
226
		database.create(EXAMPLE, DB_ROOT, HELLO_XML);
227
		String res = database.read(EXAMPLE, DB_ROOT);
228
		assertEquals("reading", HELLO_XML, res);
229

  
230
		database.remove(EXAMPLE, DB_ROOT);
231
		res = database.read(EXAMPLE, DB_ROOT);
232
		assertEquals("now it doesn't exist", null, res);
233
	}
234

  
235
	/**
236
	 * delete unexisting file.
237
	 *
238
	 * @throws XMLDBException
239
	 *             could happen
240
	 */
241
	@Test
242
	public void doubleDelete() throws XMLDBException {
243
		database.create(EXAMPLE, DB_ROOT, HELLO_XML);
244
		String res = database.read(EXAMPLE, DB_ROOT);
245
		assertEquals("reading", HELLO_XML, res);
246

  
247
		database.remove(EXAMPLE, DB_ROOT);
248
		res = database.read(EXAMPLE, DB_ROOT);
249
		assertEquals("now it doesn't exist", null, res);
250

  
251
		assertFalse("already exists", database.remove(EXAMPLE, DB_ROOT));
252
	}
253

  
254
	/**
255
	 * update an xml file.
256
	 *
257
	 * @throws XMLDBException
258
	 *             shouldn't happen
259
	 */
260
	@Test
261
	public void update() throws XMLDBException {
262
		database.create(EXAMPLE, DB_ROOT, HELLO_XML);
263
		String res = database.read(EXAMPLE, DB_ROOT);
264
		assertEquals("reading", HELLO_XML, res);
265

  
266
		database.update(EXAMPLE, DB_ROOT, "<world/>");
267
		res = database.read(EXAMPLE, DB_ROOT);
268
		assertEquals("now it doesn't exist", "<world/>", res);
269
	}
270

  
271
	/**
272
	 * update an unexisting file.
273
	 *
274
	 * @throws XMLDBException
275
	 *             expected
276
	 */
277
	@Test(expected = XMLDBException.class)
278
	public void updateError() throws XMLDBException {
279
		database.create(EXAMPLE, DB_ROOT, HELLO_XML);
280
		database.remove(EXAMPLE, DB_ROOT);
281
		final String res = database.read(EXAMPLE, DB_ROOT);
282
		assertEquals("check non existing", null, res);
283

  
284
		database.update(EXAMPLE, DB_ROOT, "<world/>"); // throws
285
	}
286

  
287
	/**
288
	 * test xquery.
289
	 *
290
	 * @throws XMLDBException
291
	 *             shouldn't happen
292
	 */
293
	@Test()
294
	public void query() throws XMLDBException {
295
		database.create(EXAMPLE, DB_ROOT, "<queryTest><one><sub/></one><two/></queryTest>");
296
		final Iterator<String> res = database.xquery("collection('/db')//queryTest/one");
297
		assertTrue("finds only one result", res.hasNext());
298

  
299
		final Iterator<String> res2 = database.xquery("collection('/db')//queryTest/two");
300
		assertTrue("finds only one result",res2.hasNext());
301
		assertEquals("check the correct result", "<two/>", res2.next());
302
	}
303

  
304
	/**
305
	 * create a collection.
306
	 *
307
	 * @throws XMLDBException
308
	 *             shouldn't happen
309
	 */
310
	@Test()
311
	public void createCollection() throws XMLDBException {
312
		database.createCollection(DB_TEST);
313
		database.create(EXAMPLE, DB_TEST, "<col/>");
314

  
315
		final String res = database.read(EXAMPLE, DB_TEST);
316
		assertEquals("check another collection", "<col/>", res);
317
	}
318

  
319
	/**
320
	 * check the existence of a collection.
321
	 *
322
	 * @throws XMLDBException
323
	 *             shouldn't happen
324
	 */
325
	@Test()
326
	public void checkCollection() throws XMLDBException {
327
		createCollection();
328

  
329
		assertTrue("check root", database.collectionExists(DB_ROOT));
330
		assertTrue("check test collection", database.collectionExists(DB_TEST));
331
		assertFalse("check non existing", database.collectionExists("/db/testNonExistingCollection"));
332
	}
333

  
334
	/**
335
	 * shows that a spurious collection create is legal.
336
	 *
337
	 * @throws XMLDBException
338
	 *             shouldn't throw
339
	 */
340
	@Test()
341
	public void createCollectionDuplicate() throws XMLDBException {
342
		database.createCollection(DB_TEST);
343
		database.createCollection(DB_TEST);
344
	}
345

  
346
	/**
347
	 * remove a collection.
348
	 *
349
	 * @throws XMLDBException
350
	 *             shouldn't throw
351
	 */
352
	@Test()
353
	public void removeCollection() throws XMLDBException {
354
		database.createCollection(DB_TEST);
355
		assertTrue("check before remove", database.collectionExists(DB_TEST));
356
		database.removeCollection(DB_TEST);
357
		assertFalse("check after remove", database.collectionExists(DB_TEST));
358
	}
359

  
360
	/**
361
	 * check useless contract with spring.
362
	 */
363
	@Test
364
	public void testIsRunning() {
365
		assertFalse("contract with spring", edb.isRunning());
366
	}
367

  
368
	/**
369
	 * Test a scenario where exist fails to create a database.
370
	 *
371
	 * @throws IOException
372
	 *             happens
373
	 * @throws XMLDBException
374
	 *             happens
375
	 */
376
	@Test(expected = IllegalStateException.class)
377
	public void checkWrongConfigFile() throws IOException, XMLDBException {
378
		edb.stop();
379
		edb = new ExistDatabase();
380
		try {
381
			edb.setConfigFile("/tmp/unexistingfile");
382
			edb.start();
383
			database = edb;
384

  
385
			create();
386
		} finally {
387
			edb = null; // NOPMD - just for junit
388
		}
389
	}
390

  
391
	/**
392
	 * get child collections.
393
	 *
394
	 * @throws XMLDBException
395
	 *             shouldn't happen
396
	 */
397
	@Test
398
	public void testListChildCollections() throws XMLDBException {
399
		database.createCollection(DB_TEST);
400
		assertTrue("check that collection exists", database.collectionExists(DB_TEST));
401

  
402
		final String[] expectedNames = new String[] { "child1", "child2", "child3" };
403
		for (String name : expectedNames)
404
			database.createCollection(DB_TEST + "/" + name);
405

  
406
		final List<String> res = database.listChildCollections(DB_TEST);
407
		// the db doesn't return then in the same order
408
		Collections.sort(res);
409
		assertArrayEquals("check list", expectedNames, res.toArray());
410
	}
411

  
412
	/**
413
	 * check list resources.
414
	 *
415
	 * @throws XMLDBException
416
	 *             shouldn't happen
417
	 */
418
	@Test
419
	public void testList() throws XMLDBException {
420
		database.createCollection(DB_TEST);
421
		assertTrue("collection should exist", database.collectionExists(DB_TEST));
422

  
423
		final String[] expectedNames = new String[] { "name1", "name2", "name3" };
424
		for (String name : expectedNames)
425
			database.create(name, DB_TEST, HELLO_XML);
426

  
427
		final List<String> res = database.list(DB_TEST);
428
		// the db doesn't return then in the same order
429
		Collections.sort(res);
430
		assertArrayEquals("check list", expectedNames, res.toArray());
431
	}
432

  
433
	/**
434
	 * test low-level set trigger.
435
	 *
436
	 * @throws XMLDBException
437
	 *             shouldn't happen
438
	 */
439
	@Test
440
	public void testSetExistTrigger() throws XMLDBException {
441
		final Map<String, String> params = new HashMap<String, String>();
442
		params.put("listenerBean", "pippo");
443

  
444
		database.createCollection(DB_TEST);
445
		edb.setExistTrigger(TestExistTrigger.class, DB_TEST, Arrays.asList(new String[] { "store", "update", "delete" }), params);
446

  
447
		// assertNotNull("check that the conf is stored", database.read(ExistDatabase.COLLECTION_XCONF, DB_ROOT + "/system/config" + DB_TEST));
448

  
449
		database.create(TRIGGER_TEST_FILE, DB_TEST, HELLO_XML_CONTENT);
450
		assertEquals("check the the write happened", HELLO_XML_CONTENT, database.read(TRIGGER_TEST_FILE, DB_TEST));
451

  
452
		database.update(TRIGGER_TEST_FILE, DB_TEST, "<hello>new content</hello>");
453

  
454
		database.xquery("for $x in collection('')/hello where $x/text() = 'new content' return update value $x/text() with 'xupdate'");
455
		assertEquals("check the the xupdate happened", "<hello>xupdate</hello>", database.read(TRIGGER_TEST_FILE, DB_TEST));
456
	}
457

  
458
	/**
459
	 * Test high level addTrigger.
460
	 *
461
	 * @throws XMLDBException
462
	 *             shouldn't happen
463
	 */
464
	@Test
465
	public void testRegisterTrigger() throws XMLDBException {
466
		final TestTrigger trigger = new TestTrigger();
467
		trigger.setName(TEST_TRIGGER);
468

  
469
		database.createCollection(DB_TEST);
470
		database.registerTrigger(trigger, DB_TEST);
471

  
472
		assertFalse("check that the tester state is correct", trigger.isCreated());
473

  
474
		database.create(TRIGGER_TEST_FILE, DB_TEST, HELLO_XML_CONTENT);
475
		assertEquals("check the the write happened", HELLO_XML_CONTENT, database.read(TRIGGER_TEST_FILE, DB_TEST));
476
		assertFalse("check that the trigger is not invoked for the update event", trigger.isUpdated());
477
		assertFalse("check that the trigger is not invoked for the deletion event", trigger.isDeleted());
478
		assertTrue("check that the trigger is invoked create", trigger.isCreated());
479
		assertEquals("check file name for create", TRIGGER_TEST_FILE, trigger.getLastFile());
480
		assertEquals("check collection name for create", DB_TEST, trigger.getLastCollection());
481

  
482
		trigger.reset();
483
		assertFalse("check that the tester state is correct", trigger.isUpdated());
484
		database.update(TRIGGER_TEST_FILE, DB_TEST, "<hello>new content</hello>");
485
		assertFalse("check that the trigger is not invoked for the creation event", trigger.isCreated());
486
		assertFalse("check that the trigger is not invoked for the deletion event", trigger.isDeleted());
487
		assertTrue("check that the trigger is invoked for update", trigger.isUpdated());
488
		assertEquals("check file name for update", TRIGGER_TEST_FILE, trigger.getLastFile());
489
		assertEquals("check collection name for update", DB_TEST, trigger.getLastCollection());
490

  
491
		trigger.reset();
492
		database.xquery("for $x in collection('')/hello where $x/text() = 'new content' return update value $x/text() with 'xupdate'");
493
		assertTrue("check that the trigger is invoked for xupdate", trigger.isUpdated());
494
		assertEquals("check file name for xupdate", TRIGGER_TEST_FILE, trigger.getLastFile());
495
		assertEquals("check collection name for xupdate", DB_TEST, trigger.getLastCollection());
496

  
497
		trigger.reset();
498
		assertFalse("check that the tester state is correct", trigger.isDeleted());
499
		database.remove(TRIGGER_TEST_FILE, DB_TEST);
500
		assertFalse("check that the trigger is not invoked for the creation event", trigger.isCreated());
501
		assertFalse("check that the trigger is not invoked for the update event", trigger.isUpdated());
502
		assertNull("check that the file is removed", database.read(TRIGGER_TEST_FILE, DB_TEST));
503
		assertTrue("check that the trigger is invoked for delete", trigger.isDeleted());
504
		assertEquals("check file name for delete", TRIGGER_TEST_FILE, trigger.getLastFile());
505
		assertEquals("check collection name for delete", DB_TEST, trigger.getLastCollection());
506
	}
507

  
508
	/**
509
	 * a trigger configuration file should not be listed as a xml file resource.
510
	 *
511
	 * @throws XMLDBException
512
	 *             shouldn't happen
513
	 */
514
	@Test
515
	public void testListWithTriggerConf() throws XMLDBException {
516
		database.createCollection(DB_TEST);
517
		assertTrue("collection should exist", database.collectionExists(DB_TEST));
518

  
519
		final TestTrigger trigger = new TestTrigger();
520
		trigger.setName(TEST_TRIGGER);
521

  
522
		database.registerTrigger(trigger, DB_TEST);
523

  
524
		final String[] expectedNames = new String[] { "name1", "name2", "name3" };
525
		for (String name : expectedNames)
526
			database.create(name, DB_TEST, HELLO_XML);
527

  
528
		assertTrue("check that trigger was invoked", trigger.isCreated());
529

  
530
		final List<String> res = database.list(DB_TEST);
531
		// the db doesn't return then in the same order
532
		Collections.sort(res);
533
		assertArrayEquals("check list", expectedNames, res.toArray());
534
	}
535

  
536
	/**
537
	 * test trigger with several collections.
538
	 *
539
	 * @throws XMLDBException
540
	 *             shoudn't happen
541
	 */
542
	@Test
543
	public void testTriggerDifferentCollections() throws XMLDBException {
544
		final TestTrigger trigger = new TestTrigger();
545
		trigger.setName(TEST_TRIGGER);
546

  
547
		database.createCollection(DB_TEST);
548
		database.createCollection(DB_OTHER);
549
		database.createCollection(DB_SUB);
550

  
551
		database.registerTrigger(trigger, DB_TEST);
552
		database.create(TRIGGER_TEST_FILE, DB_TEST, HELLO_XML);
553
		assertTrue("trigger was registered for this collection", trigger.isCreated());
554

  
555
		trigger.reset();
556
		database.create(TRIGGER_TEST_FILE, DB_OTHER, HELLO_XML);
557
		assertFalse("trigger was not registered for this collection", trigger.isCreated());
558

  
559
		trigger.reset();
560
		database.registerTrigger(trigger, DB_OTHER);
561
		database.remove(TRIGGER_TEST_FILE, DB_OTHER);
562
		assertTrue("trigger is now registered for this collection", trigger.isDeleted());
563

  
564
		trigger.reset();
565
		database.create(TRIGGER_TEST_FILE, DB_SUB, HELLO_XML);
566
		assertTrue("trigger is automatically registered for the sub collection", trigger.isCreated());
567

  
568
	}
569

  
570
	/**
571
	 * fails because eXist wants that all collection paths begin with /db.
572
	 *
573
	 * @throws XMLDBException
574
	 *             expected
575
	 */
576
	@Test(expected = XMLDBException.class)
577
	public void testGetCollection() throws XMLDBException {
578
		edb.getCollection("/something");
579
		assertNotNull("dummy", edb);
580
	}
581

  
582
	/**
583
	 * simple parallel job.
584
	 *
585
	 * @author marko
586
	 *
587
	 */
588
	class SimpleParallelJob extends Thread { // NOPMD
589
		/**
590
		 * some argument.
591
		 */
592
		private final transient int name;
593
		/**
594
		 * record eventual exceptions.
595
		 */
596
		private transient Throwable throwable = null;
597

  
598
		/**
599
		 * pass some argument to the job.
600
		 *
601
		 * @param name
602
		 *            some argument
603
		 */
604
		SimpleParallelJob(final int name) {
605
			super();
606
			this.name = name;
607
		}
608

  
609
		/**
610
		 * {@inheritDoc}
611
		 *
612
		 * @see java.lang.Runnable#run()
613
		 */
614
		@Override
615
		public void run() {
616
			try {
617
				parallelJob(name);
618
			} catch (XMLDBException e) {
619
				log.fatal("parallel job failing", e);
620
				throwable = e;
621
			} catch (Throwable e) { // NOPMD
622
				log.fatal("other exception", e);
623
				throwable = e;
624
			}
625
		}
626

  
627
		public Throwable getThrowable() {
628
			return throwable;
629
		}
630
	}
631

  
632
	/**
633
	 * stress test the eXist db.
634
	 *
635
	 * @throws Throwable
636
	 *             could
637
	 */
638
	@Test
639
	public void testParallel() throws Throwable {
640
		final TestTrigger trigger = new TestTrigger();
641
		trigger.setName(TEST_TRIGGER);
642

  
643
		database.registerTrigger(trigger, DB_ROOT);
644

  
645
		final List<SimpleParallelJob> threads = new ArrayList<SimpleParallelJob>(); // NOPMD
646
		for (int i = 0; i < PAR_TIMES; i++)
647
			threads.add(new SimpleParallelJob(i)); // NOPMD
648
		for (Thread thread : threads) { // NOPMD
649
			thread.start();
650
		}
651
		for (Thread thread : threads) { // NOPMD
652
			thread.join();
653
		}
654

  
655
		for (SimpleParallelJob thread : threads) { // NOPMD
656
			if (thread.getThrowable() != null)
657
				throw thread.getThrowable();
658
		}
659

  
660
		assertNotNull("dummy", threads);
661
	}
662

  
663
	/**
664
	 * Stress test for eXist WAL logs.
665
	 *
666
	 * @throws XMLDBException
667
	 *             could happen
668
	 */
669
	@Test
670
	@Ignore
671
	public void testManueleStress() throws XMLDBException {
672
		final StringBuffer childTemplate = new StringBuffer(200); // NOPMD
673

  
674
		for (int i = 0; i < STRESS_VALUES; i++) {
675
			childTemplate.append("<key>" + i + "-VAL</key><value>ITER</value>");
676
		}
677

  
678
		final StringBuffer hugeTemplate = new StringBuffer(200);
679
		hugeTemplate.append("<root>");
680
		for (int i = 0; i < STRESS_PROF_LEN; i++) {
681
			final String child = childTemplate.toString().replace("VAL", Integer.toString(i));
682
			hugeTemplate.append(child);
683
		}
684
		hugeTemplate.append("</root>");
685

  
686
		for (int i = 0; i < STRESS_TIMES; i++) {
687
			final String huge = hugeTemplate.toString().replace("ITER", Integer.toString(i));
688
			database.create("stressTest-" + (i % STRESS_PROFILES), DB_ROOT + "/" + (i % STRESS_COLLS), huge);
689
		}
690

  
691
		assertNotNull("dummy", hugeTemplate);
692
	}
693

  
694
	/**
695
	 * one parallel job execution.
696
	 *
697
	 * @param arg
698
	 *            some argument
699
	 * @throws XMLDBException
700
	 *             could happen.
701
	 */
702
	protected void parallelJob(final int arg) throws XMLDBException {
703
		final String name = Integer.toString(arg);
704
		final String coll = DB_ROOT + "/" + Integer.toString(arg % PAR_COLLS);
705
		database.create(name, coll, "<a" + name + "/>");
706

  
707
		for (int i = 0; i < PAR_ITERATIONS; i++) {
708
			database.update(name, coll, "<a" + name + " value=\"" + i % VALUE_SCATTER + "\"/>");
709
			final Iterator<String> res = database.xquery("collection('')//*[@value='" + i % QUERY_SCATTER + "']");
710
			while (res.hasNext())
711
				res.next();
712
		}
713
	}
714

  
715
}
modules/cnr-xmldb/tags/cnr-xmldb-2.0.1/src/test/java/eu/dnetlib/xml/database/exist/PersistentExistDatabaseTest.java
1
package eu.dnetlib.xml.database.exist;
2

  
3
import static org.junit.Assert.*;
4

  
5
import java.io.File;
6
import java.io.FileWriter;
7
import java.io.IOException;
8

  
9
import org.apache.commons.io.IOUtils;
10
import org.junit.Before;
11
import org.junit.Test;
12

  
13
public class PersistentExistDatabaseTest {
14

  
15
	private PersistentExistDatabase db;
16

  
17
	@Before
18
	public void setUp() throws Exception {
19
		db = new PersistentExistDatabase();
20
	}
21

  
22
	@Test
23
	public void testFile() throws IOException {
24
		File file = File.createTempFile("test", "conf");
25
		FileWriter writer = new FileWriter(file);
26
		try {
27
			IOUtils.write("test enable-java-binding=\"no\" test", writer);
28
		} finally {
29
			writer.close();
30
		}
31

  
32
		db.enableJava(file, true);
33
	}
34

  
35
	@Test
36
	public void testPatch() {
37
		assertEquals("test123", db.patchConfigFileEnableJava("test123", true));
38
		assertEquals("enable-java-binding=\"yes\"", db.patchConfigFileEnableJava("enable-java-binding=\"yes\"", true));
39
		assertEquals("enable-java-binding=\"no\"", db.patchConfigFileEnableJava("enable-java-binding=\"yes\"", false));
40
		assertEquals("enable-java-binding=\"yes\"", db.patchConfigFileEnableJava("enable-java-binding=\"no\"", true));
41
		assertEquals("enable-java-binding=\"no\"", db.patchConfigFileEnableJava("enable-java-binding=\"no\"", false));
42

  
43
		assertEquals("yyy enable-java-binding=\"yes\" xxx", db.patchConfigFileEnableJava("yyy enable-java-binding=\"no\" xxx", true));
44
	}
45

  
46
}
modules/cnr-xmldb/tags/cnr-xmldb-2.0.1/src/test/java/eu/dnetlib/xml/database/exist/TestTrigger.java
1
package eu.dnetlib.xml.database.exist;
2

  
3
import org.w3c.dom.Document;
4

  
5
import eu.dnetlib.xml.database.LoggingTrigger;
6

  
7
/**
8
 * test high level xml db trigger tester.
9
 *
10
 * @author marko
11
 *
12
 */
13
public class TestTrigger extends LoggingTrigger {
14

  
15
	/**
16
	 * true when the trigger is first called on 'create' event.
17
	 */
18
	private boolean created = false; // NOPMD
19
	/**
20
	 * true when the trigger is first called on 'update' event.
21
	 */
22
	private boolean updated = false; // NOPMD
23
	/**
24
	 * true when the trigger is first called on 'delete' event.
25
	 */
26
	private boolean deleted = false; // NOPMD
27

  
28
	/**
29
	 * last triggered file name. 
30
	 */
31
	private String lastFile;
32
	/**
33
	 * last triggered collection name.
34
	 */
35
	private String lastCollection;
36

  
37
	/**
38
	 * {@inheritDoc}
39
	 * @see eu.dnetlib.xml.database.Trigger#created(java.lang.String, java.lang.String, org.w3c.dom.Document)
40
	 */
41
	@Override
42
	public void created(final String file, final String collection, final Document newDoc) {
43
		super.created(file, collection, newDoc);
44

  
45
		setLastFile(file);
46
		setLastCollection(collection);
47
		created = true;
48
	}
49

  
50
	/**
51
	 * {@inheritDoc}
52
	 * @see eu.dnetlib.xml.database.Trigger#deleted(java.lang.String, java.lang.String, org.w3c.dom.Document)
53
	 */
54
	@Override
55
	public void deleted(final String file, final String collection, final Document oldDoc) {
56
		super.deleted(file, collection, oldDoc);
57

  
58
		setLastFile(file);
59
		setLastCollection(collection);
60
		deleted = true;
61
	}
62

  
63
	/**
64
	 * {@inheritDoc}
65
	 * @see eu.dnetlib.xml.database.Trigger#updated(java.lang.String, java.lang.String, org.w3c.dom.Document, org.w3c.dom.Document)
66
	 */
67
	@Override
68
	public void updated(final String file, final String collection, final Document oldDoc, final Document newDoc) {
69
		super.updated(file, collection, oldDoc, newDoc);
70

  
71
		setLastFile(file);
72
		setLastCollection(collection);
73
		updated = true;
74
	}
75

  
76
	/**
77
	 * reset crude sentinels.
78
	 */
79
	public void reset() {
80
		setCreated(false);
81
		setUpdated(false);
82
		setDeleted(false);
83
	}
84

  
85
	public boolean isCreated() {
86
		return created;
87
	}
88

  
89
	public void setCreated(final boolean created) {
90
		this.created = created;
91
	}
92

  
93
	public boolean isUpdated() {
94
		return updated;
95
	}
96

  
97
	public void setUpdated(final boolean updated) {
98
		this.updated = updated;
99
	}
100

  
101
	public boolean isDeleted() {
102
		return deleted;
103
	}
104

  
105
	public void setDeleted(final boolean deleted) {
106
		this.deleted = deleted;
107
	}
108

  
109
	String getLastFile() {
110
		return lastFile;
111
	}
112

  
113
	void setLastFile(final String lastFile) {
114
		this.lastFile = lastFile;
115
	}
116

  
117
	String getLastCollection() {
118
		return lastCollection;
119
	}
120

  
121
	void setLastCollection(final String lastCollection) {
122
		this.lastCollection = lastCollection;
123
	}
124
}
modules/cnr-xmldb/tags/cnr-xmldb-2.0.1/src/test/java/eu/dnetlib/xml/database/exist/ExistDOMConverterTest.java
1
package eu.dnetlib.xml.database.exist;
2

  
3
import static org.junit.Assert.assertNotNull;
4
import static org.junit.Assert.assertTrue;
5

  
6
import java.io.IOException;
7
import java.io.StringWriter;
8
import java.util.Arrays;
9

  
10
import javax.xml.parsers.DocumentBuilder;
11
import javax.xml.parsers.DocumentBuilderFactory;
12
import javax.xml.parsers.ParserConfigurationException;
13

  
14
import org.apache.commons.io.IOUtils;
15
import org.apache.commons.logging.Log;
16
import org.apache.commons.logging.LogFactory;
17
import org.junit.Before;
18
import org.junit.Test;
19
import org.w3c.dom.Document;
20
import org.xml.sax.SAXException;
21
import org.xmldb.api.base.XMLDBException;
22

  
23
/**
24
 * test exist dom converter.
25
 *
26
 * @author marko
27
 *
28
 */
29
public class ExistDOMConverterTest {
30

  
31
	/**
32
	 * logger.
33
	 */
34
	static final Log log = LogFactory.getLog(ExistDOMConverterTest.class); // NOPMD by marko on 11/24/08 5:02 PM
35

  
36
	/**
37
	 * test collection.
38
	 */
39
	private static final String DB_TEST = "/db/collection";
40

  
41
	/**
42
	 * check that the document is not truncated.
43
	 */
44
	private static final int MIN_LENGTH = 80;
45

  
46
	/**
47
	 * instance under test.
48
	 */
49
	private transient ExistDOMConverter converter;
50

  
51
	/**
52
	 * eXist database instance. 
53
	 */
54
	private transient ExistDatabase edb;
55

  
56
	/**
57
	 * true when the eXist trigger is called.
58
	 */
59
	private static boolean triggered;
60

  
61
	/**
62
	 * setup common stuff.
63
	 */
64
	@Before
65
	public void setUp() {
66
		converter = new ExistDOMConverter();
67

  
68
		edb = new TemporaryExistDatabase();
69
		edb.start();
70

  
71
		triggered = false;
72
	}
73

  
74
	/**
75
	 * check that the ExistDOMConverter works well with plain DOMs.
76
	 *
77
	 * @throws ParserConfigurationException shouldn't happen
78
	 * @throws SAXException shouldn't happen
79
	 * @throws IOException shouldn't happen
80
	 */
81
	@Test
82
	public void testAsString() throws ParserConfigurationException, SAXException, IOException {
83
		final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
84
		final Document doc = builder.parse(getClass().getResourceAsStream("userProfileResourceSchema.xsd"));
85

  
86
		assertNotNull("dom", doc);
87

  
88
		assertTrue("length", converter.asString(doc).length() > MIN_LENGTH);
89
	}
90

  
91
	/**
92
	 * test without comments in preable.
93
	 *
94
	 * @throws XMLDBException shouldn't happen
95
	 * @throws IOException shouldn't happen
96
	 */
97
	@Test
98
	public void testFromExist() throws XMLDBException, IOException {
99
		edb.setExistTrigger(DOMConverterTestTrigger.class, DB_TEST, Arrays.asList("store", "update", "delete"), null);
100

  
101
		final StringWriter schema = new StringWriter();
102
		IOUtils.copy(getClass().getResourceAsStream("userProfileResourceSchemaClean.xsd"), schema);
103
		edb.create("test", DB_TEST, schema.toString());
104

  
105
		final String res = edb.read("test", DB_TEST);
106
		assertNotNull("check read", res);
107

  
108
		assertTrue("check that trigger is executed", triggered);
109

  
110
	}
111

  
112
	/**
113
	 * test comments in preable.
114
	 *
115
	 * @throws XMLDBException shouldn't happen
116
	 * @throws IOException shouldn't happen
117
	 */
118
	@Test
119
	public void testFromExistCommented() throws XMLDBException, IOException {
120
		edb.setExistTrigger(DOMConverterTestTrigger.class, DB_TEST, Arrays.asList( "store", "update", "delete"), null);
121

  
122
		final StringWriter schema = new StringWriter();
123
		IOUtils.copy(getClass().getResourceAsStream("userProfileResourceSchema.xsd"), schema);
124
		edb.create("testCommented", DB_TEST, schema.toString());
125

  
126
		final String res = edb.read("testCommented", DB_TEST);
127
		assertNotNull("check read", res);
128

  
129
		assertTrue("check that trigger is executed", triggered);
130
		//assertFalse("check that trigger is executed", triggered);
131
	}
132

  
133
	public static boolean isTriggered() {
134
		return triggered;
135
	}
136

  
137
	public static void setTriggered(final boolean triggered) {
138
		ExistDOMConverterTest.triggered = triggered;
139
	}
140

  
141
}
modules/cnr-xmldb/tags/cnr-xmldb-2.0.1/src/test/java/eu/dnetlib/xml/database/exist/DOMConverterTestTrigger.java
1
package eu.dnetlib.xml.database.exist;
2

  
3
import org.exist.collections.triggers.SAXTrigger;
4
import org.exist.collections.triggers.TriggerException;
5
import org.exist.dom.persistent.DocumentImpl;
6
import org.exist.storage.DBBroker;
7
import org.exist.storage.txn.Txn;
8
import org.exist.xmldb.XmldbURI;
9

  
10
/**
11
 * helper class for the ExistDOMConverterTest.
12
 *
13
 * An instance of this class is instantiated by eXist and all new registered xml documents
14
 * should trigger the invocation of the triggerCreate method
15
 *
16
 * @author marko
17
 *
18
 */
19
public class DOMConverterTestTrigger extends SAXTrigger {
20

  
21

  
22

  
23

  
24
	@Override
25
	public void beforeCreateDocument(final DBBroker dbBroker, final Txn txn, final XmldbURI xmldbURI) throws TriggerException {
26
		ExistDOMConverterTest.setTriggered(true);
27
	}
28

  
29
	@Override
30
	public void afterCreateDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
31
		ExistDOMConverterTest.setTriggered(true);
32
	}
33

  
34
	@Override
35
	public void beforeUpdateDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
36
		ExistDOMConverterTest.setTriggered(true);
37
	}
38

  
39
	@Override
40
	public void afterUpdateDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
41
		ExistDOMConverterTest.setTriggered(true);
42
	}
43

  
44
	@Override
45
	public void beforeUpdateDocumentMetadata(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
46
		ExistDOMConverterTest.setTriggered(true);
47
	}
48

  
49
	@Override
50
	public void afterUpdateDocumentMetadata(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
51
		ExistDOMConverterTest.setTriggered(true);
52
	}
53

  
54
	@Override
55
	public void beforeCopyDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document, final XmldbURI xmldbURI) throws TriggerException {
56
		ExistDOMConverterTest.setTriggered(true);
57
	}
58

  
59
	@Override
60
	public void afterCopyDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document, final XmldbURI xmldbURI) throws TriggerException {
61
		ExistDOMConverterTest.setTriggered(true);
62
	}
63

  
64
	@Override
65
	public void beforeMoveDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document, final XmldbURI xmldbURI) throws TriggerException {
66
		ExistDOMConverterTest.setTriggered(true);
67
	}
68

  
69
	@Override
70
	public void afterMoveDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document, final XmldbURI xmldbURI) throws TriggerException {
71
		ExistDOMConverterTest.setTriggered(true);
72
	}
73

  
74
	@Override
75
	public void beforeDeleteDocument(final DBBroker dbBroker, final Txn txn, final DocumentImpl document) throws TriggerException {
76
		ExistDOMConverterTest.setTriggered(true);
77
	}
78

  
79
	@Override
80
	public void afterDeleteDocument(final DBBroker dbBroker, final Txn txn, final XmldbURI xmldbURI) throws TriggerException {
81
		ExistDOMConverterTest.setTriggered(true);
82
	}
83
}
modules/cnr-xmldb/tags/cnr-xmldb-2.0.1/src/test/resources/eu/dnetlib/xml/database/exist/userProfileResourceSchema.xsd
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!-- edited with XMLSpy v2007 sp1 (http://www.altova.com) by pagano (CNR) -->
3
<!--W3C Schema generated by XMLSpy v2007 sp1 (http://www.altova.com)-->
4
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
5

  
6
	<xs:element name="RESOURCE_PROFILE">
7
		<xs:complexType>
8
			<xs:sequence>
9
				<xs:element name="HEADER" type="HEADERType" />
10
				<xs:element name="BODY" type="BODYType" />
11
			</xs:sequence>
12
		</xs:complexType>
13
	</xs:element>
14

  
15
	<xs:complexType name="HEADERType">
16
		<xs:all>
17
			<xs:element name="RESOURCE_IDENTIFIER" type="RESOURCE_IDENTIFIERType" />
18
			<xs:element name="RESOURCE_TYPE" type="RESOURCE_TYPEType" />
19
			<xs:element name="RESOURCE_KIND" type="RESOURCE_KINDType" />
20
			<xs:element name="RESOURCE_URI" type="RESOURCE_URIType" />
21
			<xs:element name="DATE_OF_CREATION" type="DATE_OF_CREATIONType" />
22
		</xs:all>
23
	</xs:complexType>
24

  
25
	<xs:complexType name="RESOURCE_IDENTIFIERType">
26
		<xs:attribute name="value" type="xs:string" use="required" />
27
	</xs:complexType>
28

  
29
	<xs:complexType name="RESOURCE_TYPEType">
30
		<xs:attribute name="value" use="required">
31
			<xs:simpleType>
32
				<xs:restriction base="xs:string">
33
					<xs:enumeration value="UserDSResourceType" />
34
				</xs:restriction>
35
			</xs:simpleType>
36
		</xs:attribute>
37
	</xs:complexType>
38

  
39
	<xs:complexType name="RESOURCE_KINDType">
40
		<xs:attribute name="value" use="required">
41
			<xs:simpleType>
42
				<xs:restriction base="xs:string">
43
					<xs:enumeration value="UserDSResources" />
44
					<xs:enumeration value="PendingDSResources"/>
45
				</xs:restriction>
46
			</xs:simpleType>
47
		</xs:attribute>
48
	</xs:complexType>
49

  
50
	<xs:complexType name="RESOURCE_URIType">
51
		<xs:attribute name="value" type="xs:string" use="required" />
52
	</xs:complexType>
53

  
54
	<xs:complexType name="DATE_OF_CREATIONType">
55
		<xs:attribute name="value" type="xs:string" use="required" />
56
	</xs:complexType>
57

  
58
	<xs:complexType name="BODYType">
59
		<xs:sequence>
60
			<xs:element name="CONFIGURATION" type="CONFIGURATIONType" />
61
			<xs:element name="STATUS" type="xs:string" />
62
			<xs:element name="SECURITY_PARAMETERS"
63
				type="SECURITY_PARAMETERSType" />
64
		</xs:sequence>
65
	</xs:complexType>
66

  
67
	<xs:complexType name="CONFIGURATIONType">
68
		<xs:sequence>
69
			<xs:element name="PERSONAL_INFO" type="PERSONAL_INFOType" />
70
			<xs:element name="COMMUNITIES" type="COMMUNITIESType" />
71
			<xs:element name="LAYOUT" type="LAYOUTType" />
72
			<xs:element name="SAVED_QUERIES" type="SAVED_QUERYType" minOccurs="0" maxOccurs="unbounded" />
73
			<xs:element name="RECOMMENDATION" type="RECOMMENDATIONType" />
74
		</xs:sequence>
75
	</xs:complexType>
76

  
77
	<xs:complexType name="SECURITY_PARAMETERSType">
78
		<xs:all>
79
			<xs:element name="SECURITY_PARAMETER" type="xs:string" />
80
		</xs:all>
81
	</xs:complexType>
82

  
83
	<xs:complexType name="SAVED_QUERYType">
84
       <xs:sequence>
85
           <xs:element name="query" type="QUERYType" />
86
           <xs:element name="hashValue" type="xs:string" minOccurs="0"
87
               maxOccurs="unbounded" />
88
           <xs:element name="alertOnChange" type="xs:boolean" />
89
       </xs:sequence>
90
   </xs:complexType>
91

  
92
   <xs:complexType name="QUERYType">
93
	   <xs:sequence>
94
			<xs:element name="CQL">
95
				<xs:complexType>
96
					<xs:attribute name="value" type="xs:string" />
97
				</xs:complexType>
98
			</xs:element>
99
			<xs:element name="COMMUNITYID" minOccurs="0" maxOccurs="unbounded">
100
				<xs:complexType>
101
					<xs:attribute name="communityId" type="xs:string"  />
102
				</xs:complexType>
103
			</xs:element>
104
			<xs:element name="COLLECTIONID" minOccurs="0" maxOccurs="unbounded">
105
				<xs:complexType>
106
					<xs:attribute name="collectionId" type="xs:string"  />
107
				</xs:complexType>
108
			</xs:element>
109
		</xs:sequence>
110
   </xs:complexType>
111

  
112
	<xs:complexType name="PERSONAL_INFOType">
113
		<xs:sequence>
114
			<xs:element name="FIRST_NAME">
115
				<xs:complexType>
116
					<xs:attribute name="value" type="xs:string" />
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff