|
21 | 21 | */
|
22 | 22 | package org.exist.validation;
|
23 | 23 |
|
24 |
| -import java.io.IOException; |
25 |
| -import java.io.InputStream; |
26 |
| -import java.util.Optional; |
27 |
| - |
28 | 24 | import org.exist.collections.Collection;
|
29 | 25 | import org.exist.storage.BrokerPool;
|
30 | 26 | import org.exist.storage.DBBroker;
|
|
39 | 35 | import org.junit.ClassRule;
|
40 | 36 | import org.junit.Test;
|
41 | 37 |
|
| 38 | +import java.io.IOException; |
| 39 | +import java.io.InputStream; |
| 40 | +import java.util.Optional; |
| 41 | + |
42 | 42 | import static org.exist.TestUtils.*;
|
43 |
| -import static org.exist.util.PropertiesBuilder.propertiesBuilder; |
44 | 43 | import static org.exist.samples.Samples.SAMPLES;
|
| 44 | +import static org.exist.util.PropertiesBuilder.propertiesBuilder; |
45 | 45 |
|
46 | 46 | /**
|
47 |
| - * Insert documents for validation tests. |
| 47 | + * Insert documents for validation tests. |
48 | 48 | *
|
49 | 49 | * @author Dannes Wessels ([email protected])
|
50 | 50 | */
|
51 | 51 | public class DatabaseInsertResources_NoValidation_Test {
|
52 | 52 |
|
| 53 | + @ClassRule |
| 54 | + public static final ExistEmbeddedServer existEmbeddedServer = new ExistEmbeddedServer( |
| 55 | + propertiesBuilder() |
| 56 | + .set(XMLReaderObjectFactory.PROPERTY_VALIDATION_MODE, "auto") |
| 57 | + .build(), |
| 58 | + true, |
| 59 | + true); |
53 | 60 | private final static String TEST_COLLECTION = "testNoValidationInsert";
|
54 |
| - |
55 | 61 | private final static String VALIDATION_HOME_COLLECTION_URI = "/db/" + TEST_COLLECTION + "/" + TestTools.VALIDATION_HOME_COLLECTION;
|
56 |
| - |
| 62 | + |
| 63 | + @BeforeClass |
| 64 | + public static void startup() throws Exception { |
| 65 | + //create the collections we need for these tests |
| 66 | + createTestCollections(); |
| 67 | + } |
| 68 | + |
| 69 | + @AfterClass |
| 70 | + public static void shutdown() throws Exception { |
| 71 | + removeTestCollections(); |
| 72 | + } |
| 73 | + |
| 74 | + private static void createTestCollections() throws Exception { |
| 75 | + final BrokerPool pool = existEmbeddedServer.getBrokerPool(); |
| 76 | + final TransactionManager transact = pool.getTransactionManager(); |
| 77 | + |
| 78 | + try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().authenticate(ADMIN_DB_USER, ADMIN_DB_PWD))); |
| 79 | + final Txn txn = transact.beginTransaction()) { |
| 80 | + |
| 81 | + /** create necessary collections if they dont exist */ |
| 82 | + final Collection testCollection = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI)); |
| 83 | + testCollection.getPermissions().setOwner(GUEST_DB_USER); |
| 84 | + broker.saveCollection(txn, testCollection); |
| 85 | + |
| 86 | + Collection col = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI + "/" + TestTools.VALIDATION_DTD_COLLECTION)); |
| 87 | + col.getPermissions().setOwner(GUEST_DB_USER); |
| 88 | + broker.saveCollection(txn, col); |
| 89 | + |
| 90 | + col = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI + "/" + TestTools.VALIDATION_XSD_COLLECTION)); |
| 91 | + col.getPermissions().setOwner(GUEST_DB_USER); |
| 92 | + broker.saveCollection(txn, col); |
| 93 | + |
| 94 | + col = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI + "/" + TestTools.VALIDATION_TMP_COLLECTION)); |
| 95 | + col.getPermissions().setOwner(GUEST_DB_USER); |
| 96 | + broker.saveCollection(txn, col); |
| 97 | + |
| 98 | + transact.commit(txn); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + private static void removeTestCollections() throws Exception { |
| 103 | + final BrokerPool pool = existEmbeddedServer.getBrokerPool(); |
| 104 | + final TransactionManager transact = pool.getTransactionManager(); |
| 105 | + |
| 106 | + try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().authenticate(ADMIN_DB_USER, ADMIN_DB_PWD))); |
| 107 | + final Txn txn = transact.beginTransaction()) { |
| 108 | + |
| 109 | + /** create necessary collections if they dont exist */ |
| 110 | + final Collection testCollection = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI)); |
| 111 | + broker.removeCollection(txn, testCollection); |
| 112 | + |
| 113 | + transact.commit(txn); |
| 114 | + } |
| 115 | + } |
57 | 116 |
|
58 | 117 | /**
|
59 | 118 | * Insert all documents into database, switch of validation.
|
@@ -125,66 +184,4 @@ public void insertValidationResource_dtd_badDocType() throws IOException {
|
125 | 184 | "xmldb:exist://" + VALIDATION_HOME_COLLECTION_URI + "/hamlet_wrongdoctype.xml");
|
126 | 185 | }
|
127 | 186 | }
|
128 |
| - |
129 |
| - @ClassRule |
130 |
| - public static final ExistEmbeddedServer existEmbeddedServer = new ExistEmbeddedServer( |
131 |
| - propertiesBuilder() |
132 |
| - .set(XMLReaderObjectFactory.PROPERTY_VALIDATION_MODE, "auto") |
133 |
| - .build(), |
134 |
| - true, |
135 |
| - true); |
136 |
| - |
137 |
| - @BeforeClass |
138 |
| - public static void startup() throws Exception { |
139 |
| - //create the collections we need for these tests |
140 |
| - createTestCollections(); |
141 |
| - } |
142 |
| - |
143 |
| - @AfterClass |
144 |
| - public static void shutdown() throws Exception { |
145 |
| - removeTestCollections(); |
146 |
| - } |
147 |
| - |
148 |
| - private static void createTestCollections() throws Exception { |
149 |
| - final BrokerPool pool = existEmbeddedServer.getBrokerPool(); |
150 |
| - final TransactionManager transact = pool.getTransactionManager(); |
151 |
| - |
152 |
| - try(final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().authenticate(ADMIN_DB_USER, ADMIN_DB_PWD))); |
153 |
| - final Txn txn = transact.beginTransaction()) { |
154 |
| - |
155 |
| - /** create necessary collections if they dont exist */ |
156 |
| - Collection testCollection = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI)); |
157 |
| - testCollection.getPermissions().setOwner(GUEST_DB_USER); |
158 |
| - broker.saveCollection(txn, testCollection); |
159 |
| - |
160 |
| - Collection col = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI + "/" + TestTools.VALIDATION_DTD_COLLECTION)); |
161 |
| - col.getPermissions().setOwner(GUEST_DB_USER); |
162 |
| - broker.saveCollection(txn, col); |
163 |
| - |
164 |
| - col = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI + "/" + TestTools.VALIDATION_XSD_COLLECTION)); |
165 |
| - col.getPermissions().setOwner(GUEST_DB_USER); |
166 |
| - broker.saveCollection(txn, col); |
167 |
| - |
168 |
| - col = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI + "/" + TestTools.VALIDATION_TMP_COLLECTION)); |
169 |
| - col.getPermissions().setOwner(GUEST_DB_USER); |
170 |
| - broker.saveCollection(txn, col); |
171 |
| - |
172 |
| - transact.commit(txn); |
173 |
| - } |
174 |
| - } |
175 |
| - |
176 |
| - private static void removeTestCollections() throws Exception { |
177 |
| - final BrokerPool pool = existEmbeddedServer.getBrokerPool(); |
178 |
| - final TransactionManager transact = pool.getTransactionManager(); |
179 |
| - |
180 |
| - try(final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().authenticate(ADMIN_DB_USER, ADMIN_DB_PWD))); |
181 |
| - final Txn txn = transact.beginTransaction()) { |
182 |
| - |
183 |
| - /** create necessary collections if they dont exist */ |
184 |
| - Collection testCollection = broker.getOrCreateCollection(txn, XmldbURI.create(VALIDATION_HOME_COLLECTION_URI)); |
185 |
| - broker.removeCollection(txn, testCollection); |
186 |
| - |
187 |
| - transact.commit(txn); |
188 |
| - } |
189 |
| - } |
190 | 187 | }
|
0 commit comments