Web Services組件可由多個利益相關者來共同構建和部署。因此,測試這些組件過程中會發現確定代碼質量、可用性等都有很大的難度。Web Services的標準是簡單的,數據驅動的,并且共享一個公共的基于xml的基礎。傳統的測試工具可能不足以有效地測試這些標準。而且GUI自動化工具也不足以有效地測試Web Services的接口點和消息格式。
System.out. with following arguments:: action:" + action +
" symbol:" + symbol + " quantity:" + quantity);
if(action == null) {
throw new SOAPFaultException(new QName( "http://StockTrade/execute", "ServerFailed" ),
"action parameter is null.",
null,
detail);
}
if(symbol == null) {
throw new SOAPFaultException(new QName( "http://StockTrade/execute", "ServerFailed" ),
"symbol parameter is null.",
null,
detail);
}
if(action.equalsIgnoreCase("BUY"))
System.out.println("BUYING quantity: "+ quantity + " of symbol:" + symbol);
// Invoke method to execute trade here.
else if(action.equalsIgnoreCase("SELL"))
System.out.println("SELLING quantity: "+ quantity + " of symbol:" + symbol);
// Invoke method to execute trade here.
else
{
System.out.println("INVALID action: "+ action);
throw new SOAPFaultException(new QName( "http://StockTrade/execute", "ServerFailed" ),
"Invalid Action:" + action,
null,
detail);
}
return true;
}
代碼摘錄:Stock Trade Web Services 該段摘錄的代碼是Stock Trade Web Services的“execute()”方法的實現代碼。該方法首先驗證輸入參數的有效性,驗證成功才執行功能。舉例說明,假如參數action是空值,它就會拋出一個SoapFaultException異常,用faultstring參數(第二個參數)說明造成異常的原因。為了舉例說明,在對參數symbol進行相似的驗證之后,Web Services給出了處理機。在實際的情況下,商業邏輯應該在此位置中實現: