test: genService 单元测试方法
parent
f835488f07
commit
aced04e349
|
|
@ -1 +1 @@
|
||||||
call C:\Ext\mvn17\bin\mvn.cmd clean package verify sonar:sonar -Dsonar.projectKey=scfs-api-sdk -Dsonar.projectName=scfs-api-sdk -Dsonar.host.url=http://10.129.135.192:7100 -Dsonar.login=sqp_90e5fb014f985e2c458e46b9239926cfbbd4fffe
|
call C:\Ext\mvn17\bin\mvn.cmd clean test verify sonar:sonar -Dsonar.projectKey=scfs-api-sdk -Dsonar.projectName=scfs-api-sdk -Dsonar.host.url=http://10.129.135.192:7100 -Dsonar.login=sqp_90e5fb014f985e2c458e46b9239926cfbbd4fffe
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
package com.czcb.scfs.api.test;
|
package com.czcb.scfs.api.test;
|
||||||
|
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.assertj.core.util.Lists;
|
import org.assertj.core.util.Lists;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
|
|
@ -34,61 +37,127 @@ public class RefGenTestMethod {
|
||||||
private static final String EXTRACTED_RESPONSE = "\textracted%sParams(response);\n";
|
private static final String EXTRACTED_RESPONSE = "\textracted%sParams(response);\n";
|
||||||
private static final String EXTRACTED_RESPONSE_ASSERTIONS = "\textracted%sAssertions(response);\n\n";
|
private static final String EXTRACTED_RESPONSE_ASSERTIONS = "\textracted%sAssertions(response);\n\n";
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
private static void genRequestParams(Class<?> request) {
|
private static void genRequestParams(Class<?> request) {
|
||||||
print("void extracted%sParams(%s request) {\n", request.getSimpleName(), request.getSimpleName());
|
print("void extracted%sParams(%s request) {\n", request.getSimpleName(), request.getSimpleName());
|
||||||
|
|
||||||
|
List<Class<?>> list = new ArrayList<>();
|
||||||
Method[] methods = request.getMethods();
|
Method[] methods = request.getMethods();
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
if (!method.getName().startsWith("set")) {
|
if (!method.getName().startsWith("set")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printParams(FMT_REQUEST_METHOD, method);
|
if (method.getParameterTypes()[0].isAssignableFrom(List.class)) {
|
||||||
|
ParameterizedType type = (ParameterizedType) method.getGenericParameterTypes()[0];
|
||||||
|
Class<?> actualType = Class.forName(type.getActualTypeArguments()[0].getTypeName());
|
||||||
|
list.add(actualType);
|
||||||
|
|
||||||
|
String sun = actualType.getSimpleName();
|
||||||
|
print("\t%s.%s %s = new %s.%s();\n", request.getSimpleName(), actualType.getSimpleName(), sun.toLowerCase(), request.getSimpleName(), actualType.getSimpleName());
|
||||||
|
print("\textracted%sNestParams(%s);\n", actualType.getSimpleName(), sun.toLowerCase());
|
||||||
|
print("\trequest.%s(Lists.list(%s));\n", method.getName(), sun.toLowerCase());
|
||||||
|
} else {
|
||||||
|
printParams(FMT_REQUEST_METHOD, method);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print("}\n");
|
print("}\n");
|
||||||
|
|
||||||
|
for (Class<?> clazz : list) {
|
||||||
|
genNest(clazz);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
private static void genRequestAssertions(Class<?> request) {
|
private static void genRequestAssertions(Class<?> request) {
|
||||||
print("void extracted%sAssertions(%s request) {\n", request.getSimpleName(), request.getSimpleName());
|
print("void extracted%sAssertions(%s request) {\n", request.getSimpleName(), request.getSimpleName());
|
||||||
|
|
||||||
|
List<Class<?>> list = new ArrayList<>();
|
||||||
Method[] methods = request.getMethods();
|
Method[] methods = request.getMethods();
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
if (!method.getName().startsWith("set")) {
|
if (!method.getName().startsWith("set")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printAssertions(FMT_REQUEST_ASSERTIONS, method, true);
|
if (method.getParameterTypes()[0].isAssignableFrom(List.class)) {
|
||||||
|
ParameterizedType type = (ParameterizedType) method.getGenericParameterTypes()[0];
|
||||||
|
Class<?> actualType = Class.forName(type.getActualTypeArguments()[0].getTypeName());
|
||||||
|
list.add(actualType);
|
||||||
|
|
||||||
|
String sun = actualType.getSimpleName();
|
||||||
|
print("\tfor (%s.%s %s : request.%s()) {\n", request.getSimpleName(), actualType.getSimpleName(), sun.toLowerCase(), method.getName().replace("set", "get"));
|
||||||
|
print("\t\textracted%sNestNestAssertions(%s);\n", actualType.getSimpleName(), sun.toLowerCase());
|
||||||
|
print("\t}\n", method.getName(), sun.toLowerCase());
|
||||||
|
} else {
|
||||||
|
printAssertions(FMT_REQUEST_ASSERTIONS, method, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print("}\n");
|
print("}\n");
|
||||||
|
|
||||||
|
for (Class<?> clazz : list) {
|
||||||
|
genNest(clazz);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
private static void genResponseParams(Class<?> response) {
|
private static void genResponseParams(Class<?> response) {
|
||||||
print("void extracted%sParams(%s response) {\n", response.getSimpleName(), response.getSimpleName());
|
print("void extracted%sParams(%s response) {\n", response.getSimpleName(), response.getSimpleName());
|
||||||
|
|
||||||
|
List<Class<?>> list = new ArrayList<>();
|
||||||
Method[] methods = response.getMethods();
|
Method[] methods = response.getMethods();
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
if (!method.getName().startsWith("set")) {
|
if (!method.getName().startsWith("set")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (method.getParameterTypes()[0].isAssignableFrom(List.class)) {
|
||||||
|
ParameterizedType type = (ParameterizedType) method.getGenericParameterTypes()[0];
|
||||||
|
Class<?> actualType = Class.forName(type.getActualTypeArguments()[0].getTypeName());
|
||||||
|
list.add(actualType);
|
||||||
|
|
||||||
printParams(FMT_RESPONSE_METHOD, method);
|
String sun = actualType.getSimpleName();
|
||||||
|
print("\t%s.%s %s = new %s.%s();\n", response.getSimpleName(), actualType.getSimpleName(), sun.toLowerCase(), response.getSimpleName(), actualType.getSimpleName());
|
||||||
|
print("\textracted%sNestParams(%s);\n", actualType.getSimpleName(), sun.toLowerCase());
|
||||||
|
print("\tresponse.set%s(Lists.list(%s));\n", method.getName(), sun.toLowerCase());
|
||||||
|
} else {
|
||||||
|
printParams(FMT_RESPONSE_METHOD, method);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print("}\n");
|
print("}\n");
|
||||||
|
|
||||||
|
for (Class<?> clazz : list) {
|
||||||
|
genNest(clazz);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
private static void genResponseAssertions(Class<?> response) {
|
private static void genResponseAssertions(Class<?> response) {
|
||||||
print("void extracted%sAssertions(%s response) {\n", response.getSimpleName(), response.getSimpleName());
|
print("void extracted%sAssertions(%s response) {\n", response.getSimpleName(), response.getSimpleName());
|
||||||
|
|
||||||
|
List<Class<?>> list = new ArrayList<>();
|
||||||
Method[] methods = response.getMethods();
|
Method[] methods = response.getMethods();
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
if (!method.getName().startsWith("set")) {
|
if (!method.getName().startsWith("set")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (method.getParameterTypes()[0].isAssignableFrom(List.class)) {
|
||||||
|
ParameterizedType type = (ParameterizedType) method.getGenericParameterTypes()[0];
|
||||||
|
Class<?> actualType = Class.forName(type.getActualTypeArguments()[0].getTypeName());
|
||||||
|
list.add(actualType);
|
||||||
|
|
||||||
printAssertions(FMT_RESPONSE_ASSERTIONS, method, false);
|
String sun = actualType.getSimpleName();
|
||||||
|
print("\tfor (%s.%s %s : response.%s()) {\n", response.getSimpleName(), actualType.getSimpleName(), sun.toLowerCase(), method.getName().replace("set", "get"));
|
||||||
|
print("\t\textracted%sNestNestAssertions(%s);\n", actualType.getSimpleName(), sun.toLowerCase());
|
||||||
|
print("\t}\n", method.getName(), sun.toLowerCase());
|
||||||
|
} else {
|
||||||
|
printAssertions(FMT_RESPONSE_ASSERTIONS, method, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print("}\n");
|
print("}\n");
|
||||||
|
|
||||||
|
for (Class<?> clazz : list) {
|
||||||
|
genNest(clazz);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void gen(Class<?> request, Class<?> response, String methodName, String url) {
|
public static void gen(Class<?> request, Class<?> response, String methodName, String url) {
|
||||||
|
|
|
||||||
|
|
@ -32,43 +32,43 @@ class RefGenTestMethodTest {
|
||||||
RefGenTestMethod.gen(PersonOpenAccountThreeElementRequest.class, PersonOpenAccountThreeElementResponse.class,
|
RefGenTestMethod.gen(PersonOpenAccountThreeElementRequest.class, PersonOpenAccountThreeElementResponse.class,
|
||||||
"personOpenAccountThreeElement", "/account/v2/person-open-account-three-element");
|
"personOpenAccountThreeElement", "/account/v2/person-open-account-three-element");
|
||||||
|
|
||||||
RefGenTestMethod.gen(PersonOpenAccountFourElementRequest.class, PersonOpenAccountFourElementResponse.class,
|
// RefGenTestMethod.gen(PersonOpenAccountFourElementRequest.class, PersonOpenAccountFourElementResponse.class,
|
||||||
"personOpenAccountFourElement", "/account/v2/person-open-account-four-element");
|
// "personOpenAccountFourElement", "/account/v2/person-open-account-four-element");
|
||||||
|
//
|
||||||
RefGenTestMethod.gen(OpenAccountCompanyRequest.class, OpenAccountCompanyResponse.class,
|
// RefGenTestMethod.gen(OpenAccountCompanyRequest.class, OpenAccountCompanyResponse.class,
|
||||||
"openAccountCompany", "/account/v2/company-open-account");
|
// "openAccountCompany", "/account/v2/company-open-account");
|
||||||
|
//
|
||||||
RefGenTestMethod.gen(ModAccPersonRequest.class, ModAccPersonResponse.class,
|
// RefGenTestMethod.gen(ModAccPersonRequest.class, ModAccPersonResponse.class,
|
||||||
"modAccPerson", "/account/v2/person-mod-account");
|
// "modAccPerson", "/account/v2/person-mod-account");
|
||||||
|
//
|
||||||
RefGenTestMethod.gen(ModAccCompanyRequest.class, ModAccCompanyResponse.class,
|
// RefGenTestMethod.gen(ModAccCompanyRequest.class, ModAccCompanyResponse.class,
|
||||||
"modAccCompany", "/account/v2/company-mod-account");
|
// "modAccCompany", "/account/v2/company-mod-account");
|
||||||
|
//
|
||||||
RefGenTestMethod.gen(QueryBalanceRequest.class, QueryBalanceResponse.class,
|
// RefGenTestMethod.gen(QueryBalanceRequest.class, QueryBalanceResponse.class,
|
||||||
"queryBalance", "/account/v2/query-balance");
|
// "queryBalance", "/account/v2/query-balance");
|
||||||
|
//
|
||||||
RefGenTestMethod.gen(QueryCardInfoRequest.class, QueryCardInfoResponse.class,
|
// RefGenTestMethod.gen(QueryCardInfoRequest.class, QueryCardInfoResponse.class,
|
||||||
"queryCardInfo", "/card-bin/v2/query");
|
// "queryCardInfo", "/card-bin/v2/query");
|
||||||
|
//
|
||||||
RefGenTestMethod.gen(PersonBindRequest.class, PersonBindResponse.class,
|
// RefGenTestMethod.gen(PersonBindRequest.class, PersonBindResponse.class,
|
||||||
"personBind", "/bank-card/v2/person-bind");
|
// "personBind", "/bank-card/v2/person-bind");
|
||||||
|
//
|
||||||
RefGenTestMethod.gen(CompanyBindRequest.class, CompanyBindResponse.class,
|
// RefGenTestMethod.gen(CompanyBindRequest.class, CompanyBindResponse.class,
|
||||||
"companyBind", "/bank-card/v2/company-bind");
|
// "companyBind", "/bank-card/v2/company-bind");
|
||||||
|
//
|
||||||
|
//
|
||||||
RefGenTestMethod.gen(BankCardQueryRequest.class, BankCardQueryResponse.class,
|
// RefGenTestMethod.gen(BankCardQueryRequest.class, BankCardQueryResponse.class,
|
||||||
"bankCardQuery", "/bank-card/v2/query");
|
// "bankCardQuery", "/bank-card/v2/query");
|
||||||
|
//
|
||||||
|
//
|
||||||
RefGenTestMethod.gen(UnbindRequest.class, UnbindResponse.class,
|
// RefGenTestMethod.gen(UnbindRequest.class, UnbindResponse.class,
|
||||||
"unbind", "/bank-card/v2/unbind");
|
// "unbind", "/bank-card/v2/unbind");
|
||||||
|
//
|
||||||
RefGenTestMethod.gen(ClosedAccRequest.class, ClosedAccResponse.class,
|
// RefGenTestMethod.gen(ClosedAccRequest.class, ClosedAccResponse.class,
|
||||||
"closedAcc", "/account/v2/closed-account");
|
// "closedAcc", "/account/v2/closed-account");
|
||||||
|
//
|
||||||
RefGenTestMethod.gen(OpenAccInnerRequest.class, OpenAccInnerResponse.class,
|
// RefGenTestMethod.gen(OpenAccInnerRequest.class, OpenAccInnerResponse.class,
|
||||||
"openAccInner", "/account/v2/inner-open-account");
|
// "openAccInner", "/account/v2/inner-open-account");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue