Skip to content

Commit

Permalink
Integration tests with testcontainers
Browse files Browse the repository at this point in the history
 - framework in tests/integration/junit5
 - DbClient tests for H2/MySQL/PostgreSQL

Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
  • Loading branch information
Tomas-Kraus committed Feb 23, 2024
1 parent 0a5a494 commit 05597a9
Show file tree
Hide file tree
Showing 165 changed files with 7,428 additions and 9,130 deletions.
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,11 @@
<artifactId>helidon-integrations-db-mysql</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.integrations.db</groupId>
<artifactId>helidon-integrations-db-pgsql</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.integrations.cdi</groupId>
<artifactId>helidon-integrations-cdi-configurable</artifactId>
Expand Down
13 changes: 12 additions & 1 deletion dbclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.helidon</groupId>
<artifactId>helidon-project</artifactId>
<version>4.0.0-SNAPSHOT</version>
</parent>
<packaging>pom</packaging>

<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient-project</artifactId>
<name>Helidon Database Client Project</name>
<packaging>pom</packaging>

<modules>
<module>dbclient</module>
Expand All @@ -41,4 +42,14 @@
<module>health</module>
<module>jsonp</module>
</modules>

<profiles>
<profile>
<id>tests</id>
<modules>
<module>tests</module>
</modules>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2019, 2024 Oracle and/or its affiliates.
Copyright (c) 2024 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -13,27 +14,32 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.helidon.tests.integration.dbclient</groupId>
<artifactId>helidon-tests-integration-dbclient-project</artifactId>
<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient-tests-project</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>helidon-tests-integration-dbclient-common</artifactId>
<name>Helidon Tests Integration Database Client Common</name>

<artifactId>helidon-dbclient-tests-common</artifactId>
<name>Helidon Database Client Common Tests</name>
<description>Database client tests for all vendors</description>

