From 10165c6fc8843f38b9484e5fd73032e7e7ecdf6a Mon Sep 17 00:00:00 2001
From: Herwin van Welbergen <hvanwelbergen@TechFak.Uni-Bielefeld.DE>
Date: Mon, 5 Mar 2012 12:33:32 +0100
Subject: [PATCH] added testcases, added converters to java versions

---
 .gitignore                                    |   1 +
 java/src/ipaaca/Initializer.java              |   9 +-
 java/src/ipaaca/LinkUpdateConverter.java      |  47 +++++
 java/src/ipaaca/LocalIU.java                  |   5 +-
 java/src/ipaaca/PayloadConverter.java         |  47 +++++
 ...ComponentCommunicationIntegrationTest.java |  35 +++-
 java/test/src/ipaaca/JavaPythonTest.java      | 165 ++++++++++++++----
 python/src/ipaaca.py                          |   3 +-
 python/test/ivy.xml                           |   3 +-
 python/test/src/testipaaca.py                 |  40 ++++-
 10 files changed, 302 insertions(+), 53 deletions(-)
 create mode 100644 java/src/ipaaca/LinkUpdateConverter.java
 create mode 100644 java/src/ipaaca/PayloadConverter.java

diff --git a/.gitignore b/.gitignore
index b3b54fa..a8e501f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@ java/dist
 java/privateprops
 java/.project
 java/.classpath
+*.pyc
 .project
 .classpath
 **/.*.swp
diff --git a/java/src/ipaaca/Initializer.java b/java/src/ipaaca/Initializer.java
index f293663..afe105e 100644
--- a/java/src/ipaaca/Initializer.java
+++ b/java/src/ipaaca/Initializer.java
@@ -27,14 +27,15 @@ public final class Initializer {
 	    DefaultConverterRepository.getDefaultConverterRepository().addConverter(new IntConverter());
 	    DefaultConverterRepository.getDefaultConverterRepository()
 		  .addConverter(new ProtocolBufferConverter<IUCommission>(IUCommission.getDefaultInstance()));
-	    DefaultConverterRepository.getDefaultConverterRepository()
-            .addConverter(new ProtocolBufferConverter<IUPayloadUpdate>(IUPayloadUpdate.getDefaultInstance()));
-	    DefaultConverterRepository.getDefaultConverterRepository()
-            .addConverter(new ProtocolBufferConverter<IULinkUpdate>(IULinkUpdate.getDefaultInstance()));
+	    
 	    DefaultConverterRepository.getDefaultConverterRepository().addConverter(
 	            new IUConverter(new ConverterSignature("ipaaca-iu", RemotePushIU.class)));
 	    DefaultConverterRepository.getDefaultConverterRepository().addConverter(
                 new IUConverter(new ConverterSignature("ipaaca-localiu", LocalIU.class)));
+	    DefaultConverterRepository.getDefaultConverterRepository().addConverter(
+                new PayloadConverter());
+	    DefaultConverterRepository.getDefaultConverterRepository().addConverter(
+                new LinkUpdateConverter());
 	    	    
 	}
 }
diff --git a/java/src/ipaaca/LinkUpdateConverter.java b/java/src/ipaaca/LinkUpdateConverter.java
new file mode 100644
index 0000000..fa506d0
--- /dev/null
+++ b/java/src/ipaaca/LinkUpdateConverter.java
@@ -0,0 +1,47 @@
+package ipaaca;
+
+import ipaaca.Ipaaca.IULinkUpdate;
+
+import java.nio.ByteBuffer;
+
+import rsb.converter.ConversionException;
+import rsb.converter.Converter;
+import rsb.converter.ConverterSignature;
+import rsb.converter.UserData;
+import rsb.converter.WireContents;
+
+import com.google.protobuf.InvalidProtocolBufferException;
+
+public class LinkUpdateConverter implements Converter<ByteBuffer>
+{
+    private static final String LINKUPDATE_WIRESCHEMA = "ipaaca-iu-link-update";
+
+    @Override
+    public UserData<?> deserialize(String wireSchema, ByteBuffer buffer) throws ConversionException
+    {
+        IULinkUpdate pl;
+        try
+        {
+            pl = IULinkUpdate.newBuilder().mergeFrom(buffer.array()).build();
+        }
+        catch (InvalidProtocolBufferException e)
+        {
+            throw new RuntimeException(e);
+        }
+        return new UserData<IULinkUpdate>(pl, IULinkUpdate.class);   
+    }
+
+    @Override
+    public ConverterSignature getSignature()
+    {
+        return new ConverterSignature(LINKUPDATE_WIRESCHEMA,IULinkUpdate.class);
+    }
+
+    @Override
+    public WireContents<ByteBuffer> serialize(Class<?> typeInfo, Object obj) throws ConversionException
+    {
+        IULinkUpdate pl = (IULinkUpdate)obj;
+        return new WireContents<ByteBuffer>(ByteBuffer.wrap(pl.toByteArray()),LINKUPDATE_WIRESCHEMA);        
+    }
+
+}
diff --git a/java/src/ipaaca/LocalIU.java b/java/src/ipaaca/LocalIU.java
index 5752c0b..a73d882 100644
--- a/java/src/ipaaca/LocalIU.java
+++ b/java/src/ipaaca/LocalIU.java
@@ -74,7 +74,10 @@ public class LocalIU extends AbstractIU
             {
                 increaseRevisionNumber();
                 committed = true;
-                outputBuffer.sendIUCommission(this, writerName);
+                if(outputBuffer!=null)
+                {    
+                    outputBuffer.sendIUCommission(this, writerName);                
+                }
             }
         }
     }
