5
5
import com .github .tomakehurst .wiremock .matching .EqualToPattern ;
6
6
import com .github .tomakehurst .wiremock .matching .UrlPattern ;
7
7
import dev .rilling .webmention4j .common .Webmention ;
8
- import dev .rilling .webmention4j .common .test .AutoClosableExtension ;
9
8
import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
10
9
import org .apache .hc .client5 .http .impl .classic .HttpClients ;
11
10
import org .apache .hc .core5 .http .HttpHeaders ;
12
11
import org .apache .hc .core5 .http .HttpStatus ;
12
+ import org .junit .jupiter .api .AutoClose ;
13
13
import org .junit .jupiter .api .DisplayName ;
14
14
import org .junit .jupiter .api .Tag ;
15
15
import org .junit .jupiter .api .Test ;
@@ -32,9 +32,8 @@ class EndpointServiceSpecIT {
32
32
.options (wireMockConfig ().dynamicPort ())
33
33
.build ();
34
34
35
- @ RegisterExtension
36
- static final AutoClosableExtension <CloseableHttpClient > HTTP_CLIENT_EXTENSION = new AutoClosableExtension <>(
37
- HttpClients ::createDefault );
35
+ @ AutoClose
36
+ static final CloseableHttpClient HTTP_CLIENT = HttpClients .createDefault ();
38
37
39
38
final EndpointService endpointService = new EndpointService ();
40
39
@@ -48,7 +47,7 @@ void sendsEncodedData() throws IOException {
48
47
URI source = URI .create ("https://waterpigs.example/post-by-barnaby" );
49
48
URI target = URI .create ("https://aaronpk.example/post-by-aaron" );
50
49
51
- endpointService .notifyEndpoint (HTTP_CLIENT_EXTENSION . get () , endpoint , new Webmention (source , target ));
50
+ endpointService .notifyEndpoint (HTTP_CLIENT , endpoint , new Webmention (source , target ));
52
51
53
52
UrlPattern urlPattern = new UrlPattern (new EqualToPattern ("/webmention-endpoint" , false ), false );
54
53
EqualToPattern contentTypePattern = new EqualToPattern ("application/x-www-form-urlencoded; charset=UTF-8" );
@@ -68,7 +67,7 @@ void keepsQueryParams() throws IOException {
68
67
URI source = URI .create ("https://waterpigs.example/post-by-barnaby" );
69
68
URI target = URI .create ("https://aaronpk.example/post-by-aaron" );
70
69
71
- endpointService .notifyEndpoint (HTTP_CLIENT_EXTENSION . get () , endpoint , new Webmention (source , target ));
70
+ endpointService .notifyEndpoint (HTTP_CLIENT , endpoint , new Webmention (source , target ));
72
71
73
72
UrlPattern urlPattern = new UrlPattern (new EqualToPattern ("/webmention-endpoint?version=1" , false ), false );
74
73
EqualToPattern bodyPattern = new EqualToPattern ("source=https%3A%2F%2Fwaterpigs.example%2Fpost-by-barnaby" +
@@ -86,7 +85,7 @@ void returnsMonitoringUrlFor201() throws IOException {
86
85
URI source = URI .create ("https://waterpigs.example/post-by-barnaby" );
87
86
URI target = URI .create ("https://aaronpk.example/post-by-aaron" );
88
87
89
- assertThat (endpointService .notifyEndpoint (HTTP_CLIENT_EXTENSION . get () ,
88
+ assertThat (endpointService .notifyEndpoint (HTTP_CLIENT ,
90
89
URI .create (ENDPOINT_SERVER .url ("/webmention-endpoint" )),
91
90
new Webmention (source , target ))).contains (URI .create ("https://example.com/monitoring" ));
92
91
}
@@ -101,7 +100,7 @@ void returnsNoMonitoringUrlForOthers() throws IOException {
101
100
URI source = URI .create ("https://waterpigs.example/post-by-barnaby" );
102
101
URI target = URI .create ("https://aaronpk.example/post-by-aaron" );
103
102
104
- assertThat (endpointService .notifyEndpoint (HTTP_CLIENT_EXTENSION . get () ,
103
+ assertThat (endpointService .notifyEndpoint (HTTP_CLIENT ,
105
104
URI .create (ENDPOINT_SERVER .url ("/webmention-endpoint" )),
106
105
new Webmention (source , target ))).isEmpty ();
107
106
}
@@ -116,13 +115,13 @@ void allows2XXStatus() throws IOException {
116
115
URI source = URI .create ("https://waterpigs.example/post-by-barnaby" );
117
116
URI target = URI .create ("https://aaronpk.example/post-by-aaron" );
118
117
119
- endpointService .notifyEndpoint (HTTP_CLIENT_EXTENSION . get () ,
118
+ endpointService .notifyEndpoint (HTTP_CLIENT ,
120
119
URI .create (ENDPOINT_SERVER .url ("/webmention-endpoint-ok" )),
121
120
new Webmention (source , target ));
122
- endpointService .notifyEndpoint (HTTP_CLIENT_EXTENSION . get () ,
121
+ endpointService .notifyEndpoint (HTTP_CLIENT ,
123
122
URI .create (ENDPOINT_SERVER .url ("/webmention-endpoint-created" )),
124
123
new Webmention (source , target ));
125
- endpointService .notifyEndpoint (HTTP_CLIENT_EXTENSION . get () ,
124
+ endpointService .notifyEndpoint (HTTP_CLIENT ,
126
125
URI .create (ENDPOINT_SERVER .url ("/webmention-endpoint-accepted" )),
127
126
new Webmention (source , target ));
128
127
}
@@ -138,16 +137,16 @@ void throwsForNon2XXStatus() {
138
137
URI source = URI .create ("https://waterpigs.example/post-by-barnaby" );
139
138
URI target = URI .create ("https://aaronpk.example/post-by-aaron" );
140
139
141
- assertThatThrownBy (() -> endpointService .notifyEndpoint (HTTP_CLIENT_EXTENSION . get () ,
140
+ assertThatThrownBy (() -> endpointService .notifyEndpoint (HTTP_CLIENT ,
142
141
URI .create (ENDPOINT_SERVER .url ("/webmention-endpoint-client" )),
143
142
new Webmention (source , target ))).isInstanceOf (IOException .class );
144
- assertThatThrownBy (() -> endpointService .notifyEndpoint (HTTP_CLIENT_EXTENSION . get () ,
143
+ assertThatThrownBy (() -> endpointService .notifyEndpoint (HTTP_CLIENT ,
145
144
URI .create (ENDPOINT_SERVER .url ("/webmention-endpoint-unauthorized" )),
146
145
new Webmention (source , target ))).isInstanceOf (IOException .class );
147
- assertThatThrownBy (() -> endpointService .notifyEndpoint (HTTP_CLIENT_EXTENSION . get () ,
146
+ assertThatThrownBy (() -> endpointService .notifyEndpoint (HTTP_CLIENT ,
148
147
URI .create (ENDPOINT_SERVER .url ("/webmention-endpoint-not-found" )),
149
148
new Webmention (source , target ))).isInstanceOf (IOException .class );
150
- assertThatThrownBy (() -> endpointService .notifyEndpoint (HTTP_CLIENT_EXTENSION . get () ,
149
+ assertThatThrownBy (() -> endpointService .notifyEndpoint (HTTP_CLIENT ,
151
150
URI .create (ENDPOINT_SERVER .url ("/webmention-endpoint-server-error" )),
152
151
new Webmention (source , target ))).isInstanceOf (IOException .class );
153
152
}
0 commit comments