Author: elvisisking
Date: 2009-12-04 15:37:26 -0500 (Fri, 04 Dec 2009)
New Revision: 1405
Added:
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTypeManagerTest.java
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeManager.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrObservationManager.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrObservationManagerTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
Log:
DNA 570 JcrObservationManager's Logic For Filtering Events Based On Node Types Is
Incorrect
DNA 571 JcrObservationManager's Logic For Filtering Events Based On Path Is Incorrect
For Property Events
Changed the logic in JcrObservationManager to use the node's path, not the node's
parent path, when handling property events. Changed
JcrNodeTypeManager.isDerivedFrom(String[], String, String[]) to check the collection or
one or more given types to see if equal to or derived from the primary type or one of the
mixins of the Event node. Uncommented the appropriate tests in JcrObservationManagerTest
and JcrTckTest so that they now run.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeManager.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeManager.java 2009-12-04
20:33:42 UTC (rev 1404)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNodeTypeManager.java 2009-12-04
20:37:26 UTC (rev 1405)
@@ -567,30 +567,30 @@
}
/**
- * Determine whether the primary type or mixins are directly or indirectly derived
from a node type with one of the supplied
- * names.
+ * Determine if any of the test type names are equal to or have been derived from the
primary type or any of the mixins.
*
- * @param primaryTypeName the primary type being checked (never
<code>null</code>)
- * @param mixinNames the mixins being checked (may be <code>null</code>)
- * @param superTypeNames the names of the node types the primary type and mixins are
tested against (never <code>null</code>)
- * @return <code>true</code> if the primary type or one of the mixins are
derived from one of the type names
+ * @param testTypeNames the names of the types or mixins being tested against (never
<code>null</code>)
+ * @param primaryTypeName the primary type name (never
<code>null</code>)
+ * @param mixinNames the mixin names (may be <code>null</code>)
+ * @return <code>true</code> if at least one test type name is equal to
or derived from the primary type or one of the mixins
* @throws RepositoryException if there is an exception obtaining node types
- * @throws IllegalArgumentException if <code>primaryTypeProperty</code>
is <code>null</code>
+ * @throws IllegalArgumentException if <code>testTypeNames</code> is
<code>null</code> or empty or if
+ * <code>primaryTypeName</code> is <code>null</code>
or zero length
*/
- public boolean isDerivedFrom( String primaryTypeName,
- String[] mixinNames,
- String[] superTypeNames ) throws RepositoryException {
- CheckArg.isNotNull(primaryTypeName, "primaryTypeName");
- CheckArg.isNotNull(superTypeNames, "superTypeNames");
+ public boolean isDerivedFrom( String[] testTypeNames,
+ String primaryTypeName,
+ String[] mixinNames ) throws RepositoryException {
+ CheckArg.isNotEmpty(testTypeNames, "testTypeNames");
+ CheckArg.isNotEmpty(primaryTypeName, "primaryTypeName");
NameFactory nameFactory = context().getValueFactories().getNameFactory();
- Name[] typeNames = nameFactory.create(superTypeNames);
+ Name[] typeNames = nameFactory.create(testTypeNames);
// first check primary type
- JcrNodeType primaryType = getNodeType(primaryTypeName);
+ for (Name typeName : typeNames) {
+ JcrNodeType nodeType = getNodeType(typeName);
- for (Name typeName : typeNames) {
- if (primaryType.isNodeType(typeName)) {
+ if ((nodeType != null) && nodeType.isNodeType(primaryTypeName)) {
return true;
}
}
@@ -598,10 +598,10 @@
// now check mixins
if (mixinNames != null) {
for (String mixin : mixinNames) {
- JcrNodeType mixinType = getNodeType(mixin);
+ for (Name typeName : typeNames) {
+ JcrNodeType nodeType = getNodeType(typeName);
- for (Name typeName : typeNames) {
- if (mixinType.isNodeType(typeName)) {
+ if ((nodeType != null) && nodeType.isNodeType(mixin)) {
return true;
}
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrObservationManager.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrObservationManager.java 2009-12-04
20:33:42 UTC (rev 1404)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrObservationManager.java 2009-12-04
20:37:26 UTC (rev 1405)
@@ -563,7 +563,7 @@
mixinNames =
stringFactory.create(propMap.get(MIXIN_TYPES).getValuesAsArray());
}
- return getNodeTypeManager().isDerivedFrom(primaryTypeName,
mixinNames, this.nodeTypeNames);
+ return getNodeTypeManager().isDerivedFrom(this.nodeTypeNames,
primaryTypeName, mixinNames);
} catch (RepositoryException e) {
accept = false;
Logger.getLogger(getClass()).error(e,
@@ -584,12 +584,19 @@
private boolean acceptBasedOnPath( NetChange change ) {
if ((this.absPath != null) && (this.absPath.length() != 0)) {
Path matchPath =
getValueFactories().getPathFactory().create(this.absPath);
+ Path changePath = null;
+
+ if (change.includes(ChangeType.NODE_ADDED, ChangeType.NODE_REMOVED)) {
+ changePath = change.getPath().getParent();
+ } else {
+ changePath = change.getPath();
+ }
if (this.isDeep) {
- return matchPath.isAtOrAbove(change.getPath().getParent());
+ return matchPath.isAtOrAbove(changePath);
}
- return matchPath.equals(change.getPath().getParent());
+ return matchPath.equals(changePath);
}
return true;
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTypeManagerTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTypeManagerTest.java
(rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTypeManagerTest.java 2009-12-04
20:37:26 UTC (rev 1405)
@@ -0,0 +1,182 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import javax.jcr.Credentials;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import junit.framework.TestSuite;
+import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
+import org.jboss.dna.jcr.JcrRepository.Option;
+import org.jboss.security.config.IDTrustConfiguration;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * The {@link JcrNodeTypeManager} test class.
+ */
+public final class JcrNodeTypeManagerTest extends TestSuite {
+
+ //
===========================================================================================================================
+ // Constants
+ //
===========================================================================================================================
+
+ private static final String MIXIN1 = "mix:lockable";
+ private static final String MIXIN2 = "mix:referenceable";
+ private static final String[] MIXINS = new String[] {MIXIN1, MIXIN2};
+
+ private static final String HIERARCHY_NODE_TYPE = "nt:hierarchyNode";
+
+ private static final String SUBTYPE1 = "nt:folder"; // subtype of
HIERARCHY_NODE_TYPE
+ private static final String SUBTYPE2 = "nt:file"; // subtype of
HIERARCHY_NODE_TYPE
+ private static final String[] SUBTYPES = new String[] {SUBTYPE1, SUBTYPE2};
+
+ private static final String NO_MATCH_TYPE = "nt:query";
+
+ private static final String[] SUBTYPES_MIXINS;
+
+ static {
+ SUBTYPES_MIXINS = new String[SUBTYPES.length + MIXINS.length];
+ System.arraycopy(SUBTYPES, 0, SUBTYPES_MIXINS, 0, SUBTYPES.length);
+ System.arraycopy(MIXINS, 0, SUBTYPES_MIXINS, SUBTYPES.length, MIXINS.length);
+ }
+
+ //
===========================================================================================================================
+ // Class Methods
+ //
===========================================================================================================================
+
+ @BeforeClass
+ public static void beforeClass() {
+ // Initialize IDTrust
+ String configFile = "security/jaas.conf.xml";
+ IDTrustConfiguration idtrustConfig = new IDTrustConfiguration();
+
+ try {
+ idtrustConfig.config(configFile);
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex);
+ }
+ }
+
+ //
===========================================================================================================================
+ // Fields
+ //
===========================================================================================================================
+
+ private JcrEngine engine;
+ private Session session;
+ private JcrNodeTypeManager nodeTypeMgr;
+
+ //
===========================================================================================================================
+ // Methods
+ //
===========================================================================================================================
+
+ @After
+ public void afterEach() {
+ try {
+ if (this.session != null) {
+ this.session.logout();
+ }
+ } finally {
+ this.session = null;
+
+ try {
+ this.engine.shutdown();
+ } finally {
+ this.engine = null;
+ }
+ }
+ }
+
+ @Before
+ public void beforeEach() throws RepositoryException {
+ final String WORKSPACE = "ws1";
+ final String REPOSITORY = "r1";
+ final String SOURCE = "store";
+
+ JcrConfiguration config = new JcrConfiguration();
+
config.repositorySource("store").usingClass(InMemoryRepositorySource.class).setRetryLimit(100).setProperty("defaultWorkspaceName",
+
WORKSPACE);
+
config.repository(REPOSITORY).setSource(SOURCE).setOption(Option.JAAS_LOGIN_CONFIG_NAME,
"dna-jcr");
+ config.save();
+
+ // Create and start the engine ...
+ this.engine = config.build();
+ this.engine.start();
+
+ // Create repository and session
+ Repository repository = this.engine.getRepository(REPOSITORY);
+ final String USER_ID = "superuser";
+ Credentials credentials = new SimpleCredentials(USER_ID, USER_ID.toCharArray());
+ this.session = repository.login(credentials, WORKSPACE);
+ this.nodeTypeMgr =
(JcrNodeTypeManager)this.session.getWorkspace().getNodeTypeManager();
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNullSubTypeNames() throws RepositoryException {
+ this.nodeTypeMgr.isDerivedFrom(null, "nt:base", MIXINS);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowEmptySubTypeNames() throws Exception {
+ this.nodeTypeMgr.isDerivedFrom(new String[0], "nt:base", MIXINS);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNullPrimaryType() throws Exception {
+ this.nodeTypeMgr.isDerivedFrom(SUBTYPES, null, MIXINS);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowEmptyPrimaryType() throws Exception {
+ this.nodeTypeMgr.isDerivedFrom(SUBTYPES, "", MIXINS);
+ }
+
+ @Test
+ public void shouldBeDerivedFromIfSubtypeMatchesPrimaryType() throws Exception {
+ assertTrue(this.nodeTypeMgr.isDerivedFrom(SUBTYPES, SUBTYPE2, null));
+ assertTrue(this.nodeTypeMgr.isDerivedFrom(SUBTYPES, SUBTYPE2, MIXINS));
+ }
+
+ @Test
+ public void shouldBeDerivedFromIfSubtypeMatchesMixin() throws Exception {
+ assertTrue(this.nodeTypeMgr.isDerivedFrom(new String[] {MIXIN2}, SUBTYPE1,
MIXINS));
+ }
+
+ @Test
+ public void shouldBeDerivedFromIfSubtypeIsActualSubType() throws Exception {
+ assertTrue(this.nodeTypeMgr.isDerivedFrom(SUBTYPES, HIERARCHY_NODE_TYPE,
MIXINS));
+ }
+
+ @Test
+ public void shouldNotBeDerivedFromIfNoMatch() throws Exception {
+ assertFalse(this.nodeTypeMgr.isDerivedFrom(SUBTYPES, NO_MATCH_TYPE, MIXINS));
+ }
+
+}
Property changes on:
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTypeManagerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrObservationManagerTest.java
===================================================================
---
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrObservationManagerTest.java 2009-12-04
20:33:42 UTC (rev 1404)
+++
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrObservationManagerTest.java 2009-12-04
20:37:26 UTC (rev 1405)
@@ -70,9 +70,9 @@
import org.junit.Test;
/**
- *
+ * The {@link JcrObservationManager} test class.
*/
-public class JcrObservationManagerTest extends TestSuite {
+public final class JcrObservationManagerTest extends TestSuite {
//
===========================================================================================================================
// Constants
@@ -114,9 +114,7 @@
// Fields
//
===========================================================================================================================
- private JcrConfiguration config;
private JcrEngine engine;
- private Repository repository;
private Session session;
private Node testRootNode;
@@ -152,7 +150,6 @@
this.session = null;
try {
- this.repository = null;
this.engine.shutdown();
} finally {
this.engine = null;
@@ -166,22 +163,20 @@
final String REPOSITORY = "r1";
final String SOURCE = "store";
- this.config = new JcrConfiguration();
- this.config.repositorySource("store")
- .usingClass(InMemoryRepositorySource.class)
- .setRetryLimit(100)
- .setProperty("defaultWorkspaceName", WORKSPACE);
-
this.config.repository(REPOSITORY).setSource(SOURCE).setOption(Option.JAAS_LOGIN_CONFIG_NAME,
"dna-jcr");
- this.config.save();
+ JcrConfiguration config = new JcrConfiguration();
+
config.repositorySource("store").usingClass(InMemoryRepositorySource.class).setRetryLimit(100).setProperty("defaultWorkspaceName",
+
WORKSPACE);
+
config.repository(REPOSITORY).setSource(SOURCE).setOption(Option.JAAS_LOGIN_CONFIG_NAME,
"dna-jcr");
+ config.save();
// Create and start the engine ...
- this.engine = this.config.build();
+ this.engine = config.build();
this.engine.start();
// Create repository and session
- this.repository = this.engine.getRepository(REPOSITORY);
+ Repository repository = this.engine.getRepository(REPOSITORY);
Credentials credentials = new SimpleCredentials(USER_ID, USER_ID.toCharArray());
- this.session = this.repository.login(credentials, WORKSPACE);
+ this.session = repository.login(credentials, WORKSPACE);
this.testRootNode = this.session.getRootNode().addNode("testroot",
UNSTRUCTURED);
save();
@@ -574,8 +569,9 @@
// make sure same listener isn't added again
getObservationManager().addEventListener(listener, ALL_EVENTS, null, false, null,
null, false);
- assertThat("The same listener should not be added more than once.",
getObservationManager().getRegisteredEventListeners()
-
.getSize(), is(2L));
+ assertThat("The same listener should not be added more than once.",
+ getObservationManager().getRegisteredEventListeners().getSize(),
+ is(2L));
}
/**
@@ -1138,8 +1134,8 @@
// tests
checkResults(listener);
- assertTrue("Path for jrc:primaryType property was not found.",
containsPath(listener, node.getProperty("jcr:primaryType")
-
.getPath()));
+ assertTrue("Path for jrc:primaryType property was not found.",
+ containsPath(listener,
node.getProperty("jcr:primaryType").getPath()));
}
//
===========================================================================================================================
@@ -1350,7 +1346,6 @@
* @see AddEventListenerTest#testIsDeepFalseNodeAdded()
*/
@Test
- @Ignore
public void shouldTestAddEventListenerTest_testIsDeepFalseNodeAdded() throws
Exception {
// setup
String node1 = "node1";
@@ -1378,7 +1373,6 @@
* @see AddEventListenerTest#testIsDeepFalsePropertyAdded()
*/
@Test
- @Ignore
public void shouldTestAddEventListenerTest_testIsDeepFalsePropertyAdded() throws
Exception {
// setup
Node n1 = getRoot().addNode("node1", UNSTRUCTURED);
@@ -1409,7 +1403,6 @@
* @see AddEventListenerTest#testNodeType()
*/
@Test
- @Ignore
public void shouldTestAddEventListenerTest_testNodeType() throws Exception {
// setup
Node n1 = getRoot().addNode("node1", UNSTRUCTURED);
@@ -1418,7 +1411,13 @@
save();
// register listener
- TestListener listener = addListener(1, Event.NODE_ADDED, getRoot().getPath(),
true, null, new String[] {REF_MIXIN}, false);
+ TestListener listener = addListener(1,
+ Event.NODE_ADDED,
+ getRoot().getPath(),
+ true,
+ null,
+ new String[] {LOCK_MIXIN},
+ false);
// trigger events
String node3 = "node3";
@@ -1490,7 +1489,6 @@
* @see AddEventListenerTest#testUUID()
*/
@Test
- @Ignore
public void shouldTestAddEventListenerTest_testUUID() throws Exception {
// setup
Node n1 = getRoot().addNode("node1", UNSTRUCTURED);
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-12-04 20:33:42 UTC
(rev 1404)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-12-04 20:37:26 UTC
(rev 1405)
@@ -81,6 +81,7 @@
import org.apache.jackrabbit.test.api.WorkspaceMoveSameNameSibsTest;
import org.apache.jackrabbit.test.api.WorkspaceMoveTest;
import org.apache.jackrabbit.test.api.WorkspaceMoveVersionableTest;
+import org.apache.jackrabbit.test.api.observation.AddEventListenerTest;
import org.apache.jackrabbit.test.api.observation.EventIteratorTest;
import org.apache.jackrabbit.test.api.observation.EventTest;
import org.apache.jackrabbit.test.api.observation.GetRegisteredEventListenersTest;
@@ -307,7 +308,7 @@
addTestSuite(PropertyAddedTest.class);
addTestSuite(PropertyChangedTest.class);
addTestSuite(PropertyRemovedTest.class);
- // addTestSuite(AddEventListenerTest.class);
+ addTestSuite(AddEventListenerTest.class);
// addTestSuite(WorkspaceOperationTest.class);
}
}