18
18
import com .wechat .pay .java .core .certificate .model .DownloadCertificateResponse ;
19
19
import com .wechat .pay .java .core .certificate .model .EncryptCertificate ;
20
20
import com .wechat .pay .java .core .cipher .RSASigner ;
21
+ import com .wechat .pay .java .core .http .DefaultHttpClientBuilder ;
21
22
import com .wechat .pay .java .core .http .HttpClient ;
22
23
import com .wechat .pay .java .core .http .HttpHeaders ;
23
24
import com .wechat .pay .java .core .http .okhttp .OkHttpClientAdapter ;
24
25
import com .wechat .pay .java .core .util .GsonUtil ;
25
26
import com .wechat .pay .java .core .util .NonceUtil ;
27
+ import java .net .InetSocketAddress ;
28
+ import java .net .Proxy ;
26
29
import java .util .ArrayList ;
27
30
import java .util .stream .Stream ;
28
31
import okhttp3 .MediaType ;
31
34
import okhttp3 .Response ;
32
35
import okhttp3 .ResponseBody ;
33
36
import org .junit .jupiter .api .BeforeAll ;
37
+ import org .junit .jupiter .api .Disabled ;
34
38
import org .junit .jupiter .api .Test ;
35
39
import org .junit .jupiter .params .ParameterizedTest ;
36
40
import org .junit .jupiter .params .provider .MethodSource ;
37
41
38
42
class RSAAutoCertificateConfigTest implements ConfigTest {
39
43
40
44
static HttpClient httpClient ;
45
+ static OkHttpClient okHttpClient ;
41
46
42
47
@ BeforeAll
43
48
static void initHttpClient () {
@@ -48,7 +53,7 @@ public <T> boolean validate(HttpHeaders responseHeaders, String body) {
48
53
return true ;
49
54
}
50
55
};
51
- OkHttpClient okHttpClient =
56
+ okHttpClient =
52
57
new OkHttpClient .Builder ()
53
58
.addInterceptor (
54
59
chain -> {
@@ -121,7 +126,16 @@ static Stream<Builder> BuilderProvider() {
121
126
.privateKeyFromPath (MERCHANT_PRIVATE_KEY_PATH )
122
127
.merchantSerialNumber (MERCHANT_CERTIFICATE_SERIAL_NUMBER )
123
128
.httpClient (httpClient )
124
- .apiV3Key (API_V3_KEY ));
129
+ .apiV3Key (API_V3_KEY ),
130
+
131
+ // with http client builder
132
+ new Builder ()
133
+ .merchantId ("1123456" )
134
+ .privateKeyFromPath (MERCHANT_PRIVATE_KEY_PATH )
135
+ .merchantSerialNumber (MERCHANT_CERTIFICATE_SERIAL_NUMBER )
136
+ .apiV3Key (API_V3_KEY )
137
+ .httpClientBuilder (
138
+ new DefaultHttpClientBuilder ().writeTimeoutMs (1000 ).okHttpClient (okHttpClient )));
125
139
}
126
140
127
141
@ Test
@@ -144,4 +158,23 @@ public Config createConfig() {
144
158
.httpClient (httpClient )
145
159
.build ();
146
160
}
161
+
162
+ @ Disabled ("only available in production environment" )
163
+ @ Test
164
+ void testAutoCertificateWithProxy () {
165
+ DefaultHttpClientBuilder clientBuilder =
166
+ new DefaultHttpClientBuilder ()
167
+ .proxy (new Proxy (Proxy .Type .HTTP , new InetSocketAddress ("127.0.0.1" , 12639 )));
168
+
169
+ RSAAutoCertificateConfig config =
170
+ new Builder ()
171
+ .merchantId ("" )
172
+ .privateKey ("" )
173
+ .merchantSerialNumber ("" )
174
+ .httpClientBuilder (clientBuilder )
175
+ .apiV3Key ("" )
176
+ .build ();
177
+
178
+ assertNotNull (config .createValidator ());
179
+ }
147
180
}
0 commit comments