Skip to content

Commit a056d1e

Browse files
committed
QuickPerfSpringRunner did not call the Spring TestExecutionListener instances before the test method execution
1 parent 34c63a5 commit a056d1e

File tree

6 files changed

+117
-7
lines changed

6 files changed

+117
-7
lines changed

spring/junit4-spring-boot-test/src/main/java/org/quickperf/spring/springboottest/jpa/entity/Player.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class Player implements Serializable {
1919

2020
@Id
21-
@GeneratedValue(strategy = GenerationType.SEQUENCE)
21+
@GeneratedValue(strategy = GenerationType.IDENTITY)
2222
private Long id;
2323

2424
private String firstName;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
3+
*
4+
* http://www.apache.org/licenses/LICENSE-2.0
5+
*
6+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
7+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
8+
*
9+
* Copyright 2019-2020 the original author or authors.
10+
*/
11+
12+
package org.quickperf.spring.springboottest;
13+
14+
import org.junit.Before;
15+
import org.junit.Test;
16+
import org.junit.runner.RunWith;
17+
import org.quickperf.annotation.DisableGlobalAnnotations;
18+
import org.quickperf.jvm.allocation.AllocationUnit;
19+
import org.quickperf.jvm.annotations.HeapSize;
20+
import org.quickperf.spring.junit4.QuickPerfSpringRunner;
21+
import org.quickperf.spring.springboottest.jpa.entity.Player;
22+
import org.quickperf.spring.springboottest.jpa.repository.PlayerRepository;
23+
import org.quickperf.spring.sql.QuickPerfSqlConfig;
24+
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
26+
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
27+
import org.springframework.context.annotation.Import;
28+
29+
import java.util.List;
30+
31+
import static org.assertj.core.api.Assertions.assertThat;
32+
33+
@RunWith(QuickPerfSpringRunner.class)
34+
@Import(QuickPerfSqlConfig.class)
35+
@DataJpaTest()
36+
@DisableGlobalAnnotations
37+
public class QuickPerfSpringRunnerBeforeNewJvmTest {
38+
39+
@Autowired
40+
private TestEntityManager testEntityManager;
41+
42+
@Autowired
43+
private PlayerRepository playerRepository;
44+
45+
@Before
46+
public void before() {
47+
Player player = new Player();
48+
testEntityManager.persist(player);
49+
}
50+
51+
@HeapSize(value = 50, unit = AllocationUnit.MEGA_BYTE)
52+
@Test
53+
public void should_find_all_players() {
54+
List<Player> players = playerRepository.findAll();
55+
assertThat(players).hasSize(3);
56+
}
57+
58+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
3+
*
4+
* http://www.apache.org/licenses/LICENSE-2.0
5+
*
6+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
7+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
8+
*
9+
* Copyright 2019-2020 the original author or authors.
10+
*/
11+
12+
package org.quickperf.spring.springboottest;
13+
14+
import org.junit.Before;
15+
import org.junit.Test;
16+
import org.junit.runner.RunWith;
17+
import org.quickperf.annotation.DisableGlobalAnnotations;
18+
import org.quickperf.spring.junit4.QuickPerfSpringRunner;
19+
import org.quickperf.spring.springboottest.jpa.entity.Player;
20+
import org.quickperf.spring.springboottest.jpa.repository.PlayerRepository;
21+
import org.quickperf.spring.sql.QuickPerfSqlConfig;
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
24+
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
25+
import org.springframework.context.annotation.Import;
26+
27+
import java.util.List;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
@RunWith(QuickPerfSpringRunner.class)
32+
@Import(QuickPerfSqlConfig.class)
33+
@DataJpaTest()
34+
@DisableGlobalAnnotations
35+
public class QuickPerfSpringRunnerBeforeTest {
36+
37+
@Autowired
38+
private TestEntityManager testEntityManager;
39+
40+
@Autowired
41+
private PlayerRepository playerRepository;
42+
43+
@Before
44+
public void before() {
45+
Player player = new Player();
46+
testEntityManager.persist(player);
47+
}
48+
49+
@Test
50+
public void should_find_all_players() {
51+
List<Player> players = playerRepository.findAll();
52+
assertThat(players).hasSize(3);
53+
}
54+
55+
}

spring/junit4-spring3/src/main/java/org/quickperf/spring/junit4/SpringRunnerWithQuickPerfFeatures.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ protected Statement methodInvoker(FrameworkMethod frameworkMethod, Object test)
5656

5757
@Override
5858
public Statement withBefores(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
59-
Statement springBefores = super.withBefores(frameworkMethod, testInstance, statement);
60-
return quickPerfJUnitRunner.withBefores(frameworkMethod, testInstance, springBefores);
59+
return super.withBefores(frameworkMethod, testInstance, statement);
6160
}
6261

6362
@Override

spring/junit4-spring4/src/main/java/org/quickperf/spring/junit4/SpringRunnerWithQuickPerfFeatures.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ protected Statement methodInvoker(FrameworkMethod frameworkMethod, Object test)
5656

5757
@Override
5858
public Statement withBefores(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
59-
Statement springBefores = super.withBefores(frameworkMethod, testInstance, statement);
60-
return quickPerfJUnitRunner.withBefores(frameworkMethod, testInstance, springBefores);
59+
return super.withBefores(frameworkMethod, testInstance, statement);
6160
}
6261

6362
@Override

spring/junit4-spring5/src/main/java/org/quickperf/spring/junit4/SpringRunnerWithQuickPerfFeatures.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ protected Statement methodInvoker(FrameworkMethod frameworkMethod, Object test)
5656

5757
@Override
5858
public Statement withBefores(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
59-
Statement springBefores = super.withBefores(frameworkMethod, testInstance, statement);
60-
return quickPerfJUnitRunner.withBefores(frameworkMethod, testInstance, springBefores);
59+
return super.withBefores(frameworkMethod, testInstance, statement);
6160
}
6261

6362
@Override

0 commit comments

Comments
 (0)