package org.codehaus.mojo.dbunit;

/*
 * The MIT License
 *
 * Copyright (c) 2006, The Codehaus
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
*/

import java.io.File;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @author <a href="mailto:dantran@gmail.com">Dan Tran</a>
 * @version $Id$
 */
public class OperationMojoTest
    extends AbstractDbUnitMojoTest
{
    
    public void testCleanInsertOperation()
        throws Exception
    {
        //init database with fixed data
        OperationMojo operation = new OperationMojo();
        this.populateMojoCommonConfiguration( operation );
        operation.src = new File( p.getProperty( "xmlDataSource" ) );
        operation.format = "xml";
        operation.type = "CLEAN_INSERT";
        operation.execute();
        
        //export database to a file
        File exportFile = new File( getBasedir(), "target/export.xml" );
        ExportMojo export = new ExportMojo();
        this.populateMojoCommonConfiguration( export );
        export.dest = exportFile;
        export.format = "xml";
        export.execute();
        
        //check to makesure we have 2 rows
        Statement st = c.createStatement();
        ResultSet rs = st.executeQuery( "select count(*) from person" );
        rs.next();
        assertEquals( 2, rs.getInt(1) );     
        
        //then import it back to DB
        operation.src = exportFile;
        operation.execute();
        
        //check to makesure we have 2 rows
        st = c.createStatement();
        rs = st.executeQuery( "select count(*) from person" );
        rs.next();
        assertEquals( 2, rs.getInt(1) );        
    }

    public void testSkip()
        throws Exception
    {
        //init database with fixed data
        OperationMojo operation = new OperationMojo();
        this.populateMojoCommonConfiguration( operation );
        operation.src = new File( p.getProperty( "xmlDataSource" ) );
        operation.format = "xml";
        operation.type = "CLEAN_INSERT";
        operation.skip = true;
        operation.execute();
            
        //check to makesure we have 2 rows
        Statement st = c.createStatement();
        ResultSet rs = st.executeQuery( "select count(*) from person" );
        rs.next();
        //no data  since skip is set
        assertEquals( 0, rs.getInt(1) );           
    }
}

@@ -1806,32 +1806,263 @@
 ute();%0A        %0A
+        //check to makesure we have 2 rows%0A        Statement st = c.createStatement();%0A        ResultSet rs = st.executeQuery( %22select count(*) from person%22 );%0A        rs.next();%0A        assertEquals( 2, rs.getInt(1) );  %0A        %0A
         //export
@@ -2363,229 +2363,8 @@
 %0A   
-     //check to makesure we have 2 rows%0A        Statement st = c.createStatement();%0A        ResultSet rs = st.executeQuery( %22select count(*) from person%22 );%0A        rs.next();%0A        assertEquals( 2, rs.getInt(1) );     
 %0A   

add testSkip