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