esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dha...@apache.org
Subject svn commit: r741707 - in /incubator/esme/trunk/esme-java-client/src: main/java/org/apache/esme/api/EsmeRestApi.java test/java/org/apache/esme/api/RestTest.java
Date Fri, 06 Feb 2009 20:33:00 GMT
Author: dhague
Date: Fri Feb  6 20:32:59 2009
New Revision: 741707

URL: http://svn.apache.org/viewvc?rev=741707&view=rev
Log:
getMessages is now implemented.  resources/props/test.properties allows you to specify the
token & API URL to use for JUnit test.

Modified:
    incubator/esme/trunk/esme-java-client/src/main/java/org/apache/esme/api/EsmeRestApi.java
    incubator/esme/trunk/esme-java-client/src/test/java/org/apache/esme/api/RestTest.java

Modified: incubator/esme/trunk/esme-java-client/src/main/java/org/apache/esme/api/EsmeRestApi.java
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/esme-java-client/src/main/java/org/apache/esme/api/EsmeRestApi.java?rev=741707&r1=741706&r2=741707&view=diff
==============================================================================
--- incubator/esme/trunk/esme-java-client/src/main/java/org/apache/esme/api/EsmeRestApi.java
(original)
+++ incubator/esme/trunk/esme-java-client/src/main/java/org/apache/esme/api/EsmeRestApi.java
Fri Feb  6 20:32:59 2009
@@ -226,6 +226,16 @@
 
     public List getMessages()
     {
+        return getMessagesHelper("/get_msgs");
+    }
+
+    public List waitForMessages()
+    {
+        return getMessagesHelper("/wait_for_msgs");
+    }
+
+    private List getMessagesHelper(String apiCall)
+    {
 //  GET /api/get_msgs
 //
 //  <esme_api operation="get_msgs" success="true">
@@ -242,7 +252,7 @@
 //  </esme_api>
 
         // TODO
-        GetMethod method = new GetMethod(apiUrl + "/get_msgs");
+        GetMethod method = new GetMethod(apiUrl + apiCall);
 
         List messageList = new ArrayList();
 

Modified: incubator/esme/trunk/esme-java-client/src/test/java/org/apache/esme/api/RestTest.java
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/esme-java-client/src/test/java/org/apache/esme/api/RestTest.java?rev=741707&r1=741706&r2=741707&view=diff
==============================================================================
--- incubator/esme/trunk/esme-java-client/src/test/java/org/apache/esme/api/RestTest.java
(original)
+++ incubator/esme/trunk/esme-java-client/src/test/java/org/apache/esme/api/RestTest.java
Fri Feb  6 20:32:59 2009
@@ -1,10 +1,12 @@
 package org.apache.esme.api;
 
+import java.io.IOException;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.apache.esme.api.EsmeRestApi;
 import junit.framework.TestCase;
+import org.apache.esme.model.Message;
 import org.apache.esme.model.Status;
 
 public class RestTest extends TestCase {
@@ -12,6 +14,8 @@
     private static Logger logger = Logger.getLogger("org.apache.esme.api");
     private static String token = TestProperties.getProperty("esme-token");
     private static String esmeServer = TestProperties.getProperty("esme-server");
+    private String testMsg = "This is a background message to be picked up by testWaitForMessages";
+    private EsmeRestApi esme;
 
     public void testStatus() throws Exception
     {
@@ -19,7 +23,7 @@
 
         logger.log(Level.INFO, "Testing message status");
 
-        EsmeRestApi esme = new EsmeRestApi(esmeServer);
+        esme = new EsmeRestApi(esmeServer);
         Status status = esme.getStatus();
 
         logger.log(Level.INFO, "API status is "+status);
@@ -42,7 +46,7 @@
 
         logger.log(Level.INFO, "Testing message sending");
 
-        EsmeRestApi esme = new EsmeRestApi(esmeServer);
+        esme = new EsmeRestApi(esmeServer);
 
         logger.log(Level.INFO, "Login with token "+token);
         esme.login(token);
@@ -63,7 +67,7 @@
 
         logger.log(Level.INFO, "Testing getMessages");
 
-        EsmeRestApi esme = new EsmeRestApi(esmeServer);
+        esme = new EsmeRestApi(esmeServer);
         esme.login(token);
 
         Status status = esme.getStatus();
@@ -78,4 +82,54 @@
         esme.logout();
     }
 
+	public void testWaitForMessages() throws Exception
+    {
+        EsmeRestApi.debugMode = true;
+
+        logger.log(Level.INFO, "Testing waitForMessages");
+
+        esme = new EsmeRestApi(esmeServer);
+        esme.login(token);
+
+        Status status = esme.getStatus();
+        assertNotNull(status);
+        logger.log(Level.INFO, "API status is "+status);
+
+        // Get the initial message list
+        List messages = esme.getMessages();
+
+        // Kick off a thread to wait 5 seconds and then send a message
+        new BackgroundMessage().start();
+
+        // Now we wait for the new message to appear
+        messages = esme.waitForMessages();
+        assertNotNull(messages);
+
+        logger.info("Got "+messages.size()+" messages from server.");
+
+        assertNotNull((Message)messages.get(0));
+        assertEquals(testMsg, ((Message)messages.get(0)).getBody());
+        
+        esme.logout();
+    }
+
+    private class BackgroundMessage extends Thread
+    {
+        public void run()
+        {
+            try {
+                // Log into ESME, wait 5 seconds, send a message & logout
+                EsmeRestApi bgEsme = new EsmeRestApi(esmeServer);
+                bgEsme.login(token);
+                sleep(5000);
+                bgEsme.sendMsg(testMsg);
+                bgEsme.logout();
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            } catch (InterruptedException ex) {
+                ex.printStackTrace();
+            }
+
+        }
+    }
 }



Mime
View raw message