You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2014/10/10 22:25:33 UTC
svn commit: r1630975 - in /sling/trunk/tooling/ide/eclipse-test:
META-INF/MANIFEST.MF
src/org/apache/sling/ide/test/impl/helpers/FailOnModificationEventsRule.java
Author: rombert
Date: Fri Oct 10 20:25:33 2014
New Revision: 1630975
URL: http://svn.apache.org/r1630975
Log:
SLING-4020 - Importing content from the repository triggers publish
operations
Added a FailOnModificationEventsRule which fails tests when modification
events are received.
Added:
sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/FailOnModificationEventsRule.java
Modified:
sling/trunk/tooling/ide/eclipse-test/META-INF/MANIFEST.MF
Modified: sling/trunk/tooling/ide/eclipse-test/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/META-INF/MANIFEST.MF?rev=1630975&r1=1630974&r2=1630975&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/eclipse-test/META-INF/MANIFEST.MF Fri Oct 10 20:25:33 2014
@@ -26,6 +26,7 @@ Require-Bundle: org.junit,
Import-Package: javax.jcr,
javax.jcr.nodetype,
org.apache.jackrabbit.util,
- org.apache.sling.ide.jcr
+ org.apache.sling.ide.jcr,
+ org.osgi.service.event;version="1.3.0"
Bundle-Activator: org.apache.sling.ide.test.impl.Activator
Bundle-ActivationPolicy: lazy
Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/FailOnModificationEventsRule.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/FailOnModificationEventsRule.java?rev=1630975&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/FailOnModificationEventsRule.java (added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/FailOnModificationEventsRule.java Fri Oct 10 20:25:33 2014
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.test.impl.helpers;
+
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.sling.ide.eclipse.core.internal.Activator;
+import org.apache.sling.ide.transport.CommandExecutionProperties;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventHandler;
+
+/**
+ * The <tt>FailOnModificationEventsRule</tt> registers an event listener and fails the test under execution if
+ * modification events are fired, whether they are successful or not
+ *
+ */
+public class FailOnModificationEventsRule implements EventHandler, TestRule {
+
+ private ServiceRegistration<EventHandler> registration;
+ private List<Event> unexpectedEvents = new ArrayList<Event>();
+
+ public Statement apply(Statement base, Description description) {
+ return statement(base);
+ }
+
+ private Statement statement(final Statement base) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ before();
+ try {
+ base.evaluate();
+ } finally {
+ after();
+ }
+ }
+ };
+ }
+
+ protected void before() {
+
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put("event.topics", "org/apache/sling/ide/transport");
+ registration = Activator.getDefault().getBundle().getBundleContext()
+ .registerService(EventHandler.class, this, props);
+
+ }
+
+ protected void after() {
+
+ if (registration != null) {
+ registration.unregister();
+ }
+
+ if (unexpectedEvents.isEmpty()) {
+ return;
+ }
+
+ StringBuilder desc = new StringBuilder();
+ desc.append("Unexpected events captured during import : ");
+ for (Event event : unexpectedEvents) {
+ desc.append('\n');
+ desc.append(event.getProperty(CommandExecutionProperties.ACTION_TYPE));
+ desc.append(" -> ");
+ desc.append(event.getProperty(CommandExecutionProperties.ACTION_TARGET));
+ desc.append(" : ");
+ desc.append(event.getProperty(CommandExecutionProperties.RESULT_TEXT));
+ }
+
+ fail(desc.toString());
+ }
+
+ @Override
+ public void handleEvent(Event event) {
+
+ String type = (String) event.getProperty(CommandExecutionProperties.ACTION_TYPE);
+
+ if ("AddOrUpdateNodeCommand".equals(type) || "ReorderChildNodesCommand".equals(type)) {
+ unexpectedEvents.add(event);
+ }
+ }
+
+}
\ No newline at end of file