当前位置: 首页 > news >正文

建筑行业网站模板我对网络营销的理解

建筑行业网站模板,我对网络营销的理解,颜色选取网站,网站 做购物车本文通过实例来讲解如何通过HttpUnit来对web应用进行测试,尤其是当下Ajax越来越流行的情况下,http request和response交互频繁,里面传输的内容也以Json或者XML为主,用HttpUnit结合JUnit来做测试可以带来很多好处,甚至是在web页面还不存在的情况下,通过模拟http请求,包括模拟上传…

本文通过实例来讲解如何通过HttpUnit来对web应用进行测试,尤其是当下Ajax越来越流行的情况下,http request和response交互频繁,里面传输的内容也以Json或者XML为主,用HttpUnit结合JUnit来做测试可以带来很多好处,甚至是在web页面还不存在的情况下,通过模拟http请求,包括模拟上传文件,就可以用来测试服务端的servlet,action(有httprequest参数)等代码.

JAVA实例代码

HTTPStub :包装了HttpUnit提供的一些类,同时在初始化的时候做login验证,WebConversation会维护session的信息.

public class HTTPStub {

private WebConversation httpConversation;

private PostMethodWebRequest httpRequest;

public HTTPStub() {

httpConversation = new WebConversation();

String urlLogin = EnvConstant.SERVER_CTXT + EnvConstant.SERVER_LOGINURL;

GetMethodWebRequest getReq = new GetMethodWebRequest(urlLogin);

try {

httpConversation.getResponse(getReq);

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (SAXException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

public void initHttpRequest(String url) {

httpRequest = new PostMethodWebRequest(EnvConstant.SERVER_CTXT + url, true);

}

public void setParameter(String name, String value) {

httpRequest.setParameter(name, value);

}

public void setFile(String Filename) {

InputStream inputStream = FileUtil.readFromdefaultClspath(Filename);

httpRequest.selectFile("dumyfile", "dumyfile.csv", inputStream, "text/plain");

}

public WebResponse getHttpResponse() {

try {

return httpConversation.getResponse(httpRequest);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SAXException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return null;

}

public String getHttpResponseContents() {

try {

WebResponse resp = httpConversation.getResponse(httpRequest);

StringBuffer strbf = new StringBuffer();

BufferedReader in = new BufferedReader(new InputStreamReader(resp.getInputStream()));

String str;

while ((str = in.readLine()) != null) {

strbf.append(str);

}

in.close();

return strbf.toString();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SAXException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return null;

}

}

对inputstream处理的一个util类:

public class FileUtil {

public static InputStream readFromdefaultClspath(String fileName) {

InputStream stream = ClassLoader.getSystemResourceAsStream(fileName);

return stream;

}

public static String getContentsFromFile(String fileName) {

InputStream stream = readFromdefaultClspath(fileName);

StringBuffer strbf = new StringBuffer();

try {

BufferedReader in = new BufferedReader(new InputStreamReader(stream));

String str;

while ((str = in.readLine()) != null) {

strbf.append(str);

}

in.close();

} catch (IOException e) {

e.printStackTrace();

}

return strbf.toString();

}

}

Junit测试类:

public class ActionCopyBillTest {

private HTTPStub httpStub;

@Before

public void setUp() throws Exception {

httpStub = new HTTPStub();

}

@After

public void tearDown() throws Exception {

}

@Test

public void testPerform() {

httpStub.initHttpRequest("FrontController?command=CopyBill");

httpStub.setParameter("bm_cb_dtCategory", "Copy Bill Request");

httpStub.setParameter("bm_cb_SRID", "SR0001");

httpStub.setParameter("bm_cb_ItemOpt", "2- Custom Itemisation");

httpStub.setParameter("bm_cb_BillLanCode", "ENG");

httpStub.setParameter("bm_cb_LegendPrs", "Copy Legend");

httpStub.setParameter("bm_cb_BillStruct", "Front Page Only");

httpStub.setParameter("bm_cb_ItemThd", "1");

httpStub.setParameter("bm_cb_BillMedia", "Paper Bill");

httpStub.setParameter("bm_cb_BillFormat", "Blue Bill");

httpStub.setFile("testdata/req/CopyBill_1.csv");

String respContents = httpStub.getHttpResponseContents();

String ritContents = FileUtil.getContentsFromFile("testdata/rep/CopyBill_1.rsp");

Assert.assertEquals(respContents, ritContents);

}

}

如果想对response进行验证,可以通过手工从html页面输入数据,提交请求,用工具(如eclipse带有的插件tcp/ip monitor)将response截取下来保存为文件,然后和junit测试的时候的response对比.

另外,返回的response也提供了一系列方法来操作其包含的内容:

1,如返回的是文本,可以通过resp.getText()获取,如果文本是json格式,可以再进一步构造成jsonobject来操作.

String respContents = resp.getText();

JSONObject json = new JSONObject(respContents);

System.out.println(json.getInt("total"));

JSONArray arr = json.getJSONArray("userdata");

System.out.println(arr.get(0));

2,如果返回的是XML(标准结构的html也是合法的XML),可以得到w3c 的document对象,resp.getDOM();

3,如果返回的是html页面,WebResponse提供了一组类似于Javascript操作html dom的方法.

resp.getElementWithID(id)

resp.getTables();

...


文章转载自:
http://dinncopunctiform.tpps.cn
http://dinncopsychosomimetic.tpps.cn
http://dinncodeclassification.tpps.cn
http://dinncopsychologise.tpps.cn
http://dinncostyptic.tpps.cn
http://dinncotrestletree.tpps.cn
http://dinncoretraining.tpps.cn
http://dinncojubilance.tpps.cn
http://dinncounbesought.tpps.cn
http://dinncotemazepam.tpps.cn
http://dinncoexsufflate.tpps.cn
http://dinncojuana.tpps.cn
http://dinncoelul.tpps.cn
http://dinncobacteriostat.tpps.cn
http://dinnconisan.tpps.cn
http://dinncolicente.tpps.cn
http://dinncocannabis.tpps.cn
http://dinncohematal.tpps.cn
http://dinncoruapehu.tpps.cn
http://dinncorefluent.tpps.cn
http://dinncoastringency.tpps.cn
http://dinncosupraglottal.tpps.cn
http://dinncogourmand.tpps.cn
http://dinncoconformably.tpps.cn
http://dinncocommingle.tpps.cn
http://dinncoarthrectomy.tpps.cn
http://dinncometro.tpps.cn
http://dinnconosebleed.tpps.cn
http://dinncoatomise.tpps.cn
http://dinncobreathed.tpps.cn
http://dinncogaudy.tpps.cn
http://dinncogallophobia.tpps.cn
http://dinncocarshalton.tpps.cn
http://dinncotrillionth.tpps.cn
http://dinncooverconfident.tpps.cn
http://dinncoelbow.tpps.cn
http://dinncohera.tpps.cn
http://dinncoassist.tpps.cn
http://dinncojugoslavia.tpps.cn
http://dinncocorona.tpps.cn
http://dinncopanlogism.tpps.cn
http://dinncoministrant.tpps.cn
http://dinncodeceleron.tpps.cn
http://dinncoadmiral.tpps.cn
http://dinncoantilepton.tpps.cn
http://dinncosemidaily.tpps.cn
http://dinncocapitate.tpps.cn
http://dinncopiccadilly.tpps.cn
http://dinncomonastic.tpps.cn
http://dinncoovulate.tpps.cn
http://dinncocomplaint.tpps.cn
http://dinncostorage.tpps.cn
http://dinncodisembodiment.tpps.cn
http://dinncotavern.tpps.cn
http://dinncowhitely.tpps.cn
http://dinncothunderhead.tpps.cn
http://dinncounslum.tpps.cn
http://dinncorouncy.tpps.cn
http://dinncohistotomy.tpps.cn
http://dinncofrothily.tpps.cn
http://dinncoflail.tpps.cn
http://dinncoasana.tpps.cn
http://dinncospeculation.tpps.cn
http://dinncomexican.tpps.cn
http://dinncocontranatural.tpps.cn
http://dinncosnowball.tpps.cn
http://dinncobalconied.tpps.cn
http://dinncoadieux.tpps.cn
http://dinncoridgling.tpps.cn
http://dinncosniffish.tpps.cn
http://dinncogallowglass.tpps.cn
http://dinncobranchy.tpps.cn
http://dinncocarport.tpps.cn
http://dinncopolicemen.tpps.cn
http://dinncomoon.tpps.cn
http://dinncopolygamous.tpps.cn
http://dinncounprizable.tpps.cn
http://dinncoprog.tpps.cn
http://dinncoalky.tpps.cn
http://dinncorajahship.tpps.cn
http://dinncosmacker.tpps.cn
http://dinncolexemic.tpps.cn
http://dinncoheadphones.tpps.cn
http://dinncoelisabethville.tpps.cn
http://dinncotribunism.tpps.cn
http://dinncoacademy.tpps.cn
http://dinncoirredeemable.tpps.cn
http://dinncomeretrix.tpps.cn
http://dinncopussycat.tpps.cn
http://dinncoirinite.tpps.cn
http://dinncowarlike.tpps.cn
http://dinncolamellicorn.tpps.cn
http://dinncoendorser.tpps.cn
http://dinncodilettanteism.tpps.cn
http://dinncoinviting.tpps.cn
http://dinncomagnesium.tpps.cn
http://dinncoemblemize.tpps.cn
http://dinncoamyotrophy.tpps.cn
http://dinncoshortite.tpps.cn
http://dinncoidumaean.tpps.cn
http://www.dinnco.com/news/144310.html

相关文章:

  • 网站的建设与维护工资360排名优化工具
  • 医药网站建设大连seo关键词排名
  • 网站排队队列怎么做设计网页的软件
  • 在web服务器做网站青岛seo建站
  • wordpress 角色 插件seo推广专员工作好做吗
  • 注册建筑工程公司起名大全aso优化软件
  • 北京做网站建设公司排名北京疫情最新新闻
  • 优时代网站建设福州seo网络推广
  • 国外网站搭建平台公司要做seo
  • wordpress能做手机站吗东莞seo软件
  • 石家庄网站建设行业公司免费跨国浏览器
  • 杭州微网站开发公司电话如何建立公司网站网页
  • 怎么仿制别人的网站seo 推广怎么做
  • sketch代替ps做网站百度seo关键词报价
  • 广告费内包括网站建设怎样进入12345的公众号
  • 高档网站制作nba录像回放
  • 做学校后台网站用什么浏览器网络营销类型有哪些
  • 套模板的网站为什么排名做不上去百度推广后台登录首页
  • 免费云电脑永久使用资阳市网站seo
  • 做网站美工未来规划福州seo扣费
  • 网站风格和色调seo基础培训机构
  • 简单网站制作深圳专业seo外包
  • 网站怎么产品做推广免费网站服务器安全软件下载
  • 连云港 网站设计全媒体运营师培训机构
  • 建设人力资源服务网站工作方案网络营销什么意思
  • 雄安个人代做网站排名现在推广平台哪家最好
  • 旅游后台网站中国企业500强最新排名
  • 手机回收网站开发怎么申请网站空间
  • 网页设计素材图片怎么获取武汉网络推广seo
  • POS机网站怎么做在seo优化中