Skip to content

Commit

Permalink
Fixes to tests so that they use the new JUnit annotations. The biggest
Browse files Browse the repository at this point in the history
problem was in isolating dependencies through tests in the same class.
Tests SHOULD NOT assume an order of execution!
  • Loading branch information
adamretter committed Jan 26, 2014
1 parent 820a47e commit 7eb5e3f
Show file tree
Hide file tree
Showing 43 changed files with 355 additions and 286 deletions.
2 changes: 1 addition & 1 deletion test/src/org/exist/http/RESTServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public final static void createCredentials() {

@Before
public void setUp() throws Exception {
//Don't worry about closing the server : the shutdown hook will do the job
//Don't worry about closing the server : the shutdownDB hook will do the job
if (server == null) {
server = new JettyStart();
System.out.println("Starting standalone server...");
Expand Down
2 changes: 1 addition & 1 deletion test/src/org/exist/security/RestApiSecurityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected void createBinResource(final String resourceUri, final byte[] content,

@BeforeClass
public static void startServer() throws InterruptedException {
//Don't worry about closing the server : the shutdown hook will do the job
//Don't worry about closing the server : the shutdownDB hook will do the job
if (server == null) {
server = new JettyStart();
System.out.println("Starting standalone server...");
Expand Down
2 changes: 1 addition & 1 deletion test/src/org/exist/security/XMLDBSecurityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ public static void stopServer() {
// Collection root = DatabaseManager.getCollection("xmldb:exist:///db", "admin", "");
// DatabaseInstanceManager mgr =
// (DatabaseInstanceManager) root.getService("DatabaseInstanceManager", "1.0");
// mgr.shutdown();
// mgr.shutdownDB();
// } catch (XMLDBException e) {
// e.printStackTrace();
// }
Expand Down
2 changes: 1 addition & 1 deletion test/src/org/exist/security/XmldbApiSecurityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public static void stopServer() {
// Collection root = DatabaseManager.getCollection("xmldb:exist:///db", "admin", "");
// DatabaseInstanceManager mgr =
// (DatabaseInstanceManager) root.getService("DatabaseInstanceManager", "1.0");
// mgr.shutdown();
// mgr.shutdownDB();
// } catch (XMLDBException e) {
// e.printStackTrace();
// }
Expand Down
2 changes: 1 addition & 1 deletion test/src/org/exist/soap/CopyMoveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected void tearDown() throws Exception {
rex.printStackTrace();
}

//mn.shutdown();
//mn.shutdownDB();
}

private void setupTestCollection() throws RemoteException {
Expand Down
2 changes: 1 addition & 1 deletion test/src/org/exist/soap/XQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected void tearDown() throws Exception {
} catch (RemoteException rex) {
rex.printStackTrace();
}
//mn.shutdown();
//mn.shutdownDB();
}

public void testRemoveThisEmptyTest() throws Exception {
Expand Down
20 changes: 10 additions & 10 deletions test/src/org/exist/storage/AbstractUpdateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
*/
package org.exist.storage;

import junit.framework.TestCase;

import org.exist.collections.Collection;
import org.exist.collections.IndexInfo;
import org.exist.dom.DocumentImpl;
Expand All @@ -38,15 +36,20 @@
import org.exist.xquery.value.NodeValue;
import org.exist.xquery.value.Sequence;
import org.exist.xquery.value.SequenceIterator;
import org.junit.After;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

public abstract class AbstractUpdateTest extends TestCase {
public abstract class AbstractUpdateTest {

protected static XmldbURI TEST_COLLECTION_URI = XmldbURI.ROOT_COLLECTION_URI.append("test");
protected static String TEST_XML =
"<?xml version=\"1.0\"?>" +
"<products/>";

public void testRead() {
@Test
public void read() {
BrokerPool.FORCE_CORRUPTION = false;

BrokerPool pool = null;
Expand Down Expand Up @@ -121,11 +124,8 @@ protected BrokerPool startDB() {
return null;
}

protected void tearDown() {
try {
BrokerPool.stopAll(false);
} catch (Exception e) {
fail(e.getMessage());
}
@After
public void tearDown() {
BrokerPool.stopAll(false);
}
}
10 changes: 4 additions & 6 deletions test/src/org/exist/storage/AppendTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
package org.exist.storage;

import junit.textui.TestRunner;
import org.exist.collections.IndexInfo;
import org.exist.dom.DefaultDocumentSet;
import org.exist.dom.MutableDocumentSet;
Expand All @@ -31,16 +30,15 @@
import org.exist.xupdate.Modification;
import org.exist.xupdate.XUpdateProcessor;
import org.xml.sax.InputSource;
import org.junit.Test;
import static org.junit.Assert.fail;

import java.io.StringReader;

public class AppendTest extends AbstractUpdateTest {

public static void main(String[] args) {
TestRunner.run(AppendTest.class);
}

public void testUpdate() {
@Test
public void update() {
BrokerPool.FORCE_CORRUPTION = true;
BrokerPool pool = null;
DBBroker broker = null;
Expand Down
25 changes: 10 additions & 15 deletions test/src/org/exist/storage/CollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,23 @@
import java.io.Writer;
import java.util.Iterator;

import junit.framework.TestCase;
import junit.textui.TestRunner;

import org.exist.collections.Collection;
import org.exist.dom.DocumentImpl;
import org.exist.storage.btree.BTree;
import org.exist.storage.txn.TransactionManager;
import org.exist.storage.txn.Txn;
import org.exist.util.Configuration;
import org.exist.xmldb.XmldbURI;
import org.junit.After;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

/**
* @author wolf
*
*/
public class CollectionTest extends TestCase {
public class CollectionTest {

@SuppressWarnings("unused")
private static String docs[] = { "hamlet.xml", "r_and_j.xml", "macbeth.xml" };
Expand All @@ -54,12 +55,9 @@ public class CollectionTest extends TestCase {
" <title>Hello</title>" +
" <para>Hello World!</para>" +
"</test>";

public static void main(String[] args) {
TestRunner.run(CollectionTest.class);
}

public void testStoreRead() {
@Test
public void storeRead() {
store();
BrokerPool.stopAll(false);
read();
Expand Down Expand Up @@ -134,11 +132,8 @@ protected BrokerPool startDB() {
return null;
}

protected void tearDown() {
try {
BrokerPool.stopAll(false);
} catch (Exception e) {
fail(e.getMessage());
}
@After
public void tearDown() {
BrokerPool.stopAll(false);
}
}
58 changes: 38 additions & 20 deletions test/src/org/exist/storage/CopyCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
package org.exist.storage;

import java.io.File;

import junit.framework.TestCase;
import junit.textui.TestRunner;

import org.exist.collections.Collection;
import org.exist.collections.IndexInfo;
import org.exist.dom.DocumentImpl;
Expand All @@ -37,18 +33,39 @@
import org.exist.util.Configuration;
import org.exist.xmldb.CollectionManagementServiceImpl;
import org.exist.xmldb.XmldbURI;
import org.junit.After;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.xml.sax.InputSource;
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Database;
import org.xmldb.api.base.Resource;

public class CopyCollectionTest extends TestCase {
public class CopyCollectionTest {

public static void main(String[] args) {
TestRunner.run(CopyCollectionTest.class);
@Test
public void storeAndRead() {
store();
tearDown();
read();
}

public void testStore() {

@Test
public void storeAndReadAborted() {
storeAborted();
tearDown();
readAborted();
}

@Test
public void storeAndReadXmldb() {
xmldbStore();
tearDown();
xmldbRead();
}

private void store() {
BrokerPool.FORCE_CORRUPTION = true;
BrokerPool pool = startDB();
DBBroker broker = null;
Expand Down Expand Up @@ -87,8 +104,8 @@ public void testStore() {
pool.release(broker);
}
}
public void testRead() {

private void read() {
BrokerPool.FORCE_CORRUPTION = false;
BrokerPool pool = null;
DBBroker broker = null;
Expand All @@ -115,8 +132,8 @@ public void testRead() {
if (pool != null) pool.release(broker);
}
}
public void testStoreAborted() {

private void storeAborted() {
BrokerPool.FORCE_CORRUPTION = true;
BrokerPool pool = null;

Expand Down Expand Up @@ -168,8 +185,8 @@ public void testStoreAborted() {
if (pool != null) pool.release(broker);
}
}
public void testReadAborted() {

private void readAborted() {
BrokerPool.FORCE_CORRUPTION = false;
BrokerPool pool = null;
DBBroker broker = null;
Expand All @@ -192,8 +209,8 @@ public void testReadAborted() {
pool.release(broker);
}
}
public void testXMLDBStore() {

private void xmldbStore() {
BrokerPool.FORCE_CORRUPTION = false;
BrokerPool pool = null;
try {
Expand Down Expand Up @@ -232,8 +249,8 @@ public void testXMLDBStore() {
fail(e.getMessage());
}
}
public void testXMLDBRead() {

private void xmldbRead() {
BrokerPool.FORCE_CORRUPTION = false;
BrokerPool pool = null;

Expand Down Expand Up @@ -274,7 +291,8 @@ protected BrokerPool startDB() {
return null;
}

protected void tearDown() {
@After
public void tearDown() {
BrokerPool.stopAll(false);
}
}
Loading

0 comments on commit 7eb5e3f

Please sign in to comment.