提交 fdf70b98 编写于 作者: Z zhangfuzhi

网络用例整改,删除重复用例

Signed-off-by: Nzhangfuzhi <zhangfuzhi1@huawei.com>
上级 2eca517c
...@@ -14,36 +14,38 @@ ...@@ -14,36 +14,38 @@
*/ */
import net_Http from '@ohos.net.http'; import net_Http from '@ohos.net.http';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import { describe, expect, it } from '@ohos/hypium'
export default function Http2Test() { export default function Http2Test() {
describe('Http2Test', function () { describe('Http2Test', function () {
/** /**
* @tc.number Telephony_NETSTACK_Http2TestBasicGet_0100 * @tc.number Telephony_NETSTACK_Http2TestBasicGet_0100
* @tc.name set usingCache to true * @tc.name set usingCache to true
* @tc.desc usingCache test * @tc.desc usingCache test
*/ */
it('Telephony_NETSTACK_Http2TestBasicGet_0100', 0, async function (done) { it('Telephony_NETSTACK_Http2TestBasicGet_0100', 0, async function (done) {
let http = net_Http.createHttp() let http = net_Http.createHttp();
http.request("https://www.zhihu.com", { http.request("https://www.zhihu.com", {
usingProtocol: net_Http.HttpProtocol.HTTP1_1 usingProtocol: net_Http.HttpProtocol.HTTP1_1
}).then(function (data) { }).then(function (data) {
http.destroy();
expect(data.responseCode === net_Http.ResponseCode.OK).assertTrue(); expect(data.responseCode === net_Http.ResponseCode.OK).assertTrue();
done(); done();
}); });
}); });
/** /**
* @tc.number Telephony_NETSTACK_Http2TestBasicGet_0200 * @tc.number Telephony_NETSTACK_Http2TestBasicGet_0200
* @tc.name set usingCache to true * @tc.name set usingCache to true
* @tc.desc usingCache test * @tc.desc usingCache test
*/ */
it('Telephony_NETSTACK_Http2TestBasicGet_0200', 0, async function (done) { it('Telephony_NETSTACK_Http2TestBasicGet_0200', 0, async function (done) {
let http = net_Http.createHttp() let http = net_Http.createHttp();
http.request("https://www.zhihu.com", { http.request("https://www.zhihu.com", {
usingProtocol: net_Http.HttpProtocol.HTTP2 usingProtocol: net_Http.HttpProtocol.HTTP2
}).then(function (data) { }).then(function (data) {
http.destroy();
console.info("Telephony_NETSTACK_Http2TestBasicGet_0200" + JSON.stringify(data)); console.info("Telephony_NETSTACK_Http2TestBasicGet_0200" + JSON.stringify(data));
expect(data.responseCode === net_Http.ResponseCode.OK).assertTrue(); expect(data.responseCode === net_Http.ResponseCode.OK).assertTrue();
done(); done();
...@@ -51,13 +53,14 @@ export default function Http2Test() { ...@@ -51,13 +53,14 @@ export default function Http2Test() {
}); });
/** /**
* @tc.number Telephony_NETSTACK_Http2TestBasicGet_0300 * @tc.number Telephony_NETSTACK_Http2TestBasicGet_0300
* @tc.name set usingCache to true * @tc.name set usingCache to true
* @tc.desc usingCache test * @tc.desc usingCache test
*/ */
it('Telephony_NETSTACK_Http2TestBasicGet_0300', 0, async function (done) { it('Telephony_NETSTACK_Http2TestBasicGet_0300', 0, async function (done) {
let http = net_Http.createHttp() let http = net_Http.createHttp();
http.request("https://www.zhihu.com").then(function (data) { http.request("https://www.zhihu.com").then(function (data) {
http.destroy();
console.info("Telephony_NETSTACK_Http2TestBasicGet_0300" + JSON.stringify(data)); console.info("Telephony_NETSTACK_Http2TestBasicGet_0300" + JSON.stringify(data));
expect(data.responseCode === net_Http.ResponseCode.OK).assertTrue(); expect(data.responseCode === net_Http.ResponseCode.OK).assertTrue();
done(); done();
...@@ -65,9 +68,9 @@ export default function Http2Test() { ...@@ -65,9 +68,9 @@ export default function Http2Test() {
}); });
/** /**
* @tc.number Telephony_NETSTACK_Http2TestBasicGet_0400 * @tc.number Telephony_NETSTACK_Http2TestBasicGet_0400
* @tc.name set usingCache to true * @tc.name set usingCache to true
* @tc.desc usingCache test * @tc.desc usingCache test
*/ */
it('Telephony_NETSTACK_Http2TestBasicGet_0400', 0, async function (done) { it('Telephony_NETSTACK_Http2TestBasicGet_0400', 0, async function (done) {
expect(net_Http.HttpProtocol.HTTP1_1).assertEqual(0); expect(net_Http.HttpProtocol.HTTP1_1).assertEqual(0);
...@@ -76,9 +79,9 @@ export default function Http2Test() { ...@@ -76,9 +79,9 @@ export default function Http2Test() {
}); });
/** /**
* @tc.number Telephony_NETSTACK_Http2TestBasicGet_0500 * @tc.number Telephony_NETSTACK_Http2TestBasicGet_0500
* @tc.name set usingCache to true * @tc.name set usingCache to true
* @tc.desc usingCache test * @tc.desc usingCache test
*/ */
it('Telephony_NETSTACK_Http2TestBasicGet_0500', 0, async function (done) { it('Telephony_NETSTACK_Http2TestBasicGet_0500', 0, async function (done) {
expect(net_Http.HttpDataType.STRING).assertEqual(0); expect(net_Http.HttpDataType.STRING).assertEqual(0);
...@@ -87,11 +90,11 @@ export default function Http2Test() { ...@@ -87,11 +90,11 @@ export default function Http2Test() {
done(); done();
}); });
it('Telephony_http_HttpTestPriority_0100', 0, async function(done){ it('Telephony_http_HttpTestPriority_0100', 0, async function (done) {
let CaseName = 'Telephony_http_HttpTestPriority_0100'; let CaseName = 'Telephony_http_HttpTestPriority_0100';
try { try {
let httpRequestOptions ={ let httpRequestOptions = {
method: net_http.RequestMethod.GET, method: net_Http.RequestMethod.GET,
extraData: null, extraData: null,
expectDataType: net_Http.HttpDataType.STRING, expectDataType: net_Http.HttpDataType.STRING,
header: "content-type': 'application/json", header: "content-type': 'application/json",
...@@ -99,15 +102,16 @@ export default function Http2Test() { ...@@ -99,15 +102,16 @@ export default function Http2Test() {
connectTimeout: 6000, connectTimeout: 6000,
priority: 100 priority: 100
} }
var httpRequest = net_http.createHttp(); var httpRequest = net_Http.createHttp();
httpRequest.request("https://httpbin/anything", httpRequestOptions, (err,data) => { httpRequest.request("https://www.zhihu.com", httpRequestOptions, (err, data) => {
console.info(CaseName + Json.stringify(err)+ "data"+ Json.stringify(data)); httpRequest.destroy();
expect(data.responseCode === net_http.ResponseCode.Ok).assertTrue(); console.info(CaseName + JSON.stringify(err) + "data" + JSON.stringify(data));
expect(data.responseCode === net_Http.ResponseCode.OK).assertTrue();
expect(data.resultType == net_Http.HttpDataType.STRING).assertTrue(); expect(data.resultType == net_Http.HttpDataType.STRING).assertTrue();
done(); done();
}); });
} catch(err){ } catch (err) {
console.info(CaseName+ "err=" + err) console.info(CaseName + "err=" + err);
done(); done();
return; return;
} }
......
...@@ -26,11 +26,11 @@ export default function HttpCacheTest() { ...@@ -26,11 +26,11 @@ export default function HttpCacheTest() {
*/ */
it('Telephony_NetStack_HttpTestBasicGet_0100', 0, async function(done){ it('Telephony_NetStack_HttpTestBasicGet_0100', 0, async function(done){
let CaseName = 'Telephony_NetStack_HttpTestBasicGet_0100';
let http = net_http.createHttp(); let http = net_http.createHttp();
http.request('https://httpbin.org/anything', { http.request('https://httpbin.org/anything', {
usingCache : true usingCache : true
}).then(function(data){ }).then(function(data){
http.destroy();
expect(data.responseCode === net_http.ResponseCode.OK).assertTrue(); expect(data.responseCode === net_http.ResponseCode.OK).assertTrue();
done(); done();
return; return;
...@@ -49,6 +49,7 @@ export default function HttpCacheTest() { ...@@ -49,6 +49,7 @@ export default function HttpCacheTest() {
http.request('https://httpbin.org/anything', { http.request('https://httpbin.org/anything', {
usingCache : false usingCache : false
}).then(function(data){ }).then(function(data){
http.destroy();
console.info(CaseName + JSON.stringify(data)); console.info(CaseName + JSON.stringify(data));
expect(data.responseCode === net_http.ResponseCode.OK).assertTrue(); expect(data.responseCode === net_http.ResponseCode.OK).assertTrue();
done(); done();
...@@ -70,6 +71,7 @@ export default function HttpCacheTest() { ...@@ -70,6 +71,7 @@ export default function HttpCacheTest() {
usingCache : true usingCache : true
}).then(function (){ }).then(function (){
cache.flush().then(function (data){ cache.flush().then(function (data){
http.destroy();
console.info(CaseName + JSON.stringify(data)); console.info(CaseName + JSON.stringify(data));
expect(data === undefined).assertTrue(); expect(data === undefined).assertTrue();
done(); done();
...@@ -92,6 +94,7 @@ export default function HttpCacheTest() { ...@@ -92,6 +94,7 @@ export default function HttpCacheTest() {
usingCache : true usingCache : true
}).then(function (){ }).then(function (){
cache.flush(function (data){ cache.flush(function (data){
http.destroy();
console.info(CaseName + JSON.stringify(data)); console.info(CaseName + JSON.stringify(data));
expect(data === undefined).assertTrue(); expect(data === undefined).assertTrue();
done(); done();
...@@ -114,6 +117,7 @@ export default function HttpCacheTest() { ...@@ -114,6 +117,7 @@ export default function HttpCacheTest() {
usingCache : true usingCache : true
}).then(function (){ }).then(function (){
cache.delete().then(function (data){ cache.delete().then(function (data){
http.destroy();
console.info(CaseName + JSON.stringify(data)); console.info(CaseName + JSON.stringify(data));
expect(data === undefined).assertTrue(); expect(data === undefined).assertTrue();
done(); done();
...@@ -136,6 +140,7 @@ export default function HttpCacheTest() { ...@@ -136,6 +140,7 @@ export default function HttpCacheTest() {
usingCache : true usingCache : true
}).then(function (){ }).then(function (){
cache.delete(function (data){ cache.delete(function (data){
http.destroy();
console.info(CaseName + JSON.stringify(data)); console.info(CaseName + JSON.stringify(data));
expect(data === undefined).assertTrue(); expect(data === undefined).assertTrue();
done(); done();
......
...@@ -14,129 +14,143 @@ ...@@ -14,129 +14,143 @@
*/ */
import netHttp from '@ohos.net.http'; import netHttp from '@ohos.net.http';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import { describe, expect, it } from '@ohos/hypium'
export default function Telephony_NETSTACK_HTTPTest() {
describe('Telephony_NETSTACK_HTTPTest',function(){
/** export default function Telephony_NETSTACK_HTTPTest() {
* @tc.number Telephony_NETSTACK_HttpTestBasicGet_0100
* @tc.name 基本场景,测试能否GET一个网址
* @tc.desc Function test`
*/
it('Telephony_NETSTACK_HttpTestBasicGet_0100', 0, function(done){ describe('Telephony_NETSTACK_HTTPTest', function () {
let http = netHttp.createHttp()
http.request("https://httpbin.org/anything").then(function(data){ /**
expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue(); * @tc.number Telephony_NETSTACK_HttpTestBasicGet_0100
done(); * @tc.name 基本场景,测试能否GET一个网址
* @tc.desc Function test`
*/
it('Telephony_NETSTACK_HttpTestBasicGet_0100', 0, function (done) {
let http = netHttp.createHttp();
http.request("https://httpbin.org/anything").then(function (data) {
http.destroy();
expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue();
done();
});
}); });
});
/** /**
* @tc.number Telephony_NETSTACK_HttpTestUserAgent_0100 * @tc.number Telephony_NETSTACK_HttpTestUserAgent_0100
* @tc.name 返回用户代理 * @tc.name 返回用户代理
* @tc.desc Function test` * @tc.desc Function test`
*/ */
it('Telephony_NETSTACK_HttpTestUserAgent_0100', 0, function(done){ it('Telephony_NETSTACK_HttpTestUserAgent_0100', 0, function (done) {
let http = netHttp.createHttp() let http = netHttp.createHttp();
http.request("https://httpbin.org/user-agent").then(function(data){ http.request("https://httpbin.org/user-agent").then(function (data) {
expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue(); http.destroy();
console.info(JSON.stringify(data)); expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue();
expect(JSON.parse(data.result)["user-agent"] === "libcurl-agent/1.0").assertTrue(); console.info(JSON.stringify(data));
done(); expect(data.result.toString().search("user-agent") != -1).assertTrue();
expect(data.result.toString().search("libcurl-agent/1.0") != -1).assertTrue();
done();
});
}); });
});
/** /**
* @tc.number Telephony_NETSTACK_HttpTestHeader_0100 * @tc.number Telephony_NETSTACK_HttpTestHeader_0100
* @tc.name 返回Header * @tc.name 返回Header
* @tc.desc Function test` * @tc.desc Function test`
*/ */
it('Telephony_NETSTACK_HttpTestHeader_0100', 0, function(done){ it('Telephony_NETSTACK_HttpTestHeader_0100', 0, function (done) {
let http = netHttp.createHttp(); let http = netHttp.createHttp();
http.request("https://httpbin.org/headers").then(function(data){ http.request("https://httpbin.org/headers").then(function (data) {
expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue() http.destroy();
console.info("NETSTACK ####" + JSON.stringify(JSON.parse(data.result))) expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue();
expect(JSON.parse(data.result)["headers"]["Content-Type"] === "application/json").assertTrue() console.info("NETSTACK ####" + JSON.stringify(data.result));
done() expect(data.result.toString().search("Content-Type") != -1).assertTrue();
expect(data.result.toString().search("application/json") != -1).assertTrue();
done()
});
}); });
});
/** /**
* @tc.number Telephony_NETSTACK_HttpTestPost * @tc.number Telephony_NETSTACK_HttpTestPost
* @tc.name 返回post内容 * @tc.name 返回post内容
* @tc.desc Function test` * @tc.desc Function test`
*/ */
it('Telephony_NETSTACK_HttpTestPost_0100', 0, function(done){ it('Telephony_NETSTACK_HttpTestPost_0100', 0, function (done) {
let http = netHttp.createHttp() let http = netHttp.createHttp();
http.request("https://httpbin.org/post" ,{ http.request("https://httpbin.org/post", {
method : netHttp.RequestMethod.POST, method: netHttp.RequestMethod.POST,
extraData : "MineMine" extraData: "MineMine"
}).then(function(data){ }).then(function (data) {
expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue() http.destroy();
expect(JSON.parse(data.result)["data"] === "MineMine").assertTrue() expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue();
done(); expect(data.result.toString().search("MineMine") != -1).assertTrue()
done();
});
}); });
});
/** /**
* @tc.number Telephony_NETSTACK_HttpTestPUT * @tc.number Telephony_NETSTACK_HttpTestPUT
* @tc.name 返回put内容 * @tc.name 返回put内容
* @tc.desc Function test` * @tc.desc Function test`
*/ */
it('Telephony_NETSTACK_HttpTestPut_0100', 0, function(done){ it('Telephony_NETSTACK_HttpTestPut_0100', 0, function (done) {
let http = netHttp.createHttp() let http = netHttp.createHttp();
http.request("https://httpbin.org/put" ,{ http.request("https://httpbin.org/put", {
method : netHttp.RequestMethod.PUT, method: netHttp.RequestMethod.PUT,
extraData : "MineMine" extraData: "MineMine"
}).then(function(data){ }).then(function (data) {
expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue() http.destroy();
expect(JSON.parse(data.result)["data"] === "MineMine").assertTrue() expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue();
done(); expect(data.result.toString().search("MineMine") != -1).assertTrue()
done();
});
}); });
});
/** /**
* @tc.number Telephony_NETSTACK_HttpTestCookies * @tc.number Telephony_NETSTACK_HttpTestCookies
* @tc.name 返回Cookies内容 * @tc.name 返回Cookies内容
* @tc.desc Function test` * @tc.desc Function test`
*/ */
it('Telephony_NETSTACK_HttpTestCookies_0100', 0, function(done){ it('Telephony_NETSTACK_HttpTestCookies_0100', 0, function (done) {
let http = netHttp.createHttp() let http = netHttp.createHttp();
http.request("https://httpbin.org/cookies/set/name/value").then(function(data){ http.request("https://httpbin.org/cookies/set/name/value").then(function (data) {
expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue() http.destroy();
expect(data.cookies !== "").assertTrue() expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue();
done(); expect(data.cookies !== "").assertTrue();
done();
});
}); });
});
/** /**
* @tc.number Telephony_NETSTACK_HttpTestEncode * @tc.number Telephony_NETSTACK_HttpTestEncode
* @tc.name 返回Cookies内容 * @tc.name 返回Cookies内容
* @tc.desc Function test` * @tc.desc Function test`
*/ */
it('Telephony_NETSTACK_HttpTestEncode_0100', 0, function(done){ it('Telephony_NETSTACK_HttpTestEncode_0100', 0, function (done) {
let http = netHttp.createHttp() let http = netHttp.createHttp();
http.request("https://httpbin.org/response-headers?key1=val1&key2=val2",{ http.request("https://httpbin.org/response-headers?key1=val1&key2=val2", {
extraData : { extraData: {
"name1" : "mine1", "name1": "mine1",
"name2" : "mine2", "name2": "mine2",
} }
}).then(function(data){ }).then(function (data) {
expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue() http.destroy();
expect(JSON.parse(data.result)["key1"] === "val1").assertTrue() expect(data.responseCode === netHttp.ResponseCode.OK).assertTrue();
expect(JSON.parse(data.result)["key2"] === "val2").assertTrue() expect(data.result.toString().search("key1") != -1).assertTrue()
expect(JSON.parse(data.result)["name1"] === "mine1").assertTrue() expect(data.result.toString().search("val1") != -1).assertTrue()
expect(JSON.parse(data.result)["name2"] === "mine2").assertTrue() expect(data.result.toString().search("key2") != -1).assertTrue()
done(); expect(data.result.toString().search("val2") != -1).assertTrue()
expect(data.result.toString().search("name1") != -1).assertTrue()
expect(data.result.toString().search("mine1") != -1).assertTrue()
expect(data.result.toString().search("name2") != -1).assertTrue()
expect(data.result.toString().search("mine2") != -1).assertTrue()
done();
});
}); });
}); });
});
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册