Skip to content

Commit 50b5566

Browse files
committed
[#2478] Add test for terrible error reporting when JDBC scheme is not recognized
1 parent cf6bd1b commit 50b5566

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Hibernate, Relational Persistence for Idiomatic Java
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Copyright: Red Hat Inc. and Hibernate Authors
5+
*/
6+
package org.hibernate.reactive;
7+
8+
import org.hibernate.cfg.Configuration;
9+
import org.hibernate.reactive.provider.Settings;
10+
import org.hibernate.service.spi.ServiceException;
11+
12+
import org.junit.jupiter.api.Test;
13+
14+
import io.vertx.junit5.Timeout;
15+
import io.vertx.junit5.VertxTestContext;
16+
17+
import static java.util.concurrent.TimeUnit.MINUTES;
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.hibernate.reactive.testing.ReactiveAssertions.assertThrown;
20+
21+
/**
22+
* Check that the right exception is thrown when there is an error when the JDBC URI scheme is not recognized.
23+
*/
24+
@Timeout(value = 10, timeUnit = MINUTES)
25+
public class WrongJdbcUrlTest extends BaseReactiveTest {
26+
27+
@Override
28+
protected void setProperties(Configuration configuration) {
29+
configuration.setProperty( Settings.JAKARTA_JDBC_URL, "jdbc:h2:~/h2temp" );
30+
configuration.setProperty( Settings.JAKARTA_JDBC_USER, "abc" );
31+
setSqlLoggingProperties( configuration );
32+
}
33+
34+
@Override
35+
public void before(VertxTestContext context) {
36+
// We need to postpone the creation of the factory so that we can check the exception
37+
}
38+
39+
@Test
40+
public void testWithTransaction(VertxTestContext context) {
41+
test( context, assertThrown( ServiceException.class, setupSessionFactory( this::constructConfiguration ) )
42+
.thenAccept( WrongJdbcUrlTest::assertException )
43+
);
44+
}
45+
46+
private static void assertException(Throwable throwable) {
47+
assertThat( throwable.getMessage() )
48+
.contains( "Unsupported URI scheme:" );
49+
}
50+
51+
}

0 commit comments

Comments
 (0)