// Path: src/main/java/com/btmatthews/maven/plugins/inmemdb/Database.java
// public interface Database {
// 
//     /**
//      * Find the loader that supports the source file and use it to load the data
//      * into or execute the script against the database.
//      *
//      * @param logger Used to report errors and raise exceptions.
//      * @param source The source file containing data or script.
//      */
//     void load(Logger logger, Source source);
// }
// 
// Path: src/main/java/com/btmatthews/maven/plugins/inmemdb/mojo/DataSet.java
// public final class DataSet extends AbstractSource {
// 
//     /**
//      * Indicates whether or not the data set contains qualified table names.
//      */
//     private Boolean qualifiedTableNames;
// 
//     /**
//      * The default constructor.
//      *
//      * @see AbstractSource#AbstractSource()
//      */
//     public DataSet() {
//     }
// 
//     /**
//      * Construct a source object that describes DBUnit data set.
//      *
//      * @param file The source file that contains the DDL/DML script or DBUnit
//      *             data set.
//      * @param flag <ul>
//      *             <li>{@link Boolean#TRUE} if the are qualified with the schema
//      *             name.</li>
//      *             <li>{@link Boolean#FALSE} if the are not qualified with the
//      *             schema name.</li>
//      *             </ul>
//      * @see AbstractSource#AbstractSource(String)
//      */
//     public DataSet(final String file, final Boolean flag) {
//         super(file);
//         this.qualifiedTableNames = flag;
//     }
// 
//     /**
//      * Determine if the DBUnit data set contains qualified or unqualified table
//      * names.
//      *
//      * @return <ul>
//      *         <li>{@link Boolean#TRUE} if the are qualified with the schema
//      *         name.</li>
//      *         <li>{@link Boolean#FALSE} if the are not qualified with the
//      *         schema name.</li>
//      *         </ul>
//      * @see com.btmatthews.maven.plugins.inmemdb.Source#getQualifiedTableNames()
//      */
//     public Boolean getQualifiedTableNames() {
//         return this.qualifiedTableNames;
//     }
// 
//     /**
//      * Indicate whether or not the DBUnit data set contains qualified or
//      * unqualified table names.
//      *
//      * @param flag <ul>
//      *             <li>{@link Boolean#TRUE} if the are qualified with the schema
//      *             name.</li>
//      *             <li>{@link Boolean#FALSE} if the are not qualified with the
//      *             schema name.</li>
//      *             </ul>
//      */
//     public void setQualifiedTableNames(final Boolean flag) {
//         this.qualifiedTableNames = flag;
//     }
// 
//     @Override
//     public String toString() {
//         return "DataSet[" + getSourceFile() + "]";
//     }
// }
// 
// Path: src/main/java/com/btmatthews/maven/plugins/inmemdb/mojo/Script.java
// public final class Script extends AbstractSource {
// 
//     /**
//      * The default constructor.
//      */
//     public Script() {
//     }
// 
//     /**
//      * Construct a source object that describes a DDL/DML script or DBUnit data
//      * set.
//      *
//      * @param file The source file that contains the DDL/DML script or DBUnit
//      *             data set.
//      */
//     public Script(final String file) {
//         super(file);
//     }
// 
//     /**
//      * Indicates that the script source descriptor does not distinguish between
//      * qualified and unqualified table names by returning <code>null</code>.
//      *
//      * @return Always returns <code>null</code>.
//      */
//     public Boolean getQualifiedTableNames() {
//         return null;
//     }
// 
//     @Override
//     public String toString() {
//         return "Script[" + getSourceFile() + "]";
//     }
// }


import static org.mockito.MockitoAnnotations.initMocks;
import com.btmatthews.maven.plugins.inmemdb.Database;
import com.btmatthews.maven.plugins.inmemdb.mojo.DataSet;
import com.btmatthews.maven.plugins.inmemdb.mojo.Script;
import com.btmatthews.utils.monitor.Logger;
import com.btmatthews.utils.monitor.Server;
import org.apache.maven.plugin.MojoFailureException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
/*
 * Copyright 2011-2012 Brian Matthews
 *
 * 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.
 */

package com.btmatthews.maven.plugins.inmemdb.test;



/**
 * Created with IntelliJ IDEA.
 * User: Brian
 * Date: 29/11/12
 * Time: 19:53
 * To change this template use File | Settings | File Templates.
 */
public abstract class AbstractTestDatabase {

    /**
     * Mock for the logger.
     */
    @Mock
    private Logger logger;

    /**
     * The main test fixture.
     */
    private Server database;

    /**
     * Concrete class should override this method to create the main test fixture.
     *
     * @return The main test fixture.
     */
    protected abstract Server createDatabaseServer();

    /**
     * Prepare for test case execute by creating, configuring and starting the main test fixture.
     */
    @Before
    public void setUp() {
        initMocks(this);
        database = createDatabaseServer();
        database.configure("database", "test", logger);
        database.configure("username", "sa", logger);
        database.configure("password", "", logger);
        database.start(logger);
    }

    /**
     * Clean up after test case execution by stopping the main test fixture.
     */
    @After
    public void tearDown() {
        database.stop(logger);
    }

    /**
     * Verify that the database server starts and stops cleanly.
     */
    @Test
    public void testStartStop() {
    }

