• About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
AimactGrow
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
AimactGrow
No Result
View All Result

Easy methods to Integration Take a look at Saved Procedures with jOOQ – Java, SQL and jOOQ.

Admin by Admin
May 22, 2025
Home Coding
Share on FacebookShare on Twitter


Once you write saved procedures and capabilities in your database, you need to guarantee their correctness, identical to together with your Java code. In Java, that is executed with unit exams, usually with JUnit. For instance, when you have the next code in Java:

public static int add(int a, int b) {
    return a + b;
}

Then, you may write a take a look at like this:

@Take a look at
public void testAdd() {
    assertEquals(3, add(1, 2));
}

However how can we do that when writing saved procedures? Whereas there exist some unit take a look at libraries for some database merchandise (e.g. utPLSQL for Oracle) they might endure from the next limitations:

  • They won’t be as tightly built-in together with your Maven/Gradle construct as JUnit
  • They won’t be supported by your IDE with extra views corresponding to in Eclipse/IntelliJ
  • There may not be any such utility on your database merchandise in any respect
  • You may need to assist a number of database merchandise and have to take care of exams for all of them, ideally written in Java
  • Your process integration exams could work together with some Java code, so that you need to write the take a look at in Java anyway.

We’d prefer to re-use our Java take a look at infrastructure as an alternative, however with out the trouble of binding to procedures by way of JDBC immediately.

Utilizing jOOQ with testcontainers

Testcontainers is an more and more fashionable framework for database integration testing in Docker. You may rapidly spin up a database occasion and deploy your database schema together with your saved procedures, capabilities, packages, person outlined sorts, and so forth. For instance, you may resolve to maneuver the above technique into your database utilizing PostgreSQL:

CREATE OR REPLACE FUNCTION add(a integer, b integer)
RETURNS integer AS
$$
BEGIN 
  RETURN a + b;
END;
$$
LANGUAGE PLPGSQL;

Now, you possibly can name this operate with JDBC, as such:

attempt (CallableStatement s = connection.prepareCall(
    "{ ? = name add(?, ?) }"
)) {
    s.registerOutParameter(1, Sorts.INTEGER);
    s.setInt(2, 1);
    s.setInt(3, 2);
    s.executeUpdate();
    System.out.println(s.getInt(1));
}

The above prints

3

However that’s loads of handbook plumbing. Everytime you refactor your process, your take a look at fails at runtime, moderately than at compile time. And also you’ll need to tediously replace the take a look at code above.

So, why not simply use jOOQ’s code generator to generate a Routines class for you, containing an add() technique. That one, you’ll be able to name like this:

System.out.println(Routines.add(configuration, 1, 2));

The place configuration is a jOOQ sort wrapping your JDBC Connection. Now you can arrange your JUnit take a look at like this, for instance, e.g. utilizing JUnit’s ClassRule:

@ClassRule
public static PostgreSQLContainer> db = 
    new PostgreSQLContainer<>("postgres:14")
        .withUsername("postgres")
        .withDatabaseName("postgres")
        .withPassword("take a look at");

Another choice of the best way to configure testcontainers with JUnit is described right here.

And use db.getJdbcUrl() to hook up with the PostgreSQL testcontainers database with jOOQ. Your closing take a look at then simply appears to be like like this:

@Take a look at
public void testAdd() {
    attempt (CloseableDSLContext ctx = DSL.utilizing(
        db.getJdbcUrl(), "postgres", "take a look at"
    )) {
        assertEquals(3, Routines.add(ctx.configuration(), 1, 2));
    }
}

You’d clearly transfer the DSLContext logic out of the person exams right into a @Earlier than block. Not a lot completely different from what you’re used to, proper? Observe that even for code era, we advocate utilizing testcontainers as nicely, as a part of your construct. You may then re-use the code generator testcontainers occasion on your integration exams, in order for you.

Like this:

Like Loading…

Tags: IntegrationJavajOOQProceduresSQLStoredTest
Admin

Admin

Next Post
Know-how Innovation Institute TII Releases Falcon-H1: Hybrid Transformer-SSM Language Fashions for Scalable, Multilingual, and Lengthy-Context Understanding

Know-how Innovation Institute TII Releases Falcon-H1: Hybrid Transformer-SSM Language Fashions for Scalable, Multilingual, and Lengthy-Context Understanding

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended.

Find out how to Construct an Agentic Deep Reinforcement Studying System with Curriculum Development, Adaptive Exploration, and Meta-Degree UCB Planning

Find out how to Construct an Agentic Deep Reinforcement Studying System with Curriculum Development, Adaptive Exploration, and Meta-Degree UCB Planning

November 19, 2025
The Browser You Ought to Keep away from Utilizing On Your Android Telephone

The Browser You Ought to Keep away from Utilizing On Your Android Telephone

August 24, 2025

Trending.

The way to Clear up the Wall Puzzle in The place Winds Meet

The way to Clear up the Wall Puzzle in The place Winds Meet

November 16, 2025
Researchers Uncover Crucial GitHub CVE-2026-3854 RCE Flaw Exploitable by way of Single Git Push

Researchers Uncover Crucial GitHub CVE-2026-3854 RCE Flaw Exploitable by way of Single Git Push

April 29, 2026
Google Introduces Simula: A Reasoning-First Framework for Producing Controllable, Scalable Artificial Datasets Throughout Specialised AI Domains

Google Introduces Simula: A Reasoning-First Framework for Producing Controllable, Scalable Artificial Datasets Throughout Specialised AI Domains

April 21, 2026
Google DeepMind Introduces Decoupled DiLoCo: An Asynchronous Coaching Structure Reaching 88% Goodput Below Excessive {Hardware} Failure Charges

Google DeepMind Introduces Decoupled DiLoCo: An Asynchronous Coaching Structure Reaching 88% Goodput Below Excessive {Hardware} Failure Charges

April 24, 2026
5 AI Compute Architectures Each Engineer Ought to Know: CPUs, GPUs, TPUs, NPUs, and LPUs In contrast

5 AI Compute Architectures Each Engineer Ought to Know: CPUs, GPUs, TPUs, NPUs, and LPUs In contrast

April 10, 2026

AimactGrow

Welcome to AimactGrow, your ultimate source for all things technology! Our mission is to provide insightful, up-to-date content on the latest advancements in technology, coding, gaming, digital marketing, SEO, cybersecurity, and artificial intelligence (AI).

Categories

  • AI
  • Coding
  • Cybersecurity
  • Digital marketing
  • Gaming
  • SEO
  • Technology

Recent News

A profile of OpenAI CFO Sarah Friar, who sources say helped preserve OpenAI’s Microsoft deal on monitor and has privately steered ready till 2027 for an IPO (Wall Road Journal)

A profile of OpenAI CFO Sarah Friar, who sources say helped preserve OpenAI’s Microsoft deal on monitor and has privately steered ready till 2027 for an IPO (Wall Road Journal)

May 2, 2026
Huge Fb Phishing Operation Leverages AppSheet, Netlify, and Telegram

Huge Fb Phishing Operation Leverages AppSheet, Netlify, and Telegram

May 2, 2026
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved

No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved