Skip to content

Commit cc8bff9

Browse files
committed
[#1614] Add test for Parameters processors
1 parent 16d1453 commit cc8bff9

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 java.util.stream.Stream;
9+
10+
import org.hibernate.reactive.pool.impl.OracleParameters;
11+
import org.hibernate.reactive.pool.impl.PostgresParameters;
12+
import org.hibernate.reactive.pool.impl.SQLServerParameters;
13+
14+
import org.junit.jupiter.params.ParameterizedTest;
15+
import org.junit.jupiter.params.provider.Arguments;
16+
import org.junit.jupiter.params.provider.MethodSource;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.junit.jupiter.params.provider.Arguments.arguments;
20+
21+
/**
22+
* Test the {@link org.hibernate.reactive.pool.impl.Parameters} processor for each database
23+
*/
24+
public class ParametersProcessorTest {
25+
26+
/**
27+
* Each test will replace this placeholder with the correct parameter prefix for the selected database
28+
*/
29+
private static final String PARAM_PREFIX = "__paramPrefix__";
30+
31+
32+
/**
33+
* Return the strings to process and the expected result for each one
34+
*/
35+
static Stream<Arguments> expectations() {
36+
return Stream.of(
37+
arguments( "/* One comment */ \\?", "/* One comment */ ?" ),
38+
arguments( "/* One comment */ ?", "/* One comment */ " + PARAM_PREFIX + "1" ),
39+
arguments( "'Sql text ?'", "'Sql text ?'" ),
40+
arguments( "\\?", "?" ),
41+
arguments( "???", PARAM_PREFIX + "1" + PARAM_PREFIX + "2" + PARAM_PREFIX + "3" ),
42+
arguments( "\\?|?", "?|" + PARAM_PREFIX + "1" ),
43+
arguments( " ? ", " " + PARAM_PREFIX + "1 " )
44+
);
45+
}
46+
47+
@ParameterizedTest
48+
@MethodSource("expectations")
49+
public void testPostgreSQLProcessing(String unprocessed, String expected) {
50+
assertThat( PostgresParameters.INSTANCE.process( unprocessed ) )
51+
.isEqualTo( expected.replaceAll( PARAM_PREFIX, "\\$" ) );
52+
}
53+
54+
@ParameterizedTest
55+
@MethodSource("expectations")
56+
public void testSqlServerProcessing(String unprocessed, String expected) {
57+
assertThat( SQLServerParameters.INSTANCE.process( unprocessed ) )
58+
.isEqualTo( expected.replaceAll( PARAM_PREFIX, "@P" ) );
59+
}
60+
61+
@ParameterizedTest
62+
@MethodSource("expectations")
63+
public void testOracleProcessing(String unprocessed, String expected) {
64+
assertThat( OracleParameters.INSTANCE.process( unprocessed ) )
65+
.isEqualTo( expected.replaceAll( PARAM_PREFIX, ":" ) );
66+
}
67+
}

0 commit comments

Comments
 (0)