servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r951564 - /servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/PollDirectoryTest.java
Date Fri, 04 Jun 2010 20:55:13 GMT
Author: gertv
Date: Fri Jun  4 20:55:12 2010
New Revision: 951564

URL: http://svn.apache.org/viewvc?rev=951564&view=rev
Log:
SMXCOMP-643: Testing that exchanges are being sent in the right order (instead of being received
in order)

Modified:
    servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/PollDirectoryTest.java

Modified: servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/PollDirectoryTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/PollDirectoryTest.java?rev=951564&r1=951563&r2=951564&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/PollDirectoryTest.java
(original)
+++ servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/PollDirectoryTest.java
Fri Jun  4 20:55:12 2010
@@ -22,15 +22,21 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.InOnly;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.NormalizedMessage;
 import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
 
 import org.apache.servicemix.client.DefaultServiceMixClient;
 import org.apache.servicemix.components.util.DefaultFileMarshaler;
+import org.apache.servicemix.jbi.event.ExchangeEvent;
+import org.apache.servicemix.jbi.event.ExchangeListener;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.tck.Receiver;
@@ -42,6 +48,7 @@ import org.springframework.context.suppo
 public class PollDirectoryTest extends SpringTestSupport {
 
     private static final int NUMBER = 10;
+    private static final SourceTransformer TRANSFORMER = new SourceTransformer();
     
     protected void setUp() throws Exception {
 	    FileUtil.deleteFile(new File("target/archive"));
@@ -103,8 +110,27 @@ public class PollDirectoryTest extends S
         numFiles = dir.listFiles().length;
         assertEquals("There shouldn't be any files in the poll folder...but I found " + numFiles
+ " files there..." , 0, numFiles);
     }
-    
+
+    /*
+     * Test to ensure that setting a comparator on the endpoints re-orders the exchanges
being sent
+     */
     public void testComparator() throws Exception {
+        // adding a listener to register the order in which exchanges are being sent
+        final List<MessageExchange> sent = new ArrayList<MessageExchange>();
+        jbi.addListener(new ExchangeListener() {
+
+            public void exchangeSent(ExchangeEvent exchangeEvent) {
+                MessageExchange exchange = exchangeEvent.getExchange();
+                if (exchange.getStatus() == ExchangeStatus.ACTIVE && "receiver3".equals(exchange.getService().getLocalPart()))
{
+                    sent.add(exchange);
+                }
+            }
+
+            public void exchangeAccepted(ExchangeEvent exchangeEvent) {
+                // we're not interested in this one
+            }
+        });
+
         // now lets make a request on this endpoint
         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
         
@@ -127,8 +153,10 @@ public class PollDirectoryTest extends S
         Receiver receiver = (Receiver) getBean("receiver3");
         receiver.getMessageList().waitForMessagesToArrive(2, 10000);
         receiver.getMessageList().assertMessagesReceived(2);
-        assertEquals(new SourceTransformer().toString(((NormalizedMessage)receiver.getMessageList().getMessages().get(0)).getContent()),
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><first>file</first>");
-        assertEquals(new SourceTransformer().toString(((NormalizedMessage)receiver.getMessageList().getMessages().get(1)).getContent()),
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><second>file</second>");
+        assertEquals(TRANSFORMER.toString(sent.get(0).getMessage("in").getContent()),
+                     "<?xml version=\"1.0\" encoding=\"UTF-8\"?><first>file</first>");
+        assertEquals(TRANSFORMER.toString(sent.get(1).getMessage("in").getContent()),
+                     "<?xml version=\"1.0\" encoding=\"UTF-8\"?><second>file</second>");
     }
 
     // Testing the "append=false" 



Mime
View raw message