Comments (7)
Currently CompositeHandler ( used in code sample) is designed to have 1 query handler (and 1 update handler).
QueryHandler is supposed to return appropriate result according given execution context (which statement, which parameters, ...).
So if you want to handle various SELECT, within this single QueryHandler you can do it checking which is the one currently executed.
from acolyte.
In Java code samples, you can see at https://github.com/cchantep/acolyte/blob/master/core/src/test/java/usecase/JavaUseCases.java#L60 a QueryHandler returning a rowList1 for a SELECT, but a rowList3 for an EXEC.
Scala samples include similar case, with the ease given by pattern matching.
from acolyte.
As persistence rarely expect statement in a particular order I don't think simulating it for test with such sequential handler/constraint would help.
If checking execution context in handler is not sufficient, let think about other way.
from acolyte.
Thanks cchantep, It works, I now filter on sql statement and parameters to send different results.
Sorry if I ask obvious question but I really need these test before I change the code...
Another question, when I try to fake result in another test. I do
StatementHandler queryUserRecord = createQueryHandler("1", "Mike");
acolyte.Driver.register(USERS, queryUserRecord);
But, I saw that acolyte driver is reusing the connection and reuse the first test StatementHandler.
Maybe I could close the connection on test tearDown but not sure how to access the acolyte connection.
Any suggestion?
from acolyte.
No problem, questions are welcomed.
I don't understand what you mean by reusing connection?
Acolyte Driver.connect(...)
returns a new connection instance each time: https://github.com/cchantep/acolyte/blob/master/core/src/main/java/acolyte/Driver.java#L84 .
As I've updated documentation layout, there is now a section about connection.
If you want to test existing code getting connection from a JDBC URL (or throught a javax.sql.DataSource
bound to such URL), you probably need to make this URL configurable (from .properties or using Maven profiles), so that you can set an Acolyte JDBC URL for testing, and another one for production/dist.
Then you can use following code:
// setup time
acolyte.Driver.register("my-unique-id", handler/* acolyte.ConnectionHandler or acolyte.StatementHandler */);
// ... then any connection from following JDBC (DriverManager.getConnection(...)) URL will be managed by Acolyte.
// To be configured as test JDBC URL = "jdbc:acolyte:anything-you-want?handler=my-unique-id"
If you need/want to directly get a JDBC connection, to be able to pass this instance for testing, you can use:
Connection con = new acolyte.Driver().connection(handler);
from acolyte.
Somehow the server I have to maintain is Singleton infected and static oriented :o) Which is really hard to test...
During my test it reusing the connection... but I realize that I don't need this because I just have to give different parameter to my SQL and that will trigger the corner cases I want to test.
Really happy I found your framework, it's appreciated.
from acolyte.
You're welcome.
from acolyte.
Related Issues (20)
- ThreadLocal driver registry
- Optional/configurable support for untyped null
- RowResultSet hashCode
- publish acolyte to maven central repository HOT 7
- Make writing generic SQL wrappers easier with RowList.append(R) HOT 4
- Rename artifacts
- New core module
- Expert editor for column mapping
- Adding sources to repository HOT 4
- Support binding over rich match
- Support for getGeneratedKeys on update
- Optionally raise fatal error when parameter doesn't match placeholders
- Backward move on AbstractResultSet
- Raise SQLException for ResultSet TYPE_FORWARD_ONLY
- Optionally raise exception for TYPE_FORWARD_ONLY ResultSet
- Share MongoSystem for many connection
- Play JDBC DSL HOT 1
- NullPointerExceptions during ReactiveMongo Actor initialization
- ReactiveMongo FindAndModify pattern matching
- Scalac options
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acolyte.