2424import io .r2dbc .spi .Blob ;
2525import io .r2dbc .spi .Clob ;
2626import io .r2dbc .spi .Connection ;
27+ import io .r2dbc .spi .Parameters ;
2728import io .r2dbc .spi .Row ;
2829import io .r2dbc .spi .Statement ;
2930import oracle .sql .json .OracleJsonFactory ;
5051import java .util .stream .Collectors ;
5152import java .util .stream .Stream ;
5253
54+ import static io .r2dbc .spi .R2dbcType .NCHAR ;
55+ import static io .r2dbc .spi .R2dbcType .NCLOB ;
56+ import static io .r2dbc .spi .R2dbcType .NVARCHAR ;
5357import static java .util .Arrays .asList ;
5458import static oracle .r2dbc .test .DatabaseConfig .connectTimeout ;
5559import static oracle .r2dbc .test .DatabaseConfig .databaseVersion ;
@@ -95,6 +99,16 @@ public class TypeMappingTest {
9599 * <a href="https://r2dbc.io/spec/0.8.3.RELEASE/spec/html/#datatypes.mapping">
96100 * Table 4 of Section 12 of the R2DBC 0.8.3 Specification.
97101 * </a>
102+ * </p><p>
103+ * This test method makes use of {@link io.r2dbc.spi.R2dbcType#NCHAR} and
104+ * {@link io.r2dbc.spi.R2dbcType#NVARCHAR} when binding Strings that contain
105+ * non-ascii characters. By default, a String bind is mapped to the VARCHAR
106+ * SQL type. This default mapping has the driver encode the value using the
107+ * database character set. The database character set may not support
108+ * non-ascii characters. Binding Strings with the NCHAR/NVARCHAR type
109+ * configures the driver to encode the string using the national character set
110+ * of the database. The national character set is either UTF16 or UTF8, and so
111+ * it must support non-ascii characters.
98112 * </p>
99113 */
100114 @ Test
@@ -112,11 +126,18 @@ public void testCharacterTypeMappings() {
112126
113127 // Expect NCHAR and String to map
114128 verifyTypeMapping (connection ,
115- String .format ("%100s" , "你好, Oracle" ), "NCHAR(100)" );
129+ Parameters .in (NCHAR , String .format ("%100s" , "你好, Oracle" )),
130+ "NCHAR(100)" ,
131+ (expected , actual ) ->
132+ assertEquals (expected .getValue (), actual ));
116133
117134 // Expect NVARCHAR and String to map. The Oracle type named "NVARCHAR2" is
118135 // equivalent to the standard type named "NVARCHAR"
119- verifyTypeMapping (connection , "नमस्कार, Oracle" , "NVARCHAR2(100)" );
136+ verifyTypeMapping (connection ,
137+ Parameters .in (NVARCHAR , "नमस्कार, Oracle" ),
138+ "NVARCHAR2(100)" ,
139+ (expected , actual ) ->
140+ assertEquals (expected .getValue (), actual ));
120141
121142 // Expect CLOB and String to map
122143 verifyTypeMapping (connection , "Hola, Oracle" , "CLOB" );
@@ -130,7 +151,11 @@ public void testCharacterTypeMappings() {
130151
131152 // Expect NCLOB and String to map for bind values, but not for row values.
132153 // For row values, expect Oracle CLOB to be mapped to io.r2dbc.spi.Clob
133- verifyTypeMapping (connection , "こんにちは, Oracle" , "NCLOB" );
154+ verifyTypeMapping (connection ,
155+ Parameters .in (NVARCHAR , "こんにちは, Oracle" ),
156+ "NCLOB" ,
157+ (expected , actual ) ->
158+ assertEquals (expected .getValue (), actual ));
134159
135160 // Expect NCLOB and io.r2dbc.spi.Clob to map
136161 verifyTypeMapping (connection ,
0 commit comments