jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1156193 - /jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Date Wed, 10 Aug 2011 14:11:03 GMT
Author: mduerig
Date: Wed Aug 10 14:11:03 2011
New Revision: 1156193

URL: http://svn.apache.org/viewvc?rev=1156193&view=rev
Log:
spi2microkernel (WIP)
- test: observation

Modified:
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?rev=1156193&r1=1156192&r2=1156193&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Wed Aug 10 14:11:03 2011
@@ -1057,7 +1057,8 @@ public class RepositoryTest {
                 testPath + "/1/prop2",
                 testPath + "/1/jcr:primaryType",
                 testPath + "/2/jcr:primaryType",
-                testPath + "/3/jcr:primaryType");
+                testPath + "/3/jcr:primaryType",
+                testPath + "/3/prop3");
 
         final Set<String> setProperties = Arrays.toSet(
                 testPath + "/1/prop1");
@@ -1122,21 +1123,89 @@ public class RepositoryTest {
         getSession().save();
 
         n.setProperty("property", 42);
-        n.addNode("3");
+        n.addNode("3").setProperty("prop3", "val3");
         n1.setProperty("prop1", "val1 new");
         n1.getProperty("prop2").remove();
         n.getNode("2").remove();
         getSession().save();
 
         new Loop() { @Override public void test() {
+            assertTrue(failedEvents.isEmpty());
             assertTrue(addNodes.isEmpty());
             assertTrue(removeNodes.isEmpty());
             assertTrue(addProperties.isEmpty());
             assertTrue(removeProperties.isEmpty());
             assertTrue(setProperties.isEmpty());
-            assertTrue(failedEvents.isEmpty());
         }};
+    }
+
+    @Ignore  // todo fix in microkernel
+    @Test
+    public void observation2() throws RepositoryException {
+        final Set<String> addNodes = Arrays.toSet(
+                testPath + "/1",
+                testPath + "/2");
+
+        final Set<String> removeNodes = Arrays.toSet(
+                testPath + "/1");
+
+        final Set<String> addProperties = Arrays.toSet(
+                testPath + "/1/jcr:primaryType",
+                testPath + "/2/jcr:primaryType");
 
+
+        final List<Event> failedEvents = new ArrayList<Event>();
+
+        ObservationManager obsMgr = getSession().getWorkspace().getObservationManager();
+        obsMgr.setUserData("my user data");
+        obsMgr.addEventListener(new EventListener() {
+                public void onEvent(EventIterator events) {
+                    while (events.hasNext()) {
+                        Event event = events.nextEvent();
+                        try {
+                            switch (event.getType()) {
+                                case Event.NODE_ADDED:
+                                    if (!addNodes.remove(event.getPath())) {
+                                        failedEvents.add(event);
+                                    }
+                                    break;
+                                case Event.NODE_REMOVED:
+                                    if (!removeNodes.remove(event.getPath())) {
+                                        failedEvents.add(event);
+                                    }
+                                    break;
+                                case Event.PROPERTY_ADDED:
+                                    if (!addProperties.remove(event.getPath())) {
+                                        failedEvents.add(event);
+                                    }
+                                    break;
+                                default:
+                                    failedEvents.add(event);
+                            }
+                        }
+                        catch (RepositoryException e) {
+                            failedEvents.add(event);
+                        }
+                    }
+                }
+            },
+            Event.NODE_ADDED | Event.NODE_REMOVED | Event.NODE_MOVED | Event.PROPERTY_ADDED
|
+            Event.PROPERTY_REMOVED | Event.PROPERTY_CHANGED | Event.PERSIST, "/", true, null,
null, false);
+
+        Node n = getNode(testPath);
+        n.addNode("1");
+        getSession().save();
+
+        n.addNode("2");
+        n.getNode("1").remove();
+        getSession().save();
+
+        new Loop() { @Override public void test() {
+            assertTrue(failedEvents.isEmpty());
+            assertTrue(addNodes.isEmpty());
+            assertTrue(removeNodes.isEmpty());
+            assertTrue(addProperties.isEmpty());
+        }};
     }
 
     @Test



Mime
View raw message