File tree Expand file tree Collapse file tree 3 files changed +10
-1
lines changed
spring-boot-docs/src/main/asciidoc
spring-boot-test-autoconfigure/src
test/java/org/springframework/boot/test/autoconfigure/orm/jpa Expand file tree Collapse file tree 3 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -5204,7 +5204,8 @@ Data JPA tests may also inject a
5204
5204
{sc-spring-boot-test-autoconfigure}/orm/jpa/TestEntityManager.{sc-ext}[`TestEntityManager`]
5205
5205
bean which provides an alternative to the standard JPA `EntityManager` specifically
5206
5206
designed for tests. If you want to use `TestEntityManager` outside of `@DataJpaTests` you
5207
- can also use the `@AutoConfigureTestEntityManager` annotation.
5207
+ can also use the `@AutoConfigureTestEntityManager` annotation. A `JdbcTemplate` is also
5208
+ available should you need that.
5208
5209
5209
5210
[source,java,indent=0]
5210
5211
----
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration
8
8
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\
9
9
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
10
10
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
11
+ org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\
11
12
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
12
13
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
13
14
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
Original file line number Diff line number Diff line change 28
28
import org .springframework .boot .autoconfigure .flyway .FlywayAutoConfiguration ;
29
29
import org .springframework .boot .autoconfigure .liquibase .LiquibaseAutoConfiguration ;
30
30
import org .springframework .context .ApplicationContext ;
31
+ import org .springframework .jdbc .core .JdbcTemplate ;
31
32
import org .springframework .test .context .junit4 .SpringRunner ;
32
33
33
34
import static org .assertj .core .api .Assertions .assertThat ;
@@ -49,6 +50,9 @@ public class DataJpaTestIntegrationTests {
49
50
@ Autowired
50
51
private TestEntityManager entities ;
51
52
53
+ @ Autowired
54
+ private JdbcTemplate jdbcTemplate ;
55
+
52
56
@ Autowired
53
57
private ExampleRepository repository ;
54
58
@@ -72,6 +76,9 @@ public void testEntityManagerPersistAndGetId() throws Exception {
72
76
Long id = this .entities .persistAndGetId (new ExampleEntity ("spring" , "123" ),
73
77
Long .class );
74
78
assertThat (id ).isNotNull ();
79
+ String reference = this .jdbcTemplate .queryForObject (
80
+ "SELECT REFERENCE FROM EXAMPLE_ENTITY WHERE ID = ?" , new Object [] {id }, String .class );
81
+ assertThat (reference ).isEqualTo ("123" );
75
82
}
76
83
77
84
@ Test
You can’t perform that action at this time.
0 commit comments