[dna-commits] DNA SVN: r965 - in trunk/dna-cnd/src: test/java/org/jboss/dna/cnd and 1 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Wed Jun 3 15:55:23 EDT 2009


Author: rhauch
Date: 2009-06-03 15:55:23 -0400 (Wed, 03 Jun 2009)
New Revision: 965

Added:
   trunk/dna-cnd/src/test/resources/cnd/aircraft.cnd
   trunk/dna-cnd/src/test/resources/cnd/cars.cnd
Modified:
   trunk/dna-cnd/src/main/antlr3/org/jboss/dna/cnd/Cnd.g
   trunk/dna-cnd/src/test/java/org/jboss/dna/cnd/CndImporterTest.java
Log:
Added more test cases to the CND importer, including two that use regular expressions for the constraints

Modified: trunk/dna-cnd/src/main/antlr3/org/jboss/dna/cnd/Cnd.g
===================================================================
--- trunk/dna-cnd/src/main/antlr3/org/jboss/dna/cnd/Cnd.g	2009-06-03 17:29:22 UTC (rev 964)
+++ trunk/dna-cnd/src/main/antlr3/org/jboss/dna/cnd/Cnd.g	2009-06-03 19:55:23 UTC (rev 965)
@@ -348,8 +348,8 @@
 
 // Quoted strings may contain escaped characters.
 fragment QUOTED_STRING
-    : '"' ( EscapeSequence | ~('\\'|'"'))* '"'
-    | '\'' ( EscapeSequence | ~('\\'|'\''))* '\'' 
+    : '"' ( EscapeSequence | ~('"'))* '"'
+    | '\'' ( EscapeSequence | ~('\''))* '\'' 
     ;
 
 fragment EscapeSequence 

Modified: trunk/dna-cnd/src/test/java/org/jboss/dna/cnd/CndImporterTest.java
===================================================================
--- trunk/dna-cnd/src/test/java/org/jboss/dna/cnd/CndImporterTest.java	2009-06-03 17:29:22 UTC (rev 964)
+++ trunk/dna-cnd/src/test/java/org/jboss/dna/cnd/CndImporterTest.java	2009-06-03 19:55:23 UTC (rev 965)
@@ -101,10 +101,12 @@
         }
     }
 
-    protected Node node( String pathToNode, String childNodeName, String nameValue ) {
+    protected Node node( String pathToNode,
+                         String childNodeName,
+                         String nameValue ) {
         Node a = graph.getNodeAt("/a/" + pathToNode);
         List<Location> children = a.getChildren();
-        
+
         for (Location childLocation : a.getChildren()) {
             if (!childLocation.getPath().getLastSegment().getName().equals(name(childNodeName))) continue;
             Node child = graph.getNodeAt(childLocation);
@@ -113,7 +115,7 @@
                 return child;
             }
         }
-        
+
         return null;
     }
 
@@ -245,7 +247,8 @@
         // + * (nt:base) = nt:unstructured multiple version
         assertNodeType("nt:unstructured", NO_SUPERTYPES, NO_PRIMARY_NAME, NodeOptions.Ordered);
         assertProperty("nt:unstructured", "*", "Undefined", NO_DEFAULTS, PropertyOptions.Multiple);
-        // We should test for this, but we'd have to rewrite node() to look more like RepositoryNodeTypeManager.findChildNodeDefinition
+        // We should test for this, but we'd have to rewrite node() to look more like
+        // RepositoryNodeTypeManager.findChildNodeDefinition
         // assertProperty("nt:unstructured", "*", "Undefined", NO_DEFAULTS);
         assertChild("nt:unstructured", "*", "nt:base", "nt:unstructured", OnParentVersion.Version, ChildOptions.Multiple);
 
@@ -334,8 +337,9 @@
         // + * (nt:base) = nt:unstructured multiple version
         assertNodeType("nt:unstructured", NO_SUPERTYPES, NO_PRIMARY_NAME, NodeOptions.Ordered);
         assertProperty("nt:unstructured", "*", "Undefined", NO_DEFAULTS, PropertyOptions.Multiple);
-        // We should test for this, but we'd have to rewrite node() to look more like RepositoryNodeTypeManager.findChildNodeDefinition
-        //assertProperty("nt:unstructured", "*", "Undefined", NO_DEFAULTS);
+        // We should test for this, but we'd have to rewrite node() to look more like
+        // RepositoryNodeTypeManager.findChildNodeDefinition
+        // assertProperty("nt:unstructured", "*", "Undefined", NO_DEFAULTS);
         assertChild("nt:unstructured", "*", "nt:base", "nt:unstructured", OnParentVersion.Version, ChildOptions.Multiple);
 
         // [mix:referenceable]
@@ -428,6 +432,20 @@
         assertThat(problems.size(), is(1));
     }
 
+    @Test
+    public void shouldImportCndForAircraft() throws Exception {
+        importer.importFrom(openCndFile("aircraft.cnd"), problems);
+        if (problems.size() != 0) printProblems();
+        assertThat(problems.size(), is(0));
+    }
+
+    @Test
+    public void shouldImportCndForCars() throws Exception {
+        importer.importFrom(openCndFile("cars.cnd"), problems);
+        if (problems.size() != 0) printProblems();
+        assertThat(problems.size(), is(0));
+    }
+
     public static final String[] NO_DEFAULTS = {};
     public static final String[] NO_SUPERTYPES = {};
     public static final String[] NO_VALUE_CONSTRAINTS = {};

