单元测试覆盖
parent
1deae436d5
commit
4697d99d44
|
|
@ -40,7 +40,7 @@ public abstract class AbstractProfile implements Profile {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpProfile getHttpclientProfile() {
|
public HttpProfile getHttpProfile() {
|
||||||
return httpProfile;
|
return httpProfile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,5 +37,5 @@ public interface Profile {
|
||||||
*
|
*
|
||||||
* @return HttpclientProfile
|
* @return HttpclientProfile
|
||||||
*/
|
*/
|
||||||
HttpProfile getHttpclientProfile();
|
HttpProfile getHttpProfile();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ public final class DefaultValidator implements Validator {
|
||||||
public DefaultValidator(Profile profile) {
|
public DefaultValidator(Profile profile) {
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
this.verifier = profile.getSignature().getVerifier();
|
this.verifier = profile.getSignature().getVerifier();
|
||||||
this.httpLogger = new HttpLogger(profile.getHttpclientProfile().logEnabled());
|
this.httpLogger = new HttpLogger(profile.getHttpProfile() == null || profile.getHttpProfile().logEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInvalidHttpCode(int httpCode) {
|
private boolean isInvalidHttpCode(int httpCode) {
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ public abstract class AbstractApiClient implements ApiClient {
|
||||||
this.privacy = profile.getPrivacy();
|
this.privacy = profile.getPrivacy();
|
||||||
this.signature = profile.getSignature();
|
this.signature = profile.getSignature();
|
||||||
this.validator = new DefaultValidator(profile);
|
this.validator = new DefaultValidator(profile);
|
||||||
this.httpLogger = new HttpLogger(profile.getHttpclientProfile().logEnabled());
|
this.httpLogger = new HttpLogger(profile.getHttpProfile() == null || profile.getHttpProfile().logEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -99,8 +99,8 @@ public abstract class AbstractApiClient implements ApiClient {
|
||||||
.addHeader(AUTHORIZATION, getAuthorization(request))
|
.addHeader(AUTHORIZATION, getAuthorization(request))
|
||||||
.addHeader(USER_AGENT, getUserAgent())
|
.addHeader(USER_AGENT, getUserAgent())
|
||||||
.addHeaders(request.getHttpHeaders().getHeaders())
|
.addHeaders(request.getHttpHeaders().getHeaders())
|
||||||
.addHeaders(getProfile().getHttpclientProfile().getHeaders())
|
.addHeaders(getProfile().getHttpProfile().getHeaders())
|
||||||
.compression(getProfile().getHttpclientProfile().compressionEnabled())
|
.compression(getProfile().getHttpProfile().compressionEnabled())
|
||||||
.parameters(request.getParameters())
|
.parameters(request.getParameters())
|
||||||
.body(request.getRequestBody());
|
.body(request.getRequestBody());
|
||||||
if (Objects.equals(HttpMethod.POST, request.getHttpMethod())) {
|
if (Objects.equals(HttpMethod.POST, request.getHttpMethod())) {
|
||||||
|
|
@ -111,10 +111,10 @@ public abstract class AbstractApiClient implements ApiClient {
|
||||||
|
|
||||||
private String fullUrlPattern(HttpRequest request) {
|
private String fullUrlPattern(HttpRequest request) {
|
||||||
// 拼接完整URL
|
// 拼接完整URL
|
||||||
if (getProfile().getHttpclientProfile().online()) {
|
if (getProfile().getHttpProfile().online()) {
|
||||||
return Host.ONLINE_GATEWAY.address(request.getUrl());
|
return Host.ONLINE_GATEWAY.address(request.getUrl());
|
||||||
} else {
|
} else {
|
||||||
return getProfile().getHttpclientProfile().getHost() + request.getUrl();
|
return getProfile().getHttpProfile().getHost() + request.getUrl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
package com.czcb.scfs.api.core.http;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author wangwei
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
public interface AbstractApiClientBuilder<T extends AbstractApiClientBuilder<T>> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 复制工厂,复制一个当前对象
|
|
||||||
*
|
|
||||||
* @return 对象的副本
|
|
||||||
*/
|
|
||||||
T newInstance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建 AbstractHttpClient
|
|
||||||
*
|
|
||||||
* @return AbstractHttpClient
|
|
||||||
*/
|
|
||||||
AbstractApiClient build();
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.czcb.scfs.api.core.http;
|
package com.czcb.scfs.api.core.http;
|
||||||
|
|
||||||
|
import com.czcb.scfs.api.core.ApiClient;
|
||||||
import com.czcb.scfs.api.core.Profile;
|
import com.czcb.scfs.api.core.Profile;
|
||||||
import com.czcb.scfs.api.core.http.client.ApacheHttpclient;
|
import com.czcb.scfs.api.core.http.client.ApacheHttpclient;
|
||||||
import org.apache.hc.client5.http.classic.HttpClient;
|
import org.apache.hc.client5.http.classic.HttpClient;
|
||||||
|
|
@ -23,29 +24,28 @@ import static java.util.Objects.requireNonNull;
|
||||||
*
|
*
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public class DefaultApiClientBuilder implements AbstractApiClientBuilder<DefaultApiClientBuilder> {
|
public final class ApiClientBuilder {
|
||||||
private Profile profile;
|
private Profile profile;
|
||||||
private HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
|
|
||||||
/**
|
private ApiClientBuilder() {
|
||||||
* 复制工厂,复制一个当前对象
|
|
||||||
*
|
|
||||||
* @return 对象的副本
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public DefaultApiClientBuilder newInstance() {
|
|
||||||
DefaultApiClientBuilder result = new DefaultApiClientBuilder();
|
|
||||||
result.profile = profile;
|
|
||||||
result.httpClient = httpClient;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultApiClientBuilder profile(Profile profile) {
|
/**
|
||||||
this.profile = requireNonNull(profile);
|
* 创建DefaultApiClientBuilder对象
|
||||||
|
*
|
||||||
|
* @return DefaultApiClientBuilder
|
||||||
|
*/
|
||||||
|
public static ApiClientBuilder custom() {
|
||||||
|
return new ApiClientBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiClientBuilder profile(Profile profile) {
|
||||||
|
this.profile = profile;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultApiClientBuilder httpClient(HttpClient httpClient) {
|
public ApiClientBuilder httpClient(HttpClient httpClient) {
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClient;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -55,14 +55,18 @@ public class DefaultApiClientBuilder implements AbstractApiClientBuilder<Default
|
||||||
*
|
*
|
||||||
* @return httpClient
|
* @return httpClient
|
||||||
*/
|
*/
|
||||||
@Override
|
public ApiClient build() {
|
||||||
public AbstractApiClient build() {
|
requireNonNull(profile);
|
||||||
|
|
||||||
if (Objects.nonNull(httpClient)) {
|
if (Objects.nonNull(httpClient)) {
|
||||||
return new ApacheHttpclient(httpClient, profile);
|
return new ApacheHttpclient(httpClient, profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// http 客户端配置
|
// http 客户端配置
|
||||||
HttpProfile httpProfile = profile.getHttpclientProfile();
|
HttpProfile httpProfile = profile.getHttpProfile();
|
||||||
|
if (Objects.isNull(httpProfile)) {
|
||||||
|
httpProfile = new DefaultHttpProfile.Builder().build();
|
||||||
|
}
|
||||||
|
|
||||||
// 禁用自动重试
|
// 禁用自动重试
|
||||||
HttpClientBuilder builder = HttpClients.custom().disableAutomaticRetries();
|
HttpClientBuilder builder = HttpClients.custom().disableAutomaticRetries();
|
||||||
|
|
@ -15,17 +15,10 @@ class DefaultChannelTest {
|
||||||
Assertions.assertEquals("123456", channel.getAppNo());
|
Assertions.assertEquals("123456", channel.getAppNo());
|
||||||
Assertions.assertEquals("0000", channel.getChannelNo());
|
Assertions.assertEquals("0000", channel.getChannelNo());
|
||||||
|
|
||||||
|
DefaultChannel.Builder builder = new DefaultChannel.Builder().channelNo("0000");
|
||||||
|
Assertions.assertThrows(NullPointerException.class, builder::build);
|
||||||
|
|
||||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
DefaultChannel.Builder builder2 = new DefaultChannel.Builder().appNo("0000");
|
||||||
new DefaultChannel.Builder()
|
Assertions.assertThrows(NullPointerException.class, builder2::build);
|
||||||
.channelNo("0000")
|
|
||||||
.build();
|
|
||||||
});
|
|
||||||
|
|
||||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
|
||||||
new DefaultChannel.Builder()
|
|
||||||
.appNo("0000")
|
|
||||||
.build();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -70,4 +70,59 @@ public final class KeyText {
|
||||||
public static X509Certificate loadTestRSA() {
|
public static X509Certificate loadTestRSA() {
|
||||||
return PemFile.loadX509FromString(CERTIFICATE_TEXT_RSA);
|
return PemFile.loadX509FromString(CERTIFICATE_TEXT_RSA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static final String PRIVATE_RSA_2 = "-----BEGIN PRIVATE KEY-----\n" +
|
||||||
|
"MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC5CDjdTuMXkccn9l1PcM84TWTi\n" +
|
||||||
|
"h4BWFPlm9KUwYd8uWFqw8P46cwHbtBKj0yWRfW5GYi4TfVkdPCV1xDalYP+YZT4MREbgpLi8VmKX\n" +
|
||||||
|
"LyYX5lD4PPqOBpOniR/1l9sh9otN1xd6zpzxs9hXx4YxGowzKvkowyuFw0mksqWzfbP/C1cAbGpu\n" +
|
||||||
|
"HmrIN7MCiKArdGCYbgxESJ3Udz67jktQwlCtqXrkHDWdkAlnk6Ktt3HOfIIDoQcOY3iaVzfxVgsr\n" +
|
||||||
|
"jEapAJEhjn3wPjZYCud2a8NOG0AHdRDvbuWwCJz6fZyNLZJwjmJLClQQ/ouG0TGyTwQWCWvzY6v/\n" +
|
||||||
|
"owpRRgbJ3Tb1AgMBAAECggEAAN+ykQz90o8sLxqhPy5LtDrdVpqINx/bO6q9GvjjWm8tYneI49LG\n" +
|
||||||
|
"N/jmO6LUIxdCDZAKIqptYM93Z9J45ZgLLPeRbvJlmUr92lnYFlmxJty+FiYHkuMiEGD75yeD7+mf\n" +
|
||||||
|
"p8rzv+8424VbaLK3BgVXkyhJS/F8A6Iz91Smpq3Zy0MK47FX7DWgITYJvcT/Tmbpw32AHJWOgNSY\n" +
|
||||||
|
"C49CL+gQC4yTK2nCTqcnLPmMRQvuCofmGnOKWjJ6U56CoS8+BDAp964zBi81VrD5IMiq1mXDEHC7\n" +
|
||||||
|
"wkvdOooJLUKhtp0gOEdAvghrILPlvgtQTpiRLn+fFEqv6huulAEl0w5e7/qzkQKBgQDlIC17Ckmh\n" +
|
||||||
|
"VE9LsxZxHqObwEraOogjjzYf0WoXXgb0vb+bl4B2+7ZntrMdV9/Tyi99LAqwKTT1TgCEG0r2uiRz\n" +
|
||||||
|
"00zU6QA+akc3YkZPK9RxOtWLQayDtNamrJKxbbQehxfpoiZOf70DTpdmp5hdDRswGTWAWuKXNnba\n" +
|
||||||
|
"i7Z5lPsxTQKBgQDOvBKWbbeOcodBAek6tpyFpeCGv/9EmYrW046zMPlvSFF/XGITfKliuPamwZ54\n" +
|
||||||
|
"0/Z4xAfR8VDRy9ps9FcCt5A5h2Y6dL6d5nt84um3QWkIStuq0oCR26sXerouWGWLwDa6WnlQfR3M\n" +
|
||||||
|
"4PXy55j2gPifiTipLiML8lfAxCiT8pjISQKBgGo2XF7pCfDLUGbbAdA2T8lnfktjTrCNNp3RScjD\n" +
|
||||||
|
"QZ46R5QsytRdItU5EBbOIWfgFduEiv/WWkJMgli6/ikZaMR4culPiVllktXNrKIOw1Ap4cvICdyT\n" +
|
||||||
|
"+90PqoCtRg3QufkHvZIuDMR3rh9cGXkpFi1Zwj9Z4igOi1IL6e66bScRAoGBAIwAdZ4Fw07mZI4z\n" +
|
||||||
|
"mxy12h3wDbNzho2QZaPCNVtIiUNBeF+F0q1buOIwXGjlqkotUTbLmngkshTBtrQebGZcpYEwHpzr\n" +
|
||||||
|
"vsLz+SDEEn6V/2ksOMLgN02Ps7f81uTX3Dzd+LIO3yUQ9gNvPWA4UzBsevKfXQ3FPtqyTZcvwEMh\n" +
|
||||||
|
"ATJxAoGATiwjlqy8spHJrfO5UuaUeUJuT8yAseeCltjh7sA4vzFDC+PIAqyA2Zvl1AG0XWQv6nN9\n" +
|
||||||
|
"NAczDbqj4uiQ+0Z852s6NqiJfWuicAm3D9440vUcAKKews7s1HcjYHD7/So1b3bAL8Q9+5VRvO96\n" +
|
||||||
|
"jvEdHwqZ9aas/Bp53njG+V7CU4o=\n" +
|
||||||
|
"-----END PRIVATE KEY-----";
|
||||||
|
|
||||||
|
public static final String CERTIFICATE_RSA_2 = "-----BEGIN CERTIFICATE-----\n" +
|
||||||
|
"MIIDtTCCAp2gAwIBAgIhAJyeRXbDplanspYB9xwLbzeIAiXxZzCmX6PNFBhBiWVPMA0GCSqGSIb3\n" +
|
||||||
|
"DQEBCwUAMIGNMQswCQYDVQQGEwJDTjESMBAGA1UECAwJ5rWZ5rGf55yBMRIwEAYDVQQHDAnmna3l\n" +
|
||||||
|
"t57luIIxITAfBgNVBAoMGOa1meaxn+eooOW3nuWVhuS4mumTtuihjDEYMBYGA1UECwwP5pWw5a2X\n" +
|
||||||
|
"6YeR6J6N6YOoMRkwFwYDVQQDDBBzY2ZzLmN6Y2IuY29tLmNuMB4XDTI0MDIyMDEwMzY0MVoXDTI5\n" +
|
||||||
|
"MDIyMDEwMzY0MVowgY0xCzAJBgNVBAYTAkNOMRIwEAYDVQQIDAnmtZnmsZ/nnIExEjAQBgNVBAcM\n" +
|
||||||
|
"CeadreW3nuW4gjEhMB8GA1UECgwY5rWZ5rGf56ig5bee5ZWG5Lia6ZO26KGMMRgwFgYDVQQLDA/m\n" +
|
||||||
|
"lbDlrZfph5Hono3pg6gxGTAXBgNVBAMMEHNjZnMuY3pjYi5jb20uY24wggEiMA0GCSqGSIb3DQEB\n" +
|
||||||
|
"AQUAA4IBDwAwggEKAoIBAQC5CDjdTuMXkccn9l1PcM84TWTih4BWFPlm9KUwYd8uWFqw8P46cwHb\n" +
|
||||||
|
"tBKj0yWRfW5GYi4TfVkdPCV1xDalYP+YZT4MREbgpLi8VmKXLyYX5lD4PPqOBpOniR/1l9sh9otN\n" +
|
||||||
|
"1xd6zpzxs9hXx4YxGowzKvkowyuFw0mksqWzfbP/C1cAbGpuHmrIN7MCiKArdGCYbgxESJ3Udz67\n" +
|
||||||
|
"jktQwlCtqXrkHDWdkAlnk6Ktt3HOfIIDoQcOY3iaVzfxVgsrjEapAJEhjn3wPjZYCud2a8NOG0AH\n" +
|
||||||
|
"dRDvbuWwCJz6fZyNLZJwjmJLClQQ/ouG0TGyTwQWCWvzY6v/owpRRgbJ3Tb1AgMBAAEwDQYJKoZI\n" +
|
||||||
|
"hvcNAQELBQADggEBAE4aQDkoMFIzIAWtJkvtmx2yLcEp7RRsnZEQPOpfyYauUGrzgU9VBj2lnEr3\n" +
|
||||||
|
"NGcW1JWrige6um5Wy3QWgba0EuM+n69w6CUxwEobZSnWZKMkTuaSa5WKR60/MsxiB5P0B9FfUFEd\n" +
|
||||||
|
"lkPc2vLSBKtLQcAp0SPxawvNtbnSFJAbyxOuQ5zczMcG0erq2t6AIA/nOYNkZedQXbE4vsmt9A29\n" +
|
||||||
|
"mRFOOOJEklUa9JKq/03FxDEDCAZsbVrByaio3u6CqO3+zNwm2Uhf8piUkcF45MNjWJAcehDjcrc4\n" +
|
||||||
|
"ZPZc8varEGWYvhF+K+hl70kdaBz7hwOX6dg3e2/yuOEzkD3LeTwpA4M=\n" +
|
||||||
|
"-----END CERTIFICATE-----";
|
||||||
|
|
||||||
|
public static PrivateKey loadTestPrivateKeyRSA2() {
|
||||||
|
return PemFile.loadPrivateKeyFromString(PRIVATE_RSA_2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static X509Certificate loadTestRSA2() {
|
||||||
|
return PemFile.loadX509FromString(CERTIFICATE_RSA_2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,68 @@
|
||||||
package com.czcb.scfs.api.core.cipher;
|
package com.czcb.scfs.api.core.cipher;
|
||||||
|
|
||||||
import com.czcb.scfs.api.core.KeyText;
|
import com.czcb.scfs.api.core.KeyText;
|
||||||
|
import com.czcb.scfs.api.core.util.PemFile;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
class CertificateValidityTest {
|
class CertificateValidityTest {
|
||||||
|
|
||||||
|
// public static final String PRIVATE_VALIDITY_RSA = "-----BEGIN PRIVATE KEY-----\n" +
|
||||||
|
// "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDBBz/n4yiesoy2bjJ/OYCa0x0k\n" +
|
||||||
|
// "EQ196AHQRt/xeDtk2UIbsiTc1GgHDY0gBEyG2atiJOsxbHgI1VwG2zB6gCkXvwd26nS1FAcSjeeZ\n" +
|
||||||
|
// "zjR+y32NSdVd5fekez0er3q43+hIUhCgLb0nQepLBqX0Gw72Q9Oi41DqWI0V8Dsuhn+TFQKcmTC4\n" +
|
||||||
|
// "7ub9RAFUvPXfYe76EYDfadymIdgqnGV5GS7HD/ByUBodw3hpRuZVTudCg90S05xTgUB/pmY5GnE9\n" +
|
||||||
|
// "IzaNbFC2O3fq+vXqdSseDzMnQaSAmUnghBe4LdWG5buhu+b2TxKdbFdy0wG6aiuDoxUCqT9cKQ89\n" +
|
||||||
|
// "mXLACoFe2DIxAgMBAAECggEAJ7BpKjGZqknNp3wQi3rED/GNGhucgdEowE22YaTGV5XZYy71p+dP\n" +
|
||||||
|
// "rXWSmSzxHEAY3mD3cA3cv3o5RhqfBO0hpeWMMB4Ema/wxVaisowE3LZUDi9KfRhaGzqQxmSv79/w\n" +
|
||||||
|
// "F6CyFPFapX4G4d7P1BmVMbsgAqvJOSo0djiTPp1+kTvizPkZbHz+Q6uB2Rw7APf0UXC7tfHCuZHF\n" +
|
||||||
|
// "h52sFSoHJGsRBcoWsqHNFafhVQGF1qPZ9bCsO+cdzpSKu1KmxT8lIr/Phw8L7nKJeWz990pj4Uso\n" +
|
||||||
|
// "w9uLRxOT+QysgfUH47DKIAdLl3QkE2KI6pTy6lKNMrUapcoVqVBeYVz7fg3m7QKBgQDumPKaTNfB\n" +
|
||||||
|
// "4lvA6Lq3sKsHzsnzLXZ9SNXGbksx/s0xcNvaw+07TXBkpfQDyrp+CTdjQYRq8WykhNadwa+oantS\n" +
|
||||||
|
// "fGwNrWCi6ZCTMi1OVxoirkVaJ1960qv3mHcrpyuhUxjX4QAcaNYMxaYuUVOex+Fahkq8oppP/ktP\n" +
|
||||||
|
// "PLuiPYsZdQKBgQDPG3FPa8rzEkIRcCm8tXAnjzAbe1Ui/iC1reACKtTrfA12mx2XJSjAMUid6fmj\n" +
|
||||||
|
// "k8M6qdWL9pHxeIcVBBHK0wcjeANIMLJPWL+/up9xvP2tNdxeRuMXP4a1olNHwKozJIBOU1ocdR4/\n" +
|
||||||
|
// "tGp5Ad27bfnFhMPlJlDILZzrO3h15CAiTQKBgQCXsQG8e9JIX+M5uDzNgDKcWiomwuasLFxNNd30\n" +
|
||||||
|
// "wSwvnLMKWLpAk7E7LA8BQihi7PUb05GedDNAPXw8++Dz0A7rmFMSNwJTUO8rxiDrx5DEL8vDz3hy\n" +
|
||||||
|
// "m/HdDj/lrvicLjqDNXdemIBNynMmy2nAbw+k//AQEcjNxryWeeRI95ux6QKBgDbFly3d4ApwpbBe\n" +
|
||||||
|
// "7WrOwR51K8/Yyic69gOWPEvWcADnCdh4JVc3qJNLdVzt5+tuxI7bI3KkfuxRZ8gTD3GIZbbnolaR\n" +
|
||||||
|
// "Klb5rZxTCp/Vz3DjcagtLxmS31lh2Ix9U4W6/YO5X3dvMdS/LflamP1clFW8SuJrQ6ntBjbfv3fO\n" +
|
||||||
|
// "IQFxAoGAcKzUGRV/GvLZMkeWzZFSLMP1dGZXWKlE/9H5WwhPUU3s27E5Eht4thms+znwv/9cHJDS\n" +
|
||||||
|
// "Qi7autcRKDCqlfAiGbzKTQ37iB1fV7nysLCrX0Q21YSMLgj2HiMO3Ny9Y+xs4ggKZZO0PDMWtR63\n" +
|
||||||
|
// "loXsQS7xdfIu8u6qvaJvevRXvpY=\n" +
|
||||||
|
// "-----END PRIVATE KEY-----";
|
||||||
|
|
||||||
|
// 过期的证书
|
||||||
|
public static final String CERTIFICATE_VALIDITY_RSA = "-----BEGIN CERTIFICATE-----\n" +
|
||||||
|
"MIIDtTCCAp2gAwIBAgIhAJAkNnDwN9NJKe3CDViZk9d5HAfviux2NWT4SKm/IHNhMA0GCSqGSIb3\n" +
|
||||||
|
"DQEBCwUAMIGNMQswCQYDVQQGEwJDTjESMBAGA1UECAwJ5rWZ5rGf55yBMRIwEAYDVQQHDAnmna3l\n" +
|
||||||
|
"t57luIIxITAfBgNVBAoMGOa1meaxn+eooOW3nuWVhuS4mumTtuihjDEYMBYGA1UECwwP5pWw5a2X\n" +
|
||||||
|
"6YeR6J6N6YOoMRkwFwYDVQQDDBBzY2ZzLmN6Y2IuY29tLmNuMB4XDTI0MDIyMTAzMjIzMFoXDTI0\n" +
|
||||||
|
"MDIyMTAzMjIzNVowgY0xCzAJBgNVBAYTAkNOMRIwEAYDVQQIDAnmtZnmsZ/nnIExEjAQBgNVBAcM\n" +
|
||||||
|
"CeadreW3nuW4gjEhMB8GA1UECgwY5rWZ5rGf56ig5bee5ZWG5Lia6ZO26KGMMRgwFgYDVQQLDA/m\n" +
|
||||||
|
"lbDlrZfph5Hono3pg6gxGTAXBgNVBAMMEHNjZnMuY3pjYi5jb20uY24wggEiMA0GCSqGSIb3DQEB\n" +
|
||||||
|
"AQUAA4IBDwAwggEKAoIBAQDBBz/n4yiesoy2bjJ/OYCa0x0kEQ196AHQRt/xeDtk2UIbsiTc1GgH\n" +
|
||||||
|
"DY0gBEyG2atiJOsxbHgI1VwG2zB6gCkXvwd26nS1FAcSjeeZzjR+y32NSdVd5fekez0er3q43+hI\n" +
|
||||||
|
"UhCgLb0nQepLBqX0Gw72Q9Oi41DqWI0V8Dsuhn+TFQKcmTC47ub9RAFUvPXfYe76EYDfadymIdgq\n" +
|
||||||
|
"nGV5GS7HD/ByUBodw3hpRuZVTudCg90S05xTgUB/pmY5GnE9IzaNbFC2O3fq+vXqdSseDzMnQaSA\n" +
|
||||||
|
"mUnghBe4LdWG5buhu+b2TxKdbFdy0wG6aiuDoxUCqT9cKQ89mXLACoFe2DIxAgMBAAEwDQYJKoZI\n" +
|
||||||
|
"hvcNAQELBQADggEBAJU6Wd7aLjG1MRjjDdrnA2YN1/BDAvieoktdL2xbsoWkQFOV/JR1ypVYIW1E\n" +
|
||||||
|
"vl2dAZj0h3CJi7NA44zwiKi46SD4whMW5ByfRTqO6bMFiITrLh6DazLGbuyXX8aVyr8Rpb+fEebR\n" +
|
||||||
|
"eYPdH64aynE/ld8AY1nTkDzt++9RjqdOATiZF7HQrNUzXXZ6BL99jfh1nxtTKgajzq4/40V+xhID\n" +
|
||||||
|
"cvY4EWt4EbK1XvKyX44zwjwfusKu+MxygxB67eVeWedjxjb/8c4PCVbcrDj0sk0AYhCoH0r7t26z\n" +
|
||||||
|
"lEmLNbE4NGCUOdsKZwU0nHph5IXhjtSlqWmL7fPG0cBmdC0a36eOnXI=\n" +
|
||||||
|
"-----END CERTIFICATE-----";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getLongestCertificate() {
|
void getLongestCertificate() {
|
||||||
CertificateValidity validity = new CertificateValidity();
|
CertificateValidity validity = new CertificateValidity();
|
||||||
Assertions.assertNull(validity.getLongestCertificate(null));
|
Assertions.assertNull(validity.getLongestCertificate(null));
|
||||||
|
Assertions.assertNull(validity.getLongestCertificate(new HashMap<>()));
|
||||||
|
|
||||||
ConcurrentHashMap<BigInteger, X509Certificate> certificates = new ConcurrentHashMap<>();
|
ConcurrentHashMap<BigInteger, X509Certificate> certificates = new ConcurrentHashMap<>();
|
||||||
X509Certificate certificate = KeyText.loadTestRSA();
|
X509Certificate certificate = KeyText.loadTestRSA();
|
||||||
|
|
@ -25,5 +74,6 @@ class CertificateValidityTest {
|
||||||
void withinValidity() {
|
void withinValidity() {
|
||||||
CertificateValidity validity = new CertificateValidity();
|
CertificateValidity validity = new CertificateValidity();
|
||||||
Assertions.assertTrue(validity.withinValidity(KeyText.loadTestRSA()));
|
Assertions.assertTrue(validity.withinValidity(KeyText.loadTestRSA()));
|
||||||
|
Assertions.assertFalse(validity.withinValidity(PemFile.loadX509FromString(CERTIFICATE_VALIDITY_RSA)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
package com.czcb.scfs.api.core.cipher;
|
//package com.czcb.scfs.api.core.cipher;
|
||||||
|
|
||||||
class DefaultCredentialTest {
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// void buildRequestAuthorization() {
|
|
||||||
// }
|
|
||||||
//
|
//
|
||||||
// @Test
|
//class DefaultCredentialTest {
|
||||||
// void buildResponseSignature() {
|
//
|
||||||
// }
|
//// @Test
|
||||||
}
|
//// void buildRequestAuthorization() {
|
||||||
|
//// }
|
||||||
|
////
|
||||||
|
//// @Test
|
||||||
|
//// void buildResponseSignature() {
|
||||||
|
//// }
|
||||||
|
//}
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package com.czcb.scfs.api.core.cipher;
|
//package com.czcb.scfs.api.core.cipher;
|
||||||
|
|
||||||
class DefaultValidatorTest {
|
|
||||||
//
|
//
|
||||||
// @Test
|
//class DefaultValidatorTest {
|
||||||
// void validate() {
|
////
|
||||||
// }
|
//// @Test
|
||||||
}
|
//// void validate() {
|
||||||
|
//// }
|
||||||
|
//}
|
||||||
|
|
@ -10,16 +10,16 @@ import java.util.List;
|
||||||
|
|
||||||
class LocalCertificateProviderTest {
|
class LocalCertificateProviderTest {
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
void getCertificate() {
|
// void getCertificate() {
|
||||||
String xx = "38844645436081632637265568516991627875287655057";
|
// String xx = "38844645436081632637265568516991627875287655057";
|
||||||
X509Certificate certificate = KeyText.loadTestRSA();
|
// X509Certificate certificate = KeyText.loadTestRSA();
|
||||||
|
//
|
||||||
List<X509Certificate> list = new ArrayList<>();
|
// List<X509Certificate> list = new ArrayList<>();
|
||||||
list.add(certificate);
|
// list.add(certificate);
|
||||||
LocalCertificateProvider provider = new LocalCertificateProvider(list);
|
// LocalCertificateProvider provider = new LocalCertificateProvider(list);
|
||||||
// Assertions.assertNotNull(provider.getCertificate(xx));
|
//// Assertions.assertNotNull(provider.getCertificate(xx));
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getAvailableCertificate() {
|
void getAvailableCertificate() {
|
||||||
|
|
@ -30,4 +30,12 @@ class LocalCertificateProviderTest {
|
||||||
LocalCertificateProvider provider = new LocalCertificateProvider(list);
|
LocalCertificateProvider provider = new LocalCertificateProvider(list);
|
||||||
Assertions.assertNotNull(provider.getAvailableCertificate());
|
Assertions.assertNotNull(provider.getAvailableCertificate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetAvailableCertificate() {
|
||||||
|
List<X509Certificate> data = new ArrayList<>();
|
||||||
|
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||||
|
new LocalCertificateProvider(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8,20 +8,20 @@ class ApiClientExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test() {
|
void test() {
|
||||||
|
ApiClientException exception = new ApiClientException();
|
||||||
assertThrows(ApiClientException.class, () -> {
|
assertThrows(ApiClientException.class, () -> {
|
||||||
throw new ApiClientException();
|
throw exception;
|
||||||
});
|
});
|
||||||
|
|
||||||
assertThrows(ApiClientException.class, () -> {
|
assertThrows(ApiClientException.class, () -> {
|
||||||
throw new ApiClientException("error");
|
throw new ApiClientException("error");
|
||||||
});
|
});
|
||||||
|
|
||||||
assertThrows(ApiClientException.class, () -> {
|
assertThrows(ApiClientException.class, () -> {
|
||||||
throw new ApiClientException("error", new ApiClientException());
|
throw new ApiClientException("error", exception);
|
||||||
});
|
});
|
||||||
|
|
||||||
assertThrows(ApiClientException.class, () -> {
|
assertThrows(ApiClientException.class, () -> {
|
||||||
throw new ApiClientException(new ApiClientException());
|
throw new ApiClientException(exception);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,13 @@ class EncodingExceptionTest {
|
||||||
throw new EncodingException("error");
|
throw new EncodingException("error");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
EncodingException exception = new EncodingException();
|
||||||
assertThrows(EncodingException.class, () -> {
|
assertThrows(EncodingException.class, () -> {
|
||||||
throw new EncodingException("error", new EncodingException());
|
throw new EncodingException("error", exception);
|
||||||
});
|
});
|
||||||
|
|
||||||
assertThrows(EncodingException.class, () -> {
|
assertThrows(EncodingException.class, () -> {
|
||||||
throw new EncodingException(new EncodingException());
|
throw new EncodingException(exception);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,12 +16,13 @@ class EncryptExceptionTest {
|
||||||
throw new EncryptException("error");
|
throw new EncryptException("error");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
EncryptException exception = new EncryptException("");
|
||||||
assertThrows(EncryptException.class, () -> {
|
assertThrows(EncryptException.class, () -> {
|
||||||
throw new EncryptException("error", new EncryptException(""));
|
throw new EncryptException("error", exception);
|
||||||
});
|
});
|
||||||
|
|
||||||
assertThrows(EncryptException.class, () -> {
|
assertThrows(EncryptException.class, () -> {
|
||||||
throw new EncryptException(new EncryptException(""));
|
throw new EncryptException(exception);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.czcb.scfs.api.core.exception;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
class FileReadExceptionTest {
|
||||||
|
@Test
|
||||||
|
void test() {
|
||||||
|
assertThrows(FileReadException.class, () -> {
|
||||||
|
throw new FileReadException();
|
||||||
|
});
|
||||||
|
|
||||||
|
assertThrows(FileReadException.class, () -> {
|
||||||
|
throw new FileReadException("error");
|
||||||
|
});
|
||||||
|
|
||||||
|
FileReadException exception = new FileReadException("");
|
||||||
|
assertThrows(FileReadException.class, () -> {
|
||||||
|
throw new FileReadException("error", exception);
|
||||||
|
});
|
||||||
|
|
||||||
|
assertThrows(FileReadException.class, () -> {
|
||||||
|
throw new FileReadException(exception);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,12 +15,13 @@ class SignExceptionTest {
|
||||||
throw new SignException("error");
|
throw new SignException("error");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
SignException signException = new SignException();
|
||||||
assertThrows(SignException.class, () -> {
|
assertThrows(SignException.class, () -> {
|
||||||
throw new SignException("error", new SignException());
|
throw new SignException("error", signException);
|
||||||
});
|
});
|
||||||
|
|
||||||
assertThrows(SignException.class, () -> {
|
assertThrows(SignException.class, () -> {
|
||||||
throw new SignException(new SignException());
|
throw new SignException(signException);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -15,12 +15,13 @@ class TimestampExceptionTest {
|
||||||
throw new TimestampException("error");
|
throw new TimestampException("error");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
TimestampException timestampException = new TimestampException();
|
||||||
assertThrows(TimestampException.class, () -> {
|
assertThrows(TimestampException.class, () -> {
|
||||||
throw new TimestampException("error", new TimestampException());
|
throw new TimestampException("error", timestampException);
|
||||||
});
|
});
|
||||||
|
|
||||||
assertThrows(TimestampException.class, () -> {
|
assertThrows(TimestampException.class, () -> {
|
||||||
throw new TimestampException(new TimestampException());
|
throw new TimestampException(timestampException);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -15,12 +15,13 @@ class ValidationExceptionTest {
|
||||||
throw new ValidationException("error");
|
throw new ValidationException("error");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ValidationException validationException = new ValidationException();
|
||||||
assertThrows(ValidationException.class, () -> {
|
assertThrows(ValidationException.class, () -> {
|
||||||
throw new ValidationException("error", new ValidationException());
|
throw new ValidationException("error", validationException);
|
||||||
});
|
});
|
||||||
|
|
||||||
assertThrows(ValidationException.class, () -> {
|
assertThrows(ValidationException.class, () -> {
|
||||||
throw new ValidationException(new ValidationException());
|
throw new ValidationException(validationException);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,151 @@
|
||||||
|
package com.czcb.scfs.api.core.http;
|
||||||
|
|
||||||
|
import com.czcb.scfs.api.core.ApiClient;
|
||||||
|
import com.czcb.scfs.api.core.DefaultChannel;
|
||||||
|
import com.czcb.scfs.api.core.KeyText;
|
||||||
|
import com.czcb.scfs.api.core.Profile;
|
||||||
|
import com.czcb.scfs.api.core.cipher.*;
|
||||||
|
import com.czcb.scfs.api.core.http.client.TestPrivacy;
|
||||||
|
import com.czcb.scfs.api.core.http.client.TestProfile;
|
||||||
|
import com.czcb.scfs.api.core.http.client.TestSigner;
|
||||||
|
import com.czcb.scfs.api.core.http.client.TestVerifier;
|
||||||
|
import org.apache.hc.client5.http.impl.classic.HttpClients;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.security.PrivateKey;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
|
||||||
|
|
||||||
|
class ApiClientBuilderTest {
|
||||||
|
|
||||||
|
Profile buildProfile() {
|
||||||
|
PrivateKey privateKey = KeyText.loadTestPrivateKeyRSA();
|
||||||
|
X509Certificate certificate = KeyText.loadTestRSA();
|
||||||
|
List<X509Certificate> list = new ArrayList<>();
|
||||||
|
list.add(certificate);
|
||||||
|
CertificateProvider certificateProvider = new LocalCertificateProvider(list);
|
||||||
|
Privacy privacy = new TestPrivacy(privateKey, certificateProvider);
|
||||||
|
Signature signature = new DefaultSignature(certificateProvider, new TestSigner(privateKey), new TestVerifier(certificateProvider));
|
||||||
|
|
||||||
|
return new TestProfile(
|
||||||
|
privacy,
|
||||||
|
signature,
|
||||||
|
new DefaultChannel.Builder()
|
||||||
|
.channelNo("000000")
|
||||||
|
.appNo("111111")
|
||||||
|
.build(),
|
||||||
|
new DefaultHttpProfile.Builder()
|
||||||
|
.online(false)
|
||||||
|
.logEnabled(true)
|
||||||
|
.compressionEnabled(false)
|
||||||
|
.host("http://127.0.0.1:8888")
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void profile() {
|
||||||
|
ApiClient client = ApiClientBuilder.custom()
|
||||||
|
.profile(buildProfile())
|
||||||
|
.build();
|
||||||
|
Assertions.assertNotNull(client);
|
||||||
|
|
||||||
|
Profile profile = client.getProfile();
|
||||||
|
|
||||||
|
Assertions.assertNotNull(profile.getPrivacy());
|
||||||
|
Assertions.assertNotNull(profile.getSignature());
|
||||||
|
assertThatJson("{\"channelNo\":\"000000\",\"appNo\":\"111111\"}").isEqualTo(profile.getChannel());
|
||||||
|
assertThatJson("{\"host\":\"http://127.0.0.1:8888\"," +
|
||||||
|
"\"connPool\":{\"maxRequests\":64,\"maxRequestPerHost\":64,\"connectTimeout\":10,\"socketTimeout\":60}," +
|
||||||
|
"\"headers\":{}," +
|
||||||
|
"\"proxy\":{\"enabled\":false,\"host\":null,\"port\":null,\"username\":\"\",\"password\":\"\",\"scheme\":\"http\"}}\n")
|
||||||
|
.isEqualTo(profile.getHttpProfile());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void httpClient() {
|
||||||
|
ApiClient client = ApiClientBuilder.custom()
|
||||||
|
.profile(buildProfile())
|
||||||
|
.build();
|
||||||
|
Assertions.assertNotNull(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void build() {
|
||||||
|
ApiClient client = ApiClientBuilder.custom()
|
||||||
|
.profile(buildProfile())
|
||||||
|
.httpClient(HttpClients.custom().build())
|
||||||
|
.build();
|
||||||
|
Assertions.assertNotNull(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void build2() {
|
||||||
|
ApiClient client = ApiClientBuilder.custom()
|
||||||
|
.profile(buildProfileNotHttpProfile())
|
||||||
|
.build();
|
||||||
|
Assertions.assertNotNull(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void build3() {
|
||||||
|
ApiClient client = ApiClientBuilder.custom()
|
||||||
|
.profile(buildProfileHasProxy())
|
||||||
|
.build();
|
||||||
|
Assertions.assertNotNull(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
Profile buildProfileNotHttpProfile() {
|
||||||
|
PrivateKey privateKey = KeyText.loadTestPrivateKeyRSA();
|
||||||
|
X509Certificate certificate = KeyText.loadTestRSA();
|
||||||
|
List<X509Certificate> list = new ArrayList<>();
|
||||||
|
list.add(certificate);
|
||||||
|
CertificateProvider certificateProvider = new LocalCertificateProvider(list);
|
||||||
|
Privacy privacy = new TestPrivacy(privateKey, certificateProvider);
|
||||||
|
Signature signature = new DefaultSignature(certificateProvider, new TestSigner(privateKey), new TestVerifier(certificateProvider));
|
||||||
|
|
||||||
|
return new TestProfile(
|
||||||
|
privacy,
|
||||||
|
signature,
|
||||||
|
new DefaultChannel.Builder()
|
||||||
|
.channelNo("000000")
|
||||||
|
.appNo("111111")
|
||||||
|
.build(),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Profile buildProfileHasProxy() {
|
||||||
|
PrivateKey privateKey = KeyText.loadTestPrivateKeyRSA();
|
||||||
|
X509Certificate certificate = KeyText.loadTestRSA();
|
||||||
|
List<X509Certificate> list = new ArrayList<>();
|
||||||
|
list.add(certificate);
|
||||||
|
CertificateProvider certificateProvider = new LocalCertificateProvider(list);
|
||||||
|
Privacy privacy = new TestPrivacy(privateKey, certificateProvider);
|
||||||
|
Signature signature = new DefaultSignature(certificateProvider, new TestSigner(privateKey), new TestVerifier(certificateProvider));
|
||||||
|
|
||||||
|
return new TestProfile(
|
||||||
|
privacy,
|
||||||
|
signature,
|
||||||
|
new DefaultChannel.Builder()
|
||||||
|
.channelNo("000000")
|
||||||
|
.appNo("111111")
|
||||||
|
.build(),
|
||||||
|
new DefaultHttpProfile.Builder()
|
||||||
|
.proxy(new Proxy.Builder()
|
||||||
|
.host("127.0.0.1")
|
||||||
|
.enabled()
|
||||||
|
.port("1000")
|
||||||
|
.build())
|
||||||
|
.online(false)
|
||||||
|
.logEnabled(true)
|
||||||
|
.compressionEnabled(false)
|
||||||
|
.host("http://127.0.0.1:8888")
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
package com.czcb.scfs.api.core.http;
|
|
||||||
|
|
||||||
class DefaultApiClientBuilderTest {
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// void newInstance() {
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// void profile() {
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// void httpClient() {
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// void build() {
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
@ -16,7 +16,6 @@ import org.mockserver.client.MockServerClient;
|
||||||
import org.mockserver.junit.jupiter.MockServerExtension;
|
import org.mockserver.junit.jupiter.MockServerExtension;
|
||||||
import org.mockserver.junit.jupiter.MockServerSettings;
|
import org.mockserver.junit.jupiter.MockServerSettings;
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
|
|
@ -61,7 +60,7 @@ class ApacheHttpclientProxyTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void doRemoteExecuteProxy() {
|
void doRemoteExecuteProxy() {
|
||||||
ApiClient apiClient = new DefaultApiClientBuilder()
|
ApiClient apiClient = ApiClientBuilder.custom()
|
||||||
.profile(profile())
|
.profile(profile())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
@ -97,7 +96,8 @@ class ApacheHttpclientProxyTest {
|
||||||
.body(new Gson().toJson(request))
|
.body(new Gson().toJson(request))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Assertions.assertThrows(TimestampException.class, () -> apiClient.post("/mock/proxy", new HttpHeaders(), requestBody, TestResponse.class));
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
Assertions.assertThrows(TimestampException.class, () -> apiClient.post("/mock/proxy", headers, requestBody, TestResponse.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TestRequest implements ApiRequest {
|
public static class TestRequest implements ApiRequest {
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ class ApacheHttpclientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiClient mock(String body, boolean compressionEnabled) {
|
private ApiClient mock(String body, boolean compressionEnabled) {
|
||||||
ApiClient apiClient = new DefaultApiClientBuilder()
|
ApiClient apiClient = ApiClientBuilder.custom()
|
||||||
.profile(profile(compressionEnabled))
|
.profile(profile(compressionEnabled))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import static org.mockserver.model.HttpResponse.response;
|
||||||
|
|
||||||
@ExtendWith(MockServerExtension.class)
|
@ExtendWith(MockServerExtension.class)
|
||||||
@MockServerSettings(ports = {8888})
|
@MockServerSettings(ports = {8888})
|
||||||
class ApacheHttpclientTestProxy {
|
class ApacheHttpclientTestProxyTest {
|
||||||
private MockServerClient client;
|
private MockServerClient client;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
|
@ -60,7 +60,7 @@ class ApacheHttpclientTestProxy {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void doRemoteExecuteProxy() {
|
void doRemoteExecuteProxy() {
|
||||||
ApiClient apiClient = new DefaultApiClientBuilder()
|
ApiClient apiClient = ApiClientBuilder.custom()
|
||||||
.profile(profile())
|
.profile(profile())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
@ -96,7 +96,8 @@ class ApacheHttpclientTestProxy {
|
||||||
.body(new Gson().toJson(request))
|
.body(new Gson().toJson(request))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Assertions.assertThrows(TimestampException.class, () -> apiClient.post("/mock/proxy", new HttpHeaders(), requestBody, TestResponse.class));
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
Assertions.assertThrows(TimestampException.class, () -> apiClient.post("/mock/proxy", headers, requestBody, TestResponse.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TestRequest implements ApiRequest {
|
public static class TestRequest implements ApiRequest {
|
||||||
|
|
@ -6,7 +6,6 @@ import com.czcb.scfs.api.core.exception.DecryptException;
|
||||||
import com.czcb.scfs.api.core.http.*;
|
import com.czcb.scfs.api.core.http.*;
|
||||||
import com.czcb.scfs.api.core.util.DateTimes;
|
import com.czcb.scfs.api.core.util.DateTimes;
|
||||||
import com.czcb.scfs.api.core.util.Nonce;
|
import com.czcb.scfs.api.core.util.Nonce;
|
||||||
import com.czcb.scfs.api.core.util.PemFile;
|
|
||||||
import com.czcb.scfs.api.core.util.Strings;
|
import com.czcb.scfs.api.core.util.Strings;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
@ -17,7 +16,6 @@ import org.mockserver.client.MockServerClient;
|
||||||
import org.mockserver.junit.jupiter.MockServerExtension;
|
import org.mockserver.junit.jupiter.MockServerExtension;
|
||||||
import org.mockserver.junit.jupiter.MockServerSettings;
|
import org.mockserver.junit.jupiter.MockServerSettings;
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
|
|
@ -63,7 +61,7 @@ class ApacheHttpclientV2Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void doRemoteExecuteResponseBodyIsNull() {
|
void doRemoteExecuteResponseBodyIsNull() {
|
||||||
ApiClient apiClient = new DefaultApiClientBuilder()
|
ApiClient apiClient = ApiClientBuilder.custom()
|
||||||
.profile(profile())
|
.profile(profile())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
@ -99,14 +97,15 @@ class ApacheHttpclientV2Test {
|
||||||
.body(new Gson().toJson(request))
|
.body(new Gson().toJson(request))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Assertions.assertThrows(DecryptException.class, () -> apiClient.post("/mock/responseBodyIsNull", new HttpHeaders(), requestBody, TestResponse.class));
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
Assertions.assertThrows(DecryptException.class, () -> apiClient.post("/mock/responseBodyIsNull", headers, requestBody, TestResponse.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void doRemoteExecuteGet() {
|
void doRemoteExecuteGet() {
|
||||||
TestResponse mockResponse = new TestResponse();
|
TestResponse mockResponse = new TestResponse();
|
||||||
mockResponse.setName("123456");
|
mockResponse.setName("123456");
|
||||||
ApiClient apiClient = new DefaultApiClientBuilder()
|
ApiClient apiClient = ApiClientBuilder.custom()
|
||||||
.profile(profile())
|
.profile(profile())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import com.czcb.scfs.api.core.exception.TimestampException;
|
||||||
import com.czcb.scfs.api.core.http.*;
|
import com.czcb.scfs.api.core.http.*;
|
||||||
import com.czcb.scfs.api.core.util.DateTimes;
|
import com.czcb.scfs.api.core.util.DateTimes;
|
||||||
import com.czcb.scfs.api.core.util.Nonce;
|
import com.czcb.scfs.api.core.util.Nonce;
|
||||||
import com.czcb.scfs.api.core.util.PemFile;
|
|
||||||
import com.czcb.scfs.api.core.util.Strings;
|
import com.czcb.scfs.api.core.util.Strings;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
@ -18,7 +17,6 @@ import org.mockserver.client.MockServerClient;
|
||||||
import org.mockserver.junit.jupiter.MockServerExtension;
|
import org.mockserver.junit.jupiter.MockServerExtension;
|
||||||
import org.mockserver.junit.jupiter.MockServerSettings;
|
import org.mockserver.junit.jupiter.MockServerSettings;
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
|
|
@ -63,7 +61,7 @@ class ApacheHttpclientV3Test {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void doRemoteExecuteTimestamp() {
|
void doRemoteExecuteTimestamp() {
|
||||||
ApiClient apiClient = new DefaultApiClientBuilder()
|
ApiClient apiClient = ApiClientBuilder.custom()
|
||||||
.profile(profile())
|
.profile(profile())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
@ -99,12 +97,13 @@ class ApacheHttpclientV3Test {
|
||||||
.body(new Gson().toJson(request))
|
.body(new Gson().toJson(request))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Assertions.assertThrows(TimestampException.class, () -> apiClient.post("/mock/timestamp", new HttpHeaders(), requestBody, TestResponse.class));
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
Assertions.assertThrows(TimestampException.class, () -> apiClient.post("/mock/timestamp", headers, requestBody, TestResponse.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void doRemoteExecuteJsonException() {
|
void doRemoteExecuteJsonException() {
|
||||||
ApiClient apiClient = new DefaultApiClientBuilder()
|
ApiClient apiClient = ApiClientBuilder.custom()
|
||||||
.profile(profile())
|
.profile(profile())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
@ -140,7 +139,8 @@ class ApacheHttpclientV3Test {
|
||||||
.body(new Gson().toJson(request))
|
.body(new Gson().toJson(request))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Assertions.assertThrows(ApiClientException.class, () -> apiClient.post("/mock/json", new HttpHeaders(), requestBody, TestResponse.class));
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
Assertions.assertThrows(ApiClientException.class, () -> apiClient.post("/mock/json", headers, requestBody, TestResponse.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TestRequest implements ApiRequest {
|
public static class TestRequest implements ApiRequest {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ public class TestPrivacyDecryptor extends AbstractPrivacyDecryptor {
|
||||||
*
|
*
|
||||||
* @param privateKey 加密使用的私钥
|
* @param privateKey 加密使用的私钥
|
||||||
*/
|
*/
|
||||||
protected TestPrivacyDecryptor(PrivateKey privateKey) {
|
public TestPrivacyDecryptor(PrivateKey privateKey) {
|
||||||
super("RSA/ECB/OAEPWithSHA-1AndMGF1Padding", privateKey, null);
|
super("RSA/ECB/OAEPWithSHA-1AndMGF1Padding", privateKey, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ public class TestPrivacyEncryptor extends AbstractPrivacyEncryptor {
|
||||||
*
|
*
|
||||||
* @param publicKey 加密使用的公钥
|
* @param publicKey 加密使用的公钥
|
||||||
*/
|
*/
|
||||||
protected TestPrivacyEncryptor(PublicKey publicKey) {
|
public TestPrivacyEncryptor(PublicKey publicKey) {
|
||||||
super("RSA/ECB/OAEPWithSHA-1AndMGF1Padding", publicKey, null);
|
super("RSA/ECB/OAEPWithSHA-1AndMGF1Padding", publicKey, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,6 @@ class StringsTest {
|
||||||
void urlEncode() {
|
void urlEncode() {
|
||||||
String url = "https://www.baidu.com/s?ie=utf-8";
|
String url = "https://www.baidu.com/s?ie=utf-8";
|
||||||
Assertions.assertEquals("https%3A%2F%2Fwww.baidu.com%2Fs%3Fie%3Dutf-8", Strings.urlEncode(url));
|
Assertions.assertEquals("https%3A%2F%2Fwww.baidu.com%2Fs%3Fie%3Dutf-8", Strings.urlEncode(url));
|
||||||
assertThrows(EncodingException.class, () -> Assertions.assertEquals("", Strings.urlEncode(null)));
|
assertThrows(EncodingException.class, () -> Strings.urlEncode(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,19 +1,20 @@
|
||||||
package com.czcb.scfs.api.service.file;
|
//package com.czcb.scfs.api.service.file;
|
||||||
|
//
|
||||||
import com.czcb.scfs.api.core.ApiClient;
|
//import com.czcb.scfs.api.core.ApiClient;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* 文件下载
|
// * 文件下载
|
||||||
*
|
// *
|
||||||
* @since 2.0.0
|
// * @since 2.0.0
|
||||||
*/
|
// */
|
||||||
public class FileDownloadService {
|
//public class FileDownloadService {
|
||||||
private final ApiClient apiClient;
|
// private final ApiClient apiClient;
|
||||||
|
//
|
||||||
public FileDownloadService(ApiClient apiClient) {
|
// public FileDownloadService(ApiClient apiClient) {
|
||||||
this.apiClient = apiClient;
|
// this.apiClient = apiClient;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void download() {
|
// public void download() {
|
||||||
}
|
// // 待实现
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,27 @@
|
||||||
package com.czcb.scfs.api.service.file;
|
//package com.czcb.scfs.api.service.file;
|
||||||
|
//
|
||||||
import com.czcb.scfs.api.core.ApiClient;
|
//import com.czcb.scfs.api.core.ApiClient;
|
||||||
import com.czcb.scfs.api.core.http.HttpHeaders;
|
//import com.czcb.scfs.api.core.http.HttpHeaders;
|
||||||
import com.czcb.scfs.api.core.http.HttpResponse;
|
//import com.czcb.scfs.api.core.http.HttpResponse;
|
||||||
import com.czcb.scfs.api.service.file.model.FaceFileRequest;
|
//import com.czcb.scfs.api.service.file.model.FaceFileRequest;
|
||||||
import com.czcb.scfs.api.service.file.model.FaceFileResponse;
|
//import com.czcb.scfs.api.service.file.model.FaceFileResponse;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* 文件上传
|
// * 文件上传
|
||||||
*
|
// *
|
||||||
* @since 2.0.0
|
// * @since 2.0.0
|
||||||
*/
|
// */
|
||||||
public class FileUploadService {
|
//public class FileUploadService {
|
||||||
private final ApiClient apiClient;
|
// private final ApiClient apiClient;
|
||||||
|
//
|
||||||
public FileUploadService(ApiClient apiClient) {
|
// public FileUploadService(ApiClient apiClient) {
|
||||||
this.apiClient = apiClient;
|
// this.apiClient = apiClient;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public FaceFileResponse face(FaceFileRequest request) {
|
// public FaceFileResponse face(FaceFileRequest request) {
|
||||||
String url = "/face/test";
|
// String url = "/face/test";
|
||||||
HttpHeaders headers = new HttpHeaders();
|
// HttpHeaders headers = new HttpHeaders();
|
||||||
HttpResponse<FaceFileResponse> httpResponse = apiClient.post(url, headers, request.toJson(), FaceFileResponse.class);
|
// HttpResponse<FaceFileResponse> httpResponse = apiClient.post(url, headers, request.toJson(), FaceFileResponse.class);
|
||||||
return httpResponse.getServiceResponse();
|
// return httpResponse.getServiceResponse();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import com.czcb.scfs.api.core.ApiClient;
|
||||||
import com.czcb.scfs.api.core.DefaultChannel;
|
import com.czcb.scfs.api.core.DefaultChannel;
|
||||||
import com.czcb.scfs.api.core.Profile;
|
import com.czcb.scfs.api.core.Profile;
|
||||||
import com.czcb.scfs.api.core.cipher.*;
|
import com.czcb.scfs.api.core.cipher.*;
|
||||||
import com.czcb.scfs.api.core.http.DefaultApiClientBuilder;
|
import com.czcb.scfs.api.core.http.ApiClientBuilder;
|
||||||
import com.czcb.scfs.api.core.http.DefaultHttpProfile;
|
import com.czcb.scfs.api.core.http.DefaultHttpProfile;
|
||||||
import com.czcb.scfs.api.core.util.DateTimes;
|
import com.czcb.scfs.api.core.util.DateTimes;
|
||||||
import com.czcb.scfs.api.core.util.Nonce;
|
import com.czcb.scfs.api.core.util.Nonce;
|
||||||
|
|
@ -29,7 +29,7 @@ public class MockResponse {
|
||||||
|
|
||||||
public static ApiClient getApiClient() {
|
public static ApiClient getApiClient() {
|
||||||
if (apiClient == null) {
|
if (apiClient == null) {
|
||||||
apiClient = new DefaultApiClientBuilder()
|
apiClient = ApiClientBuilder.custom()
|
||||||
.profile(profile())
|
.profile(profile())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
package com.czcb.scfs.api.service.sms;
|
//package com.czcb.scfs.api.service.sms;
|
||||||
|
//
|
||||||
class SmsServiceTest {
|
//class SmsServiceTest {
|
||||||
|
//}
|
||||||
}
|
|
||||||
|
|
@ -2,8 +2,7 @@ package com.czcb.scfs.spring.boot.starter;
|
||||||
|
|
||||||
import com.czcb.scfs.api.core.ApiClient;
|
import com.czcb.scfs.api.core.ApiClient;
|
||||||
import com.czcb.scfs.api.core.Profile;
|
import com.czcb.scfs.api.core.Profile;
|
||||||
import com.czcb.scfs.api.core.http.DefaultApiClientBuilder;
|
import com.czcb.scfs.api.core.http.ApiClientBuilder;
|
||||||
import com.czcb.scfs.api.service.file.FileUploadService;
|
|
||||||
import com.czcb.scfs.api.service.health.EchoService;
|
import com.czcb.scfs.api.service.health.EchoService;
|
||||||
import com.czcb.scfs.api.service.sms.SmsService;
|
import com.czcb.scfs.api.service.sms.SmsService;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
|
@ -27,7 +26,7 @@ public class ScfsAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ApiClient apiClient() {
|
public ApiClient apiClient() {
|
||||||
return new DefaultApiClientBuilder()
|
return ApiClientBuilder.custom()
|
||||||
.profile(profile)
|
.profile(profile)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
@ -41,9 +40,4 @@ public class ScfsAutoConfiguration {
|
||||||
public EchoService echoService(ApiClient apiClient) {
|
public EchoService echoService(ApiClient apiClient) {
|
||||||
return new EchoService(apiClient);
|
return new EchoService(apiClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public FileUploadService fileUploadService(ApiClient apiClient) {
|
|
||||||
return new FileUploadService(apiClient);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ public class SmConfiguration extends AbstractAutoConfiguration {
|
||||||
private ScfsApiGatewayProperties properties;
|
private ScfsApiGatewayProperties properties;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ScfsApiGatewayProperties getProperties() {
|
public ScfsApiGatewayProperties getProperties() {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue