Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

[SIP] OPEN API test field source code

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

The first part introduces how to use orthogonal verification to realize the design of test cases. This article will introduce the implementation of the code for the previous article. Take the Case4 of authorization use case one as an example. First of all, you need to prepare the test data, and this article uses DBUNIT. First, prepare the xml file as follows:

Then use the DBUNIT method to load the data. In practice, this part is divided into loadData functions as follows: loadCaseData ("testCase4_CORE.xml", coreSchemaName); then the main part of the test, JUNIT coding work. The code is as follows: public class TestApiGroups extends TestBaseWS {

Private static String udbSchemaName

Private static String coreSchemaName

Private String api_server = "http://10.2.226.19:8180/sip/rest";

Static String mysql_url = "jdbc:mysql://10.2.226.19:3306/sip"

Private String dir = "com\ alisoft\\ aep\\ sip\\ core54"

Public TestApiGroups () throws Exception {

Super ()

Db = util.DBConnection.getDbUnit ()

UdbSchemaName = util.DBConnection.schemaMap.get ("UDB")

CoreSchemaName = util.DBConnection.schemaMap.get ("CORE")

System.out.println ("data preparation begins.")

LoadCaseData ("testCase2_CORE.xml", coreSchemaName)

LoadCaseData ("testCase3_CORE.xml", coreSchemaName)

LoadCaseData ("testCase4_CORE.xml", coreSchemaName)

LoadCaseData ("testCase5_CORE.xml", coreSchemaName)

LoadCaseData ("testCase6_CORE.xml", coreSchemaName)

Util.SIPHelp.Crush_Sip ()

System.out.println ("data ready")

/ / TODO Auto-generated constructor stub

}

Public void TestCase (Map map, String ExpXmlText,String EXPSTATUES,String EXPERROR,String sip_apiname,String AppKey)

Throws Exception {

String sip_appkey = AppKey;// "test_app003"; / / app_id

String sip_appsecret = "secret_app003"

String sessionid = "123456789"

String url = util.SIPHelp.prepareUrl (sip_appkey, sip_apiname, sip_appsecret

Api_server, sessionid,map)

System.out.println (url)

WebConversation conversation = new WebConversation ()

WebRequest request = new PostMethodWebRequest (url)

WebResponse response = conversation.getResponse (request)

String ActStatus = response.getHeaderField ("sip_status")

String ActError = response.getHeaderField ("sip_error_message")

System.out.println (ActStatus)

AssertEquals (EXPSTATUES, ActStatus)

If (EXPSTATUES.equals ("9999"))

{assertEquals (null, ActError);}

Else

{

AssertEquals (EXPERROR, ActError)

}

String ActXmlTest = response.getText ()

System.out.println (ActXmlTest)

AssertEquals (ExpXmlText, ActXmlTest)

} / * *

* the API_GROUPS field in SIP_APP_LEVEL is multiple fields, and the API is in Group

* @ throws Exception

, /

@ Test

Public void TestCase4 () throws Exception {

String sip_apiname = "alitest.ali-54-test204"

/ / data preparation

String ExpXmlText = "not OK"

String sip_appkey = "test_app059"

TestCase (null,ExpXmlText, "9999", null, sip_apiname,sip_appkey)

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 299

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report