Skip to content

Commit 0755d61

Browse files
committed
[refactor] reformat test code
1 parent 4f2527a commit 0755d61

8 files changed

+197
-198
lines changed

exist-core/src/test/java/org/exist/validation/ApacheXmlComponentsTest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,33 @@
2222

2323
package org.exist.validation;
2424

25-
import org.junit.*;
26-
import static org.junit.Assert.*;
25+
import org.junit.Test;
26+
27+
import static org.junit.Assert.assertTrue;
2728

2829
/**
29-
* Class for testing XML Parser and XML Transformer configuration.
30+
* Class for testing XML Parser and XML Transformer configuration.
3031
*
3132
* @author Dannes Wessels ([email protected])
3233
*/
33-
public class ApacheXmlComponentsTest {
34-
35-
34+
public class ApacheXmlComponentsTest {
35+
36+
3637
@Test
3738
public void parserVersion() {
38-
StringBuilder xmlLibMessage = new StringBuilder();
39-
40-
boolean validParser = XmlLibraryChecker.hasValidParser(xmlLibMessage);
41-
39+
final StringBuilder xmlLibMessage = new StringBuilder();
40+
41+
final boolean validParser = XmlLibraryChecker.hasValidParser(xmlLibMessage);
42+
4243
assertTrue(xmlLibMessage.toString(), validParser);
4344
}
4445

4546
@Test
4647
public void transformerVersion() {
47-
StringBuilder xmlLibMessage = new StringBuilder();
48-
49-
boolean validTransformer = XmlLibraryChecker.hasValidTransformer(xmlLibMessage);
50-
48+
final StringBuilder xmlLibMessage = new StringBuilder();
49+
50+
final boolean validTransformer = XmlLibraryChecker.hasValidTransformer(xmlLibMessage);
51+
5152
assertTrue(xmlLibMessage.toString(), validTransformer);
5253
}
5354
}

exist-core/src/test/java/org/exist/validation/CollectionConfigurationTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323

2424
import org.exist.test.ExistXmldbEmbeddedServer;
2525
import org.junit.ClassRule;
26-
import org.xmldb.api.base.Collection;
27-
import org.xmldb.api.base.XMLDBException;
2826
import org.junit.Test;
29-
27+
import org.xmldb.api.base.Collection;
3028
import org.xmldb.api.base.ResourceSet;
29+
import org.xmldb.api.base.XMLDBException;
3130
import org.xmldb.api.modules.CollectionManagementService;
3231

3332
import static org.exist.collections.CollectionConfiguration.DEFAULT_COLLECTION_CONFIG_FILE;
34-
import static org.junit.Assert.*;
33+
import static org.junit.Assert.assertEquals;
34+
import static org.junit.Assert.assertNotNull;
3535

3636
/**
37-
* Some tests regarding invalid collection.xconf documents.
38-
*
37+
* Some tests regarding invalid collection.xconf documents.
38+
*
3939
* @author wessels
4040
*/
4141
public class CollectionConfigurationTest {
@@ -45,7 +45,7 @@ public class CollectionConfigurationTest {
4545

4646
private static final String invalidConfig = "<invalid/>";
4747

48-
private void createCollection(String collection) throws XMLDBException {
48+
private void createCollection(final String collection) throws XMLDBException {
4949
final CollectionManagementService cmservice = existEmbeddedServer.getRoot().getService(CollectionManagementService.class);
5050
Collection testCollection = cmservice.createCollection(collection);
5151
assertNotNull(testCollection);
@@ -54,9 +54,9 @@ private void createCollection(String collection) throws XMLDBException {
5454
assertNotNull(testCollection);
5555
}
5656

57-
private void storeCollectionXconf(String collection, String document) throws XMLDBException {
57+
private void storeCollectionXconf(final String collection, final String document) throws XMLDBException {
5858
final ResourceSet result = existEmbeddedServer.executeQuery("xmldb:store(\"" + collection + "\", \"" + DEFAULT_COLLECTION_CONFIG_FILE + "\", " + document + ")");
59-
String r = (String) result.getResource(0).getContent();
59+
final String r = (String) result.getResource(0).getContent();
6060
assertEquals("Store xconf", collection + "/" + DEFAULT_COLLECTION_CONFIG_FILE, r);
6161
}
6262

exist-core/src/test/java/org/exist/validation/CollectionConfigurationValidationModeTest.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
import static org.junit.Assert.*;
3838

3939
/**
40-
* Switch validation mode yes/no/auto per collection and validate.
40+
* Switch validation mode yes/no/auto per collection and validate.
41+
*
4142
* @author wessels
4243
*/
4344
public class CollectionConfigurationValidationModeTest {
@@ -204,26 +205,26 @@ public void insertModeTrue() throws XMLDBException {
204205
try {
205206
storeDocument("/db/true", "invalid.xml", INVALID_XSD);
206207
fail("should have failed");
207-
} catch (XMLDBException ex) {
208-
String msg = ex.getMessage();
208+
} catch (final XMLDBException ex) {
209+
final String msg = ex.getMessage();
209210
assertTrue(msg.contains("cvc-complex-type.2.4.a: Invalid content was found"));
210211
}
211212

212213
// no namespace provided; should fail
213214
try {
214215
storeDocument("/db/true", "anonymous.xml", ANONYMOUS_XSD);
215216
fail("should have failed");
216-
} catch (XMLDBException ex) {
217-
String msg = ex.getMessage();
217+
} catch (final XMLDBException ex) {
218+
final String msg = ex.getMessage();
218219
assertTrue(msg.contains("cvc-elt.1.a: Cannot find the declaration of element 'schema'."));
219220
}
220221

221222
// non resolvable namespace provided, should fail
222223
try {
223224
storeDocument("/db/true", "different.xml", DIFFERENT_XSD);
224225
fail("should have failed");
225-
} catch (XMLDBException ex) {
226-
String msg = ex.getMessage();
226+
} catch (final XMLDBException ex) {
227+
final String msg = ex.getMessage();
227228
assertTrue(msg.contains("cvc-elt.1.a: Cannot find the declaration of element 'xsd:schema'"));
228229
}
229230
}
@@ -240,8 +241,8 @@ public void insertModeAuto() throws XMLDBException {
240241
try {
241242
storeDocument("/db/auto", "invalid.xml", INVALID_XSD);
242243
fail("should have failed");
243-
} catch (XMLDBException ex) {
244-
String msg = ex.getMessage();
244+
} catch (final XMLDBException ex) {
245+
final String msg = ex.getMessage();
245246
assertTrue(msg.contains("cvc-complex-type.2.4.a: Invalid content was found"));
246247
}
247248

@@ -251,8 +252,8 @@ public void insertModeAuto() throws XMLDBException {
251252
// non resolvable namespace provided, should fail
252253
try {
253254
storeDocument("/db/auto", "different.xml", DIFFERENT_XSD);
254-
} catch (XMLDBException ex) {
255-
String msg = ex.getMessage();
255+
} catch (final XMLDBException ex) {
256+
final String msg = ex.getMessage();
256257
assertTrue(msg.contains("schema_reference.4: Failed to read schema document"));
257258
}
258259
}

exist-core/src/test/java/org/exist/validation/DatabaseCollectionTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
import org.exist.security.Account;
2626
import org.exist.security.Permission;
2727
import org.exist.test.ExistXmldbEmbeddedServer;
28-
2928
import org.exist.xmldb.UserManagementService;
3029
import org.exist.xmldb.XmldbURI;
31-
3230
import org.junit.After;
3331
import org.junit.Before;
3432
import org.junit.ClassRule;
@@ -41,7 +39,7 @@
4139
import static org.junit.Assert.assertNotNull;
4240

4341
/**
44-
* Created collections needed for validation tests.
42+
* Created collections needed for validation tests.
4543
*
4644
* @author Dannes Wessels ([email protected])
4745
*/
@@ -71,7 +69,7 @@ public void tearDown() throws XMLDBException {
7169
final CollectionManagementService cms = existServer.getRoot().getService(CollectionManagementService.class);
7270
cms.removeCollection(TEST_COLLECTION);
7371
}
74-
72+
7573
@Test
7674
public void createCollections() throws XMLDBException {
7775
final Collection testCollection = DatabaseManager.getCollection(ROOT_URI + "/" + TEST_COLLECTION);

exist-core/src/test/java/org/exist/validation/DatabaseInsertResources_NoValidation_Test.java

Lines changed: 67 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
*/
2222
package org.exist.validation;
2323

24-
import java.io.IOException;
25-
import java.io.InputStream;
26-
import java.util.Optional;
27-
2824
import org.exist.collections.Collection;
2925
import org.exist.storage.BrokerPool;
3026
import org.exist.storage.DBBroker;
@@ -39,21 +35,84 @@
3935
import org.junit.ClassRule;
4036
import org.junit.Test;
4137

38+
import java.io.IOException;
39+
import java.io.InputStream;
40+
import java.util.Optional;
41+
4242
import static org.exist.TestUtils.*;
43-
import static org.exist.util.PropertiesBuilder.propertiesBuilder;
4443
import static org.exist.samples.Samples.SAMPLES;
44+
import static org.exist.util.PropertiesBuilder.propertiesBuilder;
4545

4646
/**
47-
* Insert documents for validation tests.
47+
* Insert documents for validation tests.
4848
*
4949
* @author Dannes Wessels ([email protected])
5050
*/
5151
public class DatabaseInsertResources_NoValidation_Test {
5252

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);
5360
private final static String TEST_COLLECTION = "testNoValidationInsert";
54-
5561
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+
}
57116

58117
/**
59118
* Insert all documents into database, switch of validation.
@@ -125,66 +184,4 @@ public void insertValidationResource_dtd_badDocType() throws IOException {
125184
"xmldb:exist://" + VALIDATION_HOME_COLLECTION_URI + "/hamlet_wrongdoctype.xml");
126185
}
127186
}
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-
}
190187
}

0 commit comments

Comments
 (0)