diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..93c9e84 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,41 @@ +# Java Maven CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-java/ for more details +# +version: 2 +jobs: + build: + docker: + # specify the version you desire here + - image: circleci/openjdk:8-jdk + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # - image: circleci/postgres:9.4 + + working_directory: ~/repo + + environment: + # Customize the JVM maximum heap limit + # MAVEN_OPTS: -Xmx3200m + + steps: + - checkout + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "pom.xml" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: mvn dependency:go-offline + + - save_cache: + paths: + - ~/.m2 + key: v1-dependencies-{{ checksum "pom.xml" }} + + # run tests! + - run: mvn integration-test diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c493ef..4999f0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,25 @@ Change Log ========== +Version 1.5.1 +---------------------------- + + * Fixed issues with using step number to identify testing data + +Version 1.5.0 +---------------------------- + + * Rebased to com.mindmercatis in order to continue development and provide separate CirceCI integration testing + * Added methods to simplify testing by just saying which result will be given at which step + +Version 1.4.0 +---------------------------- + + * Support for in-memory result sets + * Support for insert/update queries + * Support for capturing query parameters for test purposes + * Support for providing different resultsets depending on the query parameters + Version 1.3.0 (2018-03-14) ---------------------------- diff --git a/README.md b/README.md index aea186d..341e957 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # dummyjdbc -[![CircleCI](https://circleci.com/gh/kaiwinter/dummyjdbc.svg?style=svg)](https://circleci.com/gh/kaiwinter/dummyjdbc) +[![CircleCI](https://circleci.com/gh/SimoneAvogadro/dummyjdbc.svg?style=svg)](https://circleci.com/gh/SimoneAvogadro/dummyjdbc) dummyjdbc answers database requests of any application with dummy data to be independent of an existing database. @@ -7,15 +7,154 @@ The library can either return dummy values, or values defined by you in a CSV fi For more details please see the [Wiki](https://github.com/kaiwinter/dummyjdbc/wiki) -## dummyjdbc at Maven Central +## New Methods in 1.5.0 +Refactored package in order to use `com.mindmercatis` instead of `com.googlecode` in order to proceed with the fork and keep releasing new versions. + +Three new methods have been added to `com.mindmercatis.dummyjdbc.DummyJdbcDriver` in order to support: +* Preparing tests as a simple sequence of expected table results + +```java + Class.forName(DummyJdbcDriver.class.getCanonicalName()); + DummyJdbcDriver.reset(); //reset the step counter + DummyJdbcDriver.addInMemoryTableResource(0, // result set for the first query which will be executed + "name, age\n"+ + "John, 20" ); + DummyJdbcDriver.addInMemoryTableResource(1, // result set for the second query which will be executed + "id, country\n"+ + "1, Italy\n"+ + "2, USA" ); + DummyJdbcDriver.addInMemoryTableResource(2, // result set for the third query which will be executed + "id, make, model, owner\n"+ + "1, Mazda, CX-5, Mark Twain\n"+ + "2, Ford, Focus, JF Kennedy" ); +``` + + +## New Methods in 1.4.0 +Three new methods have been added to `com.googlecode.dummyjdbc.DummyJdbcDriver` in order to support: +* InMemory resources for resultsets +* differentiated resultsers depending on query parameters +* capturing INSERT/UPDATE parameters + +```Java +/** + * Add the CSV contained the string 'value' to the list of available resultsets + */ +public static void addInMemoryTableResource(String testID, String value); + +/** + * Add the CSV contained the InputStream 'valueStream' to the list of available resultsets + */ +public static void addInMemoryTableResource(String testID, InputStream valueStream); + +/** + * Get the current value of the resource, used mainly to examine the parameters used for INSERT/UPDATE queries + */ +public static String getInMemoryTableResource(String testID); +``` + +## Sample Usage +```java +@Test +public void testInMemoryCSVFromString() throws ClassNotFoundException, URISyntaxException, SQLException { + Class.forName(DummyJdbcDriver.class.getCanonicalName()); + + DummyJdbcDriver.addInMemoryTableResource("TEST1", + "\n"+ + "name, age\n"+ + "John, 20"+ + "\n" + ); + + Connection connection = DriverManager.getConnection("any"); + PreparedStatement statement = connection.prepareStatement( + "-- TESTCASE:test1\n"+ + "SELECT * FROM test_table"); + + Assert.assertTrue(statement instanceof CsvPreparedStatement); + resultSet = statement.executeQuery(); + + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("John", resultSet.getString(1)); + Assert.assertEquals(20, resultSet.getInt(2)); + Assert.assertEquals("John", resultSet.getString("name")); + Assert.assertEquals(20, resultSet.getInt("age")); +} +``` + +## How in memory resources are selected + +### Explicit comment in SQL +InMemory resource 'name' will be inferred by using some logic + +```SQL +-- TESTCASE: Hello1 +SELECT * +FROM TableUsedEverywhere +``` +will search for resource: `Hello1` (case insensitive) + +### Table name deduction +This is derived from the original dumymjdbc design, with some added REGEX for INSERT/UPDATE queries + +```SQL +SELECT name +FROM mytable +WHERE surname='Happy' +``` +will search for resource: `mytable` (case insensitive) + +### Parameters +In order to make possible more sophisticated test cases the driver now will try to match also parameters +So the following query: +```SQL +SELECT name +FROM mytable +WHERE surname=? AND age=? +``` +with parameters "Smith" and "34" will search for resources in the following order (always case-insensitive): +* `mytable?Smith,34` +* `mytable` + +## Testing INSERT/UPDATE/DELETE queries +One key part of testing how the application interacts with the DB is to capture if it performed the right INSERT/UPDATE queries, this is now possible. + +When updating a table now the parameters are captured and stored into a String which will be accessible for testing purposes + +### How to know which parameters have been used for a query +A new InMemory resource will be created with name equals to the name of the table + `_PARAMS` +E.g: when updating table `users` a new key will be added with name `users_PARAMS` + +### Sample code + +```java + Class.forName(DummyJdbcDriver.class.getCanonicalName()); + + Connection connection = DriverManager.getConnection("any"); + PreparedStatement statement = connection.prepareStatement("INSERT INTO users (name,age) VALUES (?,?) "); + + statement.setString(1, "hello"); + statement.setInt(2, 30); + status = statement.execute(); + params = DummyJdbcDriver.getInMemoryTableResource("users_PARAMS"); + Assert.assertEquals("hello,30", params); +``` + + +## dummyjdbc at Maven Central [OUTDATED] + +In order to use the official version you can use Maven ```xml - com.googlecode.dummyjdbc + com.mindmercastis.dummyjdbc dummyjdbc - 1.3.0 + 1.5.0 ``` +In order to use v 1.4.0 at present you must download it directly from GitHub + + ## Overview -![Design](https://raw.githubusercontent.com/wiki/kaiwinter/dummyjdbc/images/dummyjdbc-design.png) \ No newline at end of file +![Design](https://raw.githubusercontent.com/wiki/kaiwinter/dummyjdbc/images/dummyjdbc-design.png) diff --git a/pom.xml b/pom.xml index bca481d..ea0bd01 100644 --- a/pom.xml +++ b/pom.xml @@ -1,15 +1,15 @@ 4.0.0 - com.googlecode.dummyjdbc + com.mindmercatis.dummyjdbc dummyjdbc - 1.3.1-SNAPSHOT + 1.5.1 jar DummyJDBC DummyJDBC is a mock JDBC driver which can return data from CSV files - https://github.com/kaiwinter/dummyjdbc + https://github.com/SimoneAvogadro/dummyjdbc Apache 2 @@ -19,9 +19,9 @@ - https://github.com/kaiwinter/dummyjdbc - scm:git:https://github.com/kaiwinter/dummyjdbc.git - scm:git:git@github.com:kaiwinter/dummyjdbc.git + https://github.com/SimoneAvogadro/dummyjdbc + scm:git:https://github.com/SimoneAvogadro/dummyjdbc.git + scm:git:git@github.com:SimoneAvogadro/dummyjdbc.git @@ -29,11 +29,15 @@ kai Kai Winter + + simone + Simone Avogadro + GitHub Issues - https://github.com/kaiwinter/dummyjdbc/issues + https://github.com/SimoneAvogadro/dummyjdbc/issues @@ -171,4 +175,4 @@ - \ No newline at end of file + diff --git a/src/main/java/com/googlecode/dummyjdbc/DummyJdbcDriver.java b/src/main/java/com/googlecode/dummyjdbc/DummyJdbcDriver.java deleted file mode 100644 index 6dcef5a..0000000 --- a/src/main/java/com/googlecode/dummyjdbc/DummyJdbcDriver.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.googlecode.dummyjdbc; - -import com.googlecode.dummyjdbc.utils.FilenameUtils; -import com.googlecode.dummyjdbc.utils.StringUtils; -import java.io.File; -import java.io.FileFilter; -import java.net.URL; -import java.sql.Connection; -import java.sql.Driver; -import java.sql.DriverManager; -import java.sql.DriverPropertyInfo; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Logger; - -import com.googlecode.dummyjdbc.connection.impl.DummyConnection; - -/** - * The {@link DummyJdbcDriver}. The {@link #connect(String, Properties)} method returns the {@link DummyConnection}. - * - * @author Kai Winter - */ -public final class DummyJdbcDriver implements Driver { - - private final static String DEFAULT_DATABASE = "any"; - - private static Map> tableResources = Collections.synchronizedMap(new HashMap>()); - - static { - try { - // Register this with the DriverManager - DriverManager.registerDriver(new DummyJdbcDriver()); - } catch (SQLException e) { - // ignore - } - } - - /** - * Registers a CSV file for a database table. When a Query is executed like SELECT * FROM ADDRESSES the - * given csvFile for the given tablename addresses will be used. - * - * @param tablename - * The name of the database table like in the SQL statement (e.g. addresses). - * @param csvFile - * A {@link File} object of a CSV file which should be parsed in order to return table data. - */ - public static void addTableResource(String tablename, File csvFile) { - Map databaseMap = Collections.synchronizedMap(new HashMap()); - databaseMap.put(tablename, csvFile); - tableResources.put(DEFAULT_DATABASE, databaseMap); - } - - @Override - public int getMajorVersion() { - return 1; - } - - @Override - public int getMinorVersion() { - return 0; - } - - @Override - public boolean jdbcCompliant() { - return false; - } - - @Override - public boolean acceptsURL(String url) throws SQLException { - return true; - } - - @Override - public Connection connect(String url, Properties info) throws SQLException { - String database = parseConnectUrl(url); - - loadTableResources(database); - - return new DummyConnection(tableResources.get(database)); - } - - @Override - public DriverPropertyInfo[] getPropertyInfo(final String url, final Properties props) throws SQLException { - return new DriverPropertyInfo[0]; - } - - @Override - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - return null; - } - - /** - * Parse jdbc url to database file path - * - * @param url jdbc url - * @return database file path - */ - private String parseConnectUrl(String url) { - if (url == null) { - throw new RuntimeException("You should defined jdbc url first"); - } - - final int index = url.indexOf("jdbc::mock::"); - if (index == -1) { - return DEFAULT_DATABASE; - } - - final String others = url.substring("jdbc::mock::".length()); - final String[] items = others.split("::"); - switch(items.length) { - case 0: - throw new RuntimeException("No database directory defined"); - default: - return StringUtils.join(items, "/"); - } - - } - - /** - * load table resources from database directory - * - * @param database database path - */ - private void loadTableResources(String database) { - // ignore database name is any - if (DEFAULT_DATABASE.equals(database)) { - return; - } - - // check database is exists - URL dirUrl = getClass().getClassLoader().getResource(database); - if (dirUrl == null) { - throw new RuntimeException("The database directory is not exists"); - } - - File dir = new File(dirUrl.getFile()); - if (!dir.canRead() || !dir.isDirectory()) { - throw new RuntimeException("The database directory is not a directory or cannot read"); - } - - // get all table files - File[] files = dir.listFiles(new FileFilter() { - - @Override - public boolean accept(File pathname) { - return pathname.isFile() && FilenameUtils.isExtension(pathname.getName(), "csv"); - } - - }); - - // registry table resources - for (File file : files) { - Map databaseMap = tableResources.get(database); - if (databaseMap == null) { - databaseMap = Collections.synchronizedMap(new HashMap()); - tableResources.put(database, databaseMap); - } - databaseMap.put(FilenameUtils.getBaseName(file.getName()), file); - } - } - - -} diff --git a/src/main/java/com/googlecode/dummyjdbc/statement/impl/CsvPreparedStatement.java b/src/main/java/com/googlecode/dummyjdbc/statement/impl/CsvPreparedStatement.java deleted file mode 100644 index c74ebee..0000000 --- a/src/main/java/com/googlecode/dummyjdbc/statement/impl/CsvPreparedStatement.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.googlecode.dummyjdbc.statement.impl; - -import java.io.File; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Map; - -import com.googlecode.dummyjdbc.statement.PreparedStatementAdapter; - -/** - * Wraps the {@link CsvStatement} as a prepared statement. - * - * @author Kai Winter - */ -public class CsvPreparedStatement extends PreparedStatementAdapter { - - private final CsvStatement statement; - private final String sql; - - private ResultSet currentResultSet; - - /** - * Constructs a new {@link CsvPreparedStatement}. - * - * @param tableResources {@link Map} of table name to CSV file. - * @param sql - * the SQL statement. - */ - public CsvPreparedStatement(Map tableResources, String sql) { - this.statement = new CsvStatement(tableResources); - this.sql = sql; - } - - @Override - public ResultSet executeQuery() throws SQLException { - return (currentResultSet = statement.executeQuery(sql)); - } - - @Override - public ResultSet executeQuery(String sql) throws SQLException { - return (currentResultSet = statement.executeQuery(sql)); - } - - @Override - public boolean execute() throws SQLException { - currentResultSet = statement.executeQuery(sql); - return true; - } - - @Override - public boolean execute(String sql) throws SQLException { - currentResultSet = statement.executeQuery(sql); - return true; - } - - @Override - public boolean execute(String sql, int[] columnIndexes) throws SQLException { - return execute(sql); - } - - @Override - public boolean execute(String sql, String[] columnNames) throws SQLException { - return execute(sql); - } - - @Override - public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - return execute(sql); - } - - @Override - public ResultSet getResultSet() throws SQLException { - return currentResultSet; - } -} diff --git a/src/main/java/com/googlecode/dummyjdbc/AspectLogger.aj b/src/main/java/com/mindmercatis/dummyjdbc/AspectLogger.aj similarity index 94% rename from src/main/java/com/googlecode/dummyjdbc/AspectLogger.aj rename to src/main/java/com/mindmercatis/dummyjdbc/AspectLogger.aj index aa44592..ad66ca9 100644 --- a/src/main/java/com/googlecode/dummyjdbc/AspectLogger.aj +++ b/src/main/java/com/mindmercatis/dummyjdbc/AspectLogger.aj @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc; +package com.mindmercatis.dummyjdbc; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.Signature; diff --git a/src/main/java/com/mindmercatis/dummyjdbc/DummyJdbcDriver.java b/src/main/java/com/mindmercatis/dummyjdbc/DummyJdbcDriver.java new file mode 100644 index 0000000..7259e9f --- /dev/null +++ b/src/main/java/com/mindmercatis/dummyjdbc/DummyJdbcDriver.java @@ -0,0 +1,334 @@ +package com.mindmercatis.dummyjdbc; + +import java.io.File; +import java.io.FileFilter; +import java.io.InputStream; +import java.net.URL; +import java.sql.Connection; +import java.sql.Driver; +import java.sql.DriverManager; +import java.sql.DriverPropertyInfo; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.Scanner; +import java.util.logging.Logger; + +import com.mindmercatis.dummyjdbc.connection.impl.DummyConnection; +import com.mindmercatis.dummyjdbc.utils.FilenameUtils; +import com.mindmercatis.dummyjdbc.utils.StringUtils; + +/** + * The {@link DummyJdbcDriver}. The {@link #connect(String, Properties)} method returns the {@link DummyConnection}. + * + * @author Kai Winter + */ +public final class DummyJdbcDriver implements Driver { + + /** + * The date format for parsing a date from a CSV file. + */ + private static final String DATE_FORMAT = "dd-MMM-yy"; + private static final String TIME_FORMAT = "HH:mm"; + private static final String TIMESTAMP_FORMAT = "yyyyMMdd HHmmss.SSS"; + + public static final String STEP_PREFIX = "##STEP"; + + /** + * Counter for the number of statements being executed + * Used to give a sequential number to each query + * Starts from -1 because it's pre-incremented once each statement is created + */ + static int step = -1; + + /** + * CSV files stored into memory + */ + static Map inMemoryTableResources = new HashMap(); + + public static final ThreadLocal THREAD_LOCAL_DATEFORMAT = new ThreadLocal() { + @Override + protected DateFormat initialValue() { + return new SimpleDateFormat(DATE_FORMAT); + } + }; + + public static final ThreadLocal THREAD_LOCAL_TIMEFORMAT = new ThreadLocal() { + @Override + protected DateFormat initialValue() { + return new SimpleDateFormat(TIME_FORMAT); + } + }; + + public static final ThreadLocal THREAD_LOCAL_TIMESTAMPFORMAT = new ThreadLocal() { + @Override + protected DateFormat initialValue() { + return new SimpleDateFormat(TIMESTAMP_FORMAT); + } + }; + + private final static String DEFAULT_DATABASE = "any"; + + private static Map> tableResources = Collections.synchronizedMap(new HashMap>()); + + static { + try { + // Register this with the DriverManager + DriverManager.registerDriver(new DummyJdbcDriver()); + } catch (SQLException e) { + // ignore + } + } + + /** + * Reset the internal data structures to restart counting + */ + public static void reset() { + step = -1; + inMemoryTableResources = new HashMap(); + tableResources = Collections.synchronizedMap(new HashMap>()); + } + + public static String getStepName() { + return STEP_PREFIX+step; + } + + /** + * Registers a CSV file for a database table. When a Query is executed like SELECT * FROM ADDRESSES the + * given csvFile for the given tablename addresses will be used. + * + * @param tablename + * The name of the database table like in the SQL statement (e.g. addresses). + * @param csvFile + * A {@link File} object of a CSV file which should be parsed in order to return table data. + */ + public static void addTableResource(String tablename, File csvFile) { + Map databaseMap = Collections.synchronizedMap(new HashMap()); + databaseMap.put(tablename, csvFile); + tableResources.put(DEFAULT_DATABASE, databaseMap); + } + + + @Override + public int getMajorVersion() { + return 1; + } + + @Override + public int getMinorVersion() { + return 0; + } + + @Override + public boolean jdbcCompliant() { + return false; + } + + @Override + public boolean acceptsURL(String url) throws SQLException { + return + url.equals("any") || // used by JUnit test cases + url.toLowerCase().startsWith("jdbc::mock::"); + } + + @Override + public Connection connect(String url, Properties info) throws SQLException { + String database = parseConnectUrl(url); + + loadTableResources(database); + + return new DummyConnection(tableResources.get(database)); + } + + @Override + public DriverPropertyInfo[] getPropertyInfo(final String url, final Properties props) throws SQLException { + return new DriverPropertyInfo[0]; + } + + @Override + public Logger getParentLogger() throws SQLFeatureNotSupportedException { + return null; + } + + /** + * Used for parsing CSV + * + * @param format {@link SimpleDataFormat} pattern + */ + public static void setDateFormat(String format) { + THREAD_LOCAL_DATEFORMAT.set(new SimpleDateFormat(format)); + } + + /** + * Used for parsing CSV + * + * @param format {@link SimpleDataFormat} pattern + */ + public static void setTimeFormat(String format) { + THREAD_LOCAL_TIMEFORMAT.set(new SimpleDateFormat(format)); + } + + /** + * Used for parsing CSV + * + * @param format {@link SimpleDataFormat} pattern + */ + public static void setTimestampFormat(String format) { + THREAD_LOCAL_TIMESTAMPFORMAT.set(new SimpleDateFormat(format)); + } + + /** + * Parse jdbc url to database file path + * + * @param url jdbc url + * @return database file path + */ + private String parseConnectUrl(String url) { + if (url == null) { + throw new RuntimeException("You should defined jdbc url first"); + } + + final int index = url.indexOf("jdbc::mock::"); + if (index == -1) { + return DEFAULT_DATABASE; + } + + final String others = url.substring("jdbc::mock::".length()); + final String[] items = others.split("::"); + switch(items.length) { + case 0: + throw new RuntimeException("No database directory defined"); + default: + return StringUtils.join(items, "/"); + } + + } + + /** + * load table resources from database directory + * + * @param database database path + */ + private void loadTableResources(String database) { + // ignore database name is any + if (DEFAULT_DATABASE.equals(database)) { + return; + } + + // check database is exists + URL dirUrl = getClass().getClassLoader().getResource(database); + if (dirUrl == null) { + throw new RuntimeException("The database directory is not exists"); + } + + File dir = new File(dirUrl.getFile()); + if (!dir.canRead() || !dir.isDirectory()) { + throw new RuntimeException("The database directory is not a directory or cannot read"); + } + + // get all table files + File[] files = dir.listFiles(new FileFilter() { + + @Override + public boolean accept(File pathname) { + return pathname.isFile() && FilenameUtils.isExtension(pathname.getName(), "csv"); + } + + }); + + // registry table resources + for (File file : files) { + Map databaseMap = tableResources.get(database); + if (databaseMap == null) { + databaseMap = Collections.synchronizedMap(new HashMap()); + tableResources.put(database, databaseMap); + } + databaseMap.put(FilenameUtils.getBaseName(file.getName()), file); + } + } + + + /** + * Get the current value of the resource, used mainly to examine the parameters used for INSERT/UPDATE queries + * @param testID + * @return + */ + public static String getInMemoryTableResource(String testID) { + return inMemoryTableResources.get(testID.toLowerCase().trim()); + } + + /** + * Get the current value of the resource, used mainly to examine the parameters used for INSERT/UPDATE queries + * @param testID + * @return + */ + public static String getInMemoryTableResourceForCurrentStep() { + return getInMemoryTableResource(getStepName()); + } + + /** + * Signal to update to the next step + */ + public static void nextStep() { + step++; + } + + + + public static void clearInMemoryTableResources() { + inMemoryTableResources.clear(); + } + + + /** + * Add the CSV contained the string 'value' to the list of available resultsets + * + * @param testID + * @param value + */ + public static void addInMemoryTableResource(String testID, String value) { + inMemoryTableResources.put(testID.toLowerCase().trim(), value.trim()); + } + + /** + * Add the CSV contained the string 'value' to the list of available resultsets + * + * @param testID + * @param value + */ + public static void addInMemoryTableResource(int step, String value) { + addInMemoryTableResource(STEP_PREFIX+step, value); + } + + /** + * Add the CSV contained the InputStream 'valueStream' to the list of available resultsets + * + * @param testID + * @param value + */ + @SuppressWarnings("resource") + public static void addInMemoryTableResource(String testID, InputStream valueStream) { + // search for "end of stream" => read all the stream into the string ! + Scanner s = new Scanner(valueStream).useDelimiter("\\A"); + String value = s.hasNext() ? s.next() : ""; + s.close(); + DummyJdbcDriver.addInMemoryTableResource(testID,value); + } + + /** + * Add the CSV contained the InputStream 'valueStream' to the list of available resultsets + * + * @param step number of step for using this resource + * @param value + */ + public static void addInMemoryTableResource(int step, InputStream valueStream) { + addInMemoryTableResource(STEP_PREFIX+step,valueStream); + } + + +} diff --git a/src/main/java/com/googlecode/dummyjdbc/connection/ConnectionAdapter.java b/src/main/java/com/mindmercatis/dummyjdbc/connection/ConnectionAdapter.java similarity index 94% rename from src/main/java/com/googlecode/dummyjdbc/connection/ConnectionAdapter.java rename to src/main/java/com/mindmercatis/dummyjdbc/connection/ConnectionAdapter.java index 1d6b39f..d7ff089 100644 --- a/src/main/java/com/googlecode/dummyjdbc/connection/ConnectionAdapter.java +++ b/src/main/java/com/mindmercatis/dummyjdbc/connection/ConnectionAdapter.java @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc.connection; +package com.mindmercatis.dummyjdbc.connection; import java.sql.Array; import java.sql.Blob; diff --git a/src/main/java/com/googlecode/dummyjdbc/connection/DummyDatabaseMetaData.java b/src/main/java/com/mindmercatis/dummyjdbc/connection/DummyDatabaseMetaData.java similarity index 99% rename from src/main/java/com/googlecode/dummyjdbc/connection/DummyDatabaseMetaData.java rename to src/main/java/com/mindmercatis/dummyjdbc/connection/DummyDatabaseMetaData.java index 3d4503a..7cc2c84 100644 --- a/src/main/java/com/googlecode/dummyjdbc/connection/DummyDatabaseMetaData.java +++ b/src/main/java/com/mindmercatis/dummyjdbc/connection/DummyDatabaseMetaData.java @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc.connection; +package com.mindmercatis.dummyjdbc.connection; import java.sql.Connection; import java.sql.DatabaseMetaData; diff --git a/src/main/java/com/googlecode/dummyjdbc/connection/impl/DummyConnection.java b/src/main/java/com/mindmercatis/dummyjdbc/connection/impl/DummyConnection.java similarity index 90% rename from src/main/java/com/googlecode/dummyjdbc/connection/impl/DummyConnection.java rename to src/main/java/com/mindmercatis/dummyjdbc/connection/impl/DummyConnection.java index 4545e34..a6aeb4e 100644 --- a/src/main/java/com/googlecode/dummyjdbc/connection/impl/DummyConnection.java +++ b/src/main/java/com/mindmercatis/dummyjdbc/connection/impl/DummyConnection.java @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc.connection.impl; +package com.mindmercatis.dummyjdbc.connection.impl; import java.io.File; import java.sql.PreparedStatement; @@ -7,9 +7,9 @@ import java.util.Collections; import java.util.Map; -import com.googlecode.dummyjdbc.connection.ConnectionAdapter; -import com.googlecode.dummyjdbc.statement.impl.CsvPreparedStatement; -import com.googlecode.dummyjdbc.statement.impl.CsvStatement; +import com.mindmercatis.dummyjdbc.connection.ConnectionAdapter; +import com.mindmercatis.dummyjdbc.statement.impl.CsvPreparedStatement; +import com.mindmercatis.dummyjdbc.statement.impl.CsvStatement; /** * Connection which implements the methods {@link #createStatement()} and {@link #prepareStatement(String)}. The diff --git a/src/main/java/com/googlecode/dummyjdbc/resultset/DummyResultSet.java b/src/main/java/com/mindmercatis/dummyjdbc/resultset/DummyResultSet.java similarity index 95% rename from src/main/java/com/googlecode/dummyjdbc/resultset/DummyResultSet.java rename to src/main/java/com/mindmercatis/dummyjdbc/resultset/DummyResultSet.java index 434a6ba..cfbe778 100644 --- a/src/main/java/com/googlecode/dummyjdbc/resultset/DummyResultSet.java +++ b/src/main/java/com/mindmercatis/dummyjdbc/resultset/DummyResultSet.java @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc.resultset; +package com.mindmercatis.dummyjdbc.resultset; import java.io.InputStream; import java.io.Reader; diff --git a/src/main/java/com/googlecode/dummyjdbc/resultset/DummyResultSetMetaData.java b/src/main/java/com/mindmercatis/dummyjdbc/resultset/DummyResultSetMetaData.java similarity index 99% rename from src/main/java/com/googlecode/dummyjdbc/resultset/DummyResultSetMetaData.java rename to src/main/java/com/mindmercatis/dummyjdbc/resultset/DummyResultSetMetaData.java index 9cd6708..0b1fe24 100644 --- a/src/main/java/com/googlecode/dummyjdbc/resultset/DummyResultSetMetaData.java +++ b/src/main/java/com/mindmercatis/dummyjdbc/resultset/DummyResultSetMetaData.java @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc.resultset; +package com.mindmercatis.dummyjdbc.resultset; import java.sql.ResultSetMetaData; import java.sql.SQLException; diff --git a/src/main/java/com/googlecode/dummyjdbc/resultset/impl/CSVResultSet.java b/src/main/java/com/mindmercatis/dummyjdbc/resultset/impl/CSVResultSet.java similarity index 68% rename from src/main/java/com/googlecode/dummyjdbc/resultset/impl/CSVResultSet.java rename to src/main/java/com/mindmercatis/dummyjdbc/resultset/impl/CSVResultSet.java index cce030c..2b10e86 100644 --- a/src/main/java/com/googlecode/dummyjdbc/resultset/impl/CSVResultSet.java +++ b/src/main/java/com/mindmercatis/dummyjdbc/resultset/impl/CSVResultSet.java @@ -1,9 +1,11 @@ -package com.googlecode.dummyjdbc.resultset.impl; +package com.mindmercatis.dummyjdbc.resultset.impl; import java.math.BigDecimal; import java.sql.Date; import java.sql.ResultSetMetaData; import java.sql.SQLException; +import java.sql.Time; +import java.sql.Timestamp; import java.text.DateFormat; import java.text.MessageFormat; import java.text.ParseException; @@ -12,8 +14,9 @@ import java.util.Iterator; import java.util.LinkedHashMap; -import com.googlecode.dummyjdbc.resultset.DummyResultSet; -import com.googlecode.dummyjdbc.resultset.DummyResultSetMetaData; +import com.mindmercatis.dummyjdbc.DummyJdbcDriver; +import com.mindmercatis.dummyjdbc.resultset.DummyResultSet; +import com.mindmercatis.dummyjdbc.resultset.DummyResultSetMetaData; /** * The {@link CSVResultSet} which iterates over the CSV file data. @@ -22,17 +25,7 @@ */ public class CSVResultSet extends DummyResultSet { - /** - * The date format for parsing a date from a CSV file. - */ - private static final String DATE_FORMAT = "dd-MMM-yy"; - private static final ThreadLocal THREAD_LOCAL_DATEFORMAT = new ThreadLocal() { - @Override - protected DateFormat initialValue() { - return new SimpleDateFormat(DATE_FORMAT); - } - }; /** Table schema */ private DummyResultSetMetaData metaData; @@ -156,9 +149,37 @@ public Date getDate(String columnLabel) throws SQLException { return parseDate(string); } + + @Override + public Time getTime(int columnIndex) throws SQLException { + String string = getValueForColumnIndex(columnIndex, Time.class); + + return parseTime(string); + } + + @Override + public Time getTime(String columnLabel) throws SQLException { + String string = getValueForColumnLabel(columnLabel, Time.class); + + return parseTime(string); + } + + @Override + public Timestamp getTimestamp(int columnIndex) throws SQLException { + String string = getValueForColumnIndex(columnIndex, Date.class); + + return parseTimestamp(string); + } + + @Override + public Timestamp getTimestamp(String columnLabel) throws SQLException { + String string = getValueForColumnLabel(columnLabel, Timestamp.class); + + return parseTimestamp(string); + } private Date parseDate(String string) throws SQLException { - DateFormat sdf = THREAD_LOCAL_DATEFORMAT.get(); + DateFormat sdf = DummyJdbcDriver.THREAD_LOCAL_DATEFORMAT.get(); Date date = null; try { java.util.Date utilDate = sdf.parse(string); @@ -166,7 +187,37 @@ private Date parseDate(String string) throws SQLException { } catch (ParseException e) { String message = MessageFormat.format("Could not parse date: ''{0}'' using format ''{1}''", string, - DATE_FORMAT); + sdf.toString()); + throw new SQLException(message, e); + } + return date; + } + + private Time parseTime(String string) throws SQLException { + DateFormat sdf = DummyJdbcDriver.THREAD_LOCAL_TIMEFORMAT.get(); + Time date = null; + try { + java.util.Date utilDate = sdf.parse(string); + date = new Time(utilDate.getTime()); + + } catch (ParseException e) { + String message = MessageFormat.format("Could not parse date: ''{0}'' using format ''{1}''", string, + sdf.toString()); + throw new SQLException(message, e); + } + return date; + } + + private Timestamp parseTimestamp(String string) throws SQLException { + DateFormat sdf = DummyJdbcDriver.THREAD_LOCAL_TIMESTAMPFORMAT.get(); + Timestamp date = null; + try { + java.util.Date utilDate = sdf.parse(string); + date = new Timestamp(utilDate.getTime()); + + } catch (ParseException e) { + String message = MessageFormat.format("Could not parse date: ''{0}'' using format ''{1}''", string, + sdf.toString()); throw new SQLException(message, e); } return date; diff --git a/src/main/java/com/googlecode/dummyjdbc/statement/PreparedStatementAdapter.java b/src/main/java/com/mindmercatis/dummyjdbc/statement/PreparedStatementAdapter.java similarity index 94% rename from src/main/java/com/googlecode/dummyjdbc/statement/PreparedStatementAdapter.java rename to src/main/java/com/mindmercatis/dummyjdbc/statement/PreparedStatementAdapter.java index 666c13f..a5c5d8a 100644 --- a/src/main/java/com/googlecode/dummyjdbc/statement/PreparedStatementAdapter.java +++ b/src/main/java/com/mindmercatis/dummyjdbc/statement/PreparedStatementAdapter.java @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc.statement; +package com.mindmercatis.dummyjdbc.statement; import java.io.InputStream; import java.io.Reader; @@ -19,6 +19,7 @@ import java.sql.SQLException; import java.sql.SQLWarning; import java.sql.SQLXML; +import java.sql.Statement; import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; diff --git a/src/main/java/com/googlecode/dummyjdbc/statement/StatementAdapter.java b/src/main/java/com/mindmercatis/dummyjdbc/statement/StatementAdapter.java similarity index 93% rename from src/main/java/com/googlecode/dummyjdbc/statement/StatementAdapter.java rename to src/main/java/com/mindmercatis/dummyjdbc/statement/StatementAdapter.java index f82322a..044d211 100644 --- a/src/main/java/com/googlecode/dummyjdbc/statement/StatementAdapter.java +++ b/src/main/java/com/mindmercatis/dummyjdbc/statement/StatementAdapter.java @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc.statement; +package com.mindmercatis.dummyjdbc.statement; import java.sql.Connection; import java.sql.ResultSet; diff --git a/src/main/java/com/mindmercatis/dummyjdbc/statement/impl/CsvPreparedStatement.java b/src/main/java/com/mindmercatis/dummyjdbc/statement/impl/CsvPreparedStatement.java new file mode 100644 index 0000000..b669b5b --- /dev/null +++ b/src/main/java/com/mindmercatis/dummyjdbc/statement/impl/CsvPreparedStatement.java @@ -0,0 +1,263 @@ +package com.mindmercatis.dummyjdbc.statement.impl; + +import java.io.File; +import java.math.BigDecimal; +import java.sql.Date; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.mindmercatis.dummyjdbc.DummyJdbcDriver; +import com.mindmercatis.dummyjdbc.statement.PreparedStatementAdapter; + +/** + * Wraps the {@link CsvStatement} as a prepared statement. + * + * @author Kai Winter + */ +public class CsvPreparedStatement extends PreparedStatementAdapter { + + private static final Pattern INSERT_INTO_PATTERN = Pattern.compile("(?:--[^\\n]*)?\\s*insert\\s*into\\s*([a-zA-Z]*)\\s*\\(.*", Pattern.CASE_INSENSITIVE|Pattern.MULTILINE); + + private static final Pattern UPDATE_TABLE_PATTERN = Pattern.compile("(?:--[^\\\\n]*)?\\s*update\\s*([a-zA-Z]*)\\s*", Pattern.CASE_INSENSITIVE|Pattern.MULTILINE); + + /** + * Suffix used for storing the parameters last seen when running a query + */ + public static final String PARAMS_SUFFIX = "_PARAMS"; + + static final int MAX_PARAMS = 500; + + /** + * Params received during the insert/update operation + */ + Object[] params = new Object[MAX_PARAMS]; + + /** + * Target table for insert/update operations + */ + private String targetTable4Updates = null; + + private final CsvStatement statement; + private final String sql; + + private ResultSet currentResultSet; + + /** + * Constructs a new {@link CsvPreparedStatement}. + * + * @param tableResources {@link Map} of table name to CSV file. + * @param sql + * the SQL statement. + */ + public CsvPreparedStatement(Map tableResources, String sql) { + this.statement = new CsvStatement(tableResources); + this.sql = sql; + } + + + /** + * Always reply that 1 row was affected (most common case) if we can identify the target table name + * otherwise return 0 + */ + @Override + public int executeUpdate(String sql) throws SQLException { + + targetTable4Updates = null; + try { + int res = 1; + String stepRes = DummyJdbcDriver.getInMemoryTableResourceForCurrentStep(); + + if (stepRes!=null) { + targetTable4Updates = DummyJdbcDriver.getStepName(); + try { + return Integer.parseInt(stepRes); + } catch (NumberFormatException nfe) { + // that's ok, it's a simple resultset rather then an update query + return 0; + } + } + + // Try to check for a special heading comment within SQL + Matcher commentMatcher = CsvStatement.COMMENT_HEADLINE_PATTERN.matcher(sql); + if (commentMatcher.matches()) { + targetTable4Updates = commentMatcher.group(1); + return res; + } + + // Try to interpret SQL as a SELECT on a table + Matcher insertMatcher = INSERT_INTO_PATTERN.matcher(sql); + if (insertMatcher.matches()) { + targetTable4Updates = insertMatcher.group(1); + return res; + } + + // Try to interpret SQL as call of a stored procedure + Matcher updateMatcher = UPDATE_TABLE_PATTERN.matcher(sql); + if (updateMatcher.matches()) { + targetTable4Updates = updateMatcher.group(1); + return res; + } + + return 0; + + } finally { + if (targetTable4Updates!=null) + DummyJdbcDriver.addInMemoryTableResource( targetTable4Updates+PARAMS_SUFFIX, buildParamsString() ); + + params = new Object[MAX_PARAMS]; + + + } + + } + + /** + * build a string representing the objects which have been received + * @return + */ + String buildParamsString() { + // 1: build the string (space separated) + StringBuilder s = new StringBuilder(); + for (int i = 1; i < params.length; i++) { // SQL param index starts from 1 !! + if (i>1) + s.append(","); + if (params[i]!=null) { + if (params[i] instanceof java.util.Date) { + if (params[i] instanceof java.sql.Date) { + s.append(DummyJdbcDriver.THREAD_LOCAL_DATEFORMAT.get().format((java.util.Date)params[i])); + } else if (params[i] instanceof java.sql.Time) { + s.append(DummyJdbcDriver.THREAD_LOCAL_TIMEFORMAT.get().format((java.util.Date)params[i])); + } else { + s.append(DummyJdbcDriver.THREAD_LOCAL_TIMESTAMPFORMAT.get().format((java.util.Date)params[i])); + } + } else { + s.append(params[i]); + } + } + } + + // 2: trim and replace tailing commas + String res = s.toString().trim(); + res = res.replaceAll(",*$", ""); + + return res; + } + + @Override + public void setObject(int parameterIndex, Object x) throws SQLException { + params[parameterIndex]=x; + } + + @Override + public void setString(int parameterIndex, String x) throws SQLException { + params[parameterIndex]=x; + } + + @Override + public void setInt(int parameterIndex, int x) throws SQLException { + params[parameterIndex]=x; + } + + @Override + public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { + params[parameterIndex]=x; + } + + @Override + public void setDouble(int parameterIndex, double x) throws SQLException { + params[parameterIndex]=x; + } + + @Override + public void setTime(int parameterIndex, Time x) throws SQLException { + params[parameterIndex]=x; + } + + @Override + public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { + params[parameterIndex]=x; + } + + @Override + public void setDate(int parameterIndex, Date x) throws SQLException { + params[parameterIndex]=x; + } + + @Override + public int executeUpdate() throws SQLException { + return executeUpdate(sql); + } + + @Override + public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { + return executeUpdate(sql); + } + + @Override + public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { + return executeUpdate(sql); + } + + @Override + public int executeUpdate(String sql, String[] columnNames) throws SQLException { + return executeUpdate(sql); + } + + + @Override + public ResultSet executeQuery() throws SQLException { + execute(sql); + return currentResultSet; + } + + @Override + public ResultSet executeQuery(String sql) throws SQLException { + execute(sql); + return currentResultSet; + } + + @Override + public boolean execute() throws SQLException { + return execute(sql); + } + + @Override + public boolean execute(String sql) throws SQLException { + try { + statement.paramsString = buildParamsString(); + currentResultSet = statement.executeQuery(sql); + // try up update (generate params) + executeUpdate(sql); + return true; + } finally { + statement.paramsString = null; + } + } + + @Override + public boolean execute(String sql, int[] columnIndexes) throws SQLException { + return execute(sql); + } + + @Override + public boolean execute(String sql, String[] columnNames) throws SQLException { + return execute(sql); + } + + @Override + public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { + return execute(sql); + } + + @Override + public ResultSet getResultSet() throws SQLException { + return currentResultSet; + } + + +} diff --git a/src/main/java/com/googlecode/dummyjdbc/statement/impl/CsvStatement.java b/src/main/java/com/mindmercatis/dummyjdbc/statement/impl/CsvStatement.java similarity index 57% rename from src/main/java/com/googlecode/dummyjdbc/statement/impl/CsvStatement.java rename to src/main/java/com/mindmercatis/dummyjdbc/statement/impl/CsvStatement.java index 10beef7..2a0f1d4 100644 --- a/src/main/java/com/googlecode/dummyjdbc/statement/impl/CsvStatement.java +++ b/src/main/java/com/mindmercatis/dummyjdbc/statement/impl/CsvStatement.java @@ -1,11 +1,13 @@ -package com.googlecode.dummyjdbc.statement.impl; +package com.mindmercatis.dummyjdbc.statement.impl; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; import java.net.URL; import java.security.CodeSource; @@ -22,12 +24,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import au.com.bytecode.opencsv.CSVReader; +import com.mindmercatis.dummyjdbc.DummyJdbcDriver; +import com.mindmercatis.dummyjdbc.resultset.DummyResultSet; +import com.mindmercatis.dummyjdbc.resultset.DummyResultSetMetaData; +import com.mindmercatis.dummyjdbc.resultset.impl.CSVResultSet; +import com.mindmercatis.dummyjdbc.statement.StatementAdapter; -import com.googlecode.dummyjdbc.resultset.DummyResultSet; -import com.googlecode.dummyjdbc.resultset.impl.CSVResultSet; -import com.googlecode.dummyjdbc.statement.StatementAdapter; -import com.googlecode.dummyjdbc.resultset.DummyResultSetMetaData; +import au.com.bytecode.opencsv.CSVReader; /** * This class does the actual work of the Generic... classes. It tries to open a CSV file for the table name in the @@ -39,17 +42,36 @@ public final class CsvStatement extends StatementAdapter { private static final Logger LOGGER = LoggerFactory.getLogger(CsvStatement.class); + /** + * Pattern used to recognize explicitly declared table names inside an heading comment + */ + static final Pattern COMMENT_HEADLINE_PATTERN = Pattern.compile("\\s*--\\s*TESTCASE:\\s*(.*)\\n.*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); + /** Pattern to get table name from an SQL statement. */ - private static final Pattern TABLENAME_PATTERN = Pattern.compile(".*from (\\S*)\\s?.*", Pattern.CASE_INSENSITIVE); + private static final Pattern TABLENAME_PATTERN = Pattern.compile(".*from\\s*(\\S*)\\s?.*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL ); /** Pattern to get the name of a stored procedure from an SQL statement. */ - private static final Pattern STORED_PROCEDURE_PATTERN = Pattern.compile(".*(EXEC|EXECUTE) (\\S*)\\s?.*", - Pattern.CASE_INSENSITIVE); + private static final Pattern STORED_PROCEDURE_PATTERN = Pattern.compile(".*(EXEC|EXECUTE) (\\S*)\\s?.*", Pattern.CASE_INSENSITIVE); private static final Pattern PURE_SELECT_PATTERN = Pattern.compile("select .*", Pattern.CASE_INSENSITIVE); private final Map tableResources; + /** + * used to describe the "current" params. + * Always null when invoked from {@link CsvStatement} and may hold values when used from {@link CsvPreparedStatement} + */ + String paramsString = null; + + + /** + * Initializer + * + */ + { + DummyJdbcDriver.nextStep(); + } + /** * Constructs a new {@link CsvStatement}. * @@ -59,37 +81,84 @@ public final class CsvStatement extends StatementAdapter { public CsvStatement(Map tableResources) { this.tableResources = tableResources; } - + @Override public ResultSet executeQuery(String sql) throws SQLException { - // Try to interpret SQL as a SELECT on a table - Matcher tableMatcher = TABLENAME_PATTERN.matcher(sql); - if (tableMatcher.matches()) { - String tableName = tableMatcher.group(1); - return createResultSet(tableName); - } + try { + String stepRes = DummyJdbcDriver.getInMemoryTableResourceForCurrentStep(); + + // match based on the current step (sequence number) + if (stepRes!=null) { + String tableName = DummyJdbcDriver.getStepName(); + return createResultSet(tableName); + } + + // Try to check for a special heading comment within SQL + Matcher commentMatcher = COMMENT_HEADLINE_PATTERN.matcher(sql); + if (commentMatcher.matches()) { + String tableName = commentMatcher.group(1); + return createResultSet(tableName); + } + + // Try to interpret SQL as a SELECT on a table + Matcher tableMatcher = TABLENAME_PATTERN.matcher(sql); + if (tableMatcher.matches()) { + String tableName = tableMatcher.group(1); + return createResultSet(tableName); + } - // Try to interpret SQL as call of a stored procedure - Matcher storedProcedureMatcher = STORED_PROCEDURE_PATTERN.matcher(sql); - if (storedProcedureMatcher.matches()) { - String storedProcedureName = storedProcedureMatcher.group(2); - return createResultSet(storedProcedureName); - } + // Try to interpret SQL as call of a stored procedure + Matcher storedProcedureMatcher = STORED_PROCEDURE_PATTERN.matcher(sql); + if (storedProcedureMatcher.matches()) { + String storedProcedureName = storedProcedureMatcher.group(2); + return createResultSet(storedProcedureName); + } - // Try to interpret SQL as a pure select - Matcher pureSelectMatcher = PURE_SELECT_PATTERN.matcher(sql); - if (pureSelectMatcher.matches()) { - return createPureResultSet(); - } + // Try to interpret SQL as a pure select + Matcher pureSelectMatcher = PURE_SELECT_PATTERN.matcher(sql); + if (pureSelectMatcher.matches()) { + return createPureResultSet(); + } - return new DummyResultSet(); + return new DummyResultSet(); + + } finally { + // DummyJdbcDriver.nextStep(); + } + } + + static String matchTablename(String sql) { + Matcher tableMatcher = TABLENAME_PATTERN.matcher(sql); + if (tableMatcher.matches()) { + return tableMatcher.group(1); + } else { + return null; + } } private ResultSet createResultSet(String tableName) { + InputStream inMemoryDataStream = null; + String inMemoryCSV = null; + + // search for "tablename?param1,param2" etc... + if (paramsString!=null) { + inMemoryCSV = DummyJdbcDriver.getInMemoryTableResource(tableName+"?"+paramsString); + } // then search just for "tablename" + if (inMemoryCSV==null) { + inMemoryCSV = DummyJdbcDriver.getInMemoryTableResource(tableName); + } // if any in memory CSV is found convert to InputStream + if (inMemoryCSV!=null) { + try { + inMemoryDataStream = new ByteArrayInputStream(inMemoryCSV.getBytes("ISO-8859-1")); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + // Does a text file for the dummy table exist? File resource = tableResources.get(tableName.toLowerCase()); - if (resource == null) { + if (resource == null && inMemoryDataStream == null) { // Try to load a file from the ./tables/ directory CodeSource src = CsvStatement.class.getProtectionDomain().getCodeSource(); @@ -108,9 +177,13 @@ private ResultSet createResultSet(String tableName) { } } - FileInputStream dummyTableDataStream = null; + InputStream dummyTableDataStream = null; try { - dummyTableDataStream = new FileInputStream(resource); + if (resource==null) { + dummyTableDataStream = inMemoryDataStream; // might be null => no inMemoryCSV + } else { + dummyTableDataStream = new FileInputStream(resource); + } return createGenericResultSet(tableName, dummyTableDataStream); } catch (FileNotFoundException e) { LOGGER.info("No table definition found for '{}', using DummyResultSet.", tableName); @@ -196,4 +269,6 @@ private DummyResultSet createPureResultSet() { private String resolveHeaderName(String str) { return str.trim().toUpperCase(); } + + } diff --git a/src/main/java/com/mindmercatis/dummyjdbc/statement/impl/InMemoryCSV.java b/src/main/java/com/mindmercatis/dummyjdbc/statement/impl/InMemoryCSV.java new file mode 100644 index 0000000..21f6d4a --- /dev/null +++ b/src/main/java/com/mindmercatis/dummyjdbc/statement/impl/InMemoryCSV.java @@ -0,0 +1,10 @@ +package com.mindmercatis.dummyjdbc.statement.impl; + +/** + * Removed + * + * @author Simone + * + */ +public class InMemoryCSV { +} diff --git a/src/main/java/com/googlecode/dummyjdbc/utils/FilenameUtils.java b/src/main/java/com/mindmercatis/dummyjdbc/utils/FilenameUtils.java similarity index 99% rename from src/main/java/com/googlecode/dummyjdbc/utils/FilenameUtils.java rename to src/main/java/com/mindmercatis/dummyjdbc/utils/FilenameUtils.java index e394d44..fd0bf0c 100644 --- a/src/main/java/com/googlecode/dummyjdbc/utils/FilenameUtils.java +++ b/src/main/java/com/mindmercatis/dummyjdbc/utils/FilenameUtils.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package com.googlecode.dummyjdbc.utils; +package com.mindmercatis.dummyjdbc.utils; import java.io.File; import java.io.IOException; diff --git a/src/main/java/com/googlecode/dummyjdbc/utils/StringUtils.java b/src/main/java/com/mindmercatis/dummyjdbc/utils/StringUtils.java similarity index 92% rename from src/main/java/com/googlecode/dummyjdbc/utils/StringUtils.java rename to src/main/java/com/mindmercatis/dummyjdbc/utils/StringUtils.java index d637adb..20cce5d 100644 --- a/src/main/java/com/googlecode/dummyjdbc/utils/StringUtils.java +++ b/src/main/java/com/mindmercatis/dummyjdbc/utils/StringUtils.java @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc.utils; +package com.mindmercatis.dummyjdbc.utils; /** * String Utils Class diff --git a/src/test/java/com/googlecode/dummyjdbc/statement/impl/CsvPreparedStatementTest.java b/src/test/java/com/googlecode/dummyjdbc/statement/impl/CsvPreparedStatementTest.java deleted file mode 100644 index e937762..0000000 --- a/src/test/java/com/googlecode/dummyjdbc/statement/impl/CsvPreparedStatementTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.googlecode.dummyjdbc.statement.impl; - -import java.io.File; -import java.net.URISyntaxException; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import com.googlecode.dummyjdbc.DummyJdbcDriver; - -public final class CsvPreparedStatementTest { - - private ResultSet resultSet; - - @Before - public void setup() throws ClassNotFoundException, SQLException, URISyntaxException { - Class.forName(DummyJdbcDriver.class.getCanonicalName()); - - DummyJdbcDriver.addTableResource("test_table", new File(CsvGenericStatementTest.class.getResource( - "test_table.csv").toURI())); - Connection connection = DriverManager.getConnection("any"); - PreparedStatement statement = connection.prepareStatement("SELECT * FROM test_table"); - - Assert.assertTrue(statement instanceof CsvPreparedStatement); - resultSet = statement.executeQuery(); - } - - @Test - public void testGetByColumnName() throws SQLException { - - Assert.assertTrue(resultSet.next()); - - Assert.assertEquals(1, resultSet.getInt("id")); - Assert.assertEquals("Germany", resultSet.getString("country_name")); - Assert.assertEquals("DE", resultSet.getString("country_iso")); - } - - @Test - public void testGetByColumnIndex() throws SQLException { - - Assert.assertTrue(resultSet.next()); - - Assert.assertEquals(1, resultSet.getInt(1)); - Assert.assertEquals("Germany", resultSet.getString(2)); - Assert.assertEquals("DE", resultSet.getString(3)); - } - - @Test(expected = SQLException.class) - public void testGetInvalidColumnName() throws SQLException { - - Assert.assertTrue(resultSet.next()); - - resultSet.getInt("undefined"); - - Assert.fail("Expected exception not thrown"); - } - - @Test(expected = SQLException.class) - public void testGetInvalidColumnindex() throws SQLException { - - Assert.assertTrue(resultSet.next()); - resultSet.getInt(17); - - Assert.fail("Expected exception not thrown"); - } -} diff --git a/src/test/java/com/googlecode/dummyjdbc/DummyJdbcDriverTest.java b/src/test/java/com/mindmercatis/dummyjdbc/DummyJdbcDriverTest.java similarity index 83% rename from src/test/java/com/googlecode/dummyjdbc/DummyJdbcDriverTest.java rename to src/test/java/com/mindmercatis/dummyjdbc/DummyJdbcDriverTest.java index 43b8842..5f8f1eb 100644 --- a/src/test/java/com/googlecode/dummyjdbc/DummyJdbcDriverTest.java +++ b/src/test/java/com/mindmercatis/dummyjdbc/DummyJdbcDriverTest.java @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc; +package com.mindmercatis.dummyjdbc; import java.sql.Connection; import java.sql.DriverManager; @@ -7,7 +7,8 @@ import org.junit.Assert; import org.junit.Test; -import com.googlecode.dummyjdbc.connection.impl.DummyConnection; +import com.mindmercatis.dummyjdbc.DummyJdbcDriver; +import com.mindmercatis.dummyjdbc.connection.impl.DummyConnection; public final class DummyJdbcDriverTest { diff --git a/src/test/java/com/googlecode/dummyjdbc/statement/impl/CsvGenericStatementTest.java b/src/test/java/com/mindmercatis/dummyjdbc/statement/impl/CsvGenericStatementTest.java similarity index 51% rename from src/test/java/com/googlecode/dummyjdbc/statement/impl/CsvGenericStatementTest.java rename to src/test/java/com/mindmercatis/dummyjdbc/statement/impl/CsvGenericStatementTest.java index 8954110..c8e8807 100644 --- a/src/test/java/com/googlecode/dummyjdbc/statement/impl/CsvGenericStatementTest.java +++ b/src/test/java/com/mindmercatis/dummyjdbc/statement/impl/CsvGenericStatementTest.java @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc.statement.impl; +package com.mindmercatis.dummyjdbc.statement.impl; import java.io.File; import java.net.URISyntaxException; @@ -12,7 +12,7 @@ import org.junit.Before; import org.junit.Test; -import com.googlecode.dummyjdbc.DummyJdbcDriver; +import com.mindmercatis.dummyjdbc.DummyJdbcDriver; public final class CsvGenericStatementTest { @@ -22,6 +22,7 @@ public final class CsvGenericStatementTest { public void setup() throws ClassNotFoundException, SQLException, URISyntaxException { Class.forName(DummyJdbcDriver.class.getCanonicalName()); + DummyJdbcDriver.reset(); DummyJdbcDriver.addTableResource("test_table", new File(CsvGenericStatementTest.class.getResource("test_table.csv").toURI())); Connection connection = DriverManager.getConnection("any"); @@ -30,7 +31,59 @@ public void setup() throws ClassNotFoundException, SQLException, URISyntaxExcept Assert.assertTrue(statement instanceof CsvStatement); resultSet = statement.executeQuery("SELECT * FROM test_table"); } + + /** + * Within this text we expect the results to be read from memory based on the number of the execution step, + * ignoring the table name and comments + * + * @throws SQLException + * @throws URISyntaxException + */ + @Test + public void testQueryByStep() throws SQLException, URISyntaxException { + + DummyJdbcDriver.reset(); + DummyJdbcDriver.addInMemoryTableResource(0, + "\n" + + "name, age\n"+ + "John, 20"+ + "\n" + ); + DummyJdbcDriver.addInMemoryTableResource(1, + "\n" + + "where, who\n"+ + "London, Sherlock"+ + "\n" + ); + + Connection connection = DriverManager.getConnection("any"); + Statement statement = connection.createStatement(); + + Assert.assertTrue(statement instanceof CsvStatement); + resultSet = statement.executeQuery( + "-- TESTCASE:test1\n" + + "SELECT *\n" + + "FROM test_table"); + + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("John", resultSet.getString("name")); + Assert.assertEquals(20, resultSet.getInt("age")); + + // test 2nd step + statement = connection.createStatement(); + Assert.assertTrue(statement instanceof CsvStatement); + resultSet = statement.executeQuery( + "-- TESTCASE:test2\n" + + "SELECT *\n" + + "FROM test_table"); + + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("London", resultSet.getString("where")); + Assert.assertEquals("Sherlock", resultSet.getString("who")); + } + + @Test public void testGetByColumnName() throws SQLException { @@ -69,4 +122,17 @@ public void testGetInvalidColumnindex() throws SQLException { Assert.fail("Expected exception not thrown"); } + + + @Test + public void testMatchTablename() { + String query = "SELECT *\n" + + "FROM TEST1\n" + + "WHERE age= ? AND other = ?"; + Assert.assertEquals( + "TEST1", + CsvStatement.matchTablename(query) + ); + } + } diff --git a/src/test/java/com/mindmercatis/dummyjdbc/statement/impl/CsvPreparedStatementTest.java b/src/test/java/com/mindmercatis/dummyjdbc/statement/impl/CsvPreparedStatementTest.java new file mode 100644 index 0000000..a334e38 --- /dev/null +++ b/src/test/java/com/mindmercatis/dummyjdbc/statement/impl/CsvPreparedStatementTest.java @@ -0,0 +1,273 @@ +package com.mindmercatis.dummyjdbc.statement.impl; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.TimeZone; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.mindmercatis.dummyjdbc.DummyJdbcDriver; + +public final class CsvPreparedStatementTest { + + private ResultSet resultSet; + CsvPreparedStatement csvStatement; + + @Before + public void setup() throws ClassNotFoundException, SQLException, URISyntaxException { + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + + Class.forName(DummyJdbcDriver.class.getCanonicalName()); + + DummyJdbcDriver.addTableResource("test_table", new File(CsvGenericStatementTest.class.getResource( + "test_table.csv").toURI())); + Connection connection = DriverManager.getConnection("any"); + PreparedStatement statement = connection.prepareStatement("SELECT * FROM test_table"); + + Assert.assertTrue(statement instanceof CsvPreparedStatement); + csvStatement = (CsvPreparedStatement)statement; + resultSet = statement.executeQuery(); + } + + @Test + public void testGetByColumnName() throws SQLException { + + Assert.assertTrue(resultSet.next()); + + Assert.assertEquals(1, resultSet.getInt("id")); + Assert.assertEquals("Germany", resultSet.getString("country_name")); + Assert.assertEquals("DE", resultSet.getString("country_iso")); + } + + @Test + public void testBuildParamsString() { + csvStatement.params[1]=new java.sql.Timestamp(1570623440352L); // 2019-10-09,14:17:20.352 GMT+2 + csvStatement.params[2]=new Integer(920); + csvStatement.params[3]="hello"; + + String res = csvStatement.buildParamsString(); + // System.out.println("RES: "+res); + Assert.assertEquals("20191009 121720.352,920,hello", res); + } + + @Test + public void testGetByColumnIndex() throws SQLException { + + Assert.assertTrue(resultSet.next()); + + Assert.assertEquals(1, resultSet.getInt(1)); + Assert.assertEquals("Germany", resultSet.getString(2)); + Assert.assertEquals("DE", resultSet.getString(3)); + } + + @Test(expected = SQLException.class) + public void testGetInvalidColumnName() throws SQLException { + + Assert.assertTrue(resultSet.next()); + + resultSet.getInt("undefined"); + + Assert.fail("Expected exception not thrown"); + } + + @Test(expected = SQLException.class) + public void testGetInvalidColumnindex() throws SQLException { + + Assert.assertTrue(resultSet.next()); + resultSet.getInt(17); + + Assert.fail("Expected exception not thrown"); + } + + @Test + public void testInMemoryCSVFromString() throws ClassNotFoundException, URISyntaxException, SQLException { + Class.forName(DummyJdbcDriver.class.getCanonicalName()); + + DummyJdbcDriver.addInMemoryTableResource("TEST1", + "\n"+ + "name, age\n"+ + "John, 20"+ + "\n" + ); + + Connection connection = DriverManager.getConnection("any"); + PreparedStatement statement = connection.prepareStatement( + "-- TESTCASE:test1\n"+ + "SELECT * FROM test_table"); + + Assert.assertTrue(statement instanceof CsvPreparedStatement); + resultSet = statement.executeQuery(); + + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("John", resultSet.getString(1)); + Assert.assertEquals(20, resultSet.getInt(2)); + Assert.assertEquals("John", resultSet.getString("name")); + Assert.assertEquals(20, resultSet.getInt("age")); + } + + + @Test + public void testInMemoryCSVFromInputStream() throws ClassNotFoundException, URISyntaxException, SQLException, UnsupportedEncodingException { + Class.forName(DummyJdbcDriver.class.getCanonicalName()); + + DummyJdbcDriver.addInMemoryTableResource("TEST1", + new ByteArrayInputStream( + ("name, age\n"+ + "John, 20").getBytes("ISO-8859-1") + ) + ); + + Connection connection = DriverManager.getConnection("any"); + PreparedStatement statement = connection.prepareStatement( + "-- TESTCASE:test1\n"+ + "SELECT * FROM test_table"); + + Assert.assertTrue(statement instanceof CsvPreparedStatement); + resultSet = statement.executeQuery(); + + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("John", resultSet.getString(1)); + Assert.assertEquals(20, resultSet.getInt(2)); + Assert.assertEquals("John", resultSet.getString("name")); + Assert.assertEquals(20, resultSet.getInt("age")); + } + + @Test + public void testInsertWithInMemoryCSVFromInputStream() throws ClassNotFoundException, URISyntaxException, SQLException, UnsupportedEncodingException { + Class.forName(DummyJdbcDriver.class.getCanonicalName()); + + DummyJdbcDriver.addInMemoryTableResource("TEST1", + new ByteArrayInputStream( + ("name, age\n"+ + "John, 20").getBytes("ISO-8859-1") + ) + ); + + Connection connection = DriverManager.getConnection("any"); + PreparedStatement statement = connection.prepareStatement( + "INSERT INTO Target(nome,cognome)" + + "VALUES (?, ?)"); + + Assert.assertTrue(statement instanceof CsvPreparedStatement); + int rows = statement.executeUpdate(); + } + + @Test + public void testInsertWithInMemoryCSVFromInputStreamWithParameters() throws ClassNotFoundException, URISyntaxException, SQLException, UnsupportedEncodingException { + Class.forName(DummyJdbcDriver.class.getCanonicalName()); + + DummyJdbcDriver.addInMemoryTableResource("TEST1?20,hello", + new ByteArrayInputStream( + ("name, age\n"+ + "John, 20").getBytes("ISO-8859-1") + ) + ); + + Connection connection = DriverManager.getConnection("any"); + PreparedStatement statement = connection.prepareStatement( + "SELECT *\n" + + "FROM TEST1\n" + + "WHERE age= ? AND other = ?"); + + statement.setInt(1, 20); + statement.setString(2, "hello"); + + resultSet = statement.executeQuery(); + + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("John", resultSet.getString(1)); + Assert.assertEquals(20, resultSet.getInt(2)); + Assert.assertEquals("John", resultSet.getString("name")); + Assert.assertEquals(20, resultSet.getInt("age")); + } + + @Test + public void insertSQL() throws Exception { + Class.forName(DummyJdbcDriver.class.getCanonicalName()); + + Connection connection = DriverManager.getConnection("any"); + PreparedStatement statement = connection.prepareStatement("INSERT INTO users (name,age) VALUES (?,?) "); + + // 1: 0 params + Assert.assertTrue(statement instanceof CsvPreparedStatement); + boolean status = statement.execute(); + String params = DummyJdbcDriver.getInMemoryTableResource("users_PARAMS"); + Assert.assertEquals("", params); + + // 2: 2 params + statement.setString(1, "hello"); + statement.setInt(2, 30); + status = statement.execute(); + params = DummyJdbcDriver.getInMemoryTableResource("users_PARAMS"); + Assert.assertEquals("hello,30", params); + + // 3: test params reset + status = statement.execute(); + params = DummyJdbcDriver.getInMemoryTableResource("users_PARAMS"); + Assert.assertEquals("", params); + + } + + /** + * Within this text we expect the results to be read from memory based on the number of the execution step, + * ignoring the table name and comments + * + * @throws SQLException + * @throws URISyntaxException + */ + @Test + public void testQueryByStep() throws SQLException, URISyntaxException { + + DummyJdbcDriver.reset(); + DummyJdbcDriver.addInMemoryTableResource(0, + "\n" + + "name, age\n"+ + "John, 20"+ + "\n" + ); + DummyJdbcDriver.addInMemoryTableResource(1, + "\n" + + "where, who\n"+ + "London, Sherlock"+ + "\n" + ); + + Connection connection = DriverManager.getConnection("any"); + Statement statement = connection.prepareStatement("ignore me"); + + Assert.assertTrue(statement instanceof CsvPreparedStatement); + resultSet = statement.executeQuery( + "-- TESTCASE:test1\n" + + "SELECT *\n" + + "FROM test_table"); + + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("John", resultSet.getString("name")); + Assert.assertEquals(20, resultSet.getInt("age")); + + // test 2nd step + statement = connection.prepareStatement("ignore me"); + + Assert.assertTrue(statement instanceof CsvPreparedStatement); + resultSet = statement.executeQuery( + "-- TESTCASE:test2\n" + + "SELECT *\n" + + "FROM test_table"); + + Assert.assertTrue(resultSet.next()); + Assert.assertEquals("London", resultSet.getString("where")); + Assert.assertEquals("Sherlock", resultSet.getString("who")); + } + + +} diff --git a/src/test/java/com/googlecode/dummyjdbc/statement/impl/CsvStatementTest.java b/src/test/java/com/mindmercatis/dummyjdbc/statement/impl/CsvStatementTest.java similarity index 87% rename from src/test/java/com/googlecode/dummyjdbc/statement/impl/CsvStatementTest.java rename to src/test/java/com/mindmercatis/dummyjdbc/statement/impl/CsvStatementTest.java index 44d9501..28d7bc9 100644 --- a/src/test/java/com/googlecode/dummyjdbc/statement/impl/CsvStatementTest.java +++ b/src/test/java/com/mindmercatis/dummyjdbc/statement/impl/CsvStatementTest.java @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc.statement.impl; +package com.mindmercatis.dummyjdbc.statement.impl; import java.sql.Connection; import java.sql.DriverManager; @@ -8,7 +8,8 @@ import org.junit.Assert; import org.junit.Test; -import com.googlecode.dummyjdbc.DummyJdbcDriver; +import com.mindmercatis.dummyjdbc.DummyJdbcDriver; +import com.mindmercatis.dummyjdbc.statement.impl.CsvStatement; public final class CsvStatementTest { @@ -40,4 +41,6 @@ public void validSql() throws Exception { ResultSet resultSet = statement.executeQuery("SELECT 1"); boolean next = resultSet.next(); } + + } diff --git a/src/test/java/com/googlecode/dummyjdbc/statement/impl/DatatypesTest.java b/src/test/java/com/mindmercatis/dummyjdbc/statement/impl/DatatypesTest.java similarity index 96% rename from src/test/java/com/googlecode/dummyjdbc/statement/impl/DatatypesTest.java rename to src/test/java/com/mindmercatis/dummyjdbc/statement/impl/DatatypesTest.java index a7940d5..b1f7fbe 100644 --- a/src/test/java/com/googlecode/dummyjdbc/statement/impl/DatatypesTest.java +++ b/src/test/java/com/mindmercatis/dummyjdbc/statement/impl/DatatypesTest.java @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc.statement.impl; +package com.mindmercatis.dummyjdbc.statement.impl; import java.io.File; import java.math.BigDecimal; @@ -16,7 +16,7 @@ import org.junit.Before; import org.junit.Test; -import com.googlecode.dummyjdbc.DummyJdbcDriver; +import com.mindmercatis.dummyjdbc.DummyJdbcDriver; public final class DatatypesTest { diff --git a/src/test/java/com/googlecode/dummyjdbc/statement/impl/ResultSetMetaDataTest.java b/src/test/java/com/mindmercatis/dummyjdbc/statement/impl/ResultSetMetaDataTest.java similarity index 94% rename from src/test/java/com/googlecode/dummyjdbc/statement/impl/ResultSetMetaDataTest.java rename to src/test/java/com/mindmercatis/dummyjdbc/statement/impl/ResultSetMetaDataTest.java index 30b22f3..d58096f 100644 --- a/src/test/java/com/googlecode/dummyjdbc/statement/impl/ResultSetMetaDataTest.java +++ b/src/test/java/com/mindmercatis/dummyjdbc/statement/impl/ResultSetMetaDataTest.java @@ -1,4 +1,4 @@ -package com.googlecode.dummyjdbc.statement.impl; +package com.mindmercatis.dummyjdbc.statement.impl; import java.io.File; import java.net.URISyntaxException; @@ -13,7 +13,7 @@ import org.junit.Before; import org.junit.Test; -import com.googlecode.dummyjdbc.DummyJdbcDriver; +import com.mindmercatis.dummyjdbc.DummyJdbcDriver; public class ResultSetMetaDataTest { diff --git a/src/test/resources/com/googlecode/dummyjdbc/statement/impl/datatypes.csv b/src/test/resources/com/mindmercatis/dummyjdbc/statement/impl/datatypes.csv similarity index 100% rename from src/test/resources/com/googlecode/dummyjdbc/statement/impl/datatypes.csv rename to src/test/resources/com/mindmercatis/dummyjdbc/statement/impl/datatypes.csv diff --git a/src/test/resources/com/googlecode/dummyjdbc/statement/impl/metadata.csv b/src/test/resources/com/mindmercatis/dummyjdbc/statement/impl/metadata.csv similarity index 100% rename from src/test/resources/com/googlecode/dummyjdbc/statement/impl/metadata.csv rename to src/test/resources/com/mindmercatis/dummyjdbc/statement/impl/metadata.csv diff --git a/src/test/resources/com/googlecode/dummyjdbc/statement/impl/test_table.csv b/src/test/resources/com/mindmercatis/dummyjdbc/statement/impl/test_table.csv similarity index 100% rename from src/test/resources/com/googlecode/dummyjdbc/statement/impl/test_table.csv rename to src/test/resources/com/mindmercatis/dummyjdbc/statement/impl/test_table.csv diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml index e5315fb..fb2d2a7 100644 --- a/src/test/resources/logback-test.xml +++ b/src/test/resources/logback-test.xml @@ -5,7 +5,7 @@ - +