Added: trunk/dna-cnd/src/test/resources/cnd/aircraft.cnd
===================================================================
--- trunk/dna-cnd/src/test/resources/cnd/aircraft.cnd	                        (rev 0)
+++ trunk/dna-cnd/src/test/resources/cnd/aircraft.cnd	2009-06-03 19:55:23 UTC (rev 965)
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+ 
+//------------------------------------------------------------------------------
+// N A M E S P A C E S
+//------------------------------------------------------------------------------
+<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'>
+<air='http://jboss.org/dna/examples/aircraft/1.0'>
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+[air:Aircraft] > nt:unstructured
+  - air:maker (string)
+  - air:model (string)
+  - air:designedBy (string)
+  - air:introduced (string) < "(19|20)\d{2}"                // any 4 digit number starting with '19' or '20'
+  - air:range (string)                                      // any integer (with optional ',' every 1000s place)
+     < "\d{1,3}(,?\d{3})*\s*(nm|m|km|mi|ft)"                // followed by 'nm', 'm', 'km', 'mi', or 'ft'
+  - air:maxSpeed (string)                                   // any integer (with optional ',' every 1000s place)
+    < '\d{1,3}(,?\d{3})*\s*(kt|mph|km/h|kmph)'              // followed by 'kt', 'mph', 'km/h' or 'kmph'
+  - air:takeoffSpeed (string)                               // any integer (with optional ',' every 1000s place)
+    < '\d{1,3}(,?\d{3})*\s*(kt|mph|km/h|kmph)'              // followed by 'kt', 'mph', 'km/h' or 'kmph'
+  - air:cruiseSpeed (string)                                // any integer (with optional ',' every 1000s place)
+    < '\d{1,3}(,?\d{3})*\s*(kt|mph|km/h|kmph)'              // followed by 'kt', 'mph', 'km/h' or 'kmph'
+  - air:emptyWeight (string)                                // any integer (with optional ',' every 1000s place)
+    < '\d{1,3}(,?\d{3})*\s*(lb|kg)'                         // followed by 'lb' or 'kg'
+  - air:maxWeight (string)                                  // any integer (with optional ',' every 1000s place)
+    < '\d{1,3}(,?\d{3})*\s*(lb|kg)'                         // followed by 'lb' or 'kg'
+  - air:rateOfClimb (string)                                // any integer (with optional ',' every 1000s place)
+    < '\d{1,3}(,?\d{3})*\s*(ft|km|m)/(s|min)'               // followed by 'ft/s', 'ft/min', 'km/s', 'km/min', 'm/s', or 'm/min'
+  - air:serviceCeiling (string)                             // any integer (with optional ',' every 1000s place)
+    < '\d{1,3}(,?\d{3})*\s*(nm|m|km|mi|ft)'                 // followed by 'nm', 'm', 'km', 'mi', or 'ft'
+  - air:fuelCapacity (string)                               // any integer (with optional ',' every 1000s place)
+    < '\d{1,3}(,?\d{3})*\s*(lb|kg|gal|L)'                   // followed by 'lb', 'kg', 'gal', or 'L'
+  - air:crew (long) < '[0,)'                                // any non-negative value
+  - air:numberBuilt (string)                                // any integer (with optional ',' every 1000s place)
+    < '\d{1,3}(,?\d{3})*\s*[+]?' ,                          // optionally followed by '+'
+      '([<>]\s*)?\d{1,3}(,?\d{3})*'                         // or prefixed by '<' or '>'
+  - air:url (string)

Added: trunk/dna-cnd/src/test/resources/cnd/cars.cnd
===================================================================
--- trunk/dna-cnd/src/test/resources/cnd/cars.cnd	                        (rev 0)
+++ trunk/dna-cnd/src/test/resources/cnd/cars.cnd	2009-06-03 19:55:23 UTC (rev 965)
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+ 
+//------------------------------------------------------------------------------
+// N A M E S P A C E S
+//------------------------------------------------------------------------------
+<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'>
+<car='http://jboss.org/dna/examples/cars/1.0'>
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+[car:Car] > nt:unstructured
+  - car:maker (string)
+  - car:model (string)
+  - car:year (string) < '(19|20)\d{2}'                     // any 4 digit number starting with '19' or '20'
+  - car:msrp (string) < '[$]\d{1,3}[,]?\d{3}([.]\d{2})?'   // of the form "$X,XXX.ZZ", "$XX,XXX.ZZ" or "$XXX,XXX.ZZ" 
+                                                           // where '.ZZ' is optional
+  - car:userRating (long) < '[1,5]'                        // any value from 1 to 5 (inclusive)
+  - car:valueRating (long) < '[1,5]'                       // any value from 1 to 5 (inclusive)
+  - car:mpgCity (long) < '(0,]'                            // any value greater than 0
+  - car:mpgHighway (long) < '(0,]'                         // any value greater than 0
+  - car:lengthInInches (double) < '(0,]'                   // any value greater than 0
+  - car:wheelbaseInInches (double) < '(0,]'                // any value greater than 0
+  - car:engine (string)
+




More information about the dna-commits mailing list