REM:
1. 增加测试用例
2. 修改测试用例HTTP错误码判断方法
This commit is contained in:
HuangXin 2020-09-12 11:01:16 +08:00
parent 7b90ef9005
commit 9776440d04
4 changed files with 92 additions and 13 deletions

View File

@ -10,7 +10,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
@ -39,7 +38,7 @@ public class TestHelper {
String urlPath, String loginToken, String urlPath, String loginToken,
String sendMsgContent, ErrorCode errCode) throws Exception { String sendMsgContent, ErrorCode errCode) throws Exception {
MockHttpServletRequestBuilder build; MockHttpServletRequestBuilder build;
int httpCode = (errCode == ErrorCode.ERR_OK) ? HttpServletResponse.SC_OK : HttpServletResponse.SC_BAD_REQUEST; int httpCode = errCode.getHttpCode();
switch (reqType) { switch (reqType) {
case PUT: case PUT:

View File

@ -4,6 +4,7 @@ import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.mapper.DisposeTaskMapper; import com.dispose.mapper.DisposeTaskMapper;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.qa.testcase.v20.P1; import com.dispose.test.qa.testcase.v20.P1;
import com.dispose.test.qa.testcase.v20.P2Login;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -37,6 +38,7 @@ public interface TestCaseRun {
static List<QATestItem> getAllTestCase() { static List<QATestItem> getAllTestCase() {
List<QATestItem> tolTestCase = new ArrayList<>(); List<QATestItem> tolTestCase = new ArrayList<>();
Collections.addAll(tolTestCase, P1.getTestCase()); Collections.addAll(tolTestCase, P1.getTestCase());
Collections.addAll(tolTestCase, P2Login.getTestCase());
return tolTestCase; return tolTestCase;
} }
} }

View File

@ -32,7 +32,7 @@ public class P1 {
/** /**
* The Base p 1 id. * The Base p 1 id.
*/ */
public static final int BASE_P1_ID = 100; public static final int BASE_P1_ID = 0;
/** /**
* The constant testItemArray. * The constant testItemArray.
@ -50,7 +50,7 @@ public class P1 {
"\"userName\":\"admin\"}}") "\"userName\":\"admin\"}}")
.rspClass(LoginRsp.class) .rspClass(LoginRsp.class)
.rspCode(ErrorCode.ERR_OK) .rspCode(ErrorCode.ERR_OK)
.autoLogin(true) .autoLogin(false)
.verifyCallback((VerifyProtoRespCallback<LoginRsp>) (v, e, c) -> { .verifyCallback((VerifyProtoRespCallback<LoginRsp>) (v, e, c) -> {
Assert.assertNotNull(v); Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent()); Assert.assertNotNull(v.getMsgContent());
@ -72,7 +72,7 @@ public class P1 {
"jhmODlkMzYwNjJmMjA2MWViZWVmZDgwODE3ZTFkNTgiLCJ1c2VyTmFtZSI6ImFkbWluIn0\"}") "jhmODlkMzYwNjJmMjA2MWViZWVmZDgwODE3ZTFkNTgiLCJ1c2VyTmFtZSI6ImFkbWluIn0\"}")
.rspClass(LoginRsp.class) .rspClass(LoginRsp.class)
.rspCode(ErrorCode.ERR_OK) .rspCode(ErrorCode.ERR_OK)
.autoLogin(true) .autoLogin(false)
.verifyCallback((VerifyProtoRespCallback<LoginRsp>) (v, e, c) -> { .verifyCallback((VerifyProtoRespCallback<LoginRsp>) (v, e, c) -> {
Assert.assertNotNull(v); Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent()); Assert.assertNotNull(v.getMsgContent());

View File

@ -0,0 +1,78 @@
package com.dispose.test.qa.testcase.v20;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.dto.protocol.auth.LoginRsp;
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 2 login.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@Slf4j
public class P2Login {
/**
* The constant BASE_P2_LOGIN_ID.
*/
public static final int BASE_P2_LOGIN_ID = 100;
/**
* Get test case qa test item [ ].
*
* @return the qa test item [ ]
*/
public static QATestItem[] getTestCase() {
return testItemArray;
}
/**
* The constant testItemArray.
*/
private static final QATestItem[] testItemArray = new QATestItem[]{
QATestItem.builder()
.id(BASE_P2_LOGIN_ID)
.name("登陆(采用AES加密后的base64编码格式密文")
.priority(TestPriority.P1_PRIORITY)
.urlPath("/auth/login")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":2,\"timeStamp\":1599812474663," +
"\"msgContent\":\"vIqGePgNnhhbuQRZhNTLDbtawenSt" +
"+nS21iylRfU9Y8BZMEyUJxBBy3YkCxuTrnloPuJWDaUZZrhP7HVkaMUPrTP0riYfDYDCI" +
"/nFgXc9yc7JoMGy695OGm51czkytcOoqQtND2Ywd0/fNULgu664g==\"}")
.rspClass(LoginRsp.class)
.rspCode(ErrorCode.ERR_OK)
.autoLogin(false)
.verifyCallback((VerifyProtoRespCallback<LoginRsp>) (v, e, c) -> {
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()
.id(BASE_P2_LOGIN_ID + 1)
.name("ver为空")
.priority(TestPriority.P1_PRIORITY)
.urlPath("/auth/login")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\": ,\"cryptoType\": 0,\"timeStamp\": 1598580612302,\"msgContent\": " +
"{\"password\": \"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\"," +
"\"userName\": \"admin\" }}")
.rspClass(LoginRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(false)
.verifyCallback((VerifyProtoRespCallback<LoginRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode());
})
.build(),
};
}