REM:
1. 增加新的QA测试框架
This commit is contained in:
HuangXin 2020-09-10 18:13:16 +08:00
parent 9808ac4bdf
commit 3a915103d1
7 changed files with 338 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package com.dispose.test.common;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.dto.protocol.base.BaseRespStatus;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.service.ProtocolSecurityService;
import com.fasterxml.jackson.core.type.TypeReference;
@ -57,7 +58,7 @@ public class CommonRestfulJson extends CommonEnvironment {
* @return the protocol resp dto
* @throws Exception the exception
*/
public <T> ProtocolRespDTO<T> performanceRestful(String reqJson, String urlPath,
public <T> ProtocolRespDTO<? extends BaseRespStatus> performanceRestful(String reqJson, String urlPath,
Class<T> subClass,
ErrorCode errCode,
String loginToken,
@ -70,7 +71,7 @@ public class CommonRestfulJson extends CommonEnvironment {
}
return objectMapper.readValue(rspValue,
new TypeReference<ProtocolRespDTO<T>>() {
new TypeReference<ProtocolRespDTO<? extends BaseRespStatus>>() {
@Override
public Type getType() {
return Helper.createRespType(subClass);

View File

@ -60,7 +60,7 @@ public class Helper {
break;
}
if (loginToken != null && loginToken.length() > 0) {
if (loginToken != null) {
build.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", ConstValue.STRING_HTTP_AUTH_HEAD + loginToken)
.content(sendMsgContent);

View File

@ -0,0 +1,53 @@
package com.dispose.test.common;
import com.dispose.common.ErrorCode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* The type Qa test item.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class QATestItem {
/**
* The Priority.
*/
private TestPriority priority;
/**
* The Url path.
*/
private String urlPath;
/**
* The Method.
*/
private RequestMethod method;
/**
* The Case json value.
*/
private String caseJsonValue;
/**
* The Rsp class.
*/
private Class<?> rspClass;
/**
* The Rsp code.
*/
private ErrorCode rspCode;
/**
* The Auto login.
*/
private Boolean autoLogin;
/**
* The Verify callback.
*/
private VerifyProtoRespCallback verifyCallback;
}

View File

@ -0,0 +1,65 @@
package com.dispose.test.common;
import com.dispose.common.BaseEnum;
/**
* The enum Test priority.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
public enum TestPriority implements BaseEnum {
/**
* P 1 priority test priority.
*/
P1_PRIORITY(1, "P1 优先级"),
/**
* P 2 priority test priority.
*/
P2_PRIORITY(2, "P2 优先级"),
/**
* P 3 priority test priority.
*/
P3_PRIORITY(3, "P3 优先级"),
;
/**
* The Code.
*/
private final Integer code;
/**
* The Readme.
*/
private final String readme;
/**
* Instantiates a new Test priority.
*
* @param code the code
* @param readme the readme
*/
TestPriority(int code, String readme) {
this.code = code;
this.readme = readme;
}
/**
* Gets value.
*
* @return the value
*/
@Override
public Integer getValue() {
return this.code;
}
/**
* Gets description.
*
* @return the description
*/
@Override
public String getDescription() {
return this.readme;
}
}

View File

@ -0,0 +1,20 @@
package com.dispose.test.common;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
/**
* The interface Verify proto resp callback.
*
* @param <T> the type parameter
* @author <huangxin@cmhi.chinamoblie.com>
*/
public interface VerifyProtoRespCallback<T> {
/**
* Verify callback.
*
* @param obj the obj
*/
void verifyCallback(ProtocolRespDTO<T> obj, ErrorCode errorCode);
}

View File

@ -0,0 +1,95 @@
package com.dispose.test.qa.exec;
import com.dispose.pojo.dto.protocol.base.BaseRespStatus;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.test.common.CommonRestfulJson;
import com.dispose.test.common.QATestItem;
import com.dispose.test.qa.testcase.v20.P1;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.TestContextManager;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.Collection;
/**
* The type Test case run.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@RunWith(Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Slf4j
@Transactional
@Rollback
public class TestCaseRun extends CommonRestfulJson {
/**
* The Rsp object.
*/
private final QATestItem rspObject;
/**
* Instantiates a new Test case run.
*
* @param rspObject the rsp object
*/
public TestCaseRun(QATestItem rspObject) {
this.rspObject = rspObject;
}
/**
* Param data collection.
*
* @return the collection
*/
@Parameters
public static Collection<QATestItem> paramData() {
return Arrays.asList(P1.getTestCase());
}
/**
* Sets up.
*
* @throws Exception the exception
*/
@Before
public void setUp() throws Exception {
TestContextManager testContextManager = new TestContextManager(getClass());
testContextManager.prepareTestInstance(this);
}
/**
* Run qa p 1 test case.
*
* @throws Exception the exception
*/
@Test
public void runQaP1TestCase() throws Exception {
ProtocolRespDTO<? extends BaseRespStatus> o = performanceRestful(rspObject.getCaseJsonValue(),
rspObject.getUrlPath(),
rspObject.getRspClass(),
rspObject.getRspCode(),
rspObject.getAutoLogin() ? getLoginToken() : "",
true,
rspObject.getMethod());
Assert.assertNotNull(o);
if (rspObject.getVerifyCallback() != null) {
rspObject.getVerifyCallback().verifyCallback(o, rspObject.getRspCode());
}
}
}

View File

@ -0,0 +1,96 @@
package com.dispose.test.qa.testcase.v20;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.dto.protocol.auth.LoginRsp;
import com.dispose.pojo.dto.protocol.device.manager.AddDeviceRsp;
import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority;
import com.dispose.test.common.VerifyProtoRespCallback;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* The type P 1.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Slf4j
public class P1 {
/**
* The constant testItemArray.
*/
private static final QATestItem[] testItemArray = new QATestItem[]{
QATestItem.builder()
.priority(TestPriority.P1_PRIORITY)
.urlPath("/auth/login")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598580612302," +
"\"msgContent\":{\"password" +
"\":\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\"," +
"\"userName\":\"admin\"}}")
.rspClass(LoginRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<LoginRsp>) (v, e) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long)v.getMsgContent().getStatus(), e.getCode());
Assert.assertEquals("admin", v.getMsgContent().getUserName());
Assert.assertNotEquals(v.getMsgContent().getToken().length(), 0);
})
.build(),
QATestItem.builder()
.priority(TestPriority.P1_PRIORITY)
.urlPath("/auth/login")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":1,\"timeStamp\":1599116519744,\"code\":200," +
"\"msgContent" +
"\":\"eyJwYXNzd29yZCI6ImMzODU1ZTZiNmJiMTIwNDUwZjE2MGJhOTExMzQ1MjI4N" +
"jhmODlkMzYwNjJmMjA2MWViZWVmZDgwODE3ZTFkNTgiLCJ1c2VyTmFtZSI6ImFkbWluIn0\"}")
.rspClass(LoginRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<LoginRsp>) (v, e) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long)v.getMsgContent().getStatus(), e.getCode());
Assert.assertEquals("admin", v.getMsgContent().getUserName());
Assert.assertNotEquals(v.getMsgContent().getToken().length(), 0);
})
.build(),
QATestItem.builder()
.priority(TestPriority.P1_PRIORITY)
.urlPath("/manager/device")
.method(RequestMethod.PUT)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1599094454403," +
"\"msgContent\":{\"items\":[{\"ipAddr\":\"10.88.77.15\",\"ipPort\":\"\"," +
"\"deviceType\":0,\"areaCode\":0,\"deviceName\":\"中移杭研实验室迪普清洗设备\"," +
"\"manufacturer\":\"DPTech\",\"model\":\"UMC\",\"version\":\"5.7.13\"," +
"\"userName\":\"test\",\"password\":\"testpassword\"," +
"\"urlPath\":\"UMC/service/AbnormalFlowCleaningService\",\"urlType\":0," +
"\"readme\":\"实验室测试设备\",\"capacity\":[{\"capacityType\":0,\"objectType\":1," +
"\"ipType\":1,\"protectIp\":\"192.168.20.1/24\",\"reserveNetflow\":10}," +
"{\"capacityType\":1,\"objectType\":4,\"ipType\":2,\"reserveNetflow\":20}]}]}}")
.rspClass(AddDeviceRsp.class)
.rspCode(ErrorCode.ERR_LOGOUT)
.autoLogin(false)
.verifyCallback((VerifyProtoRespCallback<AddDeviceRsp>) (v, e) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long)v.getMsgContent().getStatus(), e.getCode());
})
.build()
};
/**
* Get test case qa test item [ ].
*
* @return the qa test item [ ]
*/
public static QATestItem[] getTestCase() {
return testItemArray;
}
}