You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2008/04/04 17:55:39 UTC

svn commit: r644745 [3/3] - in /jackrabbit/trunk: jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ jackrabbit-spi-commons/ jackrabbit-spi-commons/src/main/jav...

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NameConstraintTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NameConstraintTest.java?rev=644745&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NameConstraintTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NameConstraintTest.java Fri Apr  4 08:55:26 2008
@@ -0,0 +1,63 @@
+/*
+ * 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.jackrabbit.spi.commons.nodetype;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.spi.QValue;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.PropertyType;
+
+/**
+ * <code>NameConstraintTest</code>...
+ */
+public class NameConstraintTest extends ValueConstraintTest {
+
+    private static Logger log = LoggerFactory.getLogger(NameConstraintTest.class);
+
+    protected int getType() {
+        return PropertyType.NAME;
+    }
+
+    protected String[] getInvalidQualifiedDefinitions() {
+        return new String[] {"12345", "", "abc"};
+    }
+
+    protected String[] getDefinitions() throws RepositoryException {
+        return new String[] {"12345", "abc", "jcr:abc"};
+    }
+
+    protected String[] getQualifiedDefinitions() throws RepositoryException {
+        return new String[] {
+                resolver.getQName("12345").toString(),
+                resolver.getQName("abc").toString(),
+                resolver.getQName("jcr:abc").toString()
+        };
+    }
+
+    protected QValue[] createNonMatchingValues() throws RepositoryException {
+        QValue v = valueFactory.create(resolver.getQName("xyz"));
+        return new QValue[] {v, v, v};
+    }
+
+    protected QValue createOtherValueType() throws RepositoryException {
+        return valueFactory.create(resolver.getQPath("xyz"));
+    }
+
+    // TODO: add more
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NameConstraintTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NameConstraintTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NumericConstraintTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NumericConstraintTest.java?rev=644745&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NumericConstraintTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NumericConstraintTest.java Fri Apr  4 08:55:26 2008
@@ -0,0 +1,74 @@
+/*
+ * 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.jackrabbit.spi.commons.nodetype;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
+import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.PropertyType;
+import javax.jcr.NamespaceException;
+
+/**
+ * <code>NumericConstraintTest</code>...
+ */
+public class NumericConstraintTest extends ValueConstraintTest {
+
+    private static Logger log = LoggerFactory.getLogger(NumericConstraintTest.class);
+
+    protected ValueConstraint createInvalidConstraint() throws RepositoryException {
+        return new NumericConstraint("test");
+    }
+
+    protected ValueConstraint createValueConstraint(String definition) throws RepositoryException {
+        return new NumericConstraint(definition);
+    }
+
+    protected ValueConstraint createValueConstraint() throws RepositoryException {
+        return new NumericConstraint("(25, 48.5)");
+    }
+
+    protected int getType() {
+        return PropertyType.DOUBLE;
+    }
+
+    protected String[] getInvalidQualifiedDefinitions() throws NamespaceException, IllegalNameException, MalformedPathException {
+        return new String[] {"test", resolver.getQPath("/a/b/jcr:c").getString(), "true"};
+    }
+
+    protected String[] getDefinitions() throws RepositoryException {
+        return new String[] {"(25, 48.5)", "[0,27)", "(, 74)", "(73, 74.9]"};
+    }
+
+    protected String[] getQualifiedDefinitions() throws RepositoryException {
+        return getDefinitions();
+    }
+
+    protected QValue[] createNonMatchingValues() throws RepositoryException {
+        QValue v = valueFactory.create(75);
+        return new QValue[] {v, v, v, v};
+    }
+
+    protected QValue createOtherValueType() throws RepositoryException {
+        return valueFactory.create("abc", PropertyType.STRING);
+    }
+
+    // TODO: add more
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NumericConstraintTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/NumericConstraintTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/PathConstraintTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/PathConstraintTest.java?rev=644745&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/PathConstraintTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/PathConstraintTest.java Fri Apr  4 08:55:26 2008
@@ -0,0 +1,69 @@
+/*
+ * 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.jackrabbit.spi.commons.nodetype;
+
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
+import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.NamespaceException;
+import javax.jcr.PropertyType;
+
+/**
+ * <code>PathConstraintTest</code>...
+ */
+public class PathConstraintTest extends ValueConstraintTest {
+
+    private static Logger log = LoggerFactory.getLogger(PathConstraintTest.class);
+
+    protected int getType() {
+        return PropertyType.PATH;
+    }
+
+    protected String[] getInvalidQualifiedDefinitions() throws NamespaceException, IllegalNameException, MalformedPathException {
+        return new String[] {"12345", "*"};
+    }
+
+    protected String[] getDefinitions() throws RepositoryException {
+        return new String[] {"/abc/*", "/", "abc/*", "/*", "/abc/def"};
+    }
+
+    protected String[] getQualifiedDefinitions() throws RepositoryException {
+        return new String[] {
+                resolver.getQPath("/abc").getString() + "/*",
+                resolver.getQPath("/").getString(),
+                resolver.getQPath("abc").getString() + "/*",
+                resolver.getQPath("/").getString() + "*",
+                resolver.getQPath("/abc/def").getString()};
+    }
+
+    protected QValue[] createNonMatchingValues() throws RepositoryException {
+        QValue root = valueFactory.create(resolver.getQPath("/"));
+        QValue abs = valueFactory.create(resolver.getQPath("/uvw/xyz"));
+        QValue rel = valueFactory.create(resolver.getQPath("uvw/xyz"));
+        return new QValue[] {abs,abs,rel,root,abs};
+    }
+
+    protected QValue createOtherValueType() throws RepositoryException {
+        return valueFactory.create(23);
+    }
+
+    // TODO: add more
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/PathConstraintTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/PathConstraintTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/ReferenceConstraintTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/ReferenceConstraintTest.java?rev=644745&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/ReferenceConstraintTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/ReferenceConstraintTest.java Fri Apr  4 08:55:26 2008
@@ -0,0 +1,71 @@
+/*
+ * 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.jackrabbit.spi.commons.nodetype;
+
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
+import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.ConstraintViolationException;
+
+/**
+ * <code>DateConstraintTest</code>...
+ */
+public class ReferenceConstraintTest extends ValueConstraintTest {
+
+    private static Logger log = LoggerFactory.getLogger(ReferenceConstraintTest.class);
+
+    protected int getType() {
+        return PropertyType.REFERENCE;
+    }
+
+    protected String[] getInvalidQualifiedDefinitions() throws NamespaceException, IllegalNameException, MalformedPathException {
+        return new String[] {"12345", "", "abc"};
+    }
+
+    protected String[] getDefinitions() throws RepositoryException {
+        return new String[] {"12345", "abc", "jcr:abc"};
+    }
+
+    protected String[] getQualifiedDefinitions() throws RepositoryException {
+        return new String[] {
+                resolver.getQName("12345").toString(),
+                resolver.getQName("abc").toString(),
+                resolver.getQName("jcr:abc").toString()
+        };
+    }
+
+    protected QValue[] createNonMatchingValues() throws RepositoryException {
+        // TODO: reference constraints are not checked property -> not executable
+        throw new ConstraintViolationException();
+    }
+
+    protected QValue createOtherValueType() throws RepositoryException {
+        return valueFactory.create(23.56);
+    }
+
+    public void testCheckNonMatchingValue() throws RepositoryException {
+        // not executable
+    }
+
+    // TODO: add more
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/ReferenceConstraintTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/ReferenceConstraintTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/StringConstraintTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/StringConstraintTest.java?rev=644745&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/StringConstraintTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/StringConstraintTest.java Fri Apr  4 08:55:26 2008
@@ -0,0 +1,74 @@
+/*
+ * 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.jackrabbit.spi.commons.nodetype;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
+import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.PropertyType;
+import javax.jcr.NamespaceException;
+
+/**
+ * <code>StringConstraintTest</code>...
+ */
+public class StringConstraintTest extends ValueConstraintTest {
+
+    private static Logger log = LoggerFactory.getLogger(StringConstraintTest.class);
+
+    protected ValueConstraint createInvalidConstraint() throws RepositoryException {
+        return new StringConstraint("[abc");
+    }
+
+    protected ValueConstraint createValueConstraint(String definition) throws RepositoryException {
+        return new StringConstraint(definition);
+    }
+
+    protected ValueConstraint createValueConstraint() throws RepositoryException {
+        return new StringConstraint("[abc] constraint");
+    }
+
+    protected int getType() {
+        return PropertyType.STRING;
+    }
+
+    protected String[] getInvalidQualifiedDefinitions() throws NamespaceException, IllegalNameException, MalformedPathException {
+        return new String[] {"[abc"};
+    }
+
+    protected String[] getDefinitions() throws RepositoryException {
+        return new String[] {"[abc] constraint", "abc"};
+    }
+
+    protected String[] getQualifiedDefinitions() throws RepositoryException {
+        return getDefinitions();
+    }
+
+    protected QValue[] createNonMatchingValues() throws RepositoryException {
+        QValue v = valueFactory.create("another string", PropertyType.STRING);
+        return new QValue[] {v,v};
+    }
+
+    protected QValue createOtherValueType() throws RepositoryException {
+        return valueFactory.create(23);
+    }
+
+    // TODO: add more
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/StringConstraintTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/StringConstraintTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java?rev=644745&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java Fri Apr  4 08:55:26 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.jackrabbit.spi.commons.nodetype;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all test cases for compact node type tools.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a <code>Test</code> suite that executes all tests inside this
+     * package.
+     *
+     * @return a <code>Test</code> suite that executes all tests inside this
+     *         package.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Node Type Tests");
+
+        suite.addTestSuite(BooleanConstraintTest.class);
+        suite.addTestSuite(DateConstraintTest.class);
+        suite.addTestSuite(NameConstraintTest.class);
+        suite.addTestSuite(NumericConstraintTest.class);
+        suite.addTestSuite(PathConstraintTest.class);
+        suite.addTestSuite(ReferenceConstraintTest.class);
+        suite.addTestSuite(StringConstraintTest.class);
+
+        return suite;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/TestAll.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/ValueConstraintTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/ValueConstraintTest.java?rev=644745&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/ValueConstraintTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/ValueConstraintTest.java Fri Apr  4 08:55:26 2008
@@ -0,0 +1,193 @@
+/*
+ * 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.jackrabbit.spi.commons.nodetype;
+
+import junit.framework.TestCase;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
+import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
+import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
+import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
+import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.ConstraintViolationException;
+
+/**
+ * <code>ValueConstraintTest</code>...
+ */
+public abstract class ValueConstraintTest extends TestCase {
+
+    private static Logger log = LoggerFactory.getLogger(ValueConstraintTest.class);
+
+    protected QValueFactory valueFactory;
+    protected NamePathResolver resolver;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        valueFactory = QValueFactoryImpl.getInstance();
+        resolver = new DefaultNamePathResolver(new NamespaceResolver () {
+            public String getURI(String prefix) throws NamespaceException {
+                return prefix;
+            }
+            public String getPrefix(String uri) throws NamespaceException {
+                return uri;
+            }
+        });
+    }
+
+    protected abstract int getType();
+
+    protected abstract String[] getInvalidQualifiedDefinitions() throws NamespaceException, IllegalNameException, MalformedPathException;
+
+    protected abstract String[] getDefinitions() throws RepositoryException;
+
+    protected abstract String[] getQualifiedDefinitions() throws RepositoryException;
+
+    protected abstract QValue[] createNonMatchingValues() throws RepositoryException;
+
+    protected abstract QValue createOtherValueType() throws RepositoryException;
+
+
+    private ValueConstraint createValueConstraint(String qDefinition) throws RepositoryException {
+        return ValueConstraint.create(getType(), qDefinition);
+    }
+
+    private ValueConstraint createValueConstraint(String definition,
+                                                  NamePathResolver resolver) throws RepositoryException {
+        return ValueConstraint.create(getType(), definition, resolver);
+    }
+
+    public void testCreateFromNull() {
+        try {
+            createValueConstraint(null);
+            fail("attempt to create a value constraint from null should fail.");
+        } catch (Exception e) {
+            // ok
+        }
+    }
+
+    public void testCreateValueConstraints() throws RepositoryException {
+        String[] defs = getDefinitions();
+        for (int i = 0; i < defs.length; i++) {
+            ValueConstraint vc = createValueConstraint(defs[i], resolver);
+            assertEquals(defs[i], vc.getDefinition(resolver));
+        }
+    }
+
+    public void testCreateValueConstraints2() throws RepositoryException {
+        String[] qDefs = getQualifiedDefinitions();
+        for (int i = 0; i < qDefs.length; i++) {
+            ValueConstraint vc = createValueConstraint(qDefs[i]);
+            assertEquals(qDefs[i], vc.getQualifiedDefinition());
+        }
+    }
+
+    public void testCreateInvalidValueConstraints() throws RepositoryException {
+        try {
+            String[] invalidQDefs = getInvalidQualifiedDefinitions();
+            for (int i = 0; i < invalidQDefs.length; i++) {
+                createValueConstraint(invalidQDefs[i]);
+                fail("Creating an invalid definition should throw InvalidConstraintException");
+            }
+        } catch (InvalidConstraintException e) {
+            //ok
+        } catch (IllegalArgumentException e) {
+            // ok
+        }
+    }
+
+    public void testGetDefinition() throws RepositoryException {
+        String[] qDefs = getQualifiedDefinitions();
+        for (int i = 0; i < qDefs.length; i++) {
+            ValueConstraint vc = createValueConstraint(qDefs[i]);
+            assertNotNull(vc.getDefinition(resolver));
+        }
+    }
+
+    public void testGetQualifiedDefinition() throws RepositoryException {
+        String[] qDefs = getQualifiedDefinitions();
+        for (int i = 0; i < qDefs.length; i++) {
+            ValueConstraint vc = createValueConstraint(qDefs[i]);
+            assertNotNull(vc.getQualifiedDefinition());
+        }
+    }
+
+    public void testCheckNullValue() throws RepositoryException {
+        String[] qDefs = getQualifiedDefinitions();
+        for (int i = 0; i < qDefs.length; i++) {
+            ValueConstraint vc = createValueConstraint(qDefs[i]);
+            try {
+                vc.check(null);
+                fail("ValueConstraint.check(null) should throw ConstraintViolationException.");
+            } catch (ConstraintViolationException e) {
+                //ok
+            }
+        }
+    }
+
+    public void testCheckNonMatchingValue() throws RepositoryException {
+        QValue[] nonMatching = createNonMatchingValues();
+
+        String[] qDefs = getQualifiedDefinitions();
+        for (int i = 0; i < qDefs.length; i++) {
+            if (i >= nonMatching.length) {
+                break;
+            }
+
+            ValueConstraint vc = createValueConstraint(qDefs[i]);
+            try {
+                vc.check(nonMatching[i]);
+                fail("ValueConstraint.check() with non-matching value should throw ConstraintViolationException.");
+            } catch (ConstraintViolationException e) {
+                //ok
+            }
+        }
+    }
+
+    public void testCheckWrongValueType() throws RepositoryException {
+        QValue val = createOtherValueType();
+        String[] qDefs = getQualifiedDefinitions();
+        for (int i = 0; i < qDefs.length; i++) {
+            ValueConstraint vc = createValueConstraint(qDefs[i]);
+            try {
+                vc.check(val);
+                fail("ValueConstraint.check() with non-matching value should throw ConstraintViolationException.");
+            } catch (RepositoryException e) {
+                //ok
+            }
+        }
+    }
+
+    public void testEquals() throws RepositoryException {
+        String[] qDefs = getQualifiedDefinitions();
+        for (int i = 0; i < qDefs.length; i++) {
+            ValueConstraint vc = createValueConstraint(qDefs[i]);
+            ValueConstraint vc2 = createValueConstraint(qDefs[i]);
+            assertEquals(vc, vc2);
+
+            vc2 = createValueConstraint(vc.getQualifiedDefinition());
+            assertEquals(vc, vc2);
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/ValueConstraintTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/ValueConstraintTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefTest.java?rev=644745&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefTest.java Fri Apr  4 08:55:26 2008
@@ -0,0 +1,75 @@
+/*
+ * 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.jackrabbit.spi.commons.nodetype.compact;
+
+
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping;
+import org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefDiff;
+import org.apache.jackrabbit.value.ValueFactoryImpl;
+
+public class CompactNodeTypeDefTest extends TestCase {
+
+    private static final String TEST_FILE = "cnd-reader-test-input.cnd";
+
+    public void testCompactNodeTypeDef() throws Exception {
+
+        // Read in node type def from test file
+        Reader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(TEST_FILE));
+        CompactNodeTypeDefReader cndReader = new CompactNodeTypeDefReader(reader, TEST_FILE,
+                new QNodeTypeDefinitionsBuilderImpl());
+
+        List ntdList1 = cndReader.getNodeTypeDefs();
+        NamespaceMapping nsm = cndReader.getNamespaceMapping();
+        NamePathResolver resolver = new DefaultNamePathResolver(nsm);
+
+        // Put imported node type def back into CND form with CND writer
+        StringWriter sw = new StringWriter();
+        CompactNodeTypeDefWriter.write(ntdList1, nsm, resolver, ValueFactoryImpl.getInstance(), sw);
+
+        // Rerun the reader on the product of the writer
+        cndReader = new CompactNodeTypeDefReader(new StringReader(sw.toString()), TEST_FILE,
+                new QNodeTypeDefinitionsBuilderImpl());
+
+        List ntdList2 = cndReader.getNodeTypeDefs();
+
+        if (ntdList1.size() == 0 || ntdList1.size() != ntdList2.size()) {
+            fail("Exported node type definition was not successfully read back in");
+        } else {
+            for(int k = 0; k < ntdList1.size(); k++) {
+                QNodeTypeDefinition ntd1 = (QNodeTypeDefinition) ntdList1.get(k);
+                QNodeTypeDefinition ntd2 = (QNodeTypeDefinition) ntdList2.get(k);
+
+                NodeTypeDefDiff diff = NodeTypeDefDiff.create(ntd1, ntd2);
+                if (diff.isModified() && !diff.isTrivial()){
+                    fail("Exported node type definition was not successfully read back in. "
+                            + ntd2.getName() + "differs from original");
+                }
+            }
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/CompactNodeTypeDefTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/TestAll.java?rev=644745&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/TestAll.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/TestAll.java Fri Apr  4 08:55:26 2008
@@ -0,0 +1,40 @@
+/*
+ * 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.jackrabbit.spi.commons.nodetype.compact;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all test cases for compact node type tools.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a <code>Test</code> suite that executes all tests inside this
+     * package.
+     *
+     * @return a <code>Test</code> suite that executes all tests inside this
+     *         package.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Compact Node Type Tools Tests");
+        suite.addTestSuite(CompactNodeTypeDefTest.class);
+        return suite;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/nodetype/compact/TestAll.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/cnd-reader-test-input.cnd
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/cnd-reader-test-input.cnd?rev=644745&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/cnd-reader-test-input.cnd (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/cnd-reader-test-input.cnd Fri Apr  4 08:55:26 2008
@@ -0,0 +1,198 @@
+/*
+ * 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.
+ */
+<ex = "http://example.org/jackrabbit/example">
+<rep='internal'>
+<jcr='http://www.jcp.org/jcr/1.0'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+
+//------------------------------------------------------------------------------
+// E X A M P L E  T Y P E S
+//------------------------------------------------------------------------------
+
+[ex:NodeType] > ex:ParentNodeType1, ex:ParentNodeType2
+  orderable mixin
+  - ex:property (long) = '1', '2' primary mandatory autocreated protected multiple version < '[1,10]'
+  + ex:node (ex:RequiredNodeType1, ex:RequiredNodeType2) = ex:RequiredNodeType1 mandatory autocreated protected multiple version
+
+[ex:AnotherNodeType] > ex:NodeType
+  - * (string) = 'a residual property' multiple
+  + * (ex:RequiredNodeType1) multiple
+  
+[ex:Empty]
+
+[ex:Reference]
+  - ex:ref (reference) mandatory protected < 'ex:ref'
+  
+[ex:Name]
+  - ex:name (name) < 'ex:name'
+  
+[ex:Path]
+  - ex:path (path) < 'ex:a/ex:b'  
+
+//------------------------------------------------------------------------------
+// B A S E  T Y P E S
+//------------------------------------------------------------------------------
+
+[nt:base]
+  - jcr:primaryType (name) mandatory autocreated protected compute
+  - jcr:mixinTypes (name) protected multiple compute
+
+[nt:unstructured]
+  orderable
+  - * (undefined) multiple
+  - * (undefined)
+  + * (nt:base) = nt:unstructured multiple version
+
+[mix:referenceable]
+  mixin
+  - jcr:uuid (string) mandatory autocreated protected initialize
+
+[mix:lockable]
+  mixin
+  - jcr:lockOwner (string) protected ignore
+  - jcr:lockIsDeep (boolean) protected ignore
+
+//------------------------------------------------------------------------------
+// V E R S I O N I N G
+//------------------------------------------------------------------------------
+
+[mix:versionable] > mix:referenceable
+  mixin
+  - jcr:versionHistory (reference) mandatory protected
+    < 'nt:versionHistory'
+  - jcr:baseVersion (reference) mandatory protected ignore
+    < 'nt:version'
+  - jcr:isCheckedOut (boolean) = 'true' mandatory autocreated protected ignore
+  - jcr:predecessors (reference) mandatory protected multiple
+    < 'nt:version'
+  - jcr:mergeFailed (reference) protected multiple abort
+
+[nt:versionHistory] > mix:referenceable
+  - jcr:versionableUuid (string) mandatory autocreated protected abort
+  + jcr:rootVersion (nt:version) = nt:version mandatory autocreated protected abort
+  + jcr:versionLabels (nt:versionLabels) = nt:versionLabels mandatory autocreated protected abort
+  + * (nt:version) = nt:version protected abort
+
+[nt:versionLabels]
+  - * (reference) protected abort
+    < 'nt:version'
+
+[nt:version] > mix:referenceable
+  - jcr:created (date) mandatory autocreated protected abort
+  - jcr:predecessors (reference) protected multiple abort
+    < 'nt:version'
+  - jcr:successors (reference) protected multiple abort
+    < 'nt:version'
+  + jcr:frozenNode (nt:frozenNode) protected abort
+
+[nt:frozenNode] > mix:referenceable
+  orderable
+  - jcr:frozenPrimaryType (name) mandatory autocreated protected abort
+  - jcr:frozenMixinTypes (name) protected multiple abort
+  - jcr:frozenUuid (string) mandatory autocreated protected abort
+  - * (undefined) protected abort
+  - * (undefined) protected multiple abort
+  + * (nt:base) protected multiple abort
+
+[nt:versionedChild]
+  - jcr:childVersionHistory (reference) mandatory autocreated protected abort
+    < 'nt:versionHistory'
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+[nt:nodeType]
+  - jcr:nodeTypeName (name) mandatory
+  - jcr:supertypes (name) multiple
+  - jcr:isMixin (boolean) mandatory
+  - jcr:hasOrderableChildNodes (boolean) mandatory
+  - jcr:primaryItemName (name)
+  + jcr:propertyDefinition (nt:propertyDefinition) = nt:propertyDefinition multiple version
+  + jcr:childNodeDefinition (nt:childNodeDefinition) = nt:childNodeDefinition multiple version
+
+[nt:propertyDefinition]
+  - jcr:name (name)
+  - jcr:autoCreated (boolean) mandatory
+  - jcr:mandatory (boolean) mandatory
+  - jcr:onParentVersion (string) mandatory
+    < 'COPY', 'VERSION', 'INITIALIZE', 'COMPUTE', 'IGNORE', 'ABORT'
+  - jcr:protected (boolean) mandatory
+  - jcr:requiredType (string) mandatory
+    < 'STRING', 'BINARY', 'LONG', 'DOUBLE', 'BOOLEAN', 'DATE', 'NAME', 'PATH', 'REFERENCE', 'UNDEFINED'
+  - jcr:valueConstraints (string) multiple
+  - jcr:defaultValues (undefined) multiple
+  - jcr:multiple (boolean) mandatory
+
+[nt:childNodeDefinition]
+  - jcr:name (name)
+  - jcr:autoCreated (boolean) mandatory
+  - jcr:mandatory (boolean) mandatory
+  - jcr:onParentVersion (string) mandatory
+    < 'COPY', 'VERSION', 'INITIALIZE', 'COMPUTE', 'IGNORE', 'ABORT'
+  - jcr:protected (boolean) mandatory
+  - jcr:requiredPrimaryTypes (name) = 'nt:base' mandatory multiple
+  - jcr:defaultPrimaryType (name)
+  - jcr:sameNameSiblings (boolean) mandatory
+
+//------------------------------------------------------------------------------
+// M I S C
+//------------------------------------------------------------------------------
+
+[nt:hierarchyNode]
+  - jcr:created (date) autocreated protected initialize
+
+[nt:folder] > nt:hierarchyNode
+  + * (nt:hierarchyNode) version
+
+[nt:file] > nt:hierarchyNode
+  + jcr:content (nt:base) primary mandatory
+
+[nt:linkedFile] > nt:hierarchyNode
+  - jcr:content (reference) primary mandatory
+
+[nt:resource] > mix:referenceable
+  - jcr:encoding (string)
+  - jcr:mimeType (string) mandatory
+  - jcr:data (binary) primary mandatory
+  - jcr:lastModified (date) mandatory ignore
+
+[nt:query]
+  - jcr:statement (string)
+  - jcr:language (string)
+
+//------------------------------------------------------------------------------
+// J A C K R A B B I T   I N T E R N A L S
+//------------------------------------------------------------------------------
+
+[rep:nodeTypes]
+  + * (nt:nodeType) = nt:nodeType protected abort
+
+[rep:root] > nt:unstructured
+  orderable
+  + jcr:system (rep:system) = rep:system mandatory ignore
+
+[rep:system]
+  orderable
+  + jcr:versionStorage (rep:versionStorage) = rep:versionStorage mandatory protected abort
+  + jcr:nodeTypes (rep:nodeTypes) = rep:nodeTypes mandatory protected abort
+  + * (nt:base) = nt:unstructured multiple ignore
+
+[rep:versionStorage]
+  + * (nt:versionHistory) = nt:versionHistory protected multiple abort
+  + * (rep:versionStorage) = rep:versionStorage protected multiple abort