db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r918869 - in /db/torque/torque4/trunk/torque-generator/src: main/java/org/apache/torque/gf/configuration/generator/ test/java/org/apache/torque/gf/configuration/generator/ test/propertyToJava/src/main/torque-gf/generatorDefs/
Date Thu, 04 Mar 2010 06:23:11 GMT
Author: tfischer
Date: Thu Mar  4 06:23:11 2010
New Revision: 918869

URL: http://svn.apache.org/viewvc?rev=918869&view=rev
Log:
- throw correct exception if two generators are defined with same name
- added testcase for this

Added:
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/configuration/generator/
    db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationTest.java
Modified:
    db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfiguration.java
    db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/src/main/torque-gf/generatorDefs/javaTestGenerator.xml

Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfiguration.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfiguration.java?rev=918869&r1=918868&r2=918869&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfiguration.java
(original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/gf/configuration/generator/GeneratorConfiguration.java
Thu Mar  4 06:23:11 2010
@@ -54,10 +54,13 @@
      *
      * @param generators the list of generators, not null.
      *
+     * @throws ConfigurationException if generators contains
+     *         two generators with the same name.
      * @throws NullPointerException if generatorList is null.
      */
     public GeneratorConfiguration(Collection<Generator> generators,
-            Collection<MergepointMapping> mergepointMappings)
+                Collection<MergepointMapping> mergepointMappings)
+            throws ConfigurationException
     {
         if (generators == null)
         {
@@ -70,7 +73,7 @@
         }
         for (Generator generator : generators)
         {
-            this.generators.put(generator.getName(), generator);
+            addGenerator(generator);
         }
         for (MergepointMapping mergepointMapping : mergepointMappings)
         {
@@ -181,7 +184,8 @@
         {
             throw new NullPointerException("generator must not be null");
         }
-        if (generators.get(generator.getName()) != null)
+        Generator existingGenerator = generators.get(generator.getName());
+        if (existingGenerator != null)
         {
             throw new ConfigurationException("Trying to add the generator "
                     + generator.getName()
@@ -189,7 +193,7 @@
                     + generator.getClass().getName()
                     + " : A generator with the same name "
                     + " already exists, it has the class "
-                    + getGenerator(generator.getName()).getClass().getName());
+                    + existingGenerator.getClass().getName());
         }
         generators.put(generator.getName(), generator);
     }

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationTest.java?rev=918869&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationTest.java
(added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/configuration/generator/GeneratorConfigurationTest.java
Thu Mar  4 06:23:11 2010
@@ -0,0 +1,166 @@
+package org.apache.torque.gf.configuration.generator;
+
+/*
+ * 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.
+ */
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.torque.gf.configuration.ConfigurationException;
+import org.apache.torque.gf.configuration.mergepoint.MergepointMapping;
+import org.apache.torque.gf.control.action.ApplyAction;
+import org.apache.torque.gf.generator.Generator;
+import org.apache.torque.gf.generator.java.PackageToPathGenerator;
+import org.apache.torque.gf.java.JavaGenerator;
+import org.apache.torque.gf.qname.QualifiedName;
+import org.junit.Test;
+
+public class GeneratorConfigurationTest
+{
+    private GeneratorConfiguration generatorConfiguration;
+    
+    
+    /**
+     * Tests that getGenerators returns the correct result.
+     * 
+     * @throws ConfigurationException if an error occurs.
+     */
+    @Test
+    public void testGetGenerators() throws ConfigurationException
+    {
+        List<Generator> generators = new ArrayList<Generator>();
+        generators.add(new JavaGenerator(
+                new QualifiedName("test.generator.0")));
+        generators.add(new PackageToPathGenerator(
+                new QualifiedName("test.generator.1")));
+        List<MergepointMapping> mergepointMappings 
+                = new ArrayList<MergepointMapping>();
+        
+        GeneratorConfiguration generatorConfiguration
+                = new GeneratorConfiguration(generators, mergepointMappings);
+        generatorConfiguration.resolveMergepointMappings();
+        
+        assertEquals(2, generatorConfiguration.getGenerators().size());
+        assertEquals(
+                generators.get(0), 
+                generatorConfiguration.getGenerators().get(
+                        new QualifiedName("test.generator.0")));
+        assertEquals(
+                generators.get(1), 
+                generatorConfiguration.getGenerators().get(
+                        new QualifiedName("test.generator.1")));
+    }
+
+    /**
+     * Tests that one cannot add a generator with the same name twice
+     * 
+     * @throws ConfigurationException if GeneratorConfiguration cannot be
+     *         created,
+     */
+    @Test(expected = ConfigurationException.class)
+    public void testConstructorWithSameGeneratorName() 
+            throws ConfigurationException
+    {
+        List<Generator> generators = new ArrayList<Generator>();
+        generators.add(new JavaGenerator(
+                new QualifiedName("sameName")));
+        generators.add(new PackageToPathGenerator(
+                new QualifiedName("sameName")));
+        List<MergepointMapping> mergepointMappings 
+                = new ArrayList<MergepointMapping>();
+
+        new GeneratorConfiguration(generators, mergepointMappings);
+    }
+
+    /**
+     * Checks that resolveMergepointMappings adds the mergepoint
+     * to the correct generator.
+     */
+    @Test
+    public void testResolveMergepointMappings() throws ConfigurationException
+    {
+        List<Generator> generators = new ArrayList<Generator>();
+        generators.add(new JavaGenerator(
+                new QualifiedName("test.generator")));
+        generators.add(new PackageToPathGenerator(
+                new QualifiedName("test.generator.2")));
+        List<MergepointMapping> mergepointMappings 
+                = new ArrayList<MergepointMapping>();
+        mergepointMappings.add(
+                new MergepointMapping("test.generator.testMergepoint"));
+        mergepointMappings.get(0).addAction(
+                new ApplyAction(".", "test.generator.2", false));
+        
+        GeneratorConfiguration generatorConfiguration
+                = new GeneratorConfiguration(generators, mergepointMappings);
+        generatorConfiguration.resolveMergepointMappings();
+        
+        Generator generator = generatorConfiguration.getGenerator(
+                new QualifiedName("test.generator"));
+        assertEquals(1, generator.getMergepointMappings().size());
+        assertEquals(
+                1, 
+                generator.getMergepointMapping("testMergepoint")
+                    .getActions().size());
+    }
+
+    /**
+     * Checks that resolveMergepointMappings throws an error if the 
+     * generator name cannot be resolved.
+     */
+    @Test(expected = ConfigurationException.class)
+    public void testResolveMergepointMappingsNotExistingGenerator()
+            throws ConfigurationException
+    {
+        List<Generator> generators = new ArrayList<Generator>();
+        generators.add(new JavaGenerator(
+                new QualifiedName("test.generator")));
+        List<MergepointMapping> mergepointMappings 
+                = new ArrayList<MergepointMapping>();
+        mergepointMappings.add(
+                new MergepointMapping("not.existing.generator.testMergepoint"));
+        
+        GeneratorConfiguration generatorConfiguration
+                = new GeneratorConfiguration(generators, mergepointMappings);
+        generatorConfiguration.resolveMergepointMappings();
+    }
+
+    /**
+     * Checks that resolveMergepointMappings throws an error if a 
+     * mergepoint does not contain a namespace.
+     */
+    @Test(expected = ConfigurationException.class)
+    public void testResolveMergepointMappingsNoNamespace()
+            throws ConfigurationException
+    {
+        List<Generator> generators = new ArrayList<Generator>();
+        generators.add(new JavaGenerator(
+                new QualifiedName("test.generator")));
+        List<MergepointMapping> mergepointMappings 
+                = new ArrayList<MergepointMapping>();
+        mergepointMappings.add(
+                new MergepointMapping("testMergepoint"));
+        
+        GeneratorConfiguration generatorConfiguration
+                = new GeneratorConfiguration(generators, mergepointMappings);
+        generatorConfiguration.resolveMergepointMappings();
+    }
+}

Modified: db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/src/main/torque-gf/generatorDefs/javaTestGenerator.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/src/main/torque-gf/generatorDefs/javaTestGenerator.xml?rev=918869&r1=918868&r2=918869&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/src/main/torque-gf/generatorDefs/javaTestGenerator.xml
(original)
+++ db/torque/torque4/trunk/torque-generator/src/test/propertyToJava/src/main/torque-gf/generatorDefs/javaTestGenerator.xml
Thu Mar  4 06:23:11 2010
@@ -32,7 +32,4 @@
     <foo>Foo</foo>
     <bar>Bar</bar>
   </generator>
-  <generator name="org.apache.torque.gf.velocity.propertyCopy"
-      xsi:type="velocityGenerator" 
-      path="propertyCopy.vm"/>
 </generators>
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message