aboutsummaryrefslogtreecommitdiff
path: root/tests/TestApi.java
diff options
context:
space:
mode:
authorjestin2003-01-07 10:39:44 +0000
committerjestin2003-01-07 10:39:44 +0000
commit615df5f1f4058862342ec3171ceb78da09c40fc7 (patch)
tree9ff3be3eed1fa3783ac13c603033fcfb5e10dabc /tests/TestApi.java
parent2e2578904b5c3b6e2470bff1fa147631142ee5df (diff)
downloadivy-java-615df5f1f4058862342ec3171ceb78da09c40fc7.zip
ivy-java-615df5f1f4058862342ec3171ceb78da09c40fc7.tar.gz
ivy-java-615df5f1f4058862342ec3171ceb78da09c40fc7.tar.bz2
ivy-java-615df5f1f4058862342ec3171ceb78da09c40fc7.tar.xz
Je vais simplifier la constructions de tests.
TestApi est brutal et efficace pour tester l'api.
Diffstat (limited to 'tests/TestApi.java')
-rw-r--r--tests/TestApi.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/TestApi.java b/tests/TestApi.java
new file mode 100644
index 0000000..397208e
--- /dev/null
+++ b/tests/TestApi.java
@@ -0,0 +1,101 @@
+/**
+ * Ivy java library API tester.
+ *
+ * @author Yannick Jestin <mailto:jestin@cena.fr>
+ *
+ * (c) CENA
+ *
+ * usage: java TestApi
+ *
+ */
+import fr.dgac.ivy.*;
+
+class TestApi implements IvyMessageListener, IvyApplicationListener {
+
+ public static final String TestApiReadyMsg = "TestAPI ready";
+ public static final String TestMsg = "Test Message";
+
+ private Ivy bus;
+ private int test=0;
+ private String domain;
+
+ public TestApi(String domain) throws IvyException {
+ bus = new Ivy("TestAPI",TestApiReadyMsg, null);
+ bus.addApplicationListener(this);
+ bus.bindMsg("^"+TestMsg+"$",this);
+ bus.start(this.domain=domain);
+ new Sender(domain) ;
+ }
+
+ public void receive(IvyClient ic,String[] args) {
+ System.out.println("[X] received message");
+ test++;
+ }
+
+ public void connect(IvyClient ic) {
+ if (ic.getApplicationName().compareTo("Sender")!=0) return;
+ System.out.println("[X] Sender connected");
+ test++;
+ }
+
+ public void disconnect(IvyClient ic) {
+ if (ic.getApplicationName().compareTo("Sender")!=0) return;
+ System.out.println("[X] Sender disconnected");
+ test++;
+ }
+
+ public void directMessage(IvyClient ic,int id,String arg) {
+ if (id!=1) return;
+ System.out.println("[X] Direct message received, ID=1");
+ test++;
+ }
+
+ public void die(IvyClient ic,int reason) {
+ System.out.println("[X] Die received");
+ test++;
+ System.out.println(test+ "/5 tests successful, good bye");
+ bus.stop();
+ }
+
+ class Sender implements IvyMessageListener {
+ private Ivy sbus;
+ private String domain;
+ public Sender(String domain) {
+ try {
+ sbus = new Ivy("Sender","Sender ready", null);
+ sbus.bindMsg("^"+TestApiReadyMsg+"$",this);
+ sbus.start(this.domain=domain);
+ } catch (IvyException ie) {
+ ie.printStackTrace();
+ }
+ }
+ public void receive(IvyClient c,String[] args) {
+ sbus.sendMsg(TestMsg);
+ c.sendDirectMsg(1,"bye bye");
+ sbus.stop();
+ new Killer(domain);
+ }
+ }
+
+ class Killer implements IvyMessageListener {
+ private Ivy kbus;
+ public Killer(String domain) {
+ try {
+ kbus = new Ivy("Killer","Killer ready", null);
+ kbus.bindMsg("^"+TestApiReadyMsg+"$",this);
+ kbus.start(domain);
+ } catch (IvyException ie) {
+ ie.printStackTrace();
+ }
+ }
+ public void receive(IvyClient c,String[] args) {
+ c.sendDie("bye bye");
+ kbus.stop();
+ }
+ }
+
+ public static void main(String[] args) throws IvyException {
+ new TestApi(null);
+ }
+
+}