    /**
     * Verify that a valid DDL/DML script can be loaded.
     */
    @Test
    public void testLoadScript() {
        final Script source = new Script();
        source.setSourceFile("src/test/resources/create_database.sql");
// Path: src/main/java/com/btmatthews/maven/plugins/inmemdb/Database.java
// public interface Database {
// 
//     /**
//      * Find the loader that supports the source file and use it to load the data
//      * into or execute the script against the database.
//      *
//      * @param logger Used to report errors and raise exceptions.
//      * @param source The source file containing data or script.
//      */
//     void load(Logger logger, Source source);
// }
// 
// Path: src/main/java/com/btmatthews/maven/plugins/inmemdb/mojo/DataSet.java
// public final class DataSet extends AbstractSource {
// 
//     /**
//      * Indicates whether or not the data set contains qualified table names.
//      */
//     private Boolean qualifiedTableNames;
// 
//     /**
//      * The default constructor.
//      *
//      * @see AbstractSource#AbstractSource()
//      */
//     public DataSet() {
//     }
// 
//     /**
//      * Construct a source object that describes DBUnit data set.
//      *
//      * @param file The source file that contains the DDL/DML script or DBUnit
//      *             data set.
//      * @param flag <ul>
//      *             <li>{@link Boolean#TRUE} if the are qualified with the schema
//      *             name.</li>
//      *             <li>{@link Boolean#FALSE} if the are not qualified with the
//      *             schema name.</li>
//      *             </ul>
//      * @see AbstractSource#AbstractSource(String)
//      */
//     public DataSet(final String file, final Boolean flag) {
//         super(file);
//         this.qualifiedTableNames = flag;
//     }
// 
//     /**
//      * Determine if the DBUnit data set contains qualified or unqualified table
//      * names.
//      *
//      * @return <ul>
//      *         <li>{@link Boolean#TRUE} if the are qualified with the schema
//      *         name.</li>
//      *         <li>{@link Boolean#FALSE} if the are not qualified with the
//      *         schema name.</li>
//      *         </ul>
//      * @see com.btmatthews.maven.plugins.inmemdb.Source#getQualifiedTableNames()
//      */
//     public Boolean getQualifiedTableNames() {
//         return this.qualifiedTableNames;
//     }
// 
//     /**
//      * Indicate whether or not the DBUnit data set contains qualified or
//      * unqualified table names.
//      *
//      * @param flag <ul>
//      *             <li>{@link Boolean#TRUE} if the are qualified with the schema
//      *             name.</li>
//      *             <li>{@link Boolean#FALSE} if the are not qualified with the
//      *             schema name.</li>
//      *             </ul>
//      */
//     public void setQualifiedTableNames(final Boolean flag) {
//         this.qualifiedTableNames = flag;
//     }
// 
//     @Override
//     public String toString() {
//         return "DataSet[" + getSourceFile() + "]";
//     }
// }
// 
// Path: src/main/java/com/btmatthews/maven/plugins/inmemdb/mojo/Script.java
// public final class Script extends AbstractSource {
// 
//     /**
//      * The default constructor.
//      */
//     public Script() {
//     }
// 
//     /**
//      * Construct a source object that describes a DDL/DML script or DBUnit data
//      * set.
//      *
//      * @param file The source file that contains the DDL/DML script or DBUnit
//      *             data set.
//      */
//     public Script(final String file) {
//         super(file);
//     }
// 
//     /**
//      * Indicates that the script source descriptor does not distinguish between
//      * qualified and unqualified table names by returning <code>null</code>.
//      *
//      * @return Always returns <code>null</code>.
//      */
//     public Boolean getQualifiedTableNames() {
//         return null;
//     }
// 
//     @Override
//     public String toString() {
//         return "Script[" + getSourceFile() + "]";
//     }
// }


// Path: src/test/java/com/btmatthews/maven/plugins/inmemdb/test/AbstractTestDatabase.java
import static org.mockito.MockitoAnnotations.initMocks;
import com.btmatthews.maven.plugins.inmemdb.Database;
import com.btmatthews.maven.plugins.inmemdb.mojo.DataSet;
import com.btmatthews.maven.plugins.inmemdb.mojo.Script;
import com.btmatthews.utils.monitor.Logger;
import com.btmatthews.utils.monitor.Server;
import org.apache.maven.plugin.MojoFailureException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

/*
 * Copyright 2011-2012 Brian Matthews
 *
 * 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.
 */

package com.btmatthews.maven.plugins.inmemdb.test;



/**
 * Created with IntelliJ IDEA.
 * User: Brian
 * Date: 29/11/12
 * Time: 19:53
 * To change this template use File | Settings | File Templates.
 */
public abstract class AbstractTestDatabase {

    /**
     * Mock for the logger.
     */
    @Mock
    private Logger logger;

    /**
     * The main test fixture.
     */
    private Server database;

    /**
     * Concrete class should override this method to create the main test fixture.
     *
     * @return The main test fixture.
     */
    protected abstract Server createDatabaseServer();

    /**
     * Prepare for test case execute by creating, configuring and starting the main test fixture.
     */
    @Before
    public void setUp() {
        initMocks(this);
        database = createDatabaseServer();
        database.configure("database", "test", logger);
        database.configure("username", "sa", logger);
        database.configure("password", "", logger);
        database.start(logger);
    }

    /**
     * Clean up after test case execution by stopping the main test fixture.
     */
    @After
    public void tearDown() {
        database.stop(logger);
    }

    /**
     * Verify that the database server starts and stops cleanly.
     */
    @Test
    public void testStartStop() {
    }

    /**
     * Verify that a valid DDL/DML script can be loaded.
     */
    @Test
    public void testLoadScript() {
        final Script source = new Script();
        source.setSourceFile("src/test/resources/create_database.sql");
        ((Database)database).load(logger, source);