Converted the rest of the tests to JUnit unit tests.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@610 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-11-08 05:40:07 +00:00
parent ff94bd7799
commit 281c00d3a3
4 changed files with 124 additions and 34 deletions
@@ -1,22 +1,31 @@
//
// $Id: DOMTest.java,v 1.5 2001/11/08 02:07:36 mdb Exp $
// $Id: DOMTest.java,v 1.6 2001/11/08 05:40:07 mdb Exp $
package com.threerings.presents.server;
import junit.framework.Test;
import junit.framework.TestCase;
import com.threerings.presents.Log;
import com.threerings.presents.dobj.*;
/**
* A simple test case for the dobjmgr.
*/
public class DOMTest implements Subscriber, AttributeChangeListener
public class DOMTest
extends TestCase
implements Subscriber, AttributeChangeListener
{
public DOMTest ()
{
super(DOMTest.class.getName());
}
public void objectAvailable (DObject object)
{
// add ourselves as a listener
object.addListener(this);
Log.info("Object available: " + object);
// set some values
TestObject to = (TestObject)object;
to.setFoo(25);
@@ -25,29 +34,26 @@ public class DOMTest implements Subscriber, AttributeChangeListener
public void requestFailed (int oid, ObjectAccessException cause)
{
Log.info("Request failed: " + cause);
fail("Request failed: " + cause);
omgr.shutdown();
}
public void attributeChanged (AttributeChangedEvent event)
{
Log.info("Got event [event=" + event + "].");
// if this is the second event, request a shutdown
if (event.getName().equals(TestObject.BAR)) {
if (event.getName().equals(TestObject.FOO)) {
assert("foo=25", event.getIntValue() == 25);
} else if (event.getName().equals(TestObject.BAR)) {
assert("bar=howdy", "howdy".equals(event.getValue()));
omgr.shutdown();
}
}
public static PresentsDObjectMgr omgr = new PresentsDObjectMgr();
public static void main (String[] args)
public void runTest ()
{
// create our subscriber who will do things
DOMTest sub = new DOMTest();
// request that a new TestObject be created
omgr.createObject(TestObject.class, sub);
omgr.createObject(TestObject.class, this);
// or for fun you can try this bogus create request
// omgr.createObject(Integer.class, sub);
@@ -55,4 +61,11 @@ public class DOMTest implements Subscriber, AttributeChangeListener
// and run the object manager
omgr.run();
}
public static Test suite ()
{
return new RefTest();
}
public static PresentsDObjectMgr omgr = new PresentsDObjectMgr();
}
@@ -1,8 +1,11 @@
//
// $Id: DestroyedRefTest.java,v 1.5 2001/11/08 02:07:36 mdb Exp $
// $Id: DestroyedRefTest.java,v 1.6 2001/11/08 05:40:07 mdb Exp $
package com.threerings.presents.server;
import junit.framework.Test;
import junit.framework.TestCase;
import com.threerings.presents.Log;
import com.threerings.presents.dobj.*;
@@ -11,13 +14,12 @@ import com.threerings.presents.dobj.*;
* an oid list.
*/
public class DestroyedRefTest
implements Runnable, Subscriber, EventListener
extends TestCase
implements Subscriber, EventListener
{
public void run ()
public DestroyedRefTest ()
{
// create two test objects
PresentsServer.omgr.createObject(TestObject.class, this);
PresentsServer.omgr.createObject(TestObject.class, this);
super(DestroyedRefTest.class.getName());
}
public void objectAvailable (DObject object)
@@ -35,6 +37,7 @@ public class DestroyedRefTest
// add object one to object two twice in a row to make sure
// repeated adds don't result in the object being listed twice
_objtwo.addToList(_objone.getOid());
Log.info("The following addToList() should be ignored.");
_objtwo.addToList(_objone.getOid());
// now that we have both objects, try to set up the reference.
@@ -50,7 +53,7 @@ public class DestroyedRefTest
public void requestFailed (int oid, ObjectAccessException cause)
{
Log.warning("Ack. Unable to create object [cause=" + cause + "].");
fail("Ack. Unable to create object [cause=" + cause + "].");
}
public void eventReceived (DEvent event)
@@ -63,17 +66,44 @@ public class DestroyedRefTest
} else if (event instanceof ObjectAddedEvent &&
toid == _objtwo.getOid()) {
Log.info("list should contain only one oid: " + _objtwo.list);
assert("list should contain only one oid",
_objtwo.list.size() == 1);
} else if (event instanceof AttributeChangedEvent) {
// go bye bye
PresentsServer.shutdown();
} else {
Log.info("Got unexpected event: " + event);
fail("Got unexpected event: " + event);
}
}
public void runTest ()
{
PresentsServer server = new TestPresentsServer();
try {
// initialize the server
server.init();
// create two test objects
PresentsServer.omgr.createObject(TestObject.class, this);
PresentsServer.omgr.createObject(TestObject.class, this);
// start the server to running (this method call won't return
// until the server is shut down)
server.run();
} catch (Exception e) {
Log.warning("Unable to initialize server.");
Log.logStackTrace(e);
}
}
public static Test suite ()
{
return new DestroyedRefTest();
}
protected TestObject _objone;
protected TestObject _objtwo;
}
@@ -1,8 +1,11 @@
//
// $Id: RefTest.java,v 1.5 2001/11/08 02:07:36 mdb Exp $
// $Id: RefTest.java,v 1.6 2001/11/08 05:40:07 mdb Exp $
package com.threerings.presents.server;
import junit.framework.Test;
import junit.framework.TestCase;
import com.threerings.presents.Log;
import com.threerings.presents.dobj.*;
@@ -10,13 +13,12 @@ import com.threerings.presents.dobj.*;
* Tests the oid list reference tracking code.
*/
public class RefTest
implements Runnable, Subscriber, EventListener
extends TestCase
implements Subscriber, EventListener
{
public void run ()
public RefTest ()
{
// create two test objects
PresentsServer.omgr.createObject(TestObject.class, this);
PresentsServer.omgr.createObject(TestObject.class, this);
super(RefTest.class.getName());
}
public void objectAvailable (DObject object)
@@ -39,7 +41,7 @@ public class RefTest
public void requestFailed (int oid, ObjectAccessException cause)
{
Log.warning("Ack. Unable to create object [cause=" + cause + "].");
fail("Ack. Unable to create object [cause=" + cause + "].");
}
public void eventReceived (DEvent event)
@@ -51,25 +53,53 @@ public class RefTest
// target object to see if the reference is cleaned up
if (event instanceof ObjectAddedEvent &&
toid == _objtwo.getOid()) {
Log.info("Destroying object two " + _objtwo + ".");
// Log.info("Destroying object two " + _objtwo + ".");
_objtwo.destroy();
} else if (event instanceof ObjectDestroyedEvent) {
if (toid == _objtwo.getOid()) {
Log.info("List won't yet be empty: " + _objone.list);
// Log.info("List won't yet be empty: " + _objone.list);
assert("List not empty", _objone.list.size() > 0);
} else {
Log.info("Other object destroyed.");
// Log.info("Other object destroyed.");
// go bye bye
PresentsServer.shutdown();
}
} else if (event instanceof ObjectRemovedEvent) {
Log.info("List should be empty: " + _objone.list);
// Log.info("List should be empty: " + _objone.list);
assert("List empty", _objone.list.size() == 0);
// finally destroy the other object to complete the circle
_objone.destroy();
}
}
public void runTest ()
{
PresentsServer server = new TestPresentsServer();
try {
// initialize the server
server.init();
// create two test objects
PresentsServer.omgr.createObject(TestObject.class, this);
PresentsServer.omgr.createObject(TestObject.class, this);
// start the server to running (this method call won't return
// until the server is shut down)
server.run();
} catch (Exception e) {
Log.warning("Unable to initialize server.");
Log.logStackTrace(e);
}
}
public static Test suite ()
{
return new RefTest();
}
protected TestObject _objone;
protected TestObject _objtwo;
}
@@ -0,0 +1,17 @@
//
// $Id: TestPresentsServer.java,v 1.1 2001/11/08 05:40:07 mdb Exp $
package com.threerings.presents.server;
/**
* This test version of the server avoids creating a connection manager
* because that requires a shared library which we don't have available
* when testing via ant/JUnit.
*/
public class TestPresentsServer extends PresentsServer
{
protected boolean createConnectionManager ()
{
return false;
}
}