<dependencies>
<dependency>
<groupId>io.helidon.tests.integration</groupId>
<artifactId>helidon-tests-integration-harness</artifactId>
<version>${project.version}</version>
<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient-metrics</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient-health</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
Expand All @@ -44,20 +50,25 @@
<artifactId>helidon-config-yaml</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.metrics</groupId>
<artifactId>helidon-metrics</artifactId>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient-health</artifactId>
<groupId>io.helidon.webserver.observe</groupId>
<artifactId>helidon-webserver-observe-metrics</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient-metrics</artifactId>
<groupId>io.helidon.webserver.observe</groupId>
<artifactId>helidon-webserver-observe-health</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.tests.integration</groupId>
<artifactId>helidon-tests-integration-harness</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.parsson</groupId>
<artifactId>parsson</artifactId>
<groupId>io.helidon.webserver.testing.junit5</groupId>
<artifactId>helidon-webserver-testing-junit5</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -67,22 +78,6 @@
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webserver.observe</groupId>
<artifactId>helidon-webserver-observe-metrics</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webserver.observe</groupId>
<artifactId>helidon-webserver-observe-health</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
/*
* Copyright (c) 2021, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.dbclient.tests.common.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.helidon.dbclient.DbMapper;
import io.helidon.dbclient.DbRow;

import static io.helidon.dbclient.tests.common.model.Kind.KINDS;

/**
* {@code Critter} POJO.
*/
@SuppressWarnings("SpellCheckingInspection")
public class Critter {

/**
* {@code Critter} POJO mapper.
*/
public static final class CritterMapper implements DbMapper<Critter> {

public static final CritterMapper INSTANCE = new CritterMapper();

@Override
public Critter read(DbRow row) {
return new Critter(row.column("id").get(Integer.class), row.column("name").get(String.class));
}

@Override
public Map<String, ?> toNamedParameters(Critter value) {
Map<String, Object> params = new HashMap<>(2);
params.put("id", value.getId());
params.put("name", value.getName());
return params;
}

@Override
public List<?> toIndexedParameters(Critter value) {
List<Object> params = new ArrayList<>(2);
params.add(value.getName());
params.add(value.getId());
return params;
}

}

/**
* Map of {@code Critter} by ID.
*/
public static final Map<Integer, Critter> CRITTERS = new HashMap<>();

static {
// query tests
CRITTERS.put(1, new Critter(1, "Pikachu", KINDS.get(13)));
CRITTERS.put(2, new Critter(2, "Raichu", KINDS.get(13)));
CRITTERS.put(3, new Critter(3, "Machop", KINDS.get(2)));
CRITTERS.put(4, new Critter(4, "Snorlax", KINDS.get(1)));
CRITTERS.put(5, new Critter(5, "Charizard", KINDS.get(10), KINDS.get(3)));
CRITTERS.put(6, new Critter(6, "Meowth", KINDS.get(1)));
CRITTERS.put(7, new Critter(7, "Gyarados", KINDS.get(3), KINDS.get(11)));
// update tests
CRITTERS.put(8, new Critter(8, "Spearow", KINDS.get(1), KINDS.get(3)));
CRITTERS.put(9, new Critter(9, "Fearow", KINDS.get(1), KINDS.get(3)));
CRITTERS.put(10, new Critter(10, "Ekans", KINDS.get(4)));
CRITTERS.put(11, new Critter(11, "Arbok", KINDS.get(4)));
CRITTERS.put(12, new Critter(12, "Sandshrew", KINDS.get(5)));
CRITTERS.put(13, new Critter(13, "Sandslash", KINDS.get(5)));
CRITTERS.put(14, new Critter(14, "Diglett", KINDS.get(5)));
// delete tests
CRITTERS.put(15, new Critter(15, "Rayquaza", KINDS.get(3), KINDS.get(16)));
CRITTERS.put(16, new Critter(16, "Lugia", KINDS.get(3), KINDS.get(14)));
CRITTERS.put(17, new Critter(17, "Ho-Oh", KINDS.get(3), KINDS.get(10)));
CRITTERS.put(18, new Critter(18, "Raikou", KINDS.get(13)));
CRITTERS.put(19, new Critter(19, "Giratina", KINDS.get(8), KINDS.get(16)));
CRITTERS.put(20, new Critter(20, "Regirock", KINDS.get(6)));
CRITTERS.put(21, new Critter(21, "Kyogre", KINDS.get(11)));
// IDs reserved for insert tests are 22 - 28
// DML update tests
CRITTERS.put(29, new Critter(29, "Piplup", KINDS.get(11)));
CRITTERS.put(30, new Critter(30, "Prinplup", KINDS.get(11)));
CRITTERS.put(31, new Critter(31, "Empoleon", KINDS.get(9), KINDS.get(11)));
CRITTERS.put(32, new Critter(32, "Staryu", KINDS.get(11)));
CRITTERS.put(33, new Critter(33, "Starmie", KINDS.get(11), KINDS.get(14)));
CRITTERS.put(34, new Critter(34, "Horsea", KINDS.get(11)));
CRITTERS.put(35, new Critter(35, "Seadra", KINDS.get(11)));
// DML delete tests
CRITTERS.put(36, new Critter(36, "Mudkip", KINDS.get(11)));
CRITTERS.put(37, new Critter(37, "Marshtomp", KINDS.get(5), KINDS.get(11)));
CRITTERS.put(38, new Critter(38, "Swampert", KINDS.get(5), KINDS.get(11)));
CRITTERS.put(39, new Critter(39, "Muk", KINDS.get(4)));
CRITTERS.put(40, new Critter(40, "Grimer", KINDS.get(4)));
CRITTERS.put(41, new Critter(41, "Cubchoo", KINDS.get(15)));
CRITTERS.put(42, new Critter(42, "Beartic", KINDS.get(15)));
// IDs reserved for DML insert tests are 43 - 49
// DML statement IT
CRITTERS.put(50, new Critter(50, "Shinx", KINDS.get(13)));
CRITTERS.put(51, new Critter(51, "Luxio", KINDS.get(13)));
CRITTERS.put(52, new Critter(52, "Luxray", KINDS.get(13)));
CRITTERS.put(53, new Critter(53, "Kricketot", KINDS.get(7)));
CRITTERS.put(54, new Critter(54, "Kricketune", KINDS.get(7)));
CRITTERS.put(55, new Critter(55, "Phione", KINDS.get(11)));
CRITTERS.put(56, new Critter(56, "Chatot", KINDS.get(1), KINDS.get(3)));
// update tests in transaction
CRITTERS.put(57, new Critter(57, "Teddiursa", KINDS.get(1)));
CRITTERS.put(58, new Critter(58, "Ursaring", KINDS.get(1)));
CRITTERS.put(59, new Critter(59, "Slugma", KINDS.get(10)));
CRITTERS.put(60, new Critter(60, "Magcargo", KINDS.get(6), KINDS.get(10)));
CRITTERS.put(61, new Critter(61, "Lotad", KINDS.get(11), KINDS.get(12)));
CRITTERS.put(62, new Critter(62, "Lombre", KINDS.get(11), KINDS.get(12)));
CRITTERS.put(63, new Critter(63, "Ludicolo", KINDS.get(11), KINDS.get(12)));
// DML update tests in transaction
CRITTERS.put(64, new Critter(64, "Natu", KINDS.get(3), KINDS.get(14)));
CRITTERS.put(65, new Critter(65, "Xatu", KINDS.get(3), KINDS.get(14)));
CRITTERS.put(66, new Critter(66, "Snubbull", KINDS.get(18)));
CRITTERS.put(67, new Critter(67, "Granbull", KINDS.get(18)));
CRITTERS.put(68, new Critter(68, "Entei", KINDS.get(10)));
CRITTERS.put(69, new Critter(69, "Raikou", KINDS.get(13)));
CRITTERS.put(70, new Critter(70, "Suicune", KINDS.get(11)));
// delete tests in transaction
CRITTERS.put(71, new Critter(71, "Omanyte", KINDS.get(6), KINDS.get(11)));
CRITTERS.put(72, new Critter(72, "Omastar", KINDS.get(6), KINDS.get(11)));
CRITTERS.put(73, new Critter(73, "Kabuto", KINDS.get(6), KINDS.get(11)));
CRITTERS.put(74, new Critter(74, "Kabutops", KINDS.get(6), KINDS.get(11)));
CRITTERS.put(75, new Critter(75, "Chikorita", KINDS.get(12)));
CRITTERS.put(76, new Critter(76, "Bayleef", KINDS.get(12)));
CRITTERS.put(77, new Critter(77, "Meganium", KINDS.get(12)));
// DML delete tests in transaction
CRITTERS.put(78, new Critter(78, "Trapinch", KINDS.get(5)));
CRITTERS.put(79, new Critter(79, "Vibrava", KINDS.get(5), KINDS.get(16)));
CRITTERS.put(80, new Critter(80, "Spoink", KINDS.get(14)));
CRITTERS.put(81, new Critter(81, "Grumpig", KINDS.get(14)));
CRITTERS.put(82, new Critter(82, "Beldum", KINDS.get(9), KINDS.get(14)));
CRITTERS.put(83, new Critter(83, "Metang", KINDS.get(9), KINDS.get(14)));
CRITTERS.put(84, new Critter(84, "Metagross", KINDS.get(9), KINDS.get(14)));
// IDs reserved for DML insert tests in transaction are 85 - 98
// mapping tests
CRITTERS.put(99, new Critter(99, "Moltres", KINDS.get(3), KINDS.get(10)));
CRITTERS.put(100, new Critter(100, "Masquerain", KINDS.get(3), KINDS.get(7)));
CRITTERS.put(101, new Critter(101, "Makuhita", KINDS.get(2)));
CRITTERS.put(102, new Critter(102, "Hariyama", KINDS.get(2)));
// IDs reserved for mapping tests with insert are 103 - 104
}

public static List<Kind> typesList(Kind... types) {
if (types == null) {
return null;
}
List<Kind> typesList = new ArrayList<>(types.length);
typesList.addAll(Arrays.asList(types));
return typesList;
}

private final int id;
private final String name;
private final List<Kind> types;

public Critter(int id, String name, Kind... types) {
this.id = id;
this.name = name;
this.types = new ArrayList<>(types != null ? types.length : 0);
if (types != null) {
this.types.addAll(Arrays.asList(types));
}
}

public Critter(int id, String name, List<Kind> types) {
this.id = id;
this.name = name;
this.types = types != null ? types : List.of();
}

public int getId() {
return id;
}

public String getName() {
return name;
}

public List<Kind> getTypes() {
return types;
}

public Kind[] getTypesArray() {
return types.toArray(new Kind[0]);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Critter: {id=");
sb.append(id);
sb.append(", name=");
sb.append(name);
sb.append(", types=[");
boolean first = true;
for (Kind type : types) {
if (first) {
first = false;
} else {
sb.append(", ");
}
sb.append(type.toString());
}
sb.append("]}");
return sb.toString();
}

}
Loading

0 comments on commit 05597a9

Please sign in to comment.