File tree Expand file tree Collapse file tree 4 files changed +21
-7
lines changed
test/java/org/baeldung/persistence/service Expand file tree Collapse file tree 4 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 1- package org .baeldung .spring ;
1+ package org .baeldung .config ;
22
33import java .util .Properties ;
44
88import org .springframework .beans .factory .annotation .Autowired ;
99import org .springframework .context .annotation .Bean ;
1010import org .springframework .context .annotation .ComponentScan ;
11+ import org .springframework .context .annotation .Configuration ;
1112import org .springframework .context .annotation .PropertySource ;
1213import org .springframework .core .env .Environment ;
1314import org .springframework .dao .annotation .PersistenceExceptionTranslationPostProcessor ;
2021
2122import com .google .common .base .Preconditions ;
2223
23- // @Configuration
24+ @ Configuration
2425@ EnableTransactionManagement
2526@ PropertySource ({ "classpath:persistence-mysql.properties" })
2627@ ComponentScan ({ "org.baeldung.persistence" })
@@ -33,14 +34,15 @@ public PersistenceJPAConfig() {
3334 super ();
3435 }
3536
37+ // beans
38+
3639 @ Bean
3740 public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean () {
3841 final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean ();
3942 em .setDataSource (dataSource ());
4043 em .setPackagesToScan (new String [] { "org.baeldung.persistence.model" });
4144
4245 final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter ();
43- // vendorAdapter.set
4446 em .setJpaVendorAdapter (vendorAdapter );
4547 em .setJpaProperties (additionalProperties ());
4648
Original file line number Diff line number Diff line change 1- package org .baeldung .spring ;
1+ package org .baeldung .config ;
22
33import org .springframework .context .annotation .ComponentScan ;
4- import org .springframework .context .annotation .Configuration ;
54import org .springframework .context .annotation .ImportResource ;
65import org .springframework .transaction .annotation .EnableTransactionManagement ;
76
8- @ Configuration
7+ // @Configuration
98@ EnableTransactionManagement
109@ ComponentScan ({ "org.baeldung.persistence" })
1110@ ImportResource ({ "classpath:jpaConfig.xml" })
Original file line number Diff line number Diff line change @@ -23,4 +23,8 @@ public void create(final Foo entity) {
2323 dao .create (entity );
2424 }
2525
26+ public Foo findOne (final long id ) {
27+ return dao .findOne (id );
28+ }
29+
2630}
Original file line number Diff line number Diff line change 22
33import static org .apache .commons .lang3 .RandomStringUtils .randomAlphabetic ;
44
5+ import org .baeldung .config .PersistenceJPAConfig ;
56import org .baeldung .persistence .model .Foo ;
6- import org .baeldung . spring . PersistenceJPAConfig ;
7+ import org .junit . Assert ;
78import org .junit .Test ;
89import org .junit .runner .RunWith ;
910import org .springframework .beans .factory .annotation .Autowired ;
@@ -55,4 +56,12 @@ public final void temp_whenInvalidEntityIsCreated_thenDataException() {
5556 service .create (new Foo ());
5657 }
5758
59+ @ Test
60+ public final void whenEntityIsCreated_thenFound () {
61+ final Foo fooEntity = new Foo ("abc" );
62+ service .create (fooEntity );
63+ final Foo found = service .findOne (fooEntity .getId ());
64+ Assert .assertNotNull (found );
65+ }
66+
5867}
You can’t perform that action at this time.
0 commit comments