Author: rhauch
Date: 2009-03-23 22:34:43 -0400 (Mon, 23 Mar 2009)
New Revision: 790
Removed:
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestNodeTypeSource.java
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyDefinitionTest.java
Log:
DNA-305 JcrNodeType.canSetProperty Does Not Enforce Constraints
Applied the "DNA-305_path_namespace" patch that makes path constraints support
transient namespace remapping, modifies the test cases to verify this, and moves the test
node type into class to clean up the package and make JcrPropertyDefinitionTest more
consistent with the approach in SessionCacheTest. This fix should allow the defect to be
resolved.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java 2009-03-24
02:29:20 UTC (rev 789)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java 2009-03-24
02:34:43 UTC (rev 790)
@@ -642,15 +642,22 @@
}
public boolean matches( Value valueToMatch ) {
- assert valueToMatch != null;
+ assert valueToMatch instanceof JcrValue;
+
+ JcrValue jcrValue = (JcrValue) valueToMatch;
- PathFactory pathFactory = context.getValueFactories().getPathFactory();
- Path value = pathFactory.create(((JcrValue)valueToMatch).value());
+ /*
+ * Need two path factories here. One uses the permanent namespace mappings
to parse the constraints.
+ * The other also looks at the transient mappings to parse the checked value
+ */
+ PathFactory repoPathFactory = context.getValueFactories().getPathFactory();
+ PathFactory sessionPathFactory =
jcrValue.sessionCache().context().getValueFactories().getPathFactory();
+ Path value = sessionPathFactory.create(((JcrValue)valueToMatch).value());
value = value.getNormalizedPath();
for (int i = 0; i < constraints.length; i++) {
boolean matchesDescendants = constraints[i].endsWith("*");
- Path constraintPath = pathFactory.create(matchesDescendants ?
constraints[i].substring(0,
+ Path constraintPath = repoPathFactory.create(matchesDescendants ?
constraints[i].substring(0,
constraints[i].length() - 2) : constraints[i]);
if (matchesDescendants && value.isDecendantOf(constraintPath)) {
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyDefinitionTest.java
===================================================================
---
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyDefinitionTest.java 2009-03-24
02:29:20 UTC (rev 789)
+++
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyDefinitionTest.java 2009-03-24
02:34:43 UTC (rev 790)
@@ -27,8 +27,11 @@
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.stub;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.jcr.PropertyType;
import javax.jcr.Value;
@@ -55,17 +58,15 @@
*/
public class JcrPropertyDefinitionTest {
- private final String[] EXPECTED_BINARY_CONSTRAINTS = new String[] {"[,5)",
"[10, 20)", "(30,40]", "[50,]"};
- private final String[] EXPECTED_DATE_CONSTRAINTS = new String[]
{"[,+1945-08-01T01:30:00.000Z]",
+ protected final String[] EXPECTED_BINARY_CONSTRAINTS = new String[]
{"[,5)", "[10, 20)", "(30,40]", "[50,]"};
+ protected final String[] EXPECTED_DATE_CONSTRAINTS = new String[]
{"[,+1945-08-01T01:30:00.000Z]",
"[+1975-08-01T01:30:00.000Z,)"};
- private final String[] EXPECTED_DOUBLE_CONSTRAINTS = new String[]
{"[,5.0)", "[10.1, 20.2)", "(30.3,40.4]",
"[50.5,]"};
- private final String[] EXPECTED_LONG_CONSTRAINTS = new String[] {"[,5)",
"[10, 20)", "(30,40]", "[50,]"};
- private final String[] EXPECTED_NAME_CONSTRAINTS = new String[]
{"jcr:system", "dnatest:constrainedType"};
- // private final String[] EXPECTED_PATH_CONSTRAINTS = new String[] {"/" +
JcrLexicon.Namespace.URI + ":system/*", "b",
- // "/a/b/c" };
- private final String[] EXPECTED_PATH_CONSTRAINTS = new String[]
{"/jcr:system/*", "b", "/a/b/c"};
- private final String[] EXPECTED_REFERENCE_CONSTRAINTS = new String[]
{"dna:root"};
- private final String[] EXPECTED_STRING_CONSTRAINTS = new String[] {"foo",
"bar*", ".*baz"};
+ protected final String[] EXPECTED_DOUBLE_CONSTRAINTS = new String[]
{"[,5.0)", "[10.1, 20.2)", "(30.3,40.4]",
"[50.5,]"};
+ protected final String[] EXPECTED_LONG_CONSTRAINTS = new String[] {"[,5)",
"[10, 20)", "(30,40]", "[50,]"};
+ protected final String[] EXPECTED_NAME_CONSTRAINTS = new String[]
{"jcr:system", "dnatest:constrainedType"};
+ protected final String[] EXPECTED_PATH_CONSTRAINTS = new String[]
{"/jcr:system/*", "b", "/a/b/c"};
+ protected final String[] EXPECTED_REFERENCE_CONSTRAINTS = new String[]
{"dna:root"};
+ protected final String[] EXPECTED_STRING_CONSTRAINTS = new String[] {"foo",
"bar*", ".*baz"};
private String workspaceName;
private ExecutionContext context;
@@ -210,7 +211,7 @@
private Value valueFor( Object value,
int jcrType ) {
- return new JcrValue(context.getValueFactories(), session.cache(), jcrType,
value);
+ return new JcrValue(session.getExecutionContext().getValueFactories(),
session.cache(), jcrType, value);
}
private String stringOfLength( int length ) {
@@ -552,7 +553,11 @@
assertThat(prop.satisfiesConstraints(valueFor("/a/b/c",
PropertyType.PATH)), is(true));
assertThat(prop.satisfiesConstraints(valueFor("/jcr:system/dna:namespace",
PropertyType.PATH)), is(true));
assertThat(prop.satisfiesConstraints(valueFor("/a/b/c/",
PropertyType.PATH)), is(true));
- assertThat(prop.satisfiesConstraints(valueFor("/jcr:system/dna:foo",
PropertyType.PATH)), is(true));
+
+ // Test that constraints work after session rename
+ session.setNamespacePrefix("jcr2", JcrLexicon.Namespace.URI);
+
+ assertThat(prop.satisfiesConstraints(valueFor("/jcr2:system/dna:foo",
PropertyType.PATH)), is(true));
}
@Test
@@ -575,6 +580,7 @@
assertThat(prop.satisfiesConstraints(valueFor("/a/b",
PropertyType.PATH)), is(false));
assertThat(prop.satisfiesConstraints(valueFor("/jcr:system",
PropertyType.PATH)), is(false));
assertThat(prop.satisfiesConstraints(valueFor("/a/b/c/d",
PropertyType.PATH)), is(false));
+
}
@Test
@@ -628,4 +634,132 @@
assertThat(satisfiesConstraints(prop, new Value[] {value}), is(false));
}
+ class TestNodeTypeSource extends AbstractJcrNodeTypeSource {
+
+ /** The list of primary node types. */
+ private final List<JcrNodeType> primaryNodeTypes;
+ /** The list of mixin node types. */
+ private final List<JcrNodeType> mixinNodeTypes;
+
+ TestNodeTypeSource( ExecutionContext context,
+ JcrNodeTypeSource predecessor ) {
+ super(predecessor);
+
+ primaryNodeTypes = new ArrayList<JcrNodeType>();
+ mixinNodeTypes = new ArrayList<JcrNodeType>();
+
+ JcrNodeType base = findType(JcrNtLexicon.BASE);
+
+ if (base == null) {
+ String baseTypeName =
JcrNtLexicon.BASE.getString(context.getNamespaceRegistry());
+ String namespaceTypeName =
DnaLexicon.NAMESPACE.getString(context.getNamespaceRegistry());
+ throw new
IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName, namespaceTypeName));
+ }
+
+ // Stubbing in child node and property definitions for now
+ JcrNodeType constrainedType = new JcrNodeType(
+ context,
+ NO_NODE_TYPE_MANAGER,
+ TestLexicon.CONSTRAINED_TYPE,
+ Arrays.asList(new JcrNodeType[]
{base}),
+ NO_PRIMARY_ITEM_NAME,
+ NO_CHILD_NODES,
+ Arrays.asList(new
JcrPropertyDefinition[] {
+ new JcrPropertyDefinition(
+
context,
+
null,
+
TestLexicon.CONSTRAINED_BINARY,
+
OnParentVersionBehavior.IGNORE.getJcrValue(),
+
false, false, false, NO_DEFAULT_VALUES,
+
PropertyType.BINARY,
+
EXPECTED_BINARY_CONSTRAINTS, false),
+ new JcrPropertyDefinition(
+
context,
+
null,
+
TestLexicon.CONSTRAINED_DATE,
+
OnParentVersionBehavior.IGNORE.getJcrValue(),
+
false, false, false, NO_DEFAULT_VALUES,
+
PropertyType.DATE,
+
EXPECTED_DATE_CONSTRAINTS, false),
+ new JcrPropertyDefinition(
+
context,
+
null,
+
TestLexicon.CONSTRAINED_DOUBLE,
+
OnParentVersionBehavior.IGNORE.getJcrValue(),
+
false, false, false, NO_DEFAULT_VALUES,
+
PropertyType.DOUBLE,
+
EXPECTED_DOUBLE_CONSTRAINTS, false),
+
+ new JcrPropertyDefinition(
+
context,
+
null,
+
TestLexicon.CONSTRAINED_LONG,
+
OnParentVersionBehavior.IGNORE.getJcrValue(),
+
false, false, false, NO_DEFAULT_VALUES,
+
PropertyType.LONG,
+
EXPECTED_LONG_CONSTRAINTS, false),
+
+ new JcrPropertyDefinition(
+
context,
+
null,
+
TestLexicon.CONSTRAINED_NAME,
+
OnParentVersionBehavior.IGNORE.getJcrValue(),
+
false, false, false, NO_DEFAULT_VALUES,
+
PropertyType.NAME,
+
EXPECTED_NAME_CONSTRAINTS, false),
+
+ new JcrPropertyDefinition(
+
context,
+
null,
+
TestLexicon.CONSTRAINED_PATH,
+
OnParentVersionBehavior.IGNORE.getJcrValue(),
+
false, false, false, NO_DEFAULT_VALUES,
+
PropertyType.PATH,
+
EXPECTED_PATH_CONSTRAINTS, false),
+ new JcrPropertyDefinition(
+
context,
+
null,
+
TestLexicon.CONSTRAINED_REFERENCE,
+
OnParentVersionBehavior.IGNORE.getJcrValue(),
+
false, false, false, NO_DEFAULT_VALUES,
+
PropertyType.REFERENCE,
+
new String[] {"dna:root",}, false),
+
+ new JcrPropertyDefinition(
+
context,
+
null,
+
TestLexicon.CONSTRAINED_STRING,
+
OnParentVersionBehavior.IGNORE.getJcrValue(),
+
false, false, false, NO_DEFAULT_VALUES,
+
PropertyType.STRING,
+
EXPECTED_STRING_CONSTRAINTS, false),
+
+ }), NOT_MIXIN,
UNORDERABLE_CHILD_NODES);
+
+ primaryNodeTypes.addAll(Arrays.asList(new JcrNodeType[] {constrainedType}));
+ mixinNodeTypes.addAll(Arrays.asList(new JcrNodeType[] {}));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.AbstractJcrNodeTypeSource#getDeclaredMixinNodeTypes()
+ */
+ @Override
+ public Collection<JcrNodeType> getDeclaredMixinNodeTypes() {
+ return primaryNodeTypes;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.jcr.AbstractJcrNodeTypeSource#getDeclaredPrimaryNodeTypes()
+ */
+ @Override
+ public Collection<JcrNodeType> getDeclaredPrimaryNodeTypes() {
+ return mixinNodeTypes;
+ }
+
+ }
+
}
Deleted: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestNodeTypeSource.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestNodeTypeSource.java 2009-03-24
02:29:20 UTC (rev 789)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestNodeTypeSource.java 2009-03-24
02:34:43 UTC (rev 790)
@@ -1,142 +0,0 @@
-/*
- * 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 java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import javax.jcr.PropertyType;
-import org.jboss.dna.graph.ExecutionContext;
-
-/**
- * Node type source with additional node types that can be used for testing. This class
defines its own namespace for its types.
- */
-public class TestNodeTypeSource extends AbstractJcrNodeTypeSource {
-
- /** The list of primary node types. */
- private final List<JcrNodeType> primaryNodeTypes;
- /** The list of mixin node types. */
- private final List<JcrNodeType> mixinNodeTypes;
-
- TestNodeTypeSource( ExecutionContext context,
- JcrNodeTypeSource predecessor ) {
- super(predecessor);
-
- primaryNodeTypes = new ArrayList<JcrNodeType>();
- mixinNodeTypes = new ArrayList<JcrNodeType>();
-
- JcrNodeType base = findType(JcrNtLexicon.BASE);
-
- if (base == null) {
- String baseTypeName =
JcrNtLexicon.BASE.getString(context.getNamespaceRegistry());
- String namespaceTypeName =
DnaLexicon.NAMESPACE.getString(context.getNamespaceRegistry());
- throw new IllegalStateException(JcrI18n.supertypeNotFound.text(baseTypeName,
namespaceTypeName));
- }
-
- // Stubbing in child node and property definitions for now
- JcrNodeType constrainedType = new JcrNodeType(context, NO_NODE_TYPE_MANAGER,
TestLexicon.CONSTRAINED_TYPE,
- Arrays.asList(new JcrNodeType[]
{base}), NO_PRIMARY_ITEM_NAME,
- NO_CHILD_NODES, Arrays.asList(new
JcrPropertyDefinition[] {
- new
JcrPropertyDefinition(context, null,
-
TestLexicon.CONSTRAINED_BINARY,
-
OnParentVersionBehavior.IGNORE.getJcrValue(),
-
false, false, false, NO_DEFAULT_VALUES,
-
PropertyType.BINARY, new String[] {"[,5)",
-
"[10, 20)", "(30,40]", "[50,]"}, false),
- new
JcrPropertyDefinition(context, null, TestLexicon.CONSTRAINED_DATE,
-
OnParentVersionBehavior.IGNORE.getJcrValue(),
-
false, false, false, NO_DEFAULT_VALUES,
-
PropertyType.DATE, new String[] {
-
"[,+1945-08-01T01:30:00.000Z]",
-
"[+1975-08-01T01:30:00.000Z,)"}, false),
- new
JcrPropertyDefinition(context, null,
-
TestLexicon.CONSTRAINED_DOUBLE,
-
OnParentVersionBehavior.IGNORE.getJcrValue(),
-
false, false, false, NO_DEFAULT_VALUES,
-
PropertyType.DOUBLE,
- new
String[] {"[,5.0)", "[10.1, 20.2)",
-
"(30.3,40.4]", "[50.5,]"}, false),
-
- new
JcrPropertyDefinition(context, null, TestLexicon.CONSTRAINED_LONG,
-
OnParentVersionBehavior.IGNORE.getJcrValue(),
-
false, false, false, NO_DEFAULT_VALUES,
-
PropertyType.LONG, new String[] {"[,5)",
-
"[10, 20)", "(30,40]", "[50,]"}, false),
-
- new
JcrPropertyDefinition(context, null, TestLexicon.CONSTRAINED_NAME,
-
OnParentVersionBehavior.IGNORE.getJcrValue(),
-
false, false, false, NO_DEFAULT_VALUES,
-
PropertyType.NAME, new String[] {
-
"jcr:system", "dnatest:constrainedType"},
-
false),
-
- new
JcrPropertyDefinition(context, null, TestLexicon.CONSTRAINED_PATH,
-
OnParentVersionBehavior.IGNORE.getJcrValue(),
-
false, false, false, NO_DEFAULT_VALUES,
-
PropertyType.PATH, new String[] {
- //
"/" + JcrLexicon.Namespace.URI +
- //
":system/*", "b", "/a/b/c"}, false),
-
"/jcr:system/*", "b", "/a/b/c"}, false),
- new
JcrPropertyDefinition(context, null,
-
TestLexicon.CONSTRAINED_REFERENCE,
-
OnParentVersionBehavior.IGNORE.getJcrValue(),
-
false, false, false, NO_DEFAULT_VALUES,
-
PropertyType.REFERENCE,
- new
String[] {"dna:root",}, false),
-
- new
JcrPropertyDefinition(context, null,
-
TestLexicon.CONSTRAINED_STRING,
-
OnParentVersionBehavior.IGNORE.getJcrValue(),
-
false, false, false, NO_DEFAULT_VALUES,
-
PropertyType.STRING, new String[] {"foo",
-
"bar*", ".*baz",}, false),
-
- }), NOT_MIXIN,
UNORDERABLE_CHILD_NODES);
-
- primaryNodeTypes.addAll(Arrays.asList(new JcrNodeType[] {constrainedType}));
- mixinNodeTypes.addAll(Arrays.asList(new JcrNodeType[] {}));
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.jcr.AbstractJcrNodeTypeSource#getDeclaredMixinNodeTypes()
- */
- @Override
- public Collection<JcrNodeType> getDeclaredMixinNodeTypes() {
- return primaryNodeTypes;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.jcr.AbstractJcrNodeTypeSource#getDeclaredPrimaryNodeTypes()
- */
- @Override
- public Collection<JcrNodeType> getDeclaredPrimaryNodeTypes() {
- return mixinNodeTypes;
- }
-
-}