diff --git a/java/src/ipaaca/PayloadConverter.java b/java/src/ipaaca/PayloadConverter.java
new file mode 100644
index 0000000..6e32b40
--- /dev/null
+++ b/java/src/ipaaca/PayloadConverter.java
@@ -0,0 +1,47 @@
+package ipaaca;
+
+import ipaaca.Ipaaca.IUPayloadUpdate;
+
+import java.nio.ByteBuffer;
+
+import rsb.converter.ConversionException;
+import rsb.converter.Converter;
+import rsb.converter.ConverterSignature;
+import rsb.converter.UserData;
+import rsb.converter.WireContents;
+
+import com.google.protobuf.InvalidProtocolBufferException;
+
+public class PayloadConverter implements Converter<ByteBuffer>
+{
+    private static final String PAYLOAD_WIRESCHEMA = "ipaaca-iu-payload-update";
+
+    @Override
+    public UserData<?> deserialize(String wireSchema, ByteBuffer buffer) throws ConversionException
+    {
+        IUPayloadUpdate pl;
+        try
+        {
+            pl = IUPayloadUpdate.newBuilder().mergeFrom(buffer.array()).build();
+        }
+        catch (InvalidProtocolBufferException e)
+        {
+            throw new RuntimeException(e);
+        }
+        return new UserData<IUPayloadUpdate>(pl, IUPayloadUpdate.class);   
+    }
+
+    @Override
+    public ConverterSignature getSignature()
+    {
+        return new ConverterSignature(PAYLOAD_WIRESCHEMA,IUPayloadUpdate.class);
+    }
+
+    @Override
+    public WireContents<ByteBuffer> serialize(Class<?> typeInfo, Object obj) throws ConversionException
+    {
+        IUPayloadUpdate pl = (IUPayloadUpdate)obj;
+        return new WireContents<ByteBuffer>(ByteBuffer.wrap(pl.toByteArray()),PAYLOAD_WIRESCHEMA);        
+    }
+
+}
diff --git a/java/test/src/ipaaca/ComponentCommunicationIntegrationTest.java b/java/test/src/ipaaca/ComponentCommunicationIntegrationTest.java
index cb05c0e..3041995 100644
--- a/java/test/src/ipaaca/ComponentCommunicationIntegrationTest.java
+++ b/java/test/src/ipaaca/ComponentCommunicationIntegrationTest.java
@@ -109,8 +109,7 @@ public class ComponentCommunicationIntegrationTest
         localIU = new LocalIU();
         localIU.setCategory(CATEGORY);
         localIU.getPayload().put("key1", "item1");
-        localIU.addLinks("INIT", ImmutableSet.of("init1","init2"));
-        outBuffer.add(localIU);
+        localIU.addLinks("INIT", ImmutableSet.of("init1","init2"));        
     }
     
     @After
