15
15
*/
16
16
package org .springframework .data .jdbc .core ;
17
17
18
+ import static java .util .Collections .*;
18
19
import static org .assertj .core .api .Assertions .*;
19
20
20
21
import java .util .Map ;
26
27
import org .springframework .data .annotation .Id ;
27
28
import org .springframework .data .jdbc .core .mapping .PersistentPropertyPathTestUtils ;
28
29
import org .springframework .data .mapping .PersistentPropertyPath ;
29
- import org .springframework .data .mapping .PropertyPath ;
30
+ import org .springframework .data .relational . core . mapping .NamingStrategy ;
30
31
import org .springframework .data .relational .core .mapping .RelationalMappingContext ;
31
32
import org .springframework .data .relational .core .mapping .RelationalPersistentEntity ;
32
33
import org .springframework .data .relational .core .mapping .RelationalPersistentProperty ;
33
- import org .springframework .data .relational .core .mapping .NamingStrategy ;
34
34
35
35
/**
36
36
* Unit tests for the {@link SqlGenerator}.
@@ -46,10 +46,16 @@ public class SqlGeneratorUnitTests {
46
46
@ Before
47
47
public void setUp () {
48
48
49
+ this .sqlGenerator = createSqlGenerator (DummyEntity .class );
50
+ }
51
+
52
+ SqlGenerator createSqlGenerator (Class <?> type ) {
53
+
49
54
NamingStrategy namingStrategy = new PrefixingNamingStrategy ();
50
55
RelationalMappingContext context = new RelationalMappingContext (namingStrategy );
51
- RelationalPersistentEntity <?> persistentEntity = context .getRequiredPersistentEntity (DummyEntity .class );
52
- this .sqlGenerator = new SqlGenerator (context , persistentEntity , new SqlGeneratorSource (context ));
56
+ RelationalPersistentEntity <?> persistentEntity = context .getRequiredPersistentEntity (type );
57
+
58
+ return new SqlGenerator (context , persistentEntity , new SqlGeneratorSource (context ));
53
59
}
54
60
55
61
@ Test // DATAJDBC-112
@@ -170,10 +176,20 @@ public void findAllByPropertyWithKeyOrdered() {
170
176
+ "WHERE back-ref = :back-ref " + "ORDER BY key-column" );
171
177
}
172
178
179
+ @ Test // DATAJDBC-264
180
+ public void getInsertForEmptyColumnList () {
181
+
182
+ SqlGenerator sqlGenerator = createSqlGenerator (IdOnlyEntity .class );
183
+
184
+ String insert = sqlGenerator .getInsert (emptySet ());
185
+
186
+ assertThat (insert ).endsWith ("()" );
187
+ }
173
188
174
189
private PersistentPropertyPath <RelationalPersistentProperty > getPath (String path , Class <?> base ) {
175
190
return PersistentPropertyPathTestUtils .getPath (context , path , base );
176
191
}
192
+
177
193
@ SuppressWarnings ("unused" )
178
194
static class DummyEntity {
179
195
@@ -212,4 +228,11 @@ public String getColumnName(RelationalPersistentProperty property) {
212
228
}
213
229
214
230
}
231
+
232
+ @ SuppressWarnings ("unused" )
233
+ static class IdOnlyEntity {
234
+
235
+ @ Id Long id ;
236
+ }
237
+
215
238
}
0 commit comments