1515 */
1616package org .springframework .data .jdbc .core .convert ;
1717
18+ import static java .util .Arrays .*;
19+ import static java .util .Collections .*;
1820import static org .assertj .core .api .Assertions .*;
1921import static org .mockito .ArgumentMatchers .*;
2022import static org .mockito .Mockito .*;
2325import lombok .AllArgsConstructor ;
2426import lombok .Data ;
2527import lombok .RequiredArgsConstructor ;
28+ import lombok .Value ;
2629
2730import java .util .ArrayList ;
28- import java .util .Arrays ;
2931import java .util .HashMap ;
3032import java .util .List ;
3133
32- import lombok . Value ;
34+ import org . jetbrains . annotations . NotNull ;
3335import org .junit .Before ;
3436import org .junit .Test ;
3537import org .mockito .ArgumentCaptor ;
36-
3738import org .springframework .core .convert .converter .Converter ;
3839import org .springframework .data .annotation .Id ;
3940import org .springframework .data .convert .ReadingConverter ;
@@ -96,7 +97,7 @@ public void additionalParameterForIdDoesNotLeadToDuplicateParameters() {
9697
9798 additionalParameters .put (SqlIdentifier .quoted ("ID" ), ID_FROM_ADDITIONAL_VALUES );
9899
99- accessStrategy .insert (new DummyEntity (ORIGINAL_ID ), DummyEntity .class , Identifier .from ( additionalParameters ));
100+ accessStrategy .insert (new DummyEntity (ORIGINAL_ID ), DummyEntity .class , Identifier .from (additionalParameters ));
100101
101102 verify (namedJdbcOperations ).update (eq ("INSERT INTO \" DUMMY_ENTITY\" (\" ID\" ) VALUES (:ID)" ),
102103 paramSourceCaptor .capture (), any (KeyHolder .class ));
@@ -122,21 +123,8 @@ public void additionalParametersGetAddedToStatement() {
122123 @ Test // DATAJDBC-235
123124 public void considersConfiguredWriteConverter () {
124125
125- DelegatingDataAccessStrategy relationResolver = new DelegatingDataAccessStrategy ();
126-
127- Dialect dialect = HsqlDbDialect .INSTANCE ;
128-
129- JdbcConverter converter = new BasicJdbcConverter (context , relationResolver ,
130- new JdbcCustomConversions (Arrays .asList (BooleanToStringConverter .INSTANCE , StringToBooleanConverter .INSTANCE )),
131- new DefaultJdbcTypeFactory (jdbcOperations ), dialect .getIdentifierProcessing ());
132-
133- DefaultDataAccessStrategy accessStrategy = new DefaultDataAccessStrategy ( //
134- new SqlGeneratorSource (context , converter , dialect ), //
135- context , //
136- converter , //
137- namedJdbcOperations );
138-
139- relationResolver .setDelegate (accessStrategy );
126+ DefaultDataAccessStrategy accessStrategy = createAccessStrategyWithConverter (
127+ asList (BooleanToStringConverter .INSTANCE , StringToBooleanConverter .INSTANCE ));
140128
141129 ArgumentCaptor <String > sqlCaptor = ArgumentCaptor .forClass (String .class );
142130
@@ -153,21 +141,8 @@ public void considersConfiguredWriteConverter() {
153141 @ Test // DATAJDBC-412
154142 public void considersConfiguredWriteConverterForIdValueObjects () {
155143
156- DelegatingDataAccessStrategy relationResolver = new DelegatingDataAccessStrategy ();
157-
158- Dialect dialect = HsqlDbDialect .INSTANCE ;
159-
160- JdbcConverter converter = new BasicJdbcConverter (context , relationResolver ,
161- new JdbcCustomConversions (Arrays .asList (IdValueToStringConverter .INSTANCE )),
162- new DefaultJdbcTypeFactory (jdbcOperations ), dialect .getIdentifierProcessing ());
163-
164- DefaultDataAccessStrategy accessStrategy = new DefaultDataAccessStrategy ( //
165- new SqlGeneratorSource (context , converter , dialect ), //
166- context , //
167- converter , //
168- namedJdbcOperations );
169-
170- relationResolver .setDelegate (accessStrategy );
144+ DefaultDataAccessStrategy accessStrategy = createAccessStrategyWithConverter (
145+ singletonList (IdValueToStringConverter .INSTANCE ));
171146
172147 String rawId = "batman" ;
173148
@@ -187,24 +162,11 @@ public void considersConfiguredWriteConverterForIdValueObjects() {
187162 assertThat (paramSourceCaptor .getValue ().getValue ("id" )).isEqualTo (rawId );
188163 }
189164
190- @ Test // DATAJDBC-587
165+ @ Test // DATAJDBC-349
191166 public void considersConfiguredWriteConverterForIdValueObjectsWhichReferencedInOneToManyRelationship () {
192167
193- DelegatingDataAccessStrategy relationResolver = new DelegatingDataAccessStrategy ();
194-
195- Dialect dialect = HsqlDbDialect .INSTANCE ;
196-
197- JdbcConverter converter = new BasicJdbcConverter (context , relationResolver ,
198- new JdbcCustomConversions (Arrays .asList (IdValueToStringConverter .INSTANCE )),
199- new DefaultJdbcTypeFactory (jdbcOperations ), dialect .getIdentifierProcessing ());
200-
201- DefaultDataAccessStrategy accessStrategy = new DefaultDataAccessStrategy ( //
202- new SqlGeneratorSource (context , converter , dialect ), //
203- context , //
204- converter , //
205- namedJdbcOperations );
206-
207- relationResolver .setDelegate (accessStrategy );
168+ DefaultDataAccessStrategy accessStrategy = createAccessStrategyWithConverter (
169+ singletonList (IdValueToStringConverter .INSTANCE ));
208170
209171 String rawId = "batman" ;
210172 IdValue rootIdValue = new IdValue (rawId );
@@ -216,29 +178,46 @@ public void considersConfiguredWriteConverterForIdValueObjectsWhichReferencedInO
216178 additionalParameters .put (SqlIdentifier .quoted ("DUMMYENTITYROOT" ), rootIdValue );
217179 accessStrategy .insert (root , DummyEntityRoot .class , Identifier .from (additionalParameters ));
218180
219- verify (namedJdbcOperations ).update (anyString (), paramSourceCaptor .capture (),
220- any (KeyHolder .class ));
181+ verify (namedJdbcOperations ).update (anyString (), paramSourceCaptor .capture (), any (KeyHolder .class ));
221182
222183 assertThat (paramSourceCaptor .getValue ().getValue ("id" )).isEqualTo (rawId );
223184
224- PersistentPropertyPath <RelationalPersistentProperty > path =
225- context . getPersistentPropertyPath ( "dummyEntities" , DummyEntityRoot .class );
185+ PersistentPropertyPath <RelationalPersistentProperty > path = context . getPersistentPropertyPath ( "dummyEntities" ,
186+ DummyEntityRoot .class );
226187
227188 accessStrategy .findAllByPath (Identifier .from (additionalParameters ), path );
228189
229- verify (namedJdbcOperations ).query (anyString (), paramSourceCaptor .capture (),
230- any (RowMapper .class ));
190+ verify (namedJdbcOperations ).query (anyString (), paramSourceCaptor .capture (), any (RowMapper .class ));
231191
232192 assertThat (paramSourceCaptor .getValue ().getValue ("DUMMYENTITYROOT" )).isEqualTo (rawId );
233193 }
234194
195+ @ NotNull
196+ private DefaultDataAccessStrategy createAccessStrategyWithConverter (List <?> converters ) {
197+ DelegatingDataAccessStrategy relationResolver = new DelegatingDataAccessStrategy ();
198+
199+ Dialect dialect = HsqlDbDialect .INSTANCE ;
200+
201+ JdbcConverter converter = new BasicJdbcConverter (context , relationResolver , new JdbcCustomConversions (converters ),
202+ new DefaultJdbcTypeFactory (jdbcOperations ), dialect .getIdentifierProcessing ());
203+
204+ DefaultDataAccessStrategy accessStrategy = new DefaultDataAccessStrategy ( //
205+ new SqlGeneratorSource (context , converter , dialect ), //
206+ context , //
207+ converter , //
208+ namedJdbcOperations );
209+
210+ relationResolver .setDelegate (accessStrategy );
211+ return accessStrategy ;
212+ }
213+
235214 @ RequiredArgsConstructor
236215 private static class DummyEntity {
237216
238217 @ Id private final Long id ;
239218 }
240219
241- @ RequiredArgsConstructor // DATAJDBC-587
220+ @ RequiredArgsConstructor // DATAJDBC-349
242221 private static class DummyEntityRoot {
243222
244223 @ Id private final IdValue id ;
0 commit comments