Author: rhauch
Date: 2009-04-20 16:21:21 -0400 (Mon, 20 Apr 2009)
New Revision: 841
Added:
trunk/extensions/dna-sequencer-cnd/src/main/java/
trunk/extensions/dna-sequencer-cnd/src/main/java/org/
trunk/extensions/dna-sequencer-cnd/src/main/java/org/jboss/
trunk/extensions/dna-sequencer-cnd/src/main/java/org/jboss/dna/
trunk/extensions/dna-sequencer-cnd/src/main/java/org/jboss/dna/sequencer/
trunk/extensions/dna-sequencer-cnd/src/main/java/org/jboss/dna/sequencer/cnd/
trunk/extensions/dna-sequencer-cnd/src/main/java/org/jboss/dna/sequencer/cnd/CndSequencer.java
trunk/extensions/dna-sequencer-cnd/src/main/java/org/jboss/dna/sequencer/cnd/CndSequencerI18n.java
trunk/extensions/dna-sequencer-cnd/src/main/resources/
trunk/extensions/dna-sequencer-cnd/src/main/resources/org/
trunk/extensions/dna-sequencer-cnd/src/main/resources/org/jboss/
trunk/extensions/dna-sequencer-cnd/src/main/resources/org/jboss/dna/
trunk/extensions/dna-sequencer-cnd/src/main/resources/org/jboss/dna/sequencer/
trunk/extensions/dna-sequencer-cnd/src/main/resources/org/jboss/dna/sequencer/cnd/
trunk/extensions/dna-sequencer-cnd/src/main/resources/org/jboss/dna/sequencer/cnd/CndSequencerI18n.properties
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndSequencerI18nTest.java
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndSequencerTest.java
Removed:
trunk/extensions/dna-sequencer-cnd/src/main/antlr/
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParseFilesTest.java
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParserTest.java
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencer/MockSequencerContext.java
trunk/extensions/dna-sequencer-cnd/.classpath
trunk/extensions/dna-sequencer-cnd/.project
trunk/extensions/dna-sequencer-cnd/pom.xml
trunk/pom.xml
Log:
DNA-363 Define node types via CND files
Changed the DNA CND Sequencer to use the new CND importer.
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencer/MockSequencerContext.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencer/MockSequencerContext.java 2009-04-20
19:07:48 UTC (rev 840)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencer/MockSequencerContext.java 2009-04-20
20:21:21 UTC (rev 841)
@@ -26,7 +26,6 @@
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.collection.SimpleProblems;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.sequencer.SequencerContext;
/**
* @author John Verhaeg
@@ -39,4 +38,15 @@
getNamespaceRegistry().register("dnadtd",
"http://www.jboss.org/dna/dtd/1.0");
getNamespaceRegistry().register("dnaxml",
"http://www.jboss.org/dna/xml/1.0");
}
+
+ public MockSequencerContext( String inputPath ) {
+ this(new ExecutionContext(), inputPath);
+ }
+
+ public MockSequencerContext( ExecutionContext context,
+ String inputPath ) {
+ super(context, context.getValueFactories().getPathFactory().create(inputPath),
null, null, new SimpleProblems());
+ getNamespaceRegistry().register("dnadtd",
"http://www.jboss.org/dna/dtd/1.0");
+ getNamespaceRegistry().register("dnaxml",
"http://www.jboss.org/dna/xml/1.0");
+ }
}
Modified: trunk/extensions/dna-sequencer-cnd/.classpath
===================================================================
--- trunk/extensions/dna-sequencer-cnd/.classpath 2009-04-20 19:07:48 UTC (rev 840)
+++ trunk/extensions/dna-sequencer-cnd/.classpath 2009-04-20 20:21:21 UTC (rev 841)
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" output="target/test-classes"
path="src/test/java"/>
- <classpathentry kind="src"
path="target/generated-sources/antlr"/>
- <classpathentry kind="src" output="target/test-classes"
path="src/test/resources"/>
- <classpathentry kind="src" path="src/main/antlr"/>
- <classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
- <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes"
path="src/test/java"/>
+ <classpathentry kind="src" output="target/test-classes"
path="src/test/resources"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
</classpath>
Modified: trunk/extensions/dna-sequencer-cnd/.project
===================================================================
--- trunk/extensions/dna-sequencer-cnd/.project 2009-04-20 19:07:48 UTC (rev 840)
+++ trunk/extensions/dna-sequencer-cnd/.project 2009-04-20 20:21:21 UTC (rev 841)
@@ -15,16 +15,6 @@
<arguments>
</arguments>
</buildCommand>
- <buildCommand>
- <name>org.antlr.eclipse.core.warningcleanerbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.antlr.eclipse.core.smapbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
Modified: trunk/extensions/dna-sequencer-cnd/pom.xml
===================================================================
--- trunk/extensions/dna-sequencer-cnd/pom.xml 2009-04-20 19:07:48 UTC (rev 840)
+++ trunk/extensions/dna-sequencer-cnd/pom.xml 2009-04-20 20:21:21 UTC (rev 841)
@@ -19,14 +19,27 @@
<groupId>org.jboss.dna</groupId>
<artifactId>dna-graph</artifactId>
</dependency>
- <dependency>
- <groupId>org.antlr</groupId>
- <artifactId>antlr-runtime</artifactId>
- <version>3.0.1</version>
- </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-cnd</artifactId>
+ </dependency>
<!-- Testing -->
<dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-common</artifactId>
+ <version>${pom.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-graph</artifactId>
+ <version>${pom.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
@@ -35,20 +48,4 @@
<artifactId>hamcrest-library</artifactId>
</dependency>
</dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>antlr3-maven-plugin</artifactId>
- <version>1.0</version>
- <executions>
- <execution>
- <goals>
- <goal>antlr</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
</project>
\ No newline at end of file
Added:
trunk/extensions/dna-sequencer-cnd/src/main/java/org/jboss/dna/sequencer/cnd/CndSequencer.java
===================================================================
---
trunk/extensions/dna-sequencer-cnd/src/main/java/org/jboss/dna/sequencer/cnd/CndSequencer.java
(rev 0)
+++
trunk/extensions/dna-sequencer-cnd/src/main/java/org/jboss/dna/sequencer/cnd/CndSequencer.java 2009-04-20
20:21:21 UTC (rev 841)
@@ -0,0 +1,121 @@
+/*
+ * 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.
+ *
+ * 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.sequencer.cnd;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import org.jboss.dna.cnd.CndImporter;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.io.Destination;
+import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.sequencer.SequencerContext;
+import org.jboss.dna.graph.sequencer.SequencerOutput;
+import org.jboss.dna.graph.sequencer.StreamSequencer;
+
+/**
+ *
+ */
+public class CndSequencer implements StreamSequencer {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.sequencer.StreamSequencer#sequence(java.io.InputStream,
+ * org.jboss.dna.graph.sequencer.SequencerOutput,
org.jboss.dna.graph.sequencer.SequencerContext)
+ */
+ public void sequence( InputStream stream,
+ SequencerOutput output,
+ SequencerContext context ) {
+ // Create the destination that forwards to the sequencer output ...
+ Destination destination = new OutputDestination(output, context);
+ // Use the CND importer ...
+ Path root = context.getValueFactories().getPathFactory().createRootPath();
+ CndImporter importer = new CndImporter(destination, root);
+ String resourceName =
context.getInputPath().getString(context.getNamespaceRegistry());
+ try {
+ importer.importFrom(stream, context.getProblems(), resourceName);
+ } catch (IOException e) {
+ context.getProblems().addError(e, CndSequencerI18n.errorSequencingCndContent,
e.getLocalizedMessage());
+ }
+ }
+
+ protected class OutputDestination implements Destination {
+ private final SequencerOutput output;
+ private final SequencerContext context;
+
+ protected OutputDestination( SequencerOutput output,
+ SequencerContext context ) {
+ this.output = output;
+ this.context = context;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.io.Destination#getExecutionContext()
+ */
+ public ExecutionContext getExecutionContext() {
+ return context;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.io.Destination#create(org.jboss.dna.graph.property.Path,
java.util.List)
+ */
+ public void create( Path path,
+ List<Property> properties ) {
+ for (Property property : properties) {
+ output.setProperty(path, property.getName(), property.getValues());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.io.Destination#create(org.jboss.dna.graph.property.Path,
+ * org.jboss.dna.graph.property.Property,
org.jboss.dna.graph.property.Property[])
+ */
+ public void create( Path path,
+ Property firstProperty,
+ Property... additionalProperties ) {
+ output.setProperty(path, firstProperty.getName(),
firstProperty.getValues());
+ for (Property property : additionalProperties) {
+ output.setProperty(path, property.getName(), property.getValues());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.io.Destination#submit()
+ */
+ public void submit() {
+ // nothing to call on the sequencer output ...
+ }
+ }
+
+}
Added:
trunk/extensions/dna-sequencer-cnd/src/main/java/org/jboss/dna/sequencer/cnd/CndSequencerI18n.java
===================================================================
---
trunk/extensions/dna-sequencer-cnd/src/main/java/org/jboss/dna/sequencer/cnd/CndSequencerI18n.java
(rev 0)
+++
trunk/extensions/dna-sequencer-cnd/src/main/java/org/jboss/dna/sequencer/cnd/CndSequencerI18n.java 2009-04-20
20:21:21 UTC (rev 841)
@@ -0,0 +1,57 @@
+/*
+ * 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.sequencer.cnd;
+
+import java.util.Locale;
+import java.util.Set;
+import org.jboss.dna.common.i18n.I18n;
+
+/**
+ * @author Randall Hauch
+ */
+public final class CndSequencerI18n {
+
+ public static I18n sequencerTaskName;
+ public static I18n errorSequencingCndContent;
+
+ static {
+ try {
+ I18n.initialize(CndSequencerI18n.class);
+ } catch (final Exception err) {
+ System.err.println(err);
+ }
+ }
+
+ public static Set<Locale> getLocalizationProblemLocales() {
+ return I18n.getLocalizationProblemLocales(CndSequencerI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems() {
+ return I18n.getLocalizationProblems(CndSequencerI18n.class);
+ }
+
+ public static Set<String> getLocalizationProblems( Locale locale ) {
+ return I18n.getLocalizationProblems(CndSequencerI18n.class, locale);
+ }
+}
Added:
trunk/extensions/dna-sequencer-cnd/src/main/resources/org/jboss/dna/sequencer/cnd/CndSequencerI18n.properties
===================================================================
---
trunk/extensions/dna-sequencer-cnd/src/main/resources/org/jboss/dna/sequencer/cnd/CndSequencerI18n.properties
(rev 0)
+++
trunk/extensions/dna-sequencer-cnd/src/main/resources/org/jboss/dna/sequencer/cnd/CndSequencerI18n.properties 2009-04-20
20:21:21 UTC (rev 841)
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+sequencerTaskName = Processing Compact Node Definition (CND) contents
+errorSequencingCndContent = Error while sequencing the CND content: {0}
Deleted:
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParseFilesTest.java
===================================================================
---
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParseFilesTest.java 2009-04-20
19:07:48 UTC (rev 840)
+++
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParseFilesTest.java 2009-04-20
20:21:21 UTC (rev 841)
@@ -1,367 +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.sequencer.cnd;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.junit.Assert.assertThat;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import org.antlr.runtime.ANTLRInputStream;
-import org.antlr.runtime.CommonTokenStream;
-import org.antlr.runtime.RuleReturnScope;
-import org.antlr.runtime.tree.Tree;
-import org.junit.After;
-import org.junit.Test;
-
-public class CndParseFilesTest {
-
- /*
- * AST looks like this:
- *
- * root (nil)
- * COMMENTS (*)
- * comment-1
- * comment-2
- * ...
- * NAMESPACES (*)
- * namespace_mapping-1
- * namespace_mapping-2
- * ...
- * NODE_TYPE_DEFINITIONS (*)
- * NODE_TYPE_DEFINITION
- * JCR_NAME
- * node_type_definition_name-1
- * SUPERTYPES (*)
- * supertype-1
- * supertype-2
- * ...
- * NODE_TYPE_OPTIONS (*)
- * option-1
- * option-2
- * ...
- * PROPERTIES (*)
- * PROPERTY_DEFINITION
- * JCR_NAME
- * property_name-1
- * PROPERTY_TYPE (*)
- * property type
- * ATTRIBUTES (*)
- * attribute-1
- * attribute-2
- * ...
- * PROPERTY_DEFINITION
- * JCR_NAME
- * property_name-2
- * ...
- * ...
- * CHILD_NODE_DEFINTIONS (*)
- * CHILD_NODE_DEFINTION
- * JCR_NAME
- * child_node_name-1
- * REQUIRED_TYPES (*)
- * required_type-1
- * required_type-2
- * ...
- * DEFAULT_TYPE (*)
- * default_type
- * ATTRIBUTES (*)
- * attribute-1
- * attribute-2
- * ...
- * CHILD_NODE_DEFINTION
- * JCR_NAME
- * child_node_name-2
- * ...
- * ...
- * NODE_TYPE_DEFINITION
- * JCR_NAME
- * node_type_definition_name-2
- * ...
- * ...
- *
- * Note: (*) indicates node only appears if a child node exists
- */
-
- //
=============================================================================================================================
- // Constants
- //
=============================================================================================================================
- private static final String TEST_DATA_PATH = "./src/test/resources/";
-
- private static final String BUILTIN_NODETYPES_CND = TEST_DATA_PATH +
"builtin_nodetypes.cnd";
- private static final String EMPTY_CND = TEST_DATA_PATH + "empty.cnd";
- private static final String IMAGES_CND = TEST_DATA_PATH + "images.cnd";
- private static final String INVALID_CND = TEST_DATA_PATH + "invalid.cnd";
- private static final String MP3_CND = TEST_DATA_PATH + "mp3.cnd";
-
- private static final int COMMENTS_INDEX = 0;
- private static final int NAMESPACES_INDEX = 1;
- private static final int NODE_TYPE_DEFINITIONS_INDEX = 2;
- private static final int PROPERTIES_INDEX = 2;
-
- //
=============================================================================================================================
- // Fields
- //
=============================================================================================================================
-
- private InputStream stream;
-
- //
=============================================================================================================================
- // Methods
- //
=============================================================================================================================
-
- @After
- public void afterEach() throws IOException {
- if (this.stream != null) {
- try {
- this.stream.close();
- } finally {
- this.stream = null;
- }
- }
- }
-
- private void assertCommentsCount( Tree root,
- int count ) {
- Tree comments = root.getChild(COMMENTS_INDEX);
- assertThat("Tree type was not CndParser.COMMENTS", comments.getType(),
is(CndParser.COMMENTS));
-
- // make sure right number of comments
- assertThat("Incorrect number of comments", comments.getChildCount(),
is(count));
- }
-
- private void assertNamespacesCount( Tree root,
- int count ) {
- Tree namespaces = getNamespaces(root);
- assertThat("Incorrect number of namespaces",
namespaces.getChildCount(), is(count));
- }
-
- private void assertNodeTypeDefinitionsCount( Tree root,
- int count ) {
- Tree nodeTypeDefinitions = getNodeTypeDefinitions(root);
- assertThat("Incorrect number of node type definitions",
nodeTypeDefinitions.getChildCount(), is(count));
- }
-
- private void assertNodeTypeDefinitionsPropertiesCount( Tree root,
- int nodeTypeDefinitionIndex,
- int count ) {
- Tree nodeTypeDefinitions = getNodeTypeDefinitions(root);
-
- Tree nodeType = nodeTypeDefinitions.getChild(nodeTypeDefinitionIndex);
- assertThat("Tree type was not CndParser.NODE_TYPE_DEFINITION",
nodeType.getType(), is(CndParser.NODE_TYPE_DEFINITION));
-
- Tree properties = nodeType.getChild(PROPERTIES_INDEX); // properties container
node
- assertThat("Tree type was not CndParser.PROPERTIES",
properties.getType(), is(CndParser.PROPERTIES));
-
- // make sure right number of properties
- assertThat("Incorrect number of node type properties for first node
type", properties.getChildCount(), is(count));
- }
-
- private CndParser createParser( File file ) throws IOException {
- afterEach(); // make sure previous stream is closed
- assertThat('\'' + file.getAbsolutePath() + "' does not
exist", file.exists(), is(true));
-
- this.stream = new FileInputStream(file);
- CndLexer lexer = new CndLexer(new ANTLRInputStream(this.stream));
- CommonTokenStream tokens = new CommonTokenStream(lexer);
-
- return new CndParser(tokens);
- }
-
- /**
- * @param root the AST root
- * @return the NAMESPACES tree node
- */
- private Tree getNamespaces( Tree root ) {
- Tree namespaces = root.getChild(NAMESPACES_INDEX);
-
- if (namespaces != null) {
- assertThat("Tree type was not CndParser.NAMESPACES",
namespaces.getType(), is(CndParser.NAMESPACES));
- }
-
- return namespaces;
- }
-
- /**
- * @param root the AST root
- * @return the NODE_TYPE_DEFINITIONS tree node
- */
- private Tree getNodeTypeDefinitions( Tree root ) {
- Tree nodeTypeDefinitions = root.getChild(NODE_TYPE_DEFINITIONS_INDEX);
-
- if (nodeTypeDefinitions != null) {
- assertThat("Tree type was not CndParser.NODE_TYPE_DEFINITIONS",
- nodeTypeDefinitions.getType(),
- is(CndParser.NODE_TYPE_DEFINITIONS));
- }
-
- return nodeTypeDefinitions;
- }
-
- /**
- * @param fileName the name of the file to parse
- * @return the root node of the AST
- * @throws Exception if root is null
- */
- private Tree parse( String fileName ) throws Exception {
- return parse(new File(fileName).getCanonicalFile());
- }
-
- /**
- * @param file the file to parse
- * @return the root node of the AST
- * @throws Exception if root is null
- */
- private Tree parse( File file ) throws Exception {
- CndParser parser = createParser(file);
- RuleReturnScope result = parser.cnd();
- Tree root = (Tree)result.getTree();
- assertThat(root, notNullValue());
-
- return root;
- }
-
- //
=============================================================================================================================
- // Tests
- //
=============================================================================================================================
-
- @Test
- public void shouldParseEmptyCnd() throws Exception {
- Tree root = parse(EMPTY_CND);
-
- // make sure no children
- assertThat(root.getChildCount(), is(0));
-
- // make sure nothing got parsed
- assertThat(root.getTokenStartIndex(), is(-1));
- }
-
- @Test
- public void shouldNotParseInvalidCnd() throws Exception {
- Tree root = parse(INVALID_CND);
-
- // make sure nothing got parsed
- assertThat(root.getTokenStopIndex(), is(0));
- }
-
- // @Test
- public void shouldParseBuiltinNodeTypesCndComments() throws Exception {
- Tree root = parse(BUILTIN_NODETYPES_CND);
- assertCommentsCount(root, 16);
- }
-
- @Test
- public void shouldParseBuiltinNodeTypesCndNamespaces() throws Exception {
- Tree root = parse(BUILTIN_NODETYPES_CND);
- assertNamespacesCount(root, 4);
- }
-
- // @Test
- public void shouldParseBuiltinNodeTypesCndNodeTypeDefinitions() throws Exception {
- Tree root = parse(BUILTIN_NODETYPES_CND);
-
- // make sure correct number of node type definitions
- assertNodeTypeDefinitionsCount(root, 23);
-
- // make sure right number of node type definitions for each node type
- assertNodeTypeDefinitionsPropertiesCount(root, 0, 2); // [nt:base]
- assertNodeTypeDefinitionsPropertiesCount(root, 1, 2); // [nt:unstructured]
- assertNodeTypeDefinitionsPropertiesCount(root, 2, 1); // [mix:referenceable]
- assertNodeTypeDefinitionsPropertiesCount(root, 3, 2); // [mix:lockable]
- assertNodeTypeDefinitionsPropertiesCount(root, 4, 5); // [mix:versionable]
- assertNodeTypeDefinitionsPropertiesCount(root, 5, 1); // [nt:versionHistory]
- assertNodeTypeDefinitionsPropertiesCount(root, 6, 1); // [nt:versionLabels]
- assertNodeTypeDefinitionsPropertiesCount(root, 7, 3); // [nt:version]
- assertNodeTypeDefinitionsPropertiesCount(root, 8, 5); // [nt:frozenNode]
- assertNodeTypeDefinitionsPropertiesCount(root, 9, 1); // [nt:versionedChild]
- assertNodeTypeDefinitionsPropertiesCount(root, 10, 5); // [nt:nodeType]
- assertNodeTypeDefinitionsPropertiesCount(root, 11, 9); //
[nt:propertyDefinition]
- assertNodeTypeDefinitionsPropertiesCount(root, 12, 8); //
[nt:childNodeDefinition]
- assertNodeTypeDefinitionsPropertiesCount(root, 13, 1); // [nt:hierarchyNode]
- assertNodeTypeDefinitionsPropertiesCount(root, 14, 0); // [nt:folder]
- assertNodeTypeDefinitionsPropertiesCount(root, 15, 0); // [nt:file]
- assertNodeTypeDefinitionsPropertiesCount(root, 16, 1); // [nt:linkedFile]
- assertNodeTypeDefinitionsPropertiesCount(root, 17, 4); // [nt:resource]
- assertNodeTypeDefinitionsPropertiesCount(root, 18, 2); // [nt:query]
- assertNodeTypeDefinitionsPropertiesCount(root, 19, 0); // [rep:nodeTypes]
- assertNodeTypeDefinitionsPropertiesCount(root, 20, 0); // [rep:root]
- assertNodeTypeDefinitionsPropertiesCount(root, 21, 0); // [rep:system]
- assertNodeTypeDefinitionsPropertiesCount(root, 22, 0); // [rep:versionStorage]
- }
-
- @Test
- public void shouldParseImagesCndComments() throws Exception {
- Tree root = parse(IMAGES_CND);
- assertCommentsCount(root, 11);
- }
-
- @Test
- public void shouldParseImagesCndNamespaces() throws Exception {
- Tree root = parse(IMAGES_CND);
- assertNamespacesCount(root, 4);
- }
-
- @Test
- public void shouldParseImagesCndNodeTypeDefinitions() throws Exception {
- Tree root = parse(IMAGES_CND);
-
- // make sure correct number of node type definitions
- assertNodeTypeDefinitionsCount(root, 2);
-
- // make sure right number of node type definitions for each node type
- assertNodeTypeDefinitionsPropertiesCount(root, 0, 2); // [mix:mimeType]
- assertNodeTypeDefinitionsPropertiesCount(root, 1, 10); // [image:metadata]
- }
-
- @Test
- public void shouldParseMp3CndComments() throws Exception {
- Tree root = parse(MP3_CND);
-
- // this will be the COMMENTS imaginary container token
- Tree comments = root.getChild(COMMENTS_INDEX);
- assertThat("Tree type was not CndParser.COMMENTS", comments.getType(),
is(CndParser.COMMENTS));
-
- // make sure right number of comments
- assertThat("Incorrect number of comments", comments.getChildCount(),
is(10));
- }
-
- @Test
- public void shouldParseMp3CndNamespaces() throws Exception {
- Tree root = parse(MP3_CND);
- assertNamespacesCount(root, 4);
- }
-
- @Test
- public void shouldParseMp3CndNodeTypeDefinitions() throws Exception {
- Tree root = parse(MP3_CND);
-
- // make sure correct number of node type definitions
- assertNodeTypeDefinitionsCount(root, 2);
-
- // make sure right number of node type definitions for each node type
- assertNodeTypeDefinitionsPropertiesCount(root, 0, 2); // [mix:mimeType]
- assertNodeTypeDefinitionsPropertiesCount(root, 1, 5); // [mp3:metadata]
- }
-}
Deleted:
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParserTest.java
===================================================================
---
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParserTest.java 2009-04-20
19:07:48 UTC (rev 840)
+++
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndParserTest.java 2009-04-20
20:21:21 UTC (rev 841)
@@ -1,768 +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.sequencer.cnd;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import org.antlr.runtime.ANTLRInputStream;
-import org.antlr.runtime.CommonTokenStream;
-import org.antlr.runtime.RuleReturnScope;
-import org.antlr.runtime.tree.RewriteEmptyStreamException;
-import org.junit.After;
-import org.junit.Test;
-
-public class CndParserTest {
-
- //
=============================================================================================================================
- // Fields
- //
=============================================================================================================================
-
- private InputStream stream;
-
- //
=============================================================================================================================
- // Methods
- //
=============================================================================================================================
-
- @After
- public void afterEach() throws IOException {
- if (this.stream != null) {
- try {
- this.stream.close();
- } finally {
- this.stream = null;
- }
- }
- }
-
- private CndParser createParser( String input ) throws IOException {
- afterEach(); // make sure previous stream is closed
- this.stream = new ByteArrayInputStream(input.getBytes("UTF-8"));
- CndLexer lexer = new CndLexer(new ANTLRInputStream(this.stream));
- CommonTokenStream tokens = new CommonTokenStream(lexer);
- return new CndParser(tokens);
- }
-
- //
=============================================================================================================================
- // Comment Parsing Tests
- //
=============================================================================================================================
-
- private void parseComment( String option,
- boolean success ) throws Exception {
- CndParser parser = createParser(option);
- RuleReturnScope scope = parser.comment();
-
- if (success) {
- assertThat("Value '" + option + "' did not parse and
should have", scope.getTree(), notNullValue());
- assertThat(option,
is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
- } else {
- assertThat("Value '" + option + "' should not parse
and did", scope.getTree(), nullValue());
- }
- }
-
- @Test
- public void shouldParseSingleLineComment() throws Exception {
- parseComment("// This is a single line comment", true);
- }
-
- @Test
- public void shouldParseMultiLineComment() throws Exception {
- parseComment("/* This\nis\na\nmulti-line\ncomment */", true);
- }
-
- @Test
- public void shouldNotParseNonComment() throws Exception {
- parseComment("This is not a valid comment", false);
- }
-
- @Test
- public void shouldNotParseMalformedComment() throws Exception {
- parseComment("/* This comment is missing ending delimeters", false);
- }
-
- //
=============================================================================================================================
- // Node Type Name Parsing Tests
- //
=============================================================================================================================
-
- private void parseNodeTypeName( String name,
- boolean success ) throws Exception {
- CndParser parser = createParser(name);
- RuleReturnScope scope = parser.node_type_name();
-
- if (success) {
- assertThat("Value '" + name + "' did not parse and
should have", scope.getTree(), notNullValue());
-
- // strip off brackets
- assertThat(name.substring(1, name.length() - 1),
is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
- } else {
- assertThat("Value '" + name + "' should not
parse", scope.getTree(), nullValue());
- }
- }
-
- @Test
- public void shouldParseUnquotedNodeTypeName() throws Exception {
- parseNodeTypeName("[typeName]", true);
- }
-
- @Test
- public void shouldParseQuotedNodeTypeName() throws Exception {
- parseNodeTypeName("['quotedName']", true);
- }
-
- @Test
- public void shouldNotParseNodeTypeNameWithSpaces() throws Exception {
- parseNodeTypeName("[no spaces allowed]", false);
- }
-
- @Test
- public void shouldNotParseNodeTypeNameWithMissingEndBracket() throws Exception {
- parseNodeTypeName("[missingClosingBracket", false);
- }
-
- @Test( expected = RewriteEmptyStreamException.class )
- public void shouldNotParseNodeTypeNameWithMissingBracketsButNoName() throws Exception
{
- parseNodeTypeName("[]", false);
- }
-
- //
=============================================================================================================================
- // Node Type Abstract Option Parsing Tests
- //
=============================================================================================================================
-
- private void parseAbstractOption( String option,
- boolean success ) throws Exception {
- CndParser parser = createParser(option);
- RuleReturnScope scope = parser.abs_opt();
-
- if (success) {
- assertThat("Value '" + option + "' did not parse and
should have", scope.getTree(), notNullValue());
- assertThat(option,
is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
- } else {
- assertThat("Value '" + option + "' should not parse
and did", scope.getTree(), nullValue());
- }
- }
-
- @Test
- public void shouldParseAbstractOption() throws Exception {
- parseAbstractOption("abstract", true);
- parseAbstractOption("abs", true);
- parseAbstractOption("a", true);
- }
-
- @Test
- public void shouldNotParseInvalidAbstractOption() throws Exception {
- parseAbstractOption("abstractoption", false);
- parseAbstractOption("A", false);
- }
-
- //
=============================================================================================================================
- // Node Type Orderable Option Parsing Tests
- //
=============================================================================================================================
-
- private void parseOrderableOption( String option,
- boolean success ) throws Exception {
- CndParser parser = createParser(option);
- RuleReturnScope scope = parser.orderable_opt();
-
- if (success) {
- assertThat("Value '" + option + "' did not parse and
should have", scope.getTree(), notNullValue());
- assertThat(option,
is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
- } else {
- assertThat("Value '" + option + "' should not parse
and did", scope.getTree(), nullValue());
- }
- }
-
- @Test
- public void shouldParseOrderableOption() throws Exception {
- parseOrderableOption("orderable", true);
- parseOrderableOption("ord", true);
- parseOrderableOption("o", true);
- }
-
- @Test
- public void shouldNotParseInvalidOrderableOption() throws Exception {
- parseOrderableOption("orderableoption", false);
- parseOrderableOption("O", false);
- }
-
- //
=============================================================================================================================
- // Node Type Mixin Option Parsing Tests
- //
=============================================================================================================================
-
- private void parseMixinOption( String option,
- boolean success ) throws Exception {
- CndParser parser = createParser(option);
- RuleReturnScope scope = parser.mixin_opt();
-
- if (success) {
- assertThat("Value '" + option + "' did not parse and
should have", scope.getTree(), notNullValue());
- assertThat(option,
is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
- } else {
- assertThat("Value '" + option + "' should not parse
and did", scope.getTree(), nullValue());
- }
- }
-
- @Test
- public void shouldParseMixinOption() throws Exception {
- parseMixinOption("mixin", true);
- parseMixinOption("mix", true);
- parseMixinOption("m", true);
- }
-
- @Test
- public void shouldNotParseInvalidMixinOption() throws Exception {
- parseMixinOption("mixinoption", false);
- parseMixinOption("M", false);
- }
-
- //
=============================================================================================================================
- // Node Type Orderable Mixin Options Parsing Tests
- //
=============================================================================================================================
-
- private void parseNodeTypeOrderableMixinOptions( String options,
- boolean success,
- int numChildren ) throws Exception
{
- CndParser parser = createParser(options);
- RuleReturnScope scope = parser.ord_mix_opt();
-
- if (success) {
- assertThat("Value '" + options + "' did not parse and
should have", scope.getTree(), notNullValue());
-
- if (numChildren == 0) {
- assertThat(options,
is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
- } else {
- assertThat(numChildren,
is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getChildCount()));
- }
- } else {
- assertThat("Value '" + options + "' should not parse
and did", scope.getTree(), nullValue());
- }
- }
-
- @Test
- public void shouldParseNodeTypeOrderableMixinOptions() throws Exception {
- parseNodeTypeOrderableMixinOptions("orderable", true, 0);
- parseNodeTypeOrderableMixinOptions("orderable mixin", true, 2);
- parseNodeTypeOrderableMixinOptions("orderable mix", true, 2);
- parseNodeTypeOrderableMixinOptions("orderable m", true, 2);
-
- parseNodeTypeOrderableMixinOptions("ord", true, 0);
- parseNodeTypeOrderableMixinOptions("ord mixin", true, 2);
- parseNodeTypeOrderableMixinOptions("ord mix", true, 2);
- parseNodeTypeOrderableMixinOptions("ord m", true, 2);
-
- parseNodeTypeOrderableMixinOptions("o", true, 0);
- parseNodeTypeOrderableMixinOptions("o mixin", true, 2);
- parseNodeTypeOrderableMixinOptions("o mix", true, 2);
- parseNodeTypeOrderableMixinOptions("o m", true, 2);
-
- parseNodeTypeOrderableMixinOptions("mixin", true, 0);
- parseNodeTypeOrderableMixinOptions("mixin orderable", true, 2);
- parseNodeTypeOrderableMixinOptions("mixin ord", true, 2);
- parseNodeTypeOrderableMixinOptions("mixin o", true, 2);
-
- parseNodeTypeOrderableMixinOptions("mix", true, 0);
- parseNodeTypeOrderableMixinOptions("mix orderable", true, 2);
- parseNodeTypeOrderableMixinOptions("mix ord", true, 2);
- parseNodeTypeOrderableMixinOptions("mix o", true, 2);
-
- parseNodeTypeOrderableMixinOptions("m", true, 0);
- parseNodeTypeOrderableMixinOptions("m orderable", true, 2);
- parseNodeTypeOrderableMixinOptions("m ord", true, 2);
- parseNodeTypeOrderableMixinOptions("m o", true, 2);
- }
-
- //
=============================================================================================================================
- // Node Type Options Parsing Tests
- //
=============================================================================================================================
-
- private void parseNodeTypeOptions( String options,
- boolean success,
- int numChildren ) throws Exception {
- CndParser parser = createParser(options);
- RuleReturnScope scope = parser.node_type_options();
-
- if (success) {
- assertThat("Value '" + options + "' did not parse and
should have", scope.getTree(), notNullValue());
-
- if (numChildren == 0) {
- assertThat(options,
is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
- } else {
- assertThat(numChildren,
is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getChildCount()));
- }
- } else {
- assertThat("Value '" + options + "' should not parse
and did", scope.getTree(), nullValue());
- }
- }
-
- @Test
- public void shouldParseNodeTypeOptions() throws Exception {
- parseNodeTypeOptions("abstract", true, 0);
- parseNodeTypeOptions("abs", true, 0);
- parseNodeTypeOptions("a", true, 0);
-
- parseNodeTypeOptions("abstract orderable", true, 2);
- parseNodeTypeOptions("abstract ord", true, 2);
- parseNodeTypeOptions("abstract o", true, 2);
-
- parseNodeTypeOptions("abs orderable", true, 2);
- parseNodeTypeOptions("abs ord", true, 2);
- parseNodeTypeOptions("abs o", true, 2);
-
- parseNodeTypeOptions("a orderable", true, 2);
- parseNodeTypeOptions("a ord", true, 2);
- parseNodeTypeOptions("a o", true, 2);
-
- parseNodeTypeOptions("abstract mixin", true, 2);
- parseNodeTypeOptions("abstract mix", true, 2);
- parseNodeTypeOptions("abstract m", true, 2);
-
- parseNodeTypeOptions("abs mixin", true, 2);
- parseNodeTypeOptions("abs mix", true, 2);
- parseNodeTypeOptions("abs m", true, 2);
-
- parseNodeTypeOptions("a mixin", true, 2);
- parseNodeTypeOptions("a mix", true, 2);
- parseNodeTypeOptions("a m", true, 2);
-
- parseNodeTypeOptions("abstract orderable mixin", true, 3);
- parseNodeTypeOptions("abstract orderable mix", true, 3);
- parseNodeTypeOptions("abstract orderable m", true, 3);
-
- parseNodeTypeOptions("abstract ord mixin", true, 3);
- parseNodeTypeOptions("abstract ord mix", true, 3);
- parseNodeTypeOptions("abstract ord m", true, 3);
-
- parseNodeTypeOptions("abstract o mixin", true, 3);
- parseNodeTypeOptions("abstract o mix", true, 3);
- parseNodeTypeOptions("abstract o m", true, 3);
-
- parseNodeTypeOptions("abs orderable mixin", true, 3);
- parseNodeTypeOptions("abs orderable mix", true, 3);
- parseNodeTypeOptions("abs orderable m", true, 3);
-
- parseNodeTypeOptions("abs ord mixin", true, 3);
- parseNodeTypeOptions("abs ord mix", true, 3);
- parseNodeTypeOptions("abs ord m", true, 3);
-
- parseNodeTypeOptions("abs o mixin", true, 3);
- parseNodeTypeOptions("abs o mix", true, 3);
- parseNodeTypeOptions("abs o m", true, 3);
-
- parseNodeTypeOptions("a orderable mixin", true, 3);
- parseNodeTypeOptions("a orderable mix", true, 3);
- parseNodeTypeOptions("a orderable m", true, 3);
-
- parseNodeTypeOptions("a ord mixin", true, 3);
- parseNodeTypeOptions("a ord mix", true, 3);
- parseNodeTypeOptions("a ord m", true, 3);
-
- parseNodeTypeOptions("a o mixin", true, 3);
- parseNodeTypeOptions("a o mix", true, 3);
- parseNodeTypeOptions("a o m", true, 3);
-
- parseNodeTypeOptions("abstract mixin orderable", true, 3);
- parseNodeTypeOptions("abstract mixin ord", true, 3);
- parseNodeTypeOptions("abstract mixin o", true, 3);
-
- parseNodeTypeOptions("abstract mix orderable", true, 3);
- parseNodeTypeOptions("abstract mix ord", true, 3);
- parseNodeTypeOptions("abstract mix o", true, 3);
-
- parseNodeTypeOptions("abstract m orderable", true, 3);
- parseNodeTypeOptions("abstract m ord", true, 3);
- parseNodeTypeOptions("abstract m o", true, 3);
-
- parseNodeTypeOptions("abs mixin orderable", true, 3);
- parseNodeTypeOptions("abs mixin ord", true, 3);
- parseNodeTypeOptions("abs mixin o", true, 3);
-
- parseNodeTypeOptions("abs mix orderable", true, 3);
- parseNodeTypeOptions("abs mix ord", true, 3);
- parseNodeTypeOptions("abs mix o", true, 3);
-
- parseNodeTypeOptions("abs m orderable", true, 3);
- parseNodeTypeOptions("abs m ord", true, 3);
- parseNodeTypeOptions("abs m o", true, 3);
-
- parseNodeTypeOptions("a mixin orderable", true, 3);
- parseNodeTypeOptions("a mixin ord", true, 3);
- parseNodeTypeOptions("a mixin o", true, 3);
-
- parseNodeTypeOptions("a mix orderable", true, 3);
- parseNodeTypeOptions("a mix ord", true, 3);
- parseNodeTypeOptions("a mix o", true, 3);
-
- parseNodeTypeOptions("a m orderable", true, 3);
- parseNodeTypeOptions("a m ord", true, 3);
- parseNodeTypeOptions("a m o", true, 3);
-
- parseNodeTypeOptions("orderable abstract", true, 2);
- parseNodeTypeOptions("ord abstract", true, 2);
- parseNodeTypeOptions("o abstract", true, 2);
-
- parseNodeTypeOptions("orderable abs", true, 2);
- parseNodeTypeOptions("ord abs", true, 2);
- parseNodeTypeOptions("o abs", true, 2);
-
- parseNodeTypeOptions("orderable a", true, 2);
- parseNodeTypeOptions("ord a", true, 2);
- parseNodeTypeOptions("o a", true, 2);
-
- parseNodeTypeOptions("mixin abstract", true, 2);
- parseNodeTypeOptions("mix abstract", true, 2);
- parseNodeTypeOptions("m abstract", true, 2);
-
- parseNodeTypeOptions("mixin abs", true, 2);
- parseNodeTypeOptions("mix abs", true, 2);
- parseNodeTypeOptions("m abs", true, 2);
-
- parseNodeTypeOptions("mixin a", true, 2);
- parseNodeTypeOptions("mix a", true, 2);
- parseNodeTypeOptions("m a", true, 2);
-
- parseNodeTypeOptions("orderable mixin abstract", true, 3);
- parseNodeTypeOptions("orderable mix abstract", true, 3);
- parseNodeTypeOptions("orderable m abstract", true, 3);
-
- parseNodeTypeOptions("ord mixin abstract", true, 3);
- parseNodeTypeOptions("ord mix abstract", true, 3);
- parseNodeTypeOptions("ord m abstract", true, 3);
-
- parseNodeTypeOptions("o mixin abstract", true, 3);
- parseNodeTypeOptions("o mix abstract", true, 3);
- parseNodeTypeOptions("o m abstract", true, 3);
-
- parseNodeTypeOptions("orderable mixin abs", true, 3);
- parseNodeTypeOptions("orderable mix abs", true, 3);
- parseNodeTypeOptions("orderable m abs", true, 3);
-
- parseNodeTypeOptions("ord mixin abs", true, 3);
- parseNodeTypeOptions("ord mix abs", true, 3);
- parseNodeTypeOptions("ord m abs", true, 3);
-
- parseNodeTypeOptions("o mixin abs", true, 3);
- parseNodeTypeOptions("o mix abs", true, 3);
- parseNodeTypeOptions("o m abs", true, 3);
-
- parseNodeTypeOptions("orderable mixin a", true, 3);
- parseNodeTypeOptions("orderable mix a", true, 3);
- parseNodeTypeOptions("orderable m a", true, 3);
-
- parseNodeTypeOptions("ord mixin a", true, 3);
- parseNodeTypeOptions("ord mix a", true, 3);
- parseNodeTypeOptions("ord m a", true, 3);
-
- parseNodeTypeOptions("o mixin a", true, 3);
- parseNodeTypeOptions("o mix a", true, 3);
- parseNodeTypeOptions("o m a", true, 3);
-
- parseNodeTypeOptions("mixin orderable abstract", true, 3);
- parseNodeTypeOptions("mixin ord abstract", true, 3);
- parseNodeTypeOptions("mixin o abstract", true, 3);
-
- parseNodeTypeOptions("mix orderable abstract", true, 3);
- parseNodeTypeOptions("mix ord abstract", true, 3);
- parseNodeTypeOptions("mix o abstract", true, 3);
-
- parseNodeTypeOptions("m orderable abstract", true, 3);
- parseNodeTypeOptions("m ord abstract", true, 3);
- parseNodeTypeOptions("m o abstract", true, 3);
-
- parseNodeTypeOptions("mixin orderable abs", true, 3);
- parseNodeTypeOptions("mixin ord abs", true, 3);
- parseNodeTypeOptions("mixin o abs", true, 3);
-
- parseNodeTypeOptions("mix orderable abs", true, 3);
- parseNodeTypeOptions("mix ord abs", true, 3);
- parseNodeTypeOptions("mix o abs", true, 3);
-
- parseNodeTypeOptions("m orderable abs", true, 3);
- parseNodeTypeOptions("m ord abs", true, 3);
- parseNodeTypeOptions("m o abs", true, 3);
-
- parseNodeTypeOptions("mixin orderable a", true, 3);
- parseNodeTypeOptions("mixin ord a", true, 3);
- parseNodeTypeOptions("mixin o a", true, 3);
-
- parseNodeTypeOptions("mix orderable a", true, 3);
- parseNodeTypeOptions("mix ord a", true, 3);
- parseNodeTypeOptions("mix o a", true, 3);
-
- parseNodeTypeOptions("m orderable a", true, 3);
- parseNodeTypeOptions("m ord a", true, 3);
- parseNodeTypeOptions("m o a", true, 3);
-
- parseNodeTypeOptions("orderable", true, 0);
- parseNodeTypeOptions("ord", true, 0);
- parseNodeTypeOptions("o", true, 0);
-
- parseNodeTypeOptions("mixin", true, 0);
- parseNodeTypeOptions("mix", true, 0);
- parseNodeTypeOptions("m", true, 0);
-
- parseNodeTypeOptions("orderable mixin", true, 2);
- parseNodeTypeOptions("orderable mix", true, 2);
- parseNodeTypeOptions("orderable m", true, 2);
-
- parseNodeTypeOptions("ord mixin", true, 2);
- parseNodeTypeOptions("ord mix", true, 2);
- parseNodeTypeOptions("ord m", true, 2);
-
- parseNodeTypeOptions("o mixin", true, 2);
- parseNodeTypeOptions("o mix", true, 2);
- parseNodeTypeOptions("o m", true, 2);
-
- parseNodeTypeOptions("mixin orderable", true, 2);
- parseNodeTypeOptions("mixin ord", true, 2);
- parseNodeTypeOptions("mixin o", true, 2);
-
- parseNodeTypeOptions("mix orderable", true, 2);
- parseNodeTypeOptions("mix ord", true, 2);
- parseNodeTypeOptions("mix o", true, 2);
-
- parseNodeTypeOptions("m orderable", true, 2);
- parseNodeTypeOptions("m ord", true, 2);
- parseNodeTypeOptions("m o", true, 2);
- }
-
- //
=============================================================================================================================
- // Property Type Parsing Tests
- //
=============================================================================================================================
-
- private void parsePropertyType( String propertyType,
- boolean success ) throws Exception {
- CndParser parser = createParser(propertyType);
- RuleReturnScope scope = parser.property_type();
-
- if (success) {
- assertThat("Value '" + propertyType + "' did not parse
and should have", scope.getTree(), notNullValue());
- assertThat(propertyType,
is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
- } else {
- assertThat("Value '" + propertyType + "' should not
parse and did", scope.getTree(), nullValue());
- }
- }
-
- @Test
- public void shouldParseStringPropertyType() throws Exception {
- parsePropertyType("STRING", true);
- parsePropertyType("String", true);
- parsePropertyType("string", true);
- }
-
- @Test
- public void shouldParseBinaryPropertyType() throws Exception {
- parsePropertyType("BINARY", true);
- parsePropertyType("Binary", true);
- parsePropertyType("binary", true);
- }
-
- @Test
- public void shouldParseLongPropertyType() throws Exception {
- parsePropertyType("LONG", true);
- parsePropertyType("Long", true);
- parsePropertyType("long", true);
- }
-
- @Test
- public void shouldParseDoublePropertyType() throws Exception {
- parsePropertyType("DOUBLE", true);
- parsePropertyType("Double", true);
- parsePropertyType("double", true);
- }
-
- @Test
- public void shouldParseDecimalPropertyType() throws Exception {
- parsePropertyType("DECIMAL", true);
- parsePropertyType("Decimal", true);
- parsePropertyType("decimal", true);
- }
-
- @Test
- public void shouldParseBooleanPropertyType() throws Exception {
- parsePropertyType("BOOLEAN", true);
- parsePropertyType("Boolean", true);
- parsePropertyType("boolean", true);
- }
-
- @Test
- public void shouldParseDatePropertyType() throws Exception {
- parsePropertyType("DATE", true);
- parsePropertyType("Date", true);
- parsePropertyType("date", true);
- }
-
- @Test
- public void shouldParseNamePropertyType() throws Exception {
- parsePropertyType("NAME", true);
- parsePropertyType("Name", true);
- parsePropertyType("name", true);
- }
-
- @Test
- public void shouldParsePathPropertyType() throws Exception {
- parsePropertyType("PATH", true);
- parsePropertyType("Path", true);
- parsePropertyType("path", true);
- }
-
- @Test
- public void shouldParseReferencePropertyType() throws Exception {
- parsePropertyType("REFERENCE", true);
- parsePropertyType("Reference", true);
- parsePropertyType("reference", true);
- }
-
- @Test
- public void shouldParseWeakReferencePropertyType() throws Exception {
- parsePropertyType("WEAKREFERENCE", true);
- parsePropertyType("WeakReference", true);
- parsePropertyType("weakreference", true);
- }
-
- @Test
- public void shouldParseUriPropertyType() throws Exception {
- parsePropertyType("URI", true);
- parsePropertyType("Uri", true);
- parsePropertyType("uri", true);
- }
-
- @Test
- public void shouldParseUndefinedPropertyType() throws Exception {
- parsePropertyType("UNDEFINED", true);
- parsePropertyType("Undefined", true);
- parsePropertyType("undefined", true);
- }
-
- @Test
- public void shouldNotParseInvalidPropertyType() throws Exception {
- parsePropertyType("B", false);
- parsePropertyType("b", false);
- parsePropertyType("binarytype", false);
- }
-
- //
=============================================================================================================================
- // Attributes Parsing Tests
- //
=============================================================================================================================
-
- private void parseAttribute( String attribute,
- boolean success ) throws Exception {
- CndParser parser = createParser(attribute);
- RuleReturnScope scope = parser.attributes();
-
- if (success) {
- assertThat("Value '" + attribute + "' did not parse
and should have", scope.getTree(), notNullValue());
- assertThat(attribute,
is(((org.antlr.runtime.tree.CommonTree)scope.getTree()).getText()));
- } else {
- assertThat("Value '" + attribute + "' should not parse
and did", scope.getTree(), nullValue());
- }
- }
-
- @Test
- public void shouldParsePrimaryAttribute() throws Exception {
- parseAttribute("primary", true);
- parseAttribute("pri", true);
- parseAttribute("!", true);
- }
-
- @Test
- public void shouldParseAutoCreatedAttribute() throws Exception {
- parseAttribute("autocreated", true);
- parseAttribute("aut", true);
- parseAttribute("a", true);
- }
-
- @Test
- public void shouldParseMandatoryAttribute() throws Exception {
- parseAttribute("mandatory", true);
- parseAttribute("man", true);
- parseAttribute("m", true);
- }
-
- @Test
- public void shouldParseProtectedAttribute() throws Exception {
- parseAttribute("protected", true);
- parseAttribute("pro", true);
- parseAttribute("p", true);
- }
-
- @Test
- public void shouldParseMultipleAttribute() throws Exception {
- parseAttribute("multiple", true);
- parseAttribute("mul", true);
- parseAttribute("*", true);
- }
-
- @Test
- public void shouldParseCopyAttribute() throws Exception {
- parseAttribute("COPY", true);
- parseAttribute("Copy", true);
- parseAttribute("copy", true);
- }
-
- @Test
- public void shouldParseVersionAttribute() throws Exception {
- parseAttribute("VERSION", true);
- parseAttribute("Version", true);
- parseAttribute("version", true);
- }
-
- @Test
- public void shouldParseInitializeAttribute() throws Exception {
- parseAttribute("INITIALIZE", true);
- parseAttribute("Initialize", true);
- parseAttribute("initialize", true);
- }
-
- @Test
- public void shouldParseComputeAttribute() throws Exception {
- parseAttribute("COMPUTE", true);
- parseAttribute("Compute", true);
- parseAttribute("compute", true);
- }
-
- @Test
- public void shouldParseIgnoreAttribute() throws Exception {
- parseAttribute("IGNORE", true);
- parseAttribute("Ignore", true);
- parseAttribute("ignore", true);
- }
-
- @Test
- public void shouldParseAbortAttribute() throws Exception {
- parseAttribute("ABORT", true);
- parseAttribute("Abort", true);
- parseAttribute("abort", true);
- }
-
- @Test
- public void shouldNotParseInvalidAttribute() throws Exception {
- parsePropertyType("P", false);
- parsePropertyType("A", false);
- parsePropertyType("PRIMARY", false);
- }
-}
Added:
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndSequencerI18nTest.java
===================================================================
---
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndSequencerI18nTest.java
(rev 0)
+++
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndSequencerI18nTest.java 2009-04-20
20:21:21 UTC (rev 841)
@@ -0,0 +1,36 @@
+/*
+ * 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.sequencer.cnd;
+
+import org.jboss.dna.common.AbstractI18nTest;
+
+/**
+ * @author John Verhaeg
+ */
+public class CndSequencerI18nTest extends AbstractI18nTest {
+
+ public CndSequencerI18nTest() {
+ super(CndSequencerI18n.class);
+ }
+}
Added:
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndSequencerTest.java
===================================================================
---
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndSequencerTest.java
(rev 0)
+++
trunk/extensions/dna-sequencer-cnd/src/test/java/org/jboss/dna/sequencer/cnd/CndSequencerTest.java 2009-04-20
20:21:21 UTC (rev 841)
@@ -0,0 +1,127 @@
+/*
+ * 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.
+ *
+ * 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.sequencer.cnd;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import org.jboss.dna.graph.sequencer.MockSequencerContext;
+import org.jboss.dna.graph.sequencer.MockSequencerOutput;
+import org.jboss.dna.graph.sequencer.SequencerContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class CndSequencerTest {
+ private CndSequencer sequencer;
+ private InputStream content;
+ private MockSequencerOutput output;
+ private URL cndEmpty;
+ private URL cndImages;
+ private URL cndMp3;
+ private URL cndBuiltIns;
+ private SequencerContext context;
+
+ @Before
+ public void beforeEach() {
+ sequencer = new CndSequencer();
+ context = new MockSequencerContext("/a/mySequencer.cnd");
+ context.getNamespaceRegistry().register("jcr",
"http://www.jcp.org/jcr/1.0");
+ context.getNamespaceRegistry().register("nt",
"http://www.jcp.org/jcr/nt/1.0");
+ context.getNamespaceRegistry().register("mix",
"http://www.jcp.org/jcr/mix/1.0");
+ output = new MockSequencerOutput(context);
+ cndEmpty = this.getClass().getClassLoader().getResource("empty.cnd");
+ cndImages =
this.getClass().getClassLoader().getResource("images.cnd");
+ cndMp3 = this.getClass().getClassLoader().getResource("mp3.cnd");
+ cndBuiltIns =
this.getClass().getClassLoader().getResource("builtin_nodetypes.cnd");
+ }
+
+ @After
+ public void afterEach() throws Exception {
+ if (content != null) {
+ try {
+ content.close();
+ } finally {
+ content = null;
+ }
+ }
+ }
+
+ @Test
+ public void shouldGenerateNodeTypesForCndFileWithJSR170BuiltIns() throws IOException
{
+ URL url = this.cndBuiltIns;
+ assertThat(url, is(notNullValue()));
+ content = url.openStream();
+ assertThat(content, is(notNullValue()));
+ sequencer.sequence(content, output, context);
+ // assertThat(output.getPropertyValues("image:metadata",
"jcr:primaryType"), is(new Object[] {"image:metadata"}));
+ // assertThat(output.getPropertyValues("image:metadata",
"jcr:mimeType"), is(new Object[] {"image/jpeg"}));
+ // assertThat(output.getPropertyValues("image:metadata",
"image:formatName"), is(new Object[] {"JPEG"}));
+ // assertThat(output.getPropertyValues("image:metadata",
"image:width"), is(new Object[] {48}));
+ // assertThat(output.getPropertyValues("image:metadata",
"image:height"), is(new Object[] {48}));
+ // assertThat(output.getPropertyValues("image:metadata",
"image:bitsPerPixel"), is(new Object[] {24}));
+ // assertThat(output.getPropertyValues("image:metadata",
"image:progressive"), is(new Object[] {false}));
+ // assertThat(output.getPropertyValues("image:metadata",
"image:numberOfImages"), is(new Object[] {1}));
+ // assertThat(output.getPropertyValues("image:metadata",
"image:physicalWidthDpi"), is(new Object[] {72}));
+ // assertThat(output.getPropertyValues("image:metadata",
"image:physicalHeightDpi"), is(new Object[] {72}));
+ // assertThat(((Float)(output.getPropertyValues("image:metadata",
"image:physicalWidthInches")[0])).doubleValue(),
+ // is(closeTo(0.666667d, 0.0001d)));
+ // assertThat(((Float)(output.getPropertyValues("image:metadata",
"image:physicalHeightInches")[0])).doubleValue(),
+ // is(closeTo(0.666667d, 0.0001d)));
+ }
+
+ @Test
+ public void shouldGenerateNodeTypesForEmptyCndFile() throws IOException {
+ URL url = this.cndEmpty;
+ assertThat(url, is(notNullValue()));
+ content = url.openStream();
+ assertThat(content, is(notNullValue()));
+ sequencer.sequence(content, output, context);
+ }
+
+ @Test
+ public void shouldGenerateNodeTypesForCndFileWithImageNodeTypes() throws IOException
{
+ URL url = this.cndImages;
+ assertThat(url, is(notNullValue()));
+ content = url.openStream();
+ assertThat(content, is(notNullValue()));
+ sequencer.sequence(content, output, context);
+ }
+
+ @Test
+ public void shouldGenerateNodeTypesForCndFileWithMp3NodeTypes() throws IOException {
+ URL url = this.cndMp3;
+ assertThat(url, is(notNullValue()));
+ content = url.openStream();
+ assertThat(content, is(notNullValue()));
+ sequencer.sequence(content, output, context);
+ }
+
+}
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-04-20 19:07:48 UTC (rev 840)
+++ trunk/pom.xml 2009-04-20 20:21:21 UTC (rev 841)
@@ -121,7 +121,7 @@
<module>extensions/dna-sequencer-mp3</module>
<module>extensions/dna-sequencer-jbpm-jpdl</module>
<!--module>extensions/dna-sequencer-esbMessage</module-->
- <module>extensions/dna-sequencer-cnd</module>
+ <!--module>extensions/dna-sequencer-cnd</module-->
<module>extensions/dna-sequencer-java</module>
<module>extensions/dna-sequencer-msoffice</module>
<module>extensions/dna-sequencer-xml</module>
@@ -388,6 +388,11 @@
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
+ <artifactId>dna-cnd</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
<artifactId>dna-repository</artifactId>
<version>${pom.version}</version>
</dependency>