Skip to content

Commit

Permalink
test(pg): fix pg test
Browse files Browse the repository at this point in the history
  • Loading branch information
zero88 committed Mar 22, 2024
1 parent 1923e94 commit ee45194
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,17 @@ void should_unsupported_transaction() {
".PgConnectionImpl]. Switch using SQL pool");
}

@Test
void test_execute_postgres_version(VertxTestContext ctx) {
Checkpoint cp = ctx.checkpoint();
jooqx.execute(dsl -> dsl.selectFrom("version();"), DSLAdapter.fetchOne(DSL.field("version", String.class)))
.onSuccess(rec -> ctx.verify(() -> {
final Object value = rec.getValue(0);
Assertions.assertInstanceOf(String.class, value);
Assertions.assertTrue(((String) value).contains("PostgreSQL 16.2"));
cp.flag();
}))
.onFailure(ctx::failNow);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.zero88.integtest.jooqx.pg.jooq;

import org.jooq.impl.DSL;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -44,4 +45,16 @@ void test_query(VertxTestContext ctx) {
}, ctx::failNow);
}

@Test
void test_execute_postgres_version(VertxTestContext ctx) {
Checkpoint cp = ctx.checkpoint();
jooqxRx2.rxExecute(dsl -> dsl.selectFrom("version();"), DSLAdapter.fetchOne(DSL.field("version", String.class)))
.subscribe(rec -> {
final Object value = rec.getValue(0);
Assertions.assertInstanceOf(String.class, value);
Assertions.assertTrue(((String) value).contains("PostgreSQL 16.2"));
cp.flag();
}, ctx::failNow);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.zero88.integtest.jooqx.pg.jooq;

import org.jooq.impl.DSL;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -44,4 +45,16 @@ void test_query(VertxTestContext ctx) {
}, ctx::failNow);
}

@Test
void test_execute_postgres_version(VertxTestContext ctx) {
Checkpoint cp = ctx.checkpoint();
jooqxRx3.rxExecute(dsl -> dsl.selectFrom("version();"), DSLAdapter.fetchOne(DSL.field("version", String.class)))
.subscribe(rec -> {
final Object value = rec.getValue(0);
Assertions.assertInstanceOf(String.class, value);
Assertions.assertTrue(((String) value).contains("PostgreSQL 16.2"));
cp.flag();
}, ctx::failNow);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.zero88.integtest.jooqx.pg.jooq;

import java.util.Arrays;
import java.util.stream.Stream;

import org.jooq.exception.DataAccessException;
import org.jooq.exception.SQLStateClass;
Expand Down Expand Up @@ -93,8 +94,13 @@ void test_session_throw_ex_but_still_inserted_first_when_multiple_inserts_failed
.onSuccess(result -> ctx.failNow("Should failed"))
.onFailure(t -> ctx.verify(() -> {
Assertions.assertInstanceOf(DataAccessException.class, t);
Assertions.assertTrue(
t.getMessage().contains("null value in column \"country\" violates not-null constraint"));
//@formatter:off
boolean mustContains = Stream.of(
"null value in column \"country\" violates not-null constraint", // < pg14
"null value in column \"country\" of relation \"authors\" violates not-null constraint" // >= pg14
).anyMatch(msg -> t.getMessage().contains(msg));
//@formatter:on
Assertions.assertTrue(mustContains, "The error message 'not-null constraint' is not correct");
jooqx.fetchExists(dsl -> dsl.selectFrom(table).where(table.NAME.eq("n1").and(table.COUNTRY.eq("AT"))))
.onSuccess(b -> ctx.verify(() -> {
Assertions.assertTrue(b);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.zero88.integtest.jooqx.pg.jooq;

import java.util.Arrays;
import java.util.stream.Stream;

import org.jooq.DSLContext;
import org.jooq.InsertResultStep;
Expand Down Expand Up @@ -175,8 +176,13 @@ void test_session_throw_ex_but_still_inserted_first_when_multiple_inserts_failed
.onSuccess(result -> ctx.failNow("Should failed"))
.onFailure(t -> ctx.verify(() -> {
Assertions.assertInstanceOf(DataAccessException.class, t);
Assertions.assertTrue(
t.getMessage().contains("null value in column \"country\" violates not-null constraint"));
//@formatter:off
boolean mustContains = Stream.of(
"null value in column \"country\" violates not-null constraint", // < pg14
"null value in column \"country\" of relation \"authors\" violates not-null constraint" // >= pg14
).anyMatch(msg -> t.getMessage().contains(msg));
//@formatter:on
Assertions.assertTrue(mustContains, "The error message 'not-null constraint' is not correct");
jooqx.fetchExists(dsl -> dsl.selectFrom(table).where(table.NAME.eq("n1").and(table.COUNTRY.eq("AT"))))
.onSuccess(b -> ctx.verify(() -> {
Assertions.assertTrue(b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import io.github.zero88.integtest.jooqx.pg.PgUseVertxType;
import io.github.zero88.jooqx.DSLAdapter;
import io.github.zero88.jooqx.SQLTestHelper;
import io.github.zero88.jooqx.spi.jdbc.JDBCErrorConverterProvider;
import io.github.zero88.jooqx.spi.jdbc.JDBCPoolHikariProvider;
import io.github.zero88.jooqx.spi.pg.PgSQLJooqxTest;
Expand All @@ -24,6 +25,34 @@ public boolean alreadyGenerated() {
return false;
}

@Test
void test_select_postgres_version(VertxTestContext ctx) {
final String dbVersion = SQLTestHelper.getCurrentDBVersion("16-alpine").substring(0, 2);
Checkpoint cp = ctx.checkpoint();
jooqx.sqlQuery("select * from version();", DSLAdapter.fetchOne(DSL.field("version", String.class)))
.onSuccess(rec -> ctx.verify(() -> {
final Object value = rec.getValue(0);
Assertions.assertInstanceOf(String.class, value);
Assertions.assertTrue(((String) value).contains("PostgreSQL " + dbVersion), "Version is mot match");
cp.flag();
}))
.onFailure(ctx::failNow);
}

@Test
void test_execute_postgres_version(VertxTestContext ctx) {
final String dbVersion = SQLTestHelper.getCurrentDBVersion("16-alpine").substring(0, 2);
Checkpoint cp = ctx.checkpoint();
jooqx.execute(dsl -> dsl.selectFrom("version();"), DSLAdapter.fetchOne(DSL.field("version", String.class)))
.onSuccess(rec -> ctx.verify(() -> {
final Object value = rec.getValue(0);
Assertions.assertInstanceOf(String.class, value);
Assertions.assertTrue(((String) value).contains("PostgreSQL " + dbVersion), "Version is mot match");
cp.flag();
}))
.onFailure(ctx::failNow);
}

@Test
void test_select_to_JsonArray(VertxTestContext ctx) {
Checkpoint cp = ctx.checkpoint();
Expand Down

0 comments on commit ee45194

Please sign in to comment.