Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9d9a28c
Update README.md
SimoneAvogadro Mar 31, 2018
4d1c520
Initial supporto for Dell Boomi
Mar 31, 2018
1e58c4d
Initial support for Dell Boomi testing
Mar 31, 2018
469dfce
Update README.md
SimoneAvogadro Mar 31, 2018
33acd39
support for table names plus parameters
Apr 6, 2018
3051ff9
minor updates
Apr 12, 2018
bf261ad
Update README.md
SimoneAvogadro Apr 12, 2018
6e80d92
Update README.md
SimoneAvogadro Apr 12, 2018
770fdb2
Document the new recource-matching rules
SimoneAvogadro Apr 12, 2018
6b7af91
Docmented the specialization for queryes with parameters
SimoneAvogadro Apr 12, 2018
a21e46f
Update README.md
SimoneAvogadro Apr 12, 2018
9bc9753
Documentation for new 1.4.0 features
SimoneAvogadro Apr 12, 2018
e944ada
Update README.md
SimoneAvogadro Apr 12, 2018
109945f
updated documentation and tests
Apr 12, 2018
cd74df3
Merge branch 'master' of https://github.com/SimoneAvogadro/dummyjdbc.git
Apr 12, 2018
da0d70e
Update README.md
SimoneAvogadro Apr 24, 2018
b73ab1d
Update README.md
SimoneAvogadro Sep 26, 2019
e602b47
Update to use CircleCI
SimoneAvogadro Oct 8, 2019
b740ace
Create config.yml
SimoneAvogadro Oct 8, 2019
35044c2
Update config.yml
SimoneAvogadro Oct 8, 2019
f869d91
Update config.yml
SimoneAvogadro Oct 8, 2019
5759e6e
Update README.md
SimoneAvogadro Oct 8, 2019
85ffd14
Improved Statement parameters logging
Oct 9, 2019
da5f885
fixed regression
Oct 9, 2019
d65f976
fixed timezone-dependent CircleCI regression
Oct 9, 2019
d125e6c
v1.5.0
Oct 28, 2019
b5006d6
typo in readme
Oct 28, 2019
cc97bd5
- FIX: wrong sequence counter on some scenarios
Nov 5, 2019
8074b64
- fixes to the step logic
Nov 6, 2019
1d564d8
- fix to steps
Nov 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
----------------------------

Expand Down
149 changes: 144 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,160 @@
# 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.

The library can either return dummy values, or values defined by you in a CSV file. The files are determined by the SQL query which makes this a very flexible tool. Also results of Stored Procedures can be mocked with data from CSV files.

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
<dependency>
<groupId>com.googlecode.dummyjdbc</groupId>
<groupId>com.mindmercastis.dummyjdbc</groupId>
<artifactId>dummyjdbc</artifactId>
<version>1.3.0</version>
<version>1.5.0</version>
</dependency>
```

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)
![Design](https://raw.githubusercontent.com/wiki/kaiwinter/dummyjdbc/images/dummyjdbc-design.png)
20 changes: 12 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.dummyjdbc</groupId>
<groupId>com.mindmercatis.dummyjdbc</groupId>
<artifactId>dummyjdbc</artifactId>
<version>1.3.1-SNAPSHOT</version>
<version>1.5.1</version>
<packaging>jar</packaging>

<name>DummyJDBC</name>
<description>
DummyJDBC is a mock JDBC driver which can return data from CSV files
</description>
<url>https://github.com/kaiwinter/dummyjdbc</url>
<url>https://github.com/SimoneAvogadro/dummyjdbc</url>
<licenses>
<license>
<name>Apache 2</name>
Expand All @@ -19,21 +19,25 @@
</licenses>

<scm>
<url>https://github.com/kaiwinter/dummyjdbc</url>
<connection>scm:git:https://github.com/kaiwinter/dummyjdbc.git</connection>
<developerConnection>scm:git:git@github.com:kaiwinter/dummyjdbc.git</developerConnection>
<url>https://github.com/SimoneAvogadro/dummyjdbc</url>
<connection>scm:git:https://github.com/SimoneAvogadro/dummyjdbc.git</connection>
<developerConnection>scm:git:git@github.com:SimoneAvogadro/dummyjdbc.git</developerConnection>
</scm>

<developers>
<developer>
<id>kai</id>
<name>Kai Winter</name>
</developer>
<developer>
<id>simone</id>
<name>Simone Avogadro</name>
</developer>
</developers>

<issueManagement>
<system>GitHub Issues</system>
<url>https://github.com/kaiwinter/dummyjdbc/issues</url>
<url>https://github.com/SimoneAvogadro/dummyjdbc/issues</url>
</issueManagement>

<properties>
Expand Down Expand Up @@ -171,4 +175,4 @@
</profile>

</profiles>
</project>
</project>
Loading