Giter VIP home page Giter VIP logo

Comments (7)

cchantep avatar cchantep commented on September 28, 2024

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.

cchantep avatar cchantep commented on September 28, 2024

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.

cchantep avatar cchantep commented on September 28, 2024

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.

mapo-job avatar mapo-job commented on September 28, 2024

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.

cchantep avatar cchantep commented on September 28, 2024

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.

mapo-job avatar mapo-job commented on September 28, 2024

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.

cchantep avatar cchantep commented on September 28, 2024

You're welcome.

from acolyte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.