incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r590082 - in /incubator/sling/trunk/event/src: main/java/org/apache/sling/event/impl/DistributingEventHandler.java test/java/org/apache/sling/event/impl/DistributingEventHandlerTest.java
Date Tue, 30 Oct 2007 14:30:56 GMT
Author: cziegeler
Date: Tue Oct 30 07:30:53 2007
New Revision: 590082

URL: http://svn.apache.org/viewvc?rev=590082&view=rev
Log:
Test writeEvent method.

Modified:
    incubator/sling/trunk/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java
    incubator/sling/trunk/event/src/test/java/org/apache/sling/event/impl/DistributingEventHandlerTest.java

Modified: incubator/sling/trunk/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java?rev=590082&r1=590081&r2=590082&view=diff
==============================================================================
--- incubator/sling/trunk/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java
(original)
+++ incubator/sling/trunk/event/src/main/java/org/apache/sling/event/impl/DistributingEventHandler.java
Tue Oct 30 07:30:53 2007
@@ -44,7 +44,7 @@
     extends AbstractRepositoryEventHandler {
 
     /**
-     * @see org.apache.sling.core.event.impl.JobPersistenceHandler#cleanUpRepository()
+     * @see org.apache.sling.event.impl.AbstractRepositoryEventHandler#cleanUpRepository()
      */
     protected void cleanUpRepository() {
         // we create an own session for concurrency issues
@@ -147,7 +147,7 @@
     }
 
     /**
-     * @see org.apache.sling.core.event.impl.JobPersistenceHandler#addEventProperties(Node,
java.util.Dictionary)
+     * @see org.apache.sling.event.impl.AbstractRepositoryEventHandler#addEventProperties(javax.jcr.Node,
java.util.Dictionary)
      */
     protected void addEventProperties(Node eventNode, Dictionary<String, Object> properties)
     throws RepositoryException {

Modified: incubator/sling/trunk/event/src/test/java/org/apache/sling/event/impl/DistributingEventHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/event/src/test/java/org/apache/sling/event/impl/DistributingEventHandlerTest.java?rev=590082&r1=590081&r2=590082&view=diff
==============================================================================
--- incubator/sling/trunk/event/src/test/java/org/apache/sling/event/impl/DistributingEventHandlerTest.java
(original)
+++ incubator/sling/trunk/event/src/test/java/org/apache/sling/event/impl/DistributingEventHandlerTest.java
Tue Oct 30 07:30:53 2007
@@ -18,10 +18,21 @@
  */
 package org.apache.sling.event.impl;
 
+import static org.junit.Assert.*;
+
+import java.util.Calendar;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+
+import org.apache.sling.event.EventUtil;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
 import org.jmock.integration.junit4.JUnit4Mockery;
 import org.junit.runner.RunWith;
+import org.osgi.service.event.Event;
 
 @RunWith(JMock.class)
 public class DistributingEventHandlerTest extends AbstractRepositoryEventHandlerTest {
@@ -38,5 +49,43 @@
         return this.context;
     }
 
+    @org.junit.Test public void testWriteEvent() throws Exception {
+        final String topic = "write/event/test";
+        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("a property", "some value");
+        final Event e = new Event(topic, props);
+        this.handler.writeEvent(e);
+
+        final Node rootNode = (Node) session.getItem(this.handler.repositoryPath);
+        final NodeIterator iter = rootNode.getNodes();
+        iter.hasNext();
+        final Node eventNode = iter.nextNode();
+        assertEquals(topic, eventNode.getProperty(EventHelper.NODE_PROPERTY_TOPIC).getString());
+        assertEquals(handler.applicationId, eventNode.getProperty(EventHelper.NODE_PROPERTY_APPLICATION).getString());
+        assertTrue(Calendar.getInstance().compareTo(eventNode.getProperty(EventHelper.NODE_PROPERTY_CREATED).getDate())
>= 0);
+        // as a starting point we just check if the properties property exists
+        assertTrue(eventNode.hasProperty(EventHelper.NODE_PROPERTY_PROPERTIES));
+
+        // now we remove the node to have a clean repo
+        eventNode.remove();
+        rootNode.save();
+    }
 
+    @org.junit.Test public void testWriteEventPlusAppId() throws Exception {
+        final String topic = "write/event/test";
+        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("a property", "some value");
+        // now we check if the application id is handled correctly
+        props.put(EventUtil.PROPERTY_APPLICATION, "foo");
+        this.handler.writeEvent(new Event(topic, props));
+        final Node rootNode = (Node) session.getItem(this.handler.repositoryPath);
+        final NodeIterator iter = rootNode.getNodes();
+        iter.hasNext();
+        final Node eventNode = iter.nextNode();
+        assertEquals(topic, eventNode.getProperty(EventHelper.NODE_PROPERTY_TOPIC).getString());
+        assertEquals(handler.applicationId, eventNode.getProperty(EventHelper.NODE_PROPERTY_APPLICATION).getString());
+        assertTrue(Calendar.getInstance().compareTo(eventNode.getProperty(EventHelper.NODE_PROPERTY_CREATED).getDate())
>= 0);
+        // as a starting point we just check if the properties property exists
+        assertTrue(eventNode.hasProperty(EventHelper.NODE_PROPERTY_PROPERTIES));
+    }
 }



Mime
View raw message