jacoco 单元测试覆盖
parent
8d843dc84c
commit
b2fcbc31d1
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.czcb.scfs.api.core.cipher;
|
||||||
|
|
||||||
|
import com.czcb.scfs.api.core.KeyText;
|
||||||
|
import com.czcb.scfs.api.core.http.client.TestSigner;
|
||||||
|
import com.czcb.scfs.api.core.http.client.TestVerifier;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
class DefaultSignatureTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getCertificateProvider() {
|
||||||
|
List<X509Certificate> certificates = new ArrayList<>();
|
||||||
|
certificates.add(KeyText.loadTestRSA());
|
||||||
|
CertificateProvider provider = new LocalCertificateProvider(certificates);
|
||||||
|
|
||||||
|
Signer signer = new TestSigner(KeyText.loadTestPrivateKeyRSA());
|
||||||
|
Verifier verifier = new TestVerifier(provider);
|
||||||
|
DefaultSignature signature = new DefaultSignature(provider, signer, verifier);
|
||||||
|
|
||||||
|
Assertions.assertNotNull(signature.getCertificateProvider());
|
||||||
|
Assertions.assertNotNull(signature.getSigner());
|
||||||
|
Assertions.assertNotNull(signature.getCredential());
|
||||||
|
Assertions.assertNotNull(signature.getVerifier());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.czcb.scfs.api.core.http;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
class DefaultHttpProfileTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getHeaders() {
|
||||||
|
Map<String, String> data = new HashMap<>();
|
||||||
|
data.put("key", "123456");
|
||||||
|
DefaultHttpProfile httpProfile = new DefaultHttpProfile.Builder()
|
||||||
|
.headers(data)
|
||||||
|
.compressionEnabled(true)
|
||||||
|
.online(true)
|
||||||
|
.logEnabled(true)
|
||||||
|
.host("http://10.133.129.74:8761/")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Assertions.assertNotNull(httpProfile.getHeaders());
|
||||||
|
Assertions.assertEquals("123456", httpProfile.getHeaders().get("key"));
|
||||||
|
Assertions.assertEquals("http://10.133.129.74:8761/", httpProfile.getHost());
|
||||||
|
|
||||||
|
Assertions.assertTrue(httpProfile.compressionEnabled());
|
||||||
|
Assertions.assertTrue(httpProfile.online());
|
||||||
|
Assertions.assertTrue(httpProfile.logEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getConnPool() {
|
||||||
|
DefaultHttpProfile httpProfile = new DefaultHttpProfile.Builder()
|
||||||
|
.connPool(new ConnPool.Builder()
|
||||||
|
.connectTimeout(10002)
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Assertions.assertNotNull(httpProfile.getConnPool());
|
||||||
|
Assertions.assertEquals(10002, httpProfile.getConnPool().getConnectTimeout());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getProxy() {
|
||||||
|
DefaultHttpProfile httpProfile = new DefaultHttpProfile.Builder()
|
||||||
|
.proxy(new Proxy.Builder()
|
||||||
|
.host("192.168.0.11")
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Assertions.assertNotNull(httpProfile.getProxy());
|
||||||
|
Assertions.assertEquals("192.168.0.11", httpProfile.getProxy().getHost());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -85,4 +85,35 @@ class HttpResponseTest {
|
||||||
|
|
||||||
Assertions.assertArrayEquals("123456".getBytes(StandardCharsets.UTF_8), httpResponse.getOriginalBody());
|
Assertions.assertArrayEquals("123456".getBytes(StandardCharsets.UTF_8), httpResponse.getOriginalBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getServiceResponse() {
|
||||||
|
HttpResponse<String> httpResponse = new HttpResponse.Builder<String>()
|
||||||
|
.originalResponse(new OriginalResponse.Builder()
|
||||||
|
.request(new HttpRequest.Builder()
|
||||||
|
.httpMethod(HttpMethod.POST)
|
||||||
|
.url("/xx")
|
||||||
|
.headers(new HttpHeaders())
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.originalBody("123456")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Assertions.assertArrayEquals("123456".getBytes(StandardCharsets.UTF_8), httpResponse.getOriginalBody());
|
||||||
|
|
||||||
|
httpResponse = new HttpResponse.Builder<String>()
|
||||||
|
.originalResponse(new OriginalResponse.Builder()
|
||||||
|
.request(new HttpRequest.Builder()
|
||||||
|
.httpMethod(HttpMethod.POST)
|
||||||
|
.url("/xx")
|
||||||
|
.headers(new HttpHeaders())
|
||||||
|
.body(new EncryptRequestBody.Builder().build())
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.serviceResponseType(null)
|
||||||
|
.originalBody("123456")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Assertions.assertTrue(httpResponse.getResponseBody() instanceof UnkownResponseBody);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,6 +20,17 @@ class ProxyTest {
|
||||||
|
|
||||||
assertThatJson("{\"enabled\":true,\"host\":\"123\",\"port\":\"1000\",\"username\":\"name\",\"password\":\"123\",\"scheme\":\"http\"}")
|
assertThatJson("{\"enabled\":true,\"host\":\"123\",\"port\":\"1000\",\"username\":\"name\",\"password\":\"123\",\"scheme\":\"http\"}")
|
||||||
.isEqualTo(proxy);
|
.isEqualTo(proxy);
|
||||||
|
|
||||||
|
proxy = new Proxy.Builder()
|
||||||
|
.port("1000")
|
||||||
|
.disabled()
|
||||||
|
.username("name")
|
||||||
|
.password("123")
|
||||||
|
.host("123")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertThatJson("{\"enabled\":false,\"host\":\"123\",\"port\":\"1000\",\"username\":\"name\",\"password\":\"123\",\"scheme\":\"http\"}")
|
||||||
|
.isEqualTo(proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -72,4 +83,5 @@ class ProxyTest {
|
||||||
.build();
|
.build();
|
||||||
Assertions.assertEquals("https", proxy.getScheme());
|
Assertions.assertEquals("https", proxy.getScheme());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -13,7 +13,7 @@ public class TestSigner extends AbstractSigner {
|
||||||
/**
|
/**
|
||||||
* @param privateKey API私钥
|
* @param privateKey API私钥
|
||||||
*/
|
*/
|
||||||
protected TestSigner(PrivateKey privateKey) {
|
public TestSigner(PrivateKey privateKey) {
|
||||||
super("SHA256withRSA", "SHA256withRSA", privateKey, null);
|
super("SHA256withRSA", "SHA256withRSA", privateKey, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ public class TestVerifier extends AbstractVerifier {
|
||||||
/**
|
/**
|
||||||
* @param certificateProvider 验签使用的证书管理器,非空
|
* @param certificateProvider 验签使用的证书管理器,非空
|
||||||
*/
|
*/
|
||||||
protected TestVerifier(CertificateProvider certificateProvider) {
|
public TestVerifier(CertificateProvider certificateProvider) {
|
||||||
super("SHA256withRSA", certificateProvider, null);
|
super("SHA256withRSA", certificateProvider, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue