File tree Expand file tree Collapse file tree 5 files changed +46
-7
lines changed
groovy/pl/allegro/tech/workshops/testsparallelexecution/email/messagebroker Expand file tree Collapse file tree 5 files changed +46
-7
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,6 @@ dependencies {
27
27
testImplementation project(' :commons' )
28
28
testImplementation project(' :commons-rest' )
29
29
testImplementation ' pl.allegro.tech.hermes:hermes-mock:2.5.2'
30
- testImplementation ' org.spockframework:spock-junit4:2.4-M1-groovy-4.0'
31
30
testImplementation ' org.spockframework:spock-spring:2.4-M1-groovy-4.0'
32
31
}
33
32
Original file line number Diff line number Diff line change 1
1
package pl.allegro.tech.workshops.testsparallelexecution.email.messagebroker
2
2
3
- import org.junit.ClassRule
3
+ import org.spockframework.spring.EnableSharedInjection
4
+ import org.springframework.beans.factory.annotation.Autowired
4
5
import org.springframework.beans.factory.annotation.Value
5
- import pl.allegro.tech.hermes.mock.HermesMockRule
6
+ import org.springframework.context.annotation.Import
7
+ import pl.allegro.tech.hermes.mock.HermesMock
6
8
import pl.allegro.tech.workshops.testsparallelexecution.BaseTestWithRest
7
9
import spock.lang.Shared
8
10
@@ -12,14 +14,24 @@ import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR
12
14
import static org.springframework.http.HttpStatus.OK
13
15
import static pl.allegro.tech.hermes.mock.exchange.Response.Builder.aResponse
14
16
15
- class EmailsByMessageBrokerResourceTest extends BaseTestWithRest {
17
+ @EnableSharedInjection
18
+ @Import (HermesMockConfig )
19
+ class EmailsByMessageBrokerResourceTest extends BaseTestWithRest implements HermesMockPortSupport {
16
20
17
21
@Value (' ${application.services.message-broker.topic}' )
18
22
private String topic
19
23
20
- @ClassRule
21
24
@Shared
22
- private HermesMockRule hermesMock = new HermesMockRule (8089 )
25
+ @Autowired
26
+ private HermesMock hermesMock
27
+
28
+ def setupSpec () {
29
+ hermesMock. start()
30
+ }
31
+
32
+ def cleanupSpec () {
33
+ hermesMock. stop()
34
+ }
23
35
24
36
private String subject = " New workshops!"
25
37
Original file line number Diff line number Diff line change
1
+ package pl.allegro.tech.workshops.testsparallelexecution.email.messagebroker
2
+
3
+ import org.springframework.beans.factory.annotation.Value
4
+ import org.springframework.boot.test.context.TestConfiguration
5
+ import org.springframework.context.annotation.Bean
6
+ import pl.allegro.tech.hermes.mock.HermesMock
7
+
8
+ @TestConfiguration
9
+ class HermesMockConfig {
10
+ @Bean
11
+ HermesMock getHermesMock (@Value (' ${hermes-mock.port}' ) int hermesMockPort ) {
12
+ return new HermesMock.Builder (). withPort(hermesMockPort). build()
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ package pl.allegro.tech.workshops.testsparallelexecution.email.messagebroker
2
+
3
+ import org.springframework.test.context.DynamicPropertyRegistry
4
+ import org.springframework.test.context.DynamicPropertySource
5
+ import org.springframework.test.util.TestSocketUtils
6
+
7
+ trait HermesMockPortSupport {
8
+
9
+ @DynamicPropertySource
10
+ static void configurePort(DynamicPropertyRegistry registry) {
11
+ int port = TestSocketUtils . findAvailableTcpPort()
12
+ registry. add(" hermes-mock.port" , () -> port)
13
+ }
14
+ }
Original file line number Diff line number Diff line change 1
- application.services.message-broker.url : http://localhost:8089
1
+ application.services.message-broker.url : http://localhost:${hermes-mock.port}
2
2
application.services.message-broker.topic : pl.allegro.tech.workshops.testsparallelexecution.email
You can’t perform that action at this time.
0 commit comments