@@ -123,6 +122,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testAddedIU() throws InterruptedException
     {
+        outBuffer.add(localIU);
         Thread.sleep(200);        
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         assertNotNull(iuIn);
@@ -130,11 +130,12 @@ public class ComponentCommunicationIntegrationTest
         assertThat(localIU.getLinks("INIT"),containsInAnyOrder("init1","init2"));
         assertEquals(1,component2EventHandler.getNumberOfAddEvents(iuIn.getUid()));
         assertEquals(0,component1EventHandler.getNumberOfAddEvents(localIU.getUid()));
-    }
+    }    
     
     @Test
     public void testIUCommit() throws InterruptedException
     {
+        outBuffer.add(localIU);
         localIU.commit();
         Thread.sleep(200);
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
@@ -143,9 +144,22 @@ public class ComponentCommunicationIntegrationTest
         assertEquals(1,component2EventHandler.getNumberOfCommitEvents(iuIn.getUid()));        
     }
     
+    @Test
+    public void testIUCommitBeforePublish() throws InterruptedException
+    {
+        localIU.commit();
+        outBuffer.add(localIU);        
+        Thread.sleep(200);
+        AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
+        assertTrue(iuIn.isCommitted());
+        assertEquals(0,component1EventHandler.getNumberOfCommitEvents(localIU.getUid()));
+        assertEquals(0,component2EventHandler.getNumberOfCommitEvents(iuIn.getUid()));        
+    }
+    
     @Test
     public void testIUCommitFromInputBuffer() throws InterruptedException
     {
+        outBuffer.add(localIU);
         Thread.sleep(200);
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         
@@ -160,6 +174,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testIUUpdate() throws InterruptedException
     {
+        outBuffer.add(localIU);
         Thread.sleep(200);        
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         assertNull(iuIn.getPayload().get("key2"));
@@ -174,6 +189,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testSetPayload() throws InterruptedException
     {
+        outBuffer.add(localIU);
         Thread.sleep(200);        
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         
@@ -191,6 +207,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testSetPayloadRemote() throws InterruptedException
     {
+        outBuffer.add(localIU);
         Thread.sleep(200);        
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         
@@ -208,6 +225,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testIUUpdateFromInputBuffer() throws InterruptedException
     {
+        outBuffer.add(localIU);
         Thread.sleep(200);        
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         
@@ -222,6 +240,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testIUpdateRemove() throws InterruptedException
     {   
+        outBuffer.add(localIU);
         Thread.sleep(200);    
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         assertEquals("item1",iuIn.getPayload().get("key1"));
@@ -236,6 +255,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testIUpdateRemoveFromInputBuffer() throws InterruptedException
     {   
+        outBuffer.add(localIU);
         Thread.sleep(200);    
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         assertEquals("item1",iuIn.getPayload().get("key1"));
@@ -250,6 +270,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testSetLinksLocal() throws InterruptedException
     {
+        outBuffer.add(localIU);
         Thread.sleep(200);
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         localIU.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6"));        
@@ -261,6 +282,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testSetLinksRemote() throws InterruptedException
     {
+        outBuffer.add(localIU);
         Thread.sleep(200);
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         iuIn.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6"));        
@@ -272,6 +294,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testSetLinksRemoteOverwrite() throws InterruptedException
     {
+        outBuffer.add(localIU);
         Thread.sleep(200);
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         localIU.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6"));        
@@ -288,6 +311,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testAddLinksLocal() throws InterruptedException
     {
+        outBuffer.add(localIU);
         Thread.sleep(200);
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         localIU.setLinks("SAME_LEVEL",ImmutableSet.of("iu4"));
@@ -300,6 +324,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testAddLinksRemote() throws InterruptedException
     {
+        outBuffer.add(localIU);
         Thread.sleep(200);
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         iuIn.addLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6"));        
@@ -311,6 +336,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testRemoveLinksLocal() throws InterruptedException
     {
+        outBuffer.add(localIU);
         Thread.sleep(200);   
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         localIU.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6","iu7"));
@@ -323,6 +349,7 @@ public class ComponentCommunicationIntegrationTest
     @Test
     public void testRemoveLinksRemote() throws InterruptedException
     {
+        outBuffer.add(localIU);
         Thread.sleep(200);   
         AbstractIU iuIn = inBuffer.getIU(localIU.getUid());
         iuIn.setLinks("SAME_LEVEL",ImmutableSet.of("iu5","iu6","iu7"));
@@ -331,4 +358,6 @@ public class ComponentCommunicationIntegrationTest
         assertThat(localIU.getLinks("SAME_LEVEL"),containsInAnyOrder("iu7"));
         assertThat(iuIn.getLinks("SAME_LEVEL"),containsInAnyOrder("iu7"));
     }
+    
+    
 }
diff --git a/java/test/src/ipaaca/JavaPythonTest.java b/java/test/src/ipaaca/JavaPythonTest.java
index 22f1423..18e6150 100644
--- a/java/test/src/ipaaca/JavaPythonTest.java
+++ b/java/test/src/ipaaca/JavaPythonTest.java
@@ -1,6 +1,7 @@
 package ipaaca;
 
-import static org.junit.Assert.assertEquals;
+import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
+import static org.junit.Assert.*;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedReader;
@@ -14,24 +15,31 @@ import org.junit.Test;
 
 import com.google.common.collect.ImmutableSet;
 
-public class JavaPythonTest {
-	
-    static {
+public class JavaPythonTest
+{
+
+    static
+    {
         Initializer.initializeIpaacaRsb();
     }
 
     private InputBuffer inBuffer;
 
-	@Before
+    private static final String PYTHON_PREAMBLE = "import sys\n" 
+            + "sys.path.insert(0, '../python/build/')\n"
+            + "sys.path.insert(0, '../python/lib/')\n" 
+            + "import ipaaca, time\n";
+
+    @Before
     public void setup()
     {
-        Set<String> categories = new ImmutableSet.Builder<String>().add("JavaPythonTest").build();        
+        Set<String> categories = new ImmutableSet.Builder<String>().add("JavaPythonTest").build();
         inBuffer = new InputBuffer("javaside", categories);
     }
-    
-	private void printRuntimeErrors(Process p) throws IOException
-	{
-	    
+
+    private void printRuntimeErrors(Process p) throws IOException
+    {
+
         InputStream in = p.getInputStream();
         BufferedInputStream buf = new BufferedInputStream(in);
         InputStreamReader inread = new InputStreamReader(buf);
@@ -64,29 +72,116 @@ public class JavaPythonTest {
         {
             System.out.println(line);
         }
-	}
-	
-	@Test
-	public void test() throws IOException, InterruptedException {
-		
-		String pypr = 
-		"import sys\n" +
-		"sys.path.insert(0, '../python/build/')\n" +
-		"sys.path.insert(0, '../python/lib/')\n" +
-		"import ipaaca, time\n" +
-		"ob = ipaaca.OutputBuffer('pythonside')\n" + 
-		"iu = ipaaca.IU('JavaPythonTest')\n" +
-		"iu.payload = {'data':'Hello from Python!'}\n" +
-		"time.sleep(0.1)\n" +
-		"ob.add(iu)";
-		Process p = Runtime.getRuntime().exec(new String[]{"python","-c", pypr});
-		printRuntimeErrors(p);
-		
-		Thread.sleep(200);
-		assertEquals(1, inBuffer.getIUs().size());
-		AbstractIU iu = inBuffer.getIUs().iterator().next();
-		assertEquals("Hello from Python!",iu.getPayload().get("data"));
-	}
-	
-	
+    }
+
+    private boolean runPythonProgram(String pypr) throws IOException
+    {
+        Process p = Runtime.getRuntime().exec(new String[] { "python", "-c", pypr });
+        printRuntimeErrors(p);
+        return p.exitValue()==0;
+    }
+
+    @Test
+    public void testSetPayloadInPythonOutputBuffer() throws IOException, InterruptedException
+    {
+
+        String pypr = PYTHON_PREAMBLE 
+                + "ob = ipaaca.OutputBuffer('pythonside')\n" 
+                + "iu = ipaaca.IU('JavaPythonTest')\n"
+                + "iu.payload = {'data':'Hello from Python!'}\n" 
+                + "time.sleep(0.1)\n" 
+                + "ob.add(iu)\n";
+        assertTrue(runPythonProgram(pypr));
+
+        Thread.sleep(200);
+        assertEquals(1, inBuffer.getIUs().size());
+        AbstractIU iu = inBuffer.getIUs().iterator().next();
+        assertEquals("Hello from Python!", iu.getPayload().get("data"));
+    }
+    
+    @Test
+    public void testSetPayloadInPythonOutputBufferAfterPublishing() throws IOException, InterruptedException
+    {
+
+        String pypr = PYTHON_PREAMBLE 
+                + "ob = ipaaca.OutputBuffer('pythonside')\n" 
+                + "iu = ipaaca.IU('JavaPythonTest')\n"                
+                + "ob.add(iu)\n"
+                + "time.sleep(0.1)\n"
+                + "iu.payload = {'data':'Hello from Python!'}\n";
+                
+        assertTrue(runPythonProgram(pypr));
+
+        Thread.sleep(200);
+        assertEquals(1, inBuffer.getIUs().size());
+        AbstractIU iu = inBuffer.getIUs().iterator().next();
+        assertEquals("Hello from Python!", iu.getPayload().get("data"));
+    }
+    
+    @Test
+    public void testAddLinkThenPublishInPython() throws IOException, InterruptedException
+    {
+        String pypr = PYTHON_PREAMBLE 
+                +"ob = ipaaca.OutputBuffer('pythonside')\n"
+                +"iu = ipaaca.IU('JavaPythonTest')\n"
+                +"iu.add_links('testtype',['dummy1','dummy2'])\n"
+                + "time.sleep(0.1)\n" 
+                + "ob.add(iu)\n";
+        assertTrue(runPythonProgram(pypr));
+        Thread.sleep(200);
+        assertEquals(1, inBuffer.getIUs().size());
+        AbstractIU iu = inBuffer.getIUs().iterator().next();
+        assertThat(iu.getLinks("testtype"),containsInAnyOrder("dummy1","dummy2"));       
+        
+    }
+    
+    @Test
+    public void testPublishThenAddLinkInPython() throws IOException, InterruptedException
+    {
+        String pypr = PYTHON_PREAMBLE 
+                +"ob = ipaaca.OutputBuffer('pythonside')\n"
+                +"iu = ipaaca.IU('JavaPythonTest')\n"
+                + "ob.add(iu)\n"
+                + "time.sleep(0.1)\n"        
+                +"iu.add_links('testtype',['dummy1','dummy2'])\n";
+                
+        assertTrue(runPythonProgram(pypr));
+        Thread.sleep(200);
+        assertEquals(1, inBuffer.getIUs().size());
+        AbstractIU iu = inBuffer.getIUs().iterator().next();
+        assertThat(iu.getLinks("testtype"),containsInAnyOrder("dummy1","dummy2"));        
+    }
+    
+    @Test
+    public void testCommitPublishedIUFromPython()throws IOException, InterruptedException
+    {
+        String pypr = PYTHON_PREAMBLE 
+                +"ob = ipaaca.OutputBuffer('pythonside')\n"
+                +"iu = ipaaca.IU('JavaPythonTest')\n"
+                + "ob.add(iu)\n"
+                + "time.sleep(0.1)\n"
+                + "iu.commit()\n";
+        assertTrue(runPythonProgram(pypr));
+        Thread.sleep(200);
+        assertEquals(1, inBuffer.getIUs().size());
+        AbstractIU iu = inBuffer.getIUs().iterator().next();
+        assertTrue(iu.isCommitted());
+    }
+    
+    @Test
+    public void testCommitThenPublishIUFromPython()throws IOException, InterruptedException
+    {
+        String pypr = PYTHON_PREAMBLE 
+                +"ob = ipaaca.OutputBuffer('pythonside')\n"
+                +"iu = ipaaca.IU('JavaPythonTest')\n"
+                +"iu.commit()\n"
+                +"time.sleep(0.1)\n"
+                +"ob.add(iu)\n";
+                
+        assertTrue(runPythonProgram(pypr));
+        Thread.sleep(200);
+        assertEquals(1, inBuffer.getIUs().size());
+        AbstractIU iu = inBuffer.getIUs().iterator().next();
+        assertTrue(iu.isCommitted());
+    }
 }
diff --git a/python/src/ipaaca.py b/python/src/ipaaca.py
index 05431e8..32140e6 100755
--- a/python/src/ipaaca.py
+++ b/python/src/ipaaca.py
@@ -342,7 +342,8 @@ class IU(IUInterface):#{{{
 			if not self._committed:
 				self._increase_revision_number()
 				self._committed = True
-				self.buffer._send_iu_commission(self, writer_name=writer_name)
+				if self.buffer is not None:
+					self.buffer._send_iu_commission(self, writer_name=writer_name)
 	
 	def commit(self):
 		"""Commit to this IU."""
diff --git a/python/test/ivy.xml b/python/test/ivy.xml
index ffd2a4a..139b8ef 100644
--- a/python/test/ivy.xml
+++ b/python/test/ivy.xml
@@ -1,5 +1,6 @@
 <ivy-module version="2.0">
    <info organisation="ipaaca" module="IpaacaPythonTest"/>
-   <dependencies >
+   <dependencies>
+	<dependency org="hamcrest" name="hamcrest" rev="latest.release"/>
    </dependencies>
 </ivy-module>
diff --git a/python/test/src/testipaaca.py b/python/test/src/testipaaca.py
index 0c8de8b..b304c14 100755
--- a/python/test/src/testipaaca.py
+++ b/python/test/src/testipaaca.py
@@ -1,11 +1,12 @@
 #!/usr/bin/env python
 
+import sys
 import time
+import unittest
+
+import hamcrest as hc
 import ipaaca
-import sys
 
-import unittest
-	
 def handle_iu_event(iu, event_type, local):
 	print('(IU event '+event_type+' '+str(iu.uid)+')')
 
@@ -22,10 +23,10 @@ class IpaacaIUStoreTestCase(unittest.TestCase):
 	def tearDown(self):
 		pass
 	def testInputBufferContents(self):
-		self.assertIn(self.sensor_iu.uid, self.ib.iu_store)
+		hc.assert_that(self.ib.iu_store, hc.has_key(self.sensor_iu.uid))
 		self.assertEqual(len(self.ib.iu_store), 1)
 	def testOutputBufferContents(self):
-		self.assertIn(self.sensor_iu.uid, self.ob.iu_store)
+		hc.assert_that(self.ib.iu_store, hc.has_key(self.sensor_iu.uid))
 		self.assertEqual(len(self.ob.iu_store), 1)
 
 class IpaacaPayloadTestCase(unittest.TestCase):
@@ -41,6 +42,29 @@ class IpaacaPayloadTestCase(unittest.TestCase):
 		iu_received = self.ib.iu_store.get(self.sensor_iu.uid)
 		self.assertEqual(iu_received.payload["data"], 'sensordata')
 
+
+class IpaacaCommitTestCases(unittest.TestCase):
+
+	def setUp(self):
+		self.ib = ipaaca.InputBuffer('TestIn', ['sensorcategory'])
+		self.ob = ipaaca.OutputBuffer('TestOut')
+		self.iu = ipaaca.IU('sensorcategory')
+
+	def testCommitBeforePublish(self):
+		self.iu.commit()
+		self.ob.add(self.iu)
+		time.sleep(0.1)
+		received_iu = self.ib.iu_store[self.iu.uid]
+		self.assertTrue(received_iu.committed)
+
+	def testCommitAfterPublish(self):
+		self.ob.add(self.iu)
+		self.iu.commit()
+		time.sleep(0.1)
+		received_iu = self.ib.iu_store[self.iu.uid]
+		self.assertTrue(received_iu.committed)
+
+
 class IpaacaLinksTestCase(unittest.TestCase):
 	def setUp(self):
 		self.ib = ipaaca.InputBuffer('TestIn', ['sensorcategory', 'decisioncategory'])
@@ -58,10 +82,10 @@ class IpaacaLinksTestCase(unittest.TestCase):
 		self.ob.add(self.decision_iu)
 		time.sleep(0.1)
 		# test received version
-		self.assertIn(self.decision_iu.uid, self.ib.iu_store)
+		hc.assert_that(self.ib.iu_store, hc.has_key(self.decision_iu.uid))
 		received_iu = self.ib.iu_store[self.decision_iu.uid]
 		grinlinks = received_iu.get_links('grin')
-		self.assertIn(self.sensor_iu.uid, grinlinks)
+		hc.assert_that(grinlinks, hc.has_item(self.sensor_iu.uid))
 		self.assertEqual(len(grinlinks), 1)
 	def testSetAndRemoveSingleLink(self):
 		time.sleep(0.1)
@@ -73,7 +97,7 @@ class IpaacaLinksTestCase(unittest.TestCase):
 		self.decision_iu.remove_links('grin', [self.sensor_iu.uid])
 		time.sleep(0.1)
 		# test received version
-		self.assertIn(self.decision_iu.uid, self.ib.iu_store)
+		hc.assert_that(self.ib.iu_store, hc.has_key(self.decision_iu.uid))
 		received_iu = self.ib.iu_store[self.decision_iu.uid]
 		grinlinks = received_iu.get_links('grin')
 		self.assertEqual(len(grinlinks), 0)
-- 
GitLab