db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r910600 [16/29] - in /db/torque/torque4/trunk: maven-torque-gf-plugin/ maven-torque-gf-plugin/src/ maven-torque-gf-plugin/src/main/ maven-torque-gf-plugin/src/main/java/ maven-torque-gf-plugin/src/main/java/org/ maven-torque-gf-plugin/src/m...
Date Tue, 16 Feb 2010 17:16:02 GMT
Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/java/JavaGenerator.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/java/JavaGenerator.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/java/JavaGenerator.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/java/JavaGenerator.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,137 @@
+package org.apache.torque.gf.java;
+
+/*
+ * 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 org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.gf.control.ControllerState;
+import org.apache.torque.gf.generator.GeneratorException;
+import org.apache.torque.gf.generator.GeneratorImpl;
+import org.apache.torque.gf.qname.QualifiedName;
+
+public class JavaGenerator extends GeneratorImpl
+{
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((bar == null) ? 0 : bar.hashCode());
+        result = prime * result + ((foo == null) ? 0 : foo.hashCode());
+        result = prime * result + getName().hashCode();
+        result = prime * result + ((getInputElementName() == null)
+                ? 0
+                : getInputElementName().hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+        {
+            return true;
+        }
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        JavaGenerator other = (JavaGenerator) obj;
+        if (bar == null)
+        {
+            if (other.bar != null)
+            {
+                return false;
+            }
+        } else if (!bar.equals(other.bar))
+        {
+            return false;
+        }
+        if (foo == null)
+        {
+            if (other.foo != null)
+            {
+                return false;
+            }
+        } else if (!foo.equals(other.foo))
+        {
+            return false;
+        }
+        if (!getName().equals(other.getName()))
+        {
+            return false;
+        }
+        if (getInputElementName() == null)
+        {
+            if (other.getInputElementName() != null)
+            {
+                return false;
+            }
+        } else if (!getInputElementName().equals(other.getInputElementName()))
+        {
+            return false;
+        }
+        return true;
+    }
+
+    private static Log log = LogFactory.getLog(JavaGenerator.class);
+
+    private String foo;
+
+    private String bar;
+
+    public JavaGenerator(QualifiedName name)
+    {
+        super(name);
+    }
+
+    @Override
+    public String execute(ControllerState controllerState)
+            throws GeneratorException
+    {
+        return "Test Generator output";
+    }
+
+    public void setFoo(String foo)
+    {
+        log.info("foo set to " + foo);
+        this.foo = foo;
+    }
+
+    public void setBar(String bar)
+    {
+        log.info("bar set to " + bar);
+        this.bar = bar;
+    }
+
+    public String getBar()
+    {
+        return bar;
+    }
+
+    public String getFoo()
+    {
+        return foo;
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/processor/string/CamelbackerTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/processor/string/CamelbackerTest.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/processor/string/CamelbackerTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/processor/string/CamelbackerTest.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,115 @@
+package org.apache.torque.gf.processor.string;
+
+/*
+ * 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 org.junit.Before;
+import org.junit.Test;
+
+public class CamelbackerTest
+{
+    Camelbacker camelbacker;
+
+    @Before
+    public void setUp()
+    {
+        camelbacker = new Camelbacker();
+    }
+
+    @Test
+    public void testDefault()
+    {
+        String result = camelbacker.process("prOcess-ing_Test");
+        assertEquals("ProcessIngTest", result);
+    }
+
+    @Test
+    public void testRemoveWithUppercaseNull()
+    {
+        camelbacker.setRemoveWithUppercase(null);
+        String result = camelbacker.process("prOcess-ing_Test");
+        assertEquals("Process-ing_test", result);
+    }
+
+    @Test
+    public void testFirstCharacterUppercaseFalse()
+    {
+        camelbacker.setFirstCharUppercase(false);
+        String result = camelbacker.process("prOcess-ing_Test");
+        assertEquals("processIngTest", result);
+
+        result = camelbacker.process("PrOcess-ing_Test");
+        assertEquals("processIngTest", result);
+
+        camelbacker.setDefaultLowerCase(false);
+        result = camelbacker.process("PrOcess-ing_Test");
+        assertEquals("PrOcessIngTest", result);
+    }
+
+    @Test
+    public void testDefaultLowerCaseFalse()
+    {
+        camelbacker.setDefaultLowerCase(false);
+        String result = camelbacker.process("PrOcess-ing_Test");
+        assertEquals("PrOcessIngTest", result);
+    }
+
+    @Test
+    public void testIgnoreBeforeAfter()
+    {
+        String result = camelbacker.process("pro1cess-ing_te2st");
+        assertEquals("Pro1cessIngTe2st", result);
+
+        camelbacker.setIgnorePartBefore("1");
+        camelbacker.setIgnorePartAfter("2");
+
+        result = camelbacker.process("pro1cess-ing_te2st");
+        assertEquals("1cessIngTe2", result);
+
+        camelbacker.setIgnorePartAfter("1");
+        camelbacker.setIgnorePartBefore("2");
+
+        result = camelbacker.process("pro1cess-ing_te2st");
+        assertEquals("", result);
+
+        camelbacker.setIgnorePartAfter("1");
+        camelbacker.setIgnorePartBefore("1");
+
+        result = camelbacker.process("pro1cess-ing_te2st");
+        assertEquals("1", result);
+
+        // make sure IgnoreBeforeAfter plays nice with the other rules
+
+        camelbacker.setRemoveWithoutUppercase("1");
+        camelbacker.setIgnorePartAfter(null);
+
+        result = camelbacker.process("pro1cess-ing_te2st");
+        assertEquals("cessIngTe2st", result);
+
+        camelbacker.setIgnorePartAfter("1");
+        camelbacker.setRemoveWithoutUppercase(null);
+        camelbacker.setRemoveWithUppercase("1");
+
+        result = camelbacker.process("pro1cess-ing_te2st");
+        assertEquals("", result);
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/processor/string/ConstantNameCreatorTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/processor/string/ConstantNameCreatorTest.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/processor/string/ConstantNameCreatorTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/processor/string/ConstantNameCreatorTest.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,51 @@
+package org.apache.torque.gf.processor.string;
+
+/*
+ * 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 org.junit.Before;
+import org.junit.Test;
+
+public class ConstantNameCreatorTest
+{
+    ConstantNameCreator constantNameCreator;
+
+    @Before
+    public void setUp()
+    {
+        constantNameCreator = new ConstantNameCreator();
+    }
+
+    @Test
+    public void testDefault()
+    {
+        String result = constantNameCreator.process("prOceSS-*+ing~#._Test");
+        assertEquals("PR_OCE_SS_ING_TEST", result);
+    }
+
+    @Test
+    public void testFirstCharacterUppercase()
+    {
+        String result = constantNameCreator.process("Process");
+        assertEquals("PROCESS", result);
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/qname/NamespaceTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/qname/NamespaceTest.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/qname/NamespaceTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/qname/NamespaceTest.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,69 @@
+package org.apache.torque.gf.qname;
+
+/*
+ * 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.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class NamespaceTest
+{
+    @Test
+    public void testIsVisibleToe()
+    {
+        Namespace namespace
+                = new Namespace("org.apache.torque");
+        assertTrue(namespace.isVisibleTo(Namespace.ROOT_NAMESPACE));
+        assertTrue(namespace.isVisibleTo(
+                new Namespace("org")));
+        assertTrue(namespace.isVisibleTo(
+                new Namespace("org.apache")));
+        assertTrue(namespace.isVisibleTo(
+                new Namespace("org.apache.torque")));
+
+        assertFalse(namespace.isVisibleTo(
+                new Namespace("or")));
+        assertFalse(namespace.isVisibleTo(
+                new Namespace("org.apache.torque.generator")));
+
+        namespace = Namespace.ROOT_NAMESPACE;
+        assertTrue(namespace.isVisibleTo(Namespace.ROOT_NAMESPACE));
+        assertFalse(namespace.isVisibleTo(new Namespace("org.apache")));
+    }
+
+    @Test
+    public void testIsVisibleFrom()
+    {
+        Namespace namespace
+                = new Namespace("org.apache.torque");
+        assertFalse(namespace.isVisibleFrom(Namespace.ROOT_NAMESPACE));
+        assertFalse(namespace.isVisibleFrom(new Namespace("org.apache")));
+        assertTrue(namespace.isVisibleFrom(new Namespace("org.apache.torque")));
+
+        assertFalse(namespace.isVisibleFrom(new Namespace("or")));
+        assertTrue(namespace.isVisibleFrom(
+                new Namespace("org.apache.torque.generator")));
+
+        namespace = Namespace.ROOT_NAMESPACE;
+        assertTrue(namespace.isVisibleFrom(Namespace.ROOT_NAMESPACE));
+        assertTrue(namespace.isVisibleFrom(new Namespace("org.apache")));
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/qname/QualifiedNameMapTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/qname/QualifiedNameMapTest.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/qname/QualifiedNameMapTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/qname/QualifiedNameMapTest.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,191 @@
+package org.apache.torque.gf.qname;
+
+/*
+ * 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 static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class QualifiedNameMapTest
+{
+    private static final QualifiedName qualifiedNameChild
+        = new QualifiedName("org.apache.torque.generator.name");
+    private static final QualifiedName qualifiedName
+        = new QualifiedName("org.apache.torque.name");
+    private static final QualifiedName qualifiedNameParent
+        = new QualifiedName("org.apache.name");
+    private static final QualifiedName qualifiedNameAncestor
+        = new QualifiedName("org.name");
+    private static final QualifiedName qualifiedNameDefault
+        = new QualifiedName("name");
+    private static final QualifiedName qualifiedNameUnrelated
+        = new QualifiedName("org.apa.name");
+    private static final QualifiedName qualifiedNameOtherName
+        = new QualifiedName("org.apache.torque.otherName");
+
+    @Test
+    public void testGetKeyInHierarchyByQualifiedName()
+    {
+        QualifiedNameMap<String> qualifiedNameMap
+                = new QualifiedNameMap<String>();
+
+        QualifiedName result
+                = qualifiedNameMap.getKeyInHierarchy(qualifiedName);
+        assertNull(result);
+
+        qualifiedNameMap.put(qualifiedNameUnrelated, "org.apa");
+        result = qualifiedNameMap.getKeyInHierarchy(qualifiedName);
+        assertNull(result);
+
+        qualifiedNameMap.put(qualifiedNameChild, "org.apache.torque.generator");
+        result = qualifiedNameMap.getKeyInHierarchy(qualifiedName);
+        assertNull(result);
+
+        qualifiedNameMap.put(qualifiedNameDefault, "default");
+        result = qualifiedNameMap.getKeyInHierarchy(qualifiedName);
+        assertEquals(result, qualifiedNameDefault);
+
+        qualifiedNameMap.put(qualifiedNameAncestor, "org");
+        result = qualifiedNameMap.getKeyInHierarchy(qualifiedName);
+        assertEquals(result, qualifiedNameAncestor);
+
+        qualifiedNameMap.put(qualifiedNameParent, "org.apache");
+        result = qualifiedNameMap.getKeyInHierarchy(qualifiedName);
+        assertEquals(result, qualifiedNameParent);
+
+        qualifiedNameMap.put(qualifiedName, "org.apache.torque");
+        result = qualifiedNameMap.getKeyInHierarchy(qualifiedName);
+        assertEquals(result, qualifiedName);
+
+        qualifiedNameMap.remove(qualifiedName);
+        result = qualifiedNameMap.getKeyInHierarchy(qualifiedName);
+        assertEquals(result, qualifiedNameParent);
+    }
+
+    @Test
+    public void testGetInHierarchyByQualifiedName()
+    {
+        QualifiedNameMap<String> qualifiedNameMap
+                = new QualifiedNameMap<String>();
+
+        String result = qualifiedNameMap.getInHierarchy(qualifiedName);
+        assertNull(result);
+
+        qualifiedNameMap.put(qualifiedNameUnrelated, "org.apa");
+        result = qualifiedNameMap.getInHierarchy(qualifiedName);
+        assertNull(result);
+
+        qualifiedNameMap.put(qualifiedNameChild, "org.apache.torque.generator");
+        result = qualifiedNameMap.getInHierarchy(qualifiedName);
+        assertNull(result);
+
+        qualifiedNameMap.put(qualifiedNameDefault, "default");
+        result = qualifiedNameMap.getInHierarchy(qualifiedName);
+        assertEquals(result, "default");
+
+        qualifiedNameMap.put(qualifiedNameAncestor, "org");
+        result = qualifiedNameMap.getInHierarchy(qualifiedName);
+        assertEquals(result, "org");
+
+        qualifiedNameMap.put(qualifiedNameParent, "org.apache");
+        result = qualifiedNameMap.getInHierarchy(qualifiedName);
+        assertEquals(result, "org.apache");
+
+        qualifiedNameMap.put(qualifiedName, "org.apache.torque");
+        result = qualifiedNameMap.getInHierarchy(qualifiedName);
+        assertEquals(result, "org.apache.torque");
+
+        qualifiedNameMap.put(qualifiedName, null);
+        result = qualifiedNameMap.getInHierarchy(qualifiedName);
+        assertEquals(result, null);
+
+        qualifiedNameMap.remove(qualifiedName);
+        result = qualifiedNameMap.getInHierarchy(qualifiedName);
+        assertEquals(result, "org.apache");
+    }
+
+    @Test
+    public void testGetInHierarchyByNamespace()
+    {
+        QualifiedNameMap<String> qualifiedNameMap
+                = new QualifiedNameMap<String>();
+
+        qualifiedNameMap.put(qualifiedNameUnrelated, "org.apa");
+        qualifiedNameMap.put(qualifiedNameChild, "org.apache.torque.generator");
+        qualifiedNameMap.put(qualifiedNameDefault, "default");
+        qualifiedNameMap.put(qualifiedNameParent, "org.apache");
+        qualifiedNameMap.put(qualifiedName, "org.apache.torque");
+        qualifiedNameMap.put(
+                qualifiedNameOtherName,
+                "org.apache.torque.otherName");
+
+        QualifiedNameMap<String> expected
+                = new QualifiedNameMap<String>();
+
+        expected.put(qualifiedName, "org.apache.torque");
+        expected.put(
+                qualifiedNameOtherName,
+                "org.apache.torque.otherName");
+
+        QualifiedNameMap<String> result
+                = qualifiedNameMap.getInHierarchy(
+                        qualifiedName.getNamespace());
+
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void testGetAllInHierarchy()
+    {
+        QualifiedNameMap<String> qualifiedNameMap
+                = new QualifiedNameMap<String>();
+
+        qualifiedNameMap.put(qualifiedNameUnrelated, "org.apa");
+        qualifiedNameMap.put(qualifiedNameChild, "org.apache.torque.generator");
+        qualifiedNameMap.put(qualifiedNameDefault, "default");
+        qualifiedNameMap.put(qualifiedNameParent, "org.apache");
+        qualifiedNameMap.put(qualifiedName, "org.apache.torque");
+        qualifiedNameMap.put(
+                qualifiedNameOtherName,
+                "org.apache.torque.otherName");
+
+        QualifiedNameMap<String> expected
+                = new QualifiedNameMap<String>();
+
+        expected.put(qualifiedNameDefault, "default");
+        expected.put(qualifiedNameParent, "org.apache");
+        expected.put(qualifiedName, "org.apache.torque");
+        expected.put(
+                qualifiedNameOtherName,
+                "org.apache.torque.otherName");
+
+        QualifiedNameMap<String> result
+                = qualifiedNameMap.getAllInHierarchy(
+                        qualifiedName.getNamespace());
+
+        assertEquals(expected, result);
+    }
+
+    public void testGetMoreSpecific()
+    {
+        // TODO: implement !
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/qname/QualifiedNameTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/qname/QualifiedNameTest.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/qname/QualifiedNameTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/qname/QualifiedNameTest.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,177 @@
+package org.apache.torque.gf.qname;
+
+/*
+ * 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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+public class QualifiedNameTest
+{
+    @Test
+    public void testConstructors()
+    {
+        QualifiedName qualifiedName
+                = new QualifiedName("org.apache.torque.name");
+        assertEquals("name", qualifiedName.getName());
+        assertEquals(
+                new Namespace("org.apache.torque"),
+                qualifiedName.getNamespace());
+
+        qualifiedName = new QualifiedName("name");
+        assertEquals("name", qualifiedName.getName());
+        assertEquals(Namespace.ROOT_NAMESPACE, qualifiedName.getNamespace());
+
+        qualifiedName = new QualifiedName(".name");
+        assertEquals("name", qualifiedName.getName());
+        assertEquals(Namespace.ROOT_NAMESPACE, qualifiedName.getNamespace());
+
+        qualifiedName
+                = new QualifiedName("name", new Namespace("org.apache.torque"));
+        assertEquals("name", qualifiedName.getName());
+        assertEquals(
+                new Namespace("org.apache.torque"),
+                qualifiedName.getNamespace());
+
+        qualifiedName = new QualifiedName("name", (Namespace) null);
+        assertEquals("name", qualifiedName.getName());
+        assertEquals(Namespace.ROOT_NAMESPACE, qualifiedName.getNamespace());
+
+        qualifiedName = new QualifiedName("name", new Namespace(""));
+        assertEquals("name", qualifiedName.getName());
+        assertEquals(Namespace.ROOT_NAMESPACE, qualifiedName.getNamespace());
+    }
+
+    @Test
+    public void testEmptyNames()
+    {
+        try
+        {
+            new QualifiedName("org.apache.torque.");
+            fail("Could generate QualifiedName from String "
+                    + "with empty name part");
+        }
+        catch (IllegalArgumentException e)
+        {
+        }
+
+        try
+        {
+            new QualifiedName("", "org.apache.torque");
+            fail("Could generate QualifiedName with empty name");
+        }
+        catch (IllegalArgumentException e)
+        {
+        }
+    }
+
+    @Test
+    public void testNamespaceFromParts()
+    {
+        List<String> parts = new ArrayList<String>(3);
+        parts.add("org");
+        parts.add("apache");
+        parts.add("torque");
+        Namespace namespace = new Namespace(parts);
+        assertEquals(namespace, new Namespace("org.apache.torque"));
+
+        parts = new ArrayList<String>();
+        namespace = new Namespace(parts);
+        assertEquals(Namespace.ROOT_NAMESPACE, namespace);
+
+        parts = null;
+        try
+        {
+            namespace = new Namespace(parts);
+            fail("should not be able to construct namespace "
+                    + "from null list");
+        }
+        catch (NullPointerException e)
+        {
+        }
+    }
+
+    @Test
+    public void testGetNamespaceParts()
+    {
+        QualifiedName qualifiedName
+                = new QualifiedName("org.apache.torque.name");
+        List<String> parts = qualifiedName.getNamespace().getParts();
+        assertEquals(parts.size(), 3);
+        assertEquals(parts.get(0), "org");
+        assertEquals(parts.get(1), "apache");
+        assertEquals(parts.get(2), "torque");
+    }
+
+    @Test
+    public void testGetParentNamespace()
+    {
+        QualifiedName qualifiedName
+                = new QualifiedName("org.apache.torque.name");
+        Namespace parentNamespace = qualifiedName.getParentNamespace();
+        assertEquals(parentNamespace, new Namespace("org.apache"));
+
+        qualifiedName = new QualifiedName("org.name");
+        parentNamespace = qualifiedName.getParentNamespace();
+        assertEquals(Namespace.ROOT_NAMESPACE, parentNamespace);
+
+        qualifiedName = new QualifiedName(".name");
+        parentNamespace = qualifiedName.getParentNamespace();
+        assertEquals(Namespace.ROOT_NAMESPACE, parentNamespace);
+    }
+
+    @Test
+    public void testEquals()
+    {
+        QualifiedName qualifiedName
+                = new QualifiedName("org.apache.torque.name");
+        assertEquals(
+                qualifiedName,
+                new QualifiedName("org.apache.torque.name"));
+        assertFalse(
+                qualifiedName.equals(
+                        new QualifiedName("org.apache.name")));
+        assertFalse(
+                qualifiedName.equals(
+                        new QualifiedName(".name")));
+        assertFalse(
+                qualifiedName.equals(
+                        new QualifiedName("org.apache.torque.otherName")));
+
+        qualifiedName = new QualifiedName(".name");
+        assertEquals(
+                qualifiedName,
+                new QualifiedName(".name"));
+        assertEquals(
+                qualifiedName,
+                new QualifiedName("name"));
+        assertFalse(
+                qualifiedName.equals(
+                        new QualifiedName("org.apache.name")));
+        assertFalse(
+                qualifiedName.equals(
+                        new QualifiedName(".otherName")));
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/FileSourcesImplTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/FileSourcesImplTest.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/FileSourcesImplTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/FileSourcesImplTest.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,314 @@
+package org.apache.torque.gf.source;
+
+/*
+ * 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.io.File;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.torque.gf.configuration.ConfigurationException;
+import org.apache.torque.gf.configuration.ConfigurationHandlers;
+import org.apache.torque.gf.source.properties.PropertiesSourceType;
+import org.apache.torque.gf.source.xml.XmlSourceType;
+import org.junit.Test;
+
+public class FileSourcesImplTest
+{
+    private ConfigurationHandlers configurationHandler 
+        = new ConfigurationHandlers();
+
+    @Test
+    public void testGetDirsNoWildcards()
+    {
+        String path = "/tmp/schema.xml";
+        int baseDirSeparatorPos = FileSourcesImpl.getBaseDirSeparatorPos(path);
+        assertEquals(4, baseDirSeparatorPos);
+        String baseDir = FileSourcesImpl.getBaseDir(path, baseDirSeparatorPos);
+        assertEquals("/tmp", baseDir);
+        String wildcardPattern
+                = FileSourcesImpl.getWildcardPattern(path, baseDirSeparatorPos);
+        assertEquals("schema.xml", wildcardPattern);
+    }
+
+    @Test
+    public void testGetBaseDirOnlyFilename()
+    {
+        String path = "schema.xml";
+        int baseDirSeparatorPos = FileSourcesImpl.getBaseDirSeparatorPos(path);
+        assertEquals(-1, baseDirSeparatorPos);
+        String baseDir = FileSourcesImpl.getBaseDir(path, baseDirSeparatorPos);
+        assertEquals(".", baseDir);
+        String wildcardPattern
+                = FileSourcesImpl.getWildcardPattern(path, baseDirSeparatorPos);
+        assertEquals("schema.xml", wildcardPattern);
+    }
+
+    @Test
+    public void testGetBaseDirQuestionMark()
+    {
+        String path = "C:\\schema\\?\\schema.xml";
+        int baseDirSeparatorPos = FileSourcesImpl.getBaseDirSeparatorPos(path);
+        assertEquals(9, baseDirSeparatorPos);
+        String baseDir = FileSourcesImpl.getBaseDir(path, baseDirSeparatorPos);
+        assertEquals("C:\\schema", baseDir);
+        String wildcardPattern
+                = FileSourcesImpl.getWildcardPattern(path, baseDirSeparatorPos);
+        assertEquals("?\\schema.xml", wildcardPattern);
+    }
+
+    @Test
+    public void testGetBaseDirAsterisk()
+    {
+        String path = "C:\\schema\\*\\schema.xml";
+        int baseDirSeparatorPos = FileSourcesImpl.getBaseDirSeparatorPos(path);
+        assertEquals(9, baseDirSeparatorPos);
+        String baseDir = FileSourcesImpl.getBaseDir(path, baseDirSeparatorPos);
+        assertEquals("C:\\schema", baseDir);
+        String wildcardPattern
+                = FileSourcesImpl.getWildcardPattern(path, baseDirSeparatorPos);
+        assertEquals("*\\schema.xml", wildcardPattern);
+    }
+
+    @Test
+    public void testGetBaseDirMultipleWildcards()
+    {
+        String path = "/tmp/*/???/schema.xml";
+        int baseDirSeparatorPos = FileSourcesImpl.getBaseDirSeparatorPos(path);
+        assertEquals(4, baseDirSeparatorPos);
+        String baseDir = FileSourcesImpl.getBaseDir(path, baseDirSeparatorPos);
+        assertEquals("/tmp", baseDir);
+        String wildcardPattern
+                = FileSourcesImpl.getWildcardPattern(path, baseDirSeparatorPos);
+        assertEquals("*/???/schema.xml", wildcardPattern);
+    }
+
+    @Test
+    public void testGetBaseDirWildcardFirst()
+    {
+        String path = "*/???/schema.xml";
+        int baseDirSeparatorPos = FileSourcesImpl.getBaseDirSeparatorPos(path);
+        assertEquals(-1, baseDirSeparatorPos);
+        String baseDir = FileSourcesImpl.getBaseDir(path, baseDirSeparatorPos);
+        assertEquals(".", baseDir);
+        String wildcardPattern
+                = FileSourcesImpl.getWildcardPattern(path, baseDirSeparatorPos);
+        assertEquals("*/???/schema.xml", wildcardPattern);
+    }
+
+    @Test
+    public void testGetSourcesFixedNameBasedir() throws ConfigurationException
+    {
+        FileSourcesImpl fileSourcesImpl = new FileSourcesImpl(
+                null,
+                "1.properties",
+                null,
+                null,
+                new ArrayList<TransformerDefinition>(),
+                configurationHandler,
+                new File("src/test/fileSourcesImpl"));
+        Set<File> paths = new HashSet<File>();
+        while (fileSourcesImpl.hasNext())
+        {
+            FileSource fileSource = (FileSource) fileSourcesImpl.next();
+            paths.add(fileSource.getPath());
+        }
+        Set<File> expectedFiles = new HashSet<File>();
+        expectedFiles.add(new File("src/test/fileSourcesImpl/./1.properties"));
+        assertEquals(expectedFiles.size(), paths.size());
+        assertEquals(expectedFiles, paths);
+    }
+
+    @Test
+    public void testGetSourcesFixedNameSubdir() throws ConfigurationException
+    {
+        FileSourcesImpl fileSourcesImpl = new FileSourcesImpl(
+                null,
+                "subfolder/2.properties",
+                null,
+                null,
+                new ArrayList<TransformerDefinition>(),
+                configurationHandler,
+                new File("src/test/fileSourcesImpl"));
+        Set<File> paths = new HashSet<File>();
+        while (fileSourcesImpl.hasNext())
+        {
+            FileSource fileSource = (FileSource) fileSourcesImpl.next();
+            paths.add(fileSource.getPath());
+        }
+        Set<File> expectedFiles = new HashSet<File>();
+        expectedFiles.add(
+                new File("src/test/fileSourcesImpl/subfolder/2.properties"));
+        assertEquals(expectedFiles.size(), paths.size());
+        assertEquals(expectedFiles, paths);
+    }
+
+    @Test
+    public void testGetSourcesMixedSlashBackslash() throws ConfigurationException
+    {
+        FileSourcesImpl fileSourcesImpl = new FileSourcesImpl(
+                null,
+                "subfolder/subsubfolder\\3.properties",
+                null,
+                null,
+                new ArrayList<TransformerDefinition>(),
+                configurationHandler,
+                new File("src/test/fileSourcesImpl"));
+        Set<File> paths = new HashSet<File>();
+        while (fileSourcesImpl.hasNext())
+        {
+            FileSource fileSource = (FileSource) fileSourcesImpl.next();
+            paths.add(fileSource.getPath());
+        }
+        Set<File> expectedFiles = new HashSet<File>();
+        expectedFiles.add(
+                new File("src/test/fileSourcesImpl/subfolder/subsubfolder/3.properties"));
+        assertEquals(expectedFiles.size(), paths.size());
+        assertEquals(expectedFiles, paths);
+    }
+
+    @Test
+    public void testGetSourcesWildcardDir() throws ConfigurationException
+    {
+        FileSourcesImpl fileSourcesImpl = new FileSourcesImpl(
+                null,
+                "*//2.properties",
+                null,
+                null,
+                new ArrayList<TransformerDefinition>(),
+                configurationHandler,
+                new File("src/test/fileSourcesImpl"));
+        Set<File> paths = new HashSet<File>();
+        while (fileSourcesImpl.hasNext())
+        {
+            FileSource fileSource = (FileSource) fileSourcesImpl.next();
+            paths.add(fileSource.getPath());
+        }
+        Set<File> expectedFiles = new HashSet<File>();
+        expectedFiles.add(
+                new File("src/test/fileSourcesImpl/./subfolder/2.properties"));
+        assertEquals(expectedFiles.size(), paths.size());
+        assertEquals(expectedFiles, paths);
+    }
+
+    @Test
+    public void testGetSourcesQuestionmarkFilename()
+            throws ConfigurationException
+    {
+        FileSourcesImpl fileSourcesImpl = new FileSourcesImpl(
+                null,
+                "?.properties",
+                null,
+                null,
+                new ArrayList<TransformerDefinition>(),
+                configurationHandler,
+                new File("src/test/fileSourcesImpl"));
+        Set<File> paths = new HashSet<File>();
+        while (fileSourcesImpl.hasNext())
+        {
+            FileSource fileSource = (FileSource) fileSourcesImpl.next();
+            paths.add(fileSource.getPath());
+        }
+        Set<File> expectedFiles = new HashSet<File>();
+        expectedFiles.add(
+                new File("src/test/fileSourcesImpl/./1.properties"));
+        assertEquals(expectedFiles.size(), paths.size());
+        assertEquals(expectedFiles, paths);
+    }
+
+    @Test
+    public void testGetSourcesWildcardFilename()
+            throws ConfigurationException
+    {
+        FileSourcesImpl fileSourcesImpl = new FileSourcesImpl(
+                null,
+                "*.properties",
+                null,
+                null,
+                new ArrayList<TransformerDefinition>(),
+                configurationHandler,
+                new File("src/test/fileSourcesImpl"));
+        Set<File> paths = new HashSet<File>();
+        while (fileSourcesImpl.hasNext())
+        {
+            FileSource fileSource = (FileSource) fileSourcesImpl.next();
+            paths.add(fileSource.getPath());
+        }
+        Set<File> expectedFiles = new HashSet<File>();
+        expectedFiles.add(
+                new File("src/test/fileSourcesImpl/./1.properties"));
+        expectedFiles.add(
+                new File("src/test/fileSourcesImpl/./11.properties"));
+        assertEquals(expectedFiles.size(), paths.size());
+        assertEquals(expectedFiles, paths);
+    }
+
+    @Test
+    public void testGetSourcesDoubleDotsStayingInSourceDir()
+            throws ConfigurationException
+    {
+        FileSourcesImpl fileSourcesImpl = new FileSourcesImpl(
+                null,
+                "subfolder/../1.properties",
+                null,
+                null,
+                new ArrayList<TransformerDefinition>(),
+                configurationHandler,
+                new File("src/test/fileSourcesImpl"));
+        Set<File> paths = new HashSet<File>();
+        while (fileSourcesImpl.hasNext())
+        {
+            FileSource fileSource = (FileSource) fileSourcesImpl.next();
+            paths.add(fileSource.getPath());
+        }
+        Set<File> expectedFiles = new HashSet<File>();
+        expectedFiles.add(
+                new File("src/test/fileSourcesImpl/subfolder/../1.properties"));
+        assertEquals(expectedFiles.size(), paths.size());
+        assertEquals(expectedFiles, paths);
+    }
+
+    @Test
+    public void testGetSourcesDoubleDotsLeavingSourceDir()
+            throws ConfigurationException
+    {
+        FileSourcesImpl fileSourcesImpl = new FileSourcesImpl(
+                null,
+                "../1.properties",
+                null,
+                null,
+                new ArrayList<TransformerDefinition>(),
+                configurationHandler,
+                new File("src/test/fileSourcesImpl/subfolder"));
+        Set<File> paths = new HashSet<File>();
+        while (fileSourcesImpl.hasNext())
+        {
+            FileSource fileSource = (FileSource) fileSourcesImpl.next();
+            paths.add(fileSource.getPath());
+        }
+        Set<File> expectedFiles = new HashSet<File>();
+        expectedFiles.add(
+                new File("src/test/fileSourcesImpl/subfolder/../1.properties"));
+        assertEquals(expectedFiles.size(), paths.size());
+        assertEquals(expectedFiles, paths);
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/RichSourceElementImplTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/RichSourceElementImplTest.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/RichSourceElementImplTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/RichSourceElementImplTest.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,326 @@
+package org.apache.torque.gf.source;
+
+/*
+ * 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 static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import org.apache.torque.gf.configuration.paths.Maven2DirectoryProjectPaths;
+import org.apache.torque.gf.configuration.paths.ProjectPaths;
+import org.apache.torque.gf.source.properties.PropertiesSourceType;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RichSourceElementImplTest
+{
+    private RichSourceElementImpl rootSourceElement;
+
+    @Before
+    public void setUp()
+    {
+        rootSourceElement = new RichSourceElementImpl("parent");
+        RichSourceElementImpl child1 = new RichSourceElementImpl("child1");
+        rootSourceElement.addChild(child1);
+        RichSourceElementImpl child2 = new RichSourceElementImpl("child2");
+        rootSourceElement.addChild(child2);
+        RichSourceElementImpl child3 = new RichSourceElementImpl("child3");
+        rootSourceElement.addChild(child3);
+    }
+
+
+    @Test
+    public void testAddChild()
+    {
+        SourceElement child1 = rootSourceElement.getChildren().get(0);
+        SourceElement child2 = rootSourceElement.getChildren().get(1);
+        SourceElement child3 = rootSourceElement.getChildren().get(2);
+        RichSourceElementImpl child4 = new RichSourceElementImpl("child4");
+        rootSourceElement.addChild(child4);
+
+        assertEquals("parent should have 4 children",
+                4,
+                rootSourceElement.getChildren().size());
+        assertSame(child1, rootSourceElement.getChildren().get(0));
+        assertSame(child2, rootSourceElement.getChildren().get(1));
+        assertSame(child3, rootSourceElement.getChildren().get(2));
+        assertSame(child4, rootSourceElement.getChildren().get(3));
+        assertSame("child2 has wrong parent",
+                rootSourceElement,
+                child4.getParent());
+    }
+
+    @Test
+    public void testAddChildAtIndex()
+    {
+        SourceElement child1 = rootSourceElement.getChildren().get(0);
+        SourceElement child2 = rootSourceElement.getChildren().get(1);
+        SourceElement child3 = rootSourceElement.getChildren().get(2);
+        RichSourceElementImpl child4 = new RichSourceElementImpl("child4");
+        rootSourceElement.addChild(1, child4);
+        assertSame(child1, rootSourceElement.getChildren().get(0));
+        assertSame(child4, rootSourceElement.getChildren().get(1));
+        assertSame(child2, rootSourceElement.getChildren().get(2));
+        assertSame(child3, rootSourceElement.getChildren().get(3));
+    }
+
+    @Test
+    public void testRemoveChild()
+    {
+        SourceElement child1 = rootSourceElement.getChildren().get(0);
+        SourceElement child2 = rootSourceElement.getChildren().get(1);
+        SourceElement child3 = rootSourceElement.getChildren().get(2);
+        SourceElement result = rootSourceElement.removeChild(child2);
+        assertSame(child2, result);
+        assertEquals("parent should have 2 children",
+                2,
+                rootSourceElement.getChildren().size());
+        assertSame(child1, rootSourceElement.getChildren().get(0));
+        assertSame(child3, rootSourceElement.getChildren().get(1));
+    }
+
+    @Test
+    public void testRemoveNonExistingChild()
+    {
+        SourceElement child1 = rootSourceElement.getChildren().get(0);
+        SourceElement child2 = rootSourceElement.getChildren().get(1);
+        SourceElement child3 = rootSourceElement.getChildren().get(2);
+        RichSourceElementImpl child4 = new RichSourceElementImpl("child4");
+
+        SourceElement result = rootSourceElement.removeChild(child4);
+        assertNull(result);
+        assertEquals("parent should have 3 children",
+                3,
+                rootSourceElement.getChildren().size());
+        assertSame(child1, rootSourceElement.getChildren().get(0));
+        assertSame(child2, rootSourceElement.getChildren().get(1));
+        assertSame(child3, rootSourceElement.getChildren().get(2));
+    }
+
+    @Test
+    public void testGetChildIndex()
+    {
+        SourceElement child2 = rootSourceElement.getChildren().get(1);
+
+        assertEquals("child index should be 1",
+                1,
+                rootSourceElement.getChildIndex(child2));
+    }
+
+    @Test
+    public void testGetNonExistingChildIndex()
+    {
+        RichSourceElementImpl child4 = new RichSourceElementImpl("child4");
+        assertEquals("child index should be -1",
+                -1,
+                rootSourceElement.getChildIndex(child4));
+    }
+
+    @Test
+    public void testAddParent()
+    {
+        RichSourceElementImpl child = new RichSourceElementImpl("chiild");
+        RichSourceElementImpl parent1 = new RichSourceElementImpl("parent1");
+        child.addParent(parent1);
+        RichSourceElementImpl parent2 = new RichSourceElementImpl("parent2");
+        child.addParent(parent2);
+
+        assertEquals("child should have 2 parents",
+                2,
+                child.getParents().size());
+        assertSame("child has wrong primary parent",
+                parent1,
+                child.getParent());
+        assertSame("parent1 has wrong child",
+                child,
+                parent1.getChildren().get(0));
+        assertSame("child has wrong second parent",
+                parent2,
+                child.getParents().get(1));
+        assertSame("parent2 has wrong child",
+                child,
+                parent2.getChildren().get(0));
+    }
+
+    @Test
+    public void testTreeEquals()
+    {
+        RichSourceElementImpl original = new RichSourceElementImpl("root");
+        SourceElement toCompare
+                = new RichSourceElementImpl("wrongName");
+        if (original.graphEquals(toCompare))
+        {
+            fail("SourceElements with different names must not be equal");
+        }
+
+        toCompare = new RichSourceElementImpl("root");
+        if (!original.graphEquals(toCompare))
+        {
+            fail("empty SourceElements with equal names must be equal");
+        }
+
+        original.setAttribute("attributeName", "attributeValue");
+        if (original.graphEquals(toCompare))
+        {
+            fail("SourceElements with different attribute names"
+                    + " must not be equal");
+        }
+
+        toCompare.setAttribute("attributeName", "anotherAttributeValue");
+        if (original.graphEquals(toCompare))
+        {
+            fail("SourceElements with different attribute content"
+                    + " must not be equal(1)");
+        }
+
+        toCompare.setAttribute("attributeName", null);
+        if (original.graphEquals(toCompare))
+        {
+            fail("SourceElements with different attribute content"
+                    + " must not be equal(2)");
+        }
+
+        toCompare.setAttribute("attributeName", "attributeValue");
+        if (!original.graphEquals(toCompare))
+        {
+            fail("SourceElements with equal attribute content"
+                    + " must be equal(1)");
+        }
+
+        original.setAttribute("attributeName", null);
+        if (original.graphEquals(toCompare))
+        {
+            fail("SourceElements with different attribute content"
+                    + " must not be equal(3)");
+        }
+
+        toCompare.setAttribute("attributeName", null);
+        if (!original.graphEquals(toCompare))
+        {
+            fail("SourceElements with equal attribute content"
+                    + " must be equal(2)");
+        }
+
+        original.addChild(new RichSourceElementImpl("child"));
+        if (original.graphEquals(toCompare))
+        {
+            fail("SourceElements with different children"
+                    + " must not be equal(1)");
+        }
+
+        toCompare.addChild(new RichSourceElementImpl("wrongChild"));
+        if (original.graphEquals(toCompare))
+        {
+            fail("SourceElements with different children"
+                    + " must not be equal(2)");
+        }
+
+        toCompare = new RichSourceElementImpl("root");
+        toCompare.setAttribute("attributeName", null);
+        toCompare.addChild(new RichSourceElementImpl("child"));
+        if (!original.graphEquals(toCompare))
+        {
+            fail("SourceElements with equal children"
+                    + " must be equal(1)");
+        }
+
+        original.addChild(original);
+        if (original.graphEquals(toCompare))
+        {
+            fail("SourceElements with different children"
+                    + " must not be equal(3)");
+        }
+
+        toCompare.addChild(toCompare);
+        if (!original.graphEquals(toCompare))
+        {
+            fail("SourceElements with equal children"
+                    + " must be equal(2)");
+        }
+    }
+    
+    @Test
+    public void testSetAttribute()
+    {
+        SourceElement sourceElement = new RichSourceElementImpl("root");
+        assertEquals(sourceElement.getAttributeNames().size(), 0);
+        assertEquals(null, sourceElement.getAttribute("attributeName"));
+
+        sourceElement.setAttribute("attributeName", "123");
+        assertEquals(1, sourceElement.getAttributeNames().size());
+        assertEquals("123", sourceElement.getAttribute("attributeName"));
+    }
+
+    @Test
+    public void testSetAttributeToNull()
+    {
+        SourceElement sourceElement = new RichSourceElementImpl("root");
+        sourceElement.setAttribute("attributeName", "123");
+        assertEquals(1, sourceElement.getAttributeNames().size());
+
+        sourceElement.setAttribute("attributeName", null);
+        assertEquals(0, sourceElement.getAttributeNames().size());
+    }
+
+    @Test
+    public void testToString() throws Exception
+    {
+        SourceElement sourceElement = new RichSourceElementImpl("root");
+        sourceElement.setAttribute("attributeName", "123");
+        sourceElement.addChild(new RichSourceElementImpl("child"));
+        sourceElement.addChild(sourceElement);
+        String expected
+                = "(name=root,attributes=(attributeName=123),"
+                    + "children=((name=child,attributes=(),children=()),"
+                    + "<<loop detected>>))";
+        assertEquals(expected, sourceElement.toString());
+    }
+
+    @Test
+    public void testCopySourceElement() throws Exception
+    {
+        ProjectPaths projectPaths
+                = new Maven2DirectoryProjectPaths(
+                    new File("src/test/propertyToJava"));
+        File propertiesFile
+                = new File(
+                    projectPaths.getDefaultSourcePath(),
+                    "propertiesData.properties");
+        FileSource fileSource
+                = new FileSource(
+                        new PropertiesSourceType(),
+                        propertiesFile,
+                        null,
+                        null,
+                        new ArrayList<TransformerDefinition>());
+        RichSourceElementImpl rootElement
+                = (RichSourceElementImpl) fileSource.getRootElement();
+
+        SourceElement copiedRootElement = rootElement.copy();
+        if (!rootElement.graphEquals(copiedRootElement))
+        {
+            fail("copied tree does not equal original tree");
+        }
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/SourcePathTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/SourcePathTest.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/SourcePathTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/SourcePathTest.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,105 @@
+package org.apache.torque.gf.source;
+
+/*
+ * 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.generator.GeneratorException;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SourcePathTest
+{
+    private RichSourceElementImpl root;
+    private RichSourceElementImpl firstLevel;
+    private RichSourceElementImpl secondLevel;
+    private RichSourceElementImpl thirdLevel;
+
+    @Before
+    public void setUp()
+    {
+        root = new RichSourceElementImpl("root");
+        root.addChild(new RichSourceElementImpl("firstLevel1"));
+        firstLevel  = new RichSourceElementImpl("firstLevel2");
+        root.addChild(firstLevel);
+        root.addChild(new RichSourceElementImpl("firstLevel3"));
+        secondLevel = new RichSourceElementImpl("secondLevel");
+        firstLevel.addChild(secondLevel);
+        thirdLevel = new RichSourceElementImpl("thirdLevel");
+        secondLevel.addChild(thirdLevel);
+    }
+
+    @Test
+    public void testGetPath() throws GeneratorException
+    {
+        assertEquals(
+                "root/firstLevel2/secondLevel/thirdLevel",
+                SourcePath.getPathAsString(thirdLevel));
+    }
+
+    @Test(expected=GeneratorException.class)
+    public void testGetPathInfiniteLoop() throws GeneratorException
+    {
+        SourceElement loopElement1 = new RichSourceElementImpl("loopElement1");
+        SourceElement loopElement2 = new RichSourceElementImpl("loopElement2");
+        loopElement1.addChild(loopElement2);
+        loopElement2.addChild(loopElement1);
+        SourcePath.getPathAsString(loopElement1);
+    }
+
+    @Test
+    public void testGetElementFromRootSingleRelativeElement()
+    {
+        List<SourceElement> result
+                = SourcePath.getElementsFromRoot(root, "root");
+        List expected = new ArrayList<SourceElement>();
+        expected.add(root);
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void testGetElementFromRootSingleRelativeElementNoMatch()
+    {
+        List<SourceElement> result
+                = SourcePath.getElementsFromRoot(root, "root1");
+        assertEquals(0, result.size());
+    }
+
+    @Test
+    public void testGetElementFromRootSingleAbsoluteElement()
+    {
+        List<SourceElement> result
+                = SourcePath.getElementsFromRoot(root, "/root");
+        List expected = new ArrayList<SourceElement>();
+        expected.add(root);
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void testGetElementFromRootSingleAbsoluteElementNoMatch()
+    {
+        List<SourceElement> result
+                = SourcePath.getElementsFromRoot(root, "/root1");
+        assertEquals(0, result.size());
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/properties/PropertiesParserTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/properties/PropertiesParserTest.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/properties/PropertiesParserTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/properties/PropertiesParserTest.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,81 @@
+package org.apache.torque.gf.source.properties;
+
+/*
+ * 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.io.File;
+import java.util.ArrayList;
+
+import org.apache.torque.gf.configuration.ConfigurationException;
+import org.apache.torque.gf.source.FileSource;
+import org.apache.torque.gf.source.SourceElement;
+import org.apache.torque.gf.source.SourceException;
+import org.apache.torque.gf.source.TransformerDefinition;
+import org.junit.Test;
+
+public class PropertiesParserTest
+{
+    @Test
+    public void testParsePropertiesFile()
+            throws ConfigurationException, SourceException
+    {
+        File propertiesFile
+            = new File("src/test/resources/org/apache/torque/gf/source/properties/propertiesParserTest.properties");
+        FileSource fileSource
+                = new FileSource(
+                        new PropertiesSourceType(),
+                        propertiesFile,
+                        null,
+                        null,
+                        new ArrayList<TransformerDefinition>());
+
+        SourceElement rootElement = fileSource.getRootElement();
+        assertEquals("properties", rootElement.getName());
+        assertEquals(0, rootElement.getAttributeNames().size());
+
+        assertEquals(2, rootElement.getChildren().size());
+        {
+            SourceElement child0 = rootElement.getChildren().get(0);
+            assertEquals("entry", child0.getName());
+            assertEquals(2, child0.getAttributeNames().size());
+            assertEquals("propertyName1", child0.getAttribute("key"));
+            assertEquals("propertyValue1", child0.getAttribute((String) null));
+        }
+        {
+            SourceElement child1 = rootElement.getChildren().get(1);
+            assertEquals("entry", child1.getName());
+            assertEquals(2, child1.getAttributeNames().size());
+            assertEquals("propertyName2", child1.getAttribute("key"));
+            assertEquals("propertyValue2", child1.getAttribute((String) null));
+        }
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testPathNull() throws ConfigurationException
+    {
+        new FileSource(
+                new PropertiesSourceType(),
+                null,
+                null,
+                null,
+                new ArrayList<TransformerDefinition>());
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/transform/AttributeTransformerTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/transform/AttributeTransformerTest.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/transform/AttributeTransformerTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/transform/AttributeTransformerTest.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,252 @@
+package org.apache.torque.gf.source.transform;
+
+/*
+ * 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.io.StringReader;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class AttributeTransformerTest
+{
+    private AttributeTransformer emptyTransformer;
+
+    @Before
+    public void before() throws SourceTransformerException
+    {
+        StringReader stringReader = new StringReader("#");
+        emptyTransformer = new AttributeTransformer(stringReader);
+    }
+
+    @Test
+    public void testParsePlainText() throws SourceTransformerException
+    {
+        List<AttributeTransformer.Definition> result
+                = emptyTransformer.parse("abcxy", true);
+        assertEquals(1, result.size());
+        assertEquals(
+                AttributeTransformer.Definition.Type.PLAIN,
+                result.get(0).getType());
+        assertEquals("abcxy", result.get(0).getContent());
+    }
+
+    @Test
+    public void testParseOption() throws SourceTransformerException
+    {
+        List<AttributeTransformer.Definition> result
+                = emptyTransformer.parse("${option:torque:someOption}", true);
+        assertEquals(1, result.size());
+        assertEquals(
+                AttributeTransformer.Definition.Type.OPTION,
+                result.get(0).getType());
+        assertEquals("torque:someOption", result.get(0).getContent());
+    }
+
+    @Test
+    public void testParseAttribute() throws SourceTransformerException
+    {
+        List<AttributeTransformer.Definition> result
+                = emptyTransformer.parse(
+                        "${attribute:org.apache.torque:someAttribute}",
+                        true);
+        assertEquals(1, result.size());
+        assertEquals(
+                AttributeTransformer.Definition.Type.ATTRIBUTE,
+                result.get(0).getType());
+        assertEquals(
+                "org.apache.torque:someAttribute",
+                result.get(0).getContent());
+    }
+
+    @Test
+    public void testParseOverrideAttribute() throws SourceTransformerException
+    {
+        List<AttributeTransformer.Definition> result
+                = emptyTransformer.parse(
+                        "${attribute(override):torque:someAttribute}",
+                        false);
+        assertEquals(1, result.size());
+        assertEquals(
+                AttributeTransformer.Definition.Type.ATTRIBUTE_OVERRIDE,
+                result.get(0).getType());
+        assertEquals(
+                "torque:someAttribute",
+                result.get(0).getContent());
+    }
+
+    @Test
+    public void testParseNoOverrideAttribute() throws SourceTransformerException
+    {
+        List<AttributeTransformer.Definition> result
+                = emptyTransformer.parse(
+                        "${attribute(noOverride):torque:someAttribute}",
+                        false);
+        assertEquals(1, result.size());
+        assertEquals(
+                AttributeTransformer.Definition.Type.ATTRIBUTE_NO_OVERRIDE,
+                result.get(0).getType());
+        assertEquals(
+                "torque:someAttribute",
+                result.get(0).getContent());
+    }
+
+    @Test
+    public void testParseEscapingInPlain() throws SourceTransformerException
+    {
+        List<AttributeTransformer.Definition> result
+                = emptyTransformer.parse("\\:\\$\\}\\{\\\\l", true);
+        assertEquals(1, result.size());
+        assertEquals(
+                AttributeTransformer.Definition.Type.PLAIN,
+                result.get(0).getType());
+        assertEquals(
+                ":$}{\\l",
+                result.get(0).getContent());
+    }
+
+    @Test
+    public void testParseEscapingInDefinition() throws SourceTransformerException
+    {
+        List<AttributeTransformer.Definition> result
+                = emptyTransformer.parse(
+                        "${attribute:\\:\\$\\}\\{l\\\\}",
+                        true);
+        assertEquals(1, result.size());
+        assertEquals(
+                AttributeTransformer.Definition.Type.ATTRIBUTE,
+                result.get(0).getType());
+        assertEquals(
+                ":$}{l\\",
+                result.get(0).getContent());
+    }
+
+    @Test
+    public void testParseSeveralDefinitions() throws SourceTransformerException
+    {
+        List<AttributeTransformer.Definition> result
+                = emptyTransformer.parse(
+                        "${attribute:someAttribute}"
+                        + "${option:someOption}"
+                        + "plainText"
+                        + "${option:someOption1}"
+                        + "${attribute:someAttribute1}",
+                        true);
+        assertEquals(5, result.size());
+        assertEquals(
+                AttributeTransformer.Definition.Type.ATTRIBUTE,
+                result.get(0).getType());
+        assertEquals("someAttribute", result.get(0).getContent());
+        assertEquals(
+                AttributeTransformer.Definition.Type.OPTION,
+                result.get(1).getType());
+        assertEquals("someOption", result.get(1).getContent());
+        assertEquals(
+                AttributeTransformer.Definition.Type.PLAIN,
+                result.get(2).getType());
+        assertEquals("plainText", result.get(2).getContent());
+        assertEquals(
+                AttributeTransformer.Definition.Type.OPTION,
+                result.get(3).getType());
+        assertEquals("someOption1", result.get(3).getContent());
+        assertEquals(
+                AttributeTransformer.Definition.Type.ATTRIBUTE,
+                result.get(4).getType());
+        assertEquals("someAttribute1", result.get(4).getContent());
+    }
+
+    @Test(expected = SourceTransformerException.class)
+    public void testParseNotEndedDefinition() throws SourceTransformerException
+    {
+        emptyTransformer.parse(
+                "${option:torque.endlessAttribute",
+                false);
+    }
+
+    @Test(expected = SourceTransformerException.class)
+    public void testParseDefinitionInsideType()
+            throws SourceTransformerException
+    {
+        emptyTransformer.parse(
+                "${option:torque${option:torque.otherAttr}",
+                false);
+    }
+
+    @Test(expected = SourceTransformerException.class)
+    public void testParseDefinitionInsideValue()
+            throws SourceTransformerException
+    {
+        emptyTransformer.parse(
+                "${option:torque.attribute${option:torque.otherAttr}",
+                false);
+    }
+
+    @Test(expected = SourceTransformerException.class)
+    public void testUnknownDefinition() throws SourceTransformerException
+    {
+        emptyTransformer.parse(
+                "${unknownDefinition:torque.unknownDefinition}",
+                false);
+    }
+
+    @Test(expected = SourceTransformerException.class)
+    public void testParsePlainInTarget() throws SourceTransformerException
+    {
+        emptyTransformer.parse(
+                "xy",
+                false);
+    }
+
+    @Test(expected = SourceTransformerException.class)
+    public void testParseOptionInTarget() throws SourceTransformerException
+    {
+        emptyTransformer.parse(
+                "${option:torque.optionValue}",
+                false);
+    }
+
+    @Test(expected = SourceTransformerException.class)
+    public void testParseAttributeInTarget() throws SourceTransformerException
+    {
+        emptyTransformer.parse(
+                "${attribute:torque.attributeValue}",
+                false);
+    }
+
+    @Test(expected = SourceTransformerException.class)
+    public void testParseNoOverrideAttributeInSource()
+            throws SourceTransformerException
+    {
+        emptyTransformer.parse(
+                "${attribute(noOverride):torque.attributeValue}",
+                true);
+    }
+
+    @Test(expected = SourceTransformerException.class)
+    public void testParseOverrideAttributeInSource()
+            throws SourceTransformerException
+    {
+        emptyTransformer.parse(
+                "${attribute(override):torque.attributeValue}",
+                true);
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/transform/BeanPropertyMethodNameTransformerTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/transform/BeanPropertyMethodNameTransformerTest.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/transform/BeanPropertyMethodNameTransformerTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/transform/BeanPropertyMethodNameTransformerTest.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,108 @@
+package org.apache.torque.gf.source.transform;
+
+/*
+ * 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 org.apache.torque.gf.source.RichSourceElement;
+import org.apache.torque.gf.source.RichSourceElementImpl;
+import org.apache.torque.gf.source.SourceElement;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Converts a source element Attribute such that it can be used as method name.
+ * The base of the method name is the attribute content, with special characters
+ * removed and case corrected where necessary. Optionally,
+ * a prefix and/or suffix can be added. The result is stored into another
+ * attribute of the same source element.
+ *
+ * @version $Id: $
+ */
+public class BeanPropertyMethodNameTransformerTest
+{
+    private BeanPropertyMethodNameTransformer transformer;
+
+    @Before
+    public void before() throws SourceTransformerException
+    {
+        transformer = new BeanPropertyMethodNameTransformer();
+    }
+
+    @Test
+    public void testNoPrefixSuffix() throws SourceTransformerException
+    {
+        RichSourceElement sourceElement
+                = new RichSourceElementImpl("elementName");
+        sourceElement.setAttribute("name", "vaL_ue");
+
+        transformer.setTargetAttributeName("targetAttribute");
+        SourceElement result = transformer.transform(sourceElement, null);
+        assertEquals("vaLUe", result.getAttribute("targetAttribute"));
+    }
+
+    @Test
+    public void testPrefixSuffix() throws SourceTransformerException
+    {
+        RichSourceElement sourceElement
+                = new RichSourceElementImpl("elementName");
+        sourceElement.setAttribute("sourceAttribute", "someProperty");
+
+        transformer.setSourceAttributeName("sourceAttribute");
+        transformer.setTargetAttributeName("targetAttribute");
+        transformer.setPrefix("prefix");
+        transformer.setSuffix("Suffix");
+        SourceElement result = transformer.transform(sourceElement, null);
+        assertEquals(
+                "prefixSomePropertySuffix",
+                result.getAttribute("targetAttribute"));
+    }
+
+    @Test
+    public void testNoOverwrite() throws SourceTransformerException
+    {
+        RichSourceElement sourceElement
+                = new RichSourceElementImpl("elementName");
+        sourceElement.setAttribute("name", "modified");
+        sourceElement.setAttribute("targetAttribute", "unmodified");
+
+        transformer.setOverwrite(false);
+        transformer.setTargetAttributeName("targetAttribute");
+        SourceElement result = transformer.transform(sourceElement, null);
+        assertEquals(
+                "unmodified",
+                result.getAttribute("targetAttribute"));
+    }
+
+    @Test
+    public void testNoOverwriteEmptyTarget() throws SourceTransformerException
+    {
+        RichSourceElement sourceElement
+                = new RichSourceElementImpl("elementName");
+        sourceElement.setAttribute("name", "source");
+
+        transformer.setOverwrite(false);
+        transformer.setTargetAttributeName("targetAttribute");
+        SourceElement result = transformer.transform(sourceElement, null);
+        assertEquals(
+                "source",
+                result.getAttribute("targetAttribute"));
+    }
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/xml/SourceToXmlTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/xml/SourceToXmlTest.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/xml/SourceToXmlTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/xml/SourceToXmlTest.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,107 @@
+package org.apache.torque.gf.source.xml;
+
+/*
+ * 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.io.File;
+import java.util.ArrayList;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.torque.gf.source.FileSource;
+import org.apache.torque.gf.source.RichSourceElementImpl;
+import org.apache.torque.gf.source.SourceElement;
+import org.apache.torque.gf.source.TransformerDefinition;
+import org.junit.Test;
+
+/**
+ * Tests the SourceToXml functionality.
+ *
+ * $Id: $
+ */
+public class SourceToXmlTest
+{
+    @Test
+    public void testSourceToXml() throws Exception
+    {
+        File xmlFile
+            = new File("src/test/resources/org/apache/torque/gf/source/xml/source.xml");
+        FileSource fileSource = new FileSource(
+                new XmlSourceType(),
+                xmlFile,
+                null,
+                null,
+                new ArrayList<TransformerDefinition>());
+        SourceElement rootElement = fileSource.getRootElement();
+
+        String result = new SourceToXml().toXml(rootElement);
+        String expected = FileUtils.readFileToString(new File(
+                "src/test/resources/org/apache/torque/gf/source/xml/sourceToXmlResult.xml"));
+        // remove license from expected file
+        expected = StringUtils.substringAfterLast(expected, "-->\n\n");
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void testSourceToXmlWithReferences() throws Exception
+    {
+        File xmlFile
+            = new File("src/test/resources/org/apache/torque/gf/source/xml/source.xml");
+        FileSource fileSource = new FileSource(
+                new XmlSourceType(),
+                xmlFile,
+                null,
+                null,
+                new ArrayList<TransformerDefinition>());
+        SourceElement rootElement = fileSource.getRootElement();
+        rootElement.addChild(rootElement.getChildren().get(2));
+
+        String result = new SourceToXml().toXml(rootElement);
+        String expected = FileUtils.readFileToString(new File(
+                "src/test/resources/org/apache/torque/gf/source/xml/sourceToXmlWithReferenceResult.xml"));
+        // remove license from expected file
+        expected = StringUtils.substringAfterLast(expected, "-->\n\n");
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void testSourceToXmlTextEscaping() throws Exception
+    {
+        SourceElement rootElement = new RichSourceElementImpl("root");
+        rootElement.setAttribute((String) null, "X&<>Y'\"Z");
+        String result = new SourceToXml().toXml(rootElement);
+        assertEquals(
+                "<root id=\"1\">X&amp;&lt;&gt;Y&apo;&quot;Z</root>\n",
+                result);
+    }
+
+    @Test
+    public void testSourceToXmlAttributeEscaping() throws Exception
+    {
+        SourceElement rootElement = new RichSourceElementImpl("root");
+        rootElement.setAttribute("attribute", "&<>'\"");
+        String result = new SourceToXml().toXml(rootElement);
+        assertEquals(
+                "<root attribute=\"&amp;&lt;&gt;&apo;&quot;\" id=\"1\"/>\n",
+                result);
+    }
+
+}

Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/xml/XmlParserTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/xml/XmlParserTest.java?rev=910600&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/xml/XmlParserTest.java (added)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/gf/source/xml/XmlParserTest.java Tue Feb 16 17:15:43 2010
@@ -0,0 +1,91 @@
+package org.apache.torque.gf.source.xml;
+
+/*
+ * 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.io.File;
+import java.util.ArrayList;
+
+import org.apache.torque.gf.source.FileSource;
+import org.apache.torque.gf.source.SourceElement;
+import org.apache.torque.gf.source.TransformerDefinition;
+import org.junit.Test;
+
+public class XmlParserTest
+{
+    @Test
+    public void testReadXmlSource() throws Exception
+    {
+        File xmlFile = new File(
+            "src/test/resources/org/apache/torque/gf/source/xml/source.xml");
+        FileSource fileSource = new FileSource(
+                new XmlSourceType(),
+                xmlFile,
+                null,
+                null,
+                new ArrayList<TransformerDefinition>());
+        SourceElement rootElement = fileSource.getRootElement();
+
+        assertEquals("root", rootElement.getName());
+        assertEquals(1, rootElement.getAttributeNames().size());
+        assertEquals(
+                "rootElementAttributeValue",
+                rootElement.getAttribute("rootElementAttribute"));
+        assertEquals(4, rootElement.getChildren().size());
+        SourceElement child1 = rootElement.getChildren().get(0);
+        SourceElement child2 = rootElement.getChildren().get(1);
+        SourceElement child3 = rootElement.getChildren().get(2);
+        SourceElement child4 = rootElement.getChildren().get(3);
+
+        assertEquals(1, child1.getChildren().size());
+        assertEquals(0, child2.getChildren().size());
+        assertEquals(1, child3.getChildren().size());
+        assertEquals(0, child4.getChildren().size());
+
+        assertEquals("secondLevelElement1", child1.getName());
+        assertEquals("secondLevelElement2", child2.getName());
+        assertEquals("secondLevelElement3", child3.getName());
+        assertEquals("secondLevelElement4", child4.getName());
+
+        assertEquals(0, child1.getAttributeNames().size());
+        SourceElement tlElement1 = child1.getChildren().get(0);
+        assertEquals("thirdLevelElement1", tlElement1.getName());
+        assertEquals(1, tlElement1.getAttributeNames().size());
+        assertEquals("tlaValue", tlElement1.getAttribute("tla"));
+
+        assertEquals(0, child2.getAttributeNames().size());
+
+        assertEquals(2, child3.getAttributeNames().size());
+        assertEquals("slaValue", child3.getAttribute("sla"));
+        assertEquals(
+                " text For Second Level Element 3 ",
+                child3.getAttribute((String) null));
+        SourceElement tlElement2 = child3.getChildren().get(0);
+        assertEquals("thirdLevelElement2", tlElement2.getName());
+        assertEquals(1, tlElement2.getAttributeNames().size());
+        assertEquals("tla2Value", tlElement2.getAttribute("tla2"));
+
+        assertEquals(1, child4.getAttributeNames().size());
+        assertEquals(
+                "  text For Second Level Element 4  ",
+                child4.getAttribute((String) null));
+    }
+}



---------------------------------------------------------------------
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