6
6
*/
7
7
package org .hibernate .jpa .test .transaction .batch ;
8
8
9
- import static org .assertj .core .api .Assertions .assertThatThrownBy ;
10
- import static org .hamcrest .MatcherAssert .assertThat ;
11
- import static org .hamcrest .core .Is .is ;
12
- import static org .junit .jupiter .api .Assertions .fail ;
13
-
14
9
import java .sql .PreparedStatement ;
15
10
import java .sql .SQLException ;
16
11
import java .util .ArrayList ;
17
12
import java .util .List ;
13
+ import java .util .Map ;
18
14
import java .util .concurrent .atomic .AtomicReference ;
15
+ import javax .persistence .Entity ;
16
+ import javax .persistence .GeneratedValue ;
17
+ import javax .persistence .Id ;
19
18
20
19
import org .hibernate .cfg .AvailableSettings ;
21
20
import org .hibernate .engine .jdbc .batch .internal .BatchBuilderImpl ;
24
23
import org .hibernate .engine .jdbc .batch .spi .Batch ;
25
24
import org .hibernate .engine .jdbc .batch .spi .BatchKey ;
26
25
import org .hibernate .engine .jdbc .spi .JdbcCoordinator ;
26
+ import org .hibernate .jpa .test .BaseEntityManagerFunctionalTestCase ;
27
27
28
28
import org .hibernate .testing .TestForIssue ;
29
- import org .hibernate .testing .orm .junit .EntityManagerFactoryScope ;
30
- import org .hibernate .testing .orm .junit .Jpa ;
31
- import org .hibernate .testing .orm .junit .Setting ;
32
- import org .hibernate .testing .orm .junit .SettingProvider ;
33
- import org .junit .jupiter .api .BeforeEach ;
34
- import org .junit .jupiter .api .Test ;
29
+ import org .junit .Before ;
30
+ import org .junit .Test ;
35
31
36
- import javax .persistence .Entity ;
37
- import javax .persistence .GeneratedValue ;
38
- import javax .persistence .Id ;
32
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
33
+ import static org .hamcrest .MatcherAssert .assertThat ;
34
+ import static org .hamcrest .core .Is .is ;
35
+ import static org .hibernate .testing .transaction .TransactionUtil .doInJPA ;
36
+ import static org .junit .jupiter .api .Assertions .fail ;
39
37
40
38
@ TestForIssue (jiraKey = "HHH-15082" )
41
- @ Jpa (
42
- annotatedClasses = {
43
- FailingAddToBatchTest .MyEntity .class
44
- },
45
- integrationSettings = {
46
- @ Setting (name = AvailableSettings .STATEMENT_BATCH_SIZE , value = "50" )
47
- },
48
- settingProviders = {
49
- @ SettingProvider (
50
- settingName = BatchBuilderInitiator .BUILDER ,
51
- provider = FailingAddToBatchTest .BatchBuilderSettingProvider .class
52
- )
53
- }
54
- )
55
- public class FailingAddToBatchTest {
39
+ public class FailingAddToBatchTest extends BaseEntityManagerFunctionalTestCase {
56
40
57
41
private static TestBatch testBatch ;
58
42
59
- @ BeforeEach
43
+ @ Override
44
+ protected void addConfigOptions (Map options ) {
45
+ options .put ( AvailableSettings .STATEMENT_BATCH_SIZE , 50 );
46
+ options .put ( BatchBuilderInitiator .BUILDER , TestBatchBuilder .class .getName () );
47
+ }
48
+
49
+ @ Override
50
+ protected Class <?>[] getAnnotatedClasses () {
51
+ return new Class [] {
52
+ MyEntity .class
53
+ };
54
+ }
55
+
56
+ @ Before
60
57
public void setup () {
61
58
TestBatch .nextAddToBatchFailure .set ( null );
62
59
}
63
60
64
61
@ Test
65
- public void testInsert (EntityManagerFactoryScope scope ) {
62
+ public void testInsert () {
66
63
RuntimeException simulatedAddToBatchFailure = new RuntimeException ( "Simulated RuntimeException" );
67
64
68
- scope . inTransaction ( em -> {
65
+ doInJPA ( this :: entityManagerFactory , em -> {
69
66
assertThatThrownBy ( () -> {
70
67
MyEntity entity = new MyEntity ();
71
68
entity .setText ( "initial" );
@@ -80,8 +77,8 @@ public void testInsert(EntityManagerFactoryScope scope) {
80
77
}
81
78
82
79
@ Test
83
- public void testUpdate (EntityManagerFactoryScope scope ) {
84
- Long id = scope . fromTransaction ( em -> {
80
+ public void testUpdate () {
81
+ Long id = doInJPA ( this :: entityManagerFactory , em -> {
85
82
MyEntity entity = new MyEntity ();
86
83
entity .setText ( "initial" );
87
84
em .persist ( entity );
@@ -90,7 +87,7 @@ public void testUpdate(EntityManagerFactoryScope scope) {
90
87
91
88
RuntimeException simulatedAddToBatchFailure = new RuntimeException ( "Simulated RuntimeException" );
92
89
93
- scope . inTransaction ( em -> {
90
+ doInJPA ( this :: entityManagerFactory , em -> {
94
91
assertThatThrownBy ( () -> {
95
92
MyEntity entity = em .find ( MyEntity .class , id );
96
93
TestBatch .nextAddToBatchFailure .set ( simulatedAddToBatchFailure );
@@ -104,8 +101,8 @@ public void testUpdate(EntityManagerFactoryScope scope) {
104
101
}
105
102
106
103
@ Test
107
- public void testRemove (EntityManagerFactoryScope scope ) {
108
- Long id = scope . fromTransaction ( em -> {
104
+ public void testRemove () {
105
+ Long id = doInJPA ( this :: entityManagerFactory , em -> {
109
106
MyEntity entity = new MyEntity ();
110
107
entity .setText ( "initial" );
111
108
em .persist ( entity );
@@ -114,7 +111,7 @@ public void testRemove(EntityManagerFactoryScope scope) {
114
111
115
112
RuntimeException simulatedAddToBatchFailure = new RuntimeException ( "Simulated RuntimeException" );
116
113
117
- scope . inTransaction ( em -> {
114
+ doInJPA ( this :: entityManagerFactory , em -> {
118
115
assertThatThrownBy ( () -> {
119
116
MyEntity entity = em .find ( MyEntity .class , id );
120
117
TestBatch .nextAddToBatchFailure .set ( simulatedAddToBatchFailure );
@@ -162,13 +159,6 @@ public void setText(String text) {
162
159
}
163
160
}
164
161
165
- public static class BatchBuilderSettingProvider implements SettingProvider .Provider <String > {
166
- @ Override
167
- public String getSetting () {
168
- return TestBatchBuilder .class .getName ();
169
- }
170
- }
171
-
172
162
public static class TestBatch extends BatchingBatch {
173
163
private static final AtomicReference <RuntimeException > nextAddToBatchFailure = new AtomicReference <>();
174
164
0 commit comments