Skip to content

Commit

Permalink
converting to a single module project
Browse files Browse the repository at this point in the history
.. modernizing the project
.. switching from Derby to Postgres
  • Loading branch information
andrus committed Apr 28, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 0f9d9cf commit 19db837
Showing 21 changed files with 307 additions and 490 deletions.
24 changes: 8 additions & 16 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: verify
name: 'build test'

on: [pull_request, push]

@@ -8,22 +8,14 @@ jobs:

steps:
- name: Checkout...
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up JDK...
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 11
distribution: 'temurin'
cache: 'maven'

- name: Retrieve mvn repo cache...
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: maven-${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
restore-keys: maven-${{ runner.os }}

- name: App - Build and test...
run: cd jdbc-app-demo/ && mvn verify

- name: Tests - Build and test...
run: cd jdbc-test-demo-inmemory-db/ && mvn verify
- name: Build and test...
run: mvn -ntp clean verify
90 changes: 83 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,90 @@
[![verify](https://github.com/bootique-examples/bootique-jdbc-demo/actions/workflows/verify.yml/badge.svg)](https://github.com/bootique-examples/bootique-jdbc-demo/actions/workflows/verify.yml)

# bootique-jdbc-demo

Contains two examples of [bootique-jdbc](https://github.com/bootique/bootique-jdbc) use:
# Bootique 3.x REST Demo

* [jdbc-app-demo](https://github.com/bootique-examples/bootique-jdbc-demo/tree/master/jdbc-app-demo) - core JDBC API
* [jdbc-test-demo-inmemory-db](https://github.com/bootique-examples/bootique-jdbc-demo/tree/master/jdbc-test-demo-inmemory-db) - JUnit 5 tests using Derby in-memory DB
* TODO: testcontainers demo
This is an example [Bootique](http://bootique.io) JDBC app. It shows how to define and use a named DataSource,
and how to write DB-aware unit tests with Bootique and Testcontainers.

For the examples working with the older versions of Bootique check the code on the branches:
Different Git branches contain demo code for different versions of Bootique:

* [1.x](https://github.com/bootique-examples/bootique-jdbc-demo/tree/1.x)
* [3.x](https://github.com/bootique-examples/bootique-jdbc-demo/tree/3.x)
* [2.x](https://github.com/bootique-examples/bootique-jdbc-demo/tree/2.x)
* [1.x](https://github.com/bootique-examples/bootique-jdbc-demo/tree/1.x)

## Prerequisites

To build and run the demo, ensure you have the following installed on your machine:

* Docker
* Java 11 or newer
* Maven

and then follow these steps:

## Checkout
```
git clone git@github.com:bootique-examples/bootique-jdbc-demo.git
cd bootique-jdbc-demo
```

## Start Postgres DB Locally

This starts a Postgres instance listening on port 15432, with login credentials of `postgres` / `test`, and
creates a simple test schema:

```bash
docker-compose -f docker-compose.yml up -d
```

## Build, test and package

Run the following command to build the code, run the tests and package the app:
```
mvn clean package
```
This project uses a [runnable jar with lib folder](https://bootique.io/docs/3.x/bootique-docs/#runnable-jar-with-lib)
packaging recipe, so now the app is packaged for distribution as `target/bootique-jdbc-demo-3.0.tar.gz` archive. But
there is also the "unpacked" version in the `target` folder that can be used to run the app.

## Run

The following command prints a help message with supported options:
```bash
java -jar target/bootique-jdbc-demo-3.0.jar
```

```
NAME
bootique-jdbc-demo-3.0.jar
OPTIONS
-c yaml_location, --config=yaml_location
Specifies YAML config location, which can be a file path or a URL.
-h, --help
Prints this message.
-H, --help-config
Prints information about application modules and their configuration options.
-i, --insert
Inserts sample data to a DB
-s, --select
Selects data from a DB
```

Run the `--insert` command to create some test data in the DB. DB location and login credential are specified in the
provided `config.yml`.
```bash
java -jar target/bootique-jdbc-demo-3.0.jar -c config.yml -i
```

Check the data in the database using the `--select` command:
```bash
java -jar target/jdbc-app-demo-X.XX.jar -c config.yml -s
```

Note that per `config.yml` the test database is located under `target/derby/DerbyDatabase`, so running `mvn clean` will
delete it with all the inserted data.
18 changes: 18 additions & 0 deletions assembly.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 https://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>tar.gz</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<useDefaultExcludes>true</useDefaultExcludes>
<outputDirectory>./</outputDirectory>
<includes>
<include>${project.artifactId}-${project.version}.jar</include>
<include>lib/</include>
</includes>
</fileSet>
</fileSets>
</assembly>
5 changes: 5 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
jdbc:
postgres:
jdbcUrl: jdbc:postgresql://localhost:15432/postgres
username: postgres
password: test
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.3'

services:
postgres:
image: postgres:16.2
ports:
- "15432:5432"
restart: always
environment:
POSTGRES_PASSWORD: test
volumes:
- ./sql/postgres-schema.sql:/docker-entrypoint-initdb.d/postgres-schema.sql
55 changes: 0 additions & 55 deletions jdbc-app-demo/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions jdbc-app-demo/config.yml

This file was deleted.

109 changes: 0 additions & 109 deletions jdbc-app-demo/pom.xml

This file was deleted.

25 changes: 0 additions & 25 deletions jdbc-app-demo/src/main/java/io/bootique/jdbc/demo/Application.java

This file was deleted.

Loading

0 comments on commit 19db837

Please sign in to comment.