package org.apache.ddlutils;

/*
 * Copyright 1999-2006 The Apache Software Foundation.
 * 
 * Licensed 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 java.util.HashMap;
import java.util.Map;

import org.apache.ddlutils.Platform;
import org.apache.ddlutils.model.Database;
import org.apache.ddlutils.platform.SqlBuilder;
import org.apache.ddlutils.platform.TestPlatform;

/**
 * Test the base SqlBuilder class.
 * 
 * @author Martin van den Bemt
 * @version $Revision: $
 */
public class SqlBuilderTest extends TestBase
{
    /** The tested model. */
    private static final String TEST_MODEL =
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database name='ddlutils'>\n"+
        "  <table name='TestTable'>\n"+
        "    <column name='id' autoIncrement='true' type='INTEGER' primaryKey='true'/>\n"+
        "    <column name='name' type='VARCHAR' size='15'/>\n"+
        "  </table>\n"+
        "</database>";

    /**
     * {@inheritDoc}
     */
    public void setUp()
    {
    }

    /**
     * Test the updateSql method.
     */
    public void testUpdateSql()
    {
        TestPlatform platform   = new TestPlatform();
        SqlBuilder   sqlBuilder = platform.getSqlBuilder();
        Database     database   = parseDatabaseFromString(TEST_MODEL);
        Map          map        = new HashMap();

        map.put("name", "ddlutils");
        map.put("id", new Integer(0));

        String sql = sqlBuilder.getUpdateSql(database.getTable(0), map, false);

        assertEquals("UPDATE \"TestTable\" SET \"name\" = 'ddlutils' WHERE \"id\" = '0'",
                     sql);
    }

    /**
     * {@inheritDoc}
     */
    protected String getDatabaseName()
    {
        return null;
    }

    /**
     * The tested builder.
     */
    public class SqlBuilderImpl extends SqlBuilder
    {
        /**
         * Creates a new instance.
         * 
         * @param platform The plaftform this builder belongs to
         */
        public SqlBuilderImpl(Platform platform)
        {
            super(platform);
        }
    }
}

@@ -46,12 +46,12 @@
 ght 
-1999
+2005
 -200
@@ -722,46 +722,8 @@
 %0D%0A%0D%0A
-import org.apache.ddlutils.Platform;%0D%0A
 impo
@@ -762,16 +762,57 @@
 abase;%0D%0A
+import org.apache.ddlutils.model.Table;%0D%0A
 import o
@@ -1074,49 +1074,145 @@
  /**
- The tested model. */%0D%0A    priva
+%0D%0A     * Tests the %7B@link SqlBuilder#getUpdateSql(Table, Map, boolean)%7D method.%0D%0A     */%0D%0A    public void 
 te
- 
 st
-atic
+UpdateSql()%0D%0A    %7B%0D%0A       
  fin
@@ -1221,26 +1221,24 @@
  String 
-TEST_MODEL
+modelXml
  =%0D%0A    
@@ -1241,16 +1241,20 @@
         
+   
+ 
 %22%3C?xml v
@@ -1291,24 +1291,28 @@
 9-1'?%3E%5Cn%22+%0D%0A
+    
         %22%3Cda
@@ -1344,24 +1344,28 @@
 %22+%0D%0A        
+    
 %22  %3Ctable na
@@ -1385,32 +1385,36 @@
 '%3E%5Cn%22+%0D%0A        
+ 
+   
 %22    %3Ccolumn nam
@@ -1481,32 +1481,36 @@
 /%3E%5Cn%22+%0D%0A        
+    
 %22    %3Ccolumn nam
@@ -1542,32 +1542,36 @@
 ize='15'/%3E%5Cn%22+%0D%0A
+    
         %22  %3C/tab
@@ -1587,16 +1587,20 @@
         
+    
 %22%3C/datab
@@ -1613,182 +1613,8 @@
 %0D%0A%0D%0A
-    /**%0D%0A     * %7B@inheritDoc%7D%0D%0A     */%0D%0A    public void setUp()%0D%0A    %7B%0D%0A    %7D%0D%0A%0D%0A    /**%0D%0A     * Test the updateSql method.%0D%0A     */%0D%0A    public void testUpdateSql()%0D%0A    %7B%0D%0A
     
@@ -1787,18 +1787,16 @@
 ing(
-TEST_MODEL
+modelXml
 );%0D%0A
@@ -1923,24 +1923,88 @@
 ger(0));%0D%0A%0D%0A
+        platform.setDelimitedIdentifierModeOn(true);%0D%0A        %0D%0A
         Stri
@@ -2203,483 +2203,8 @@
   %7D%0D
-%0A%0D%0A    /**%0D%0A     * %7B@inheritDoc%7D%0D%0A     */%0D%0A    protected String getDatabaseName()%0D%0A    %7B%0D%0A        return null;%0D%0A    %7D%0D%0A%0D%0A    /**%0D%0A     * The tested builder.%0D%0A     */%0D%0A    public class SqlBuilderImpl extends SqlBuilder%0D%0A    %7B%0D%0A        /**%0D%0A         * Creates a new instance.%0D%0A         * %0D%0A         * @param platform The plaftform this builder belongs to%0D%0A         */%0D%0A        public SqlBuilderImpl(Platform platform)%0D%0A        %7B%0D%0A            super(platform);%0D%0A        %7D%0D%0A    %7D%0D
 %0A%7D%0D%0A

Simplified the test case