faultsservicetests.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 438 行 · 第 1/2 页
JAVA
438 行
// the invoke will throw an exception, if the test is performed right
float total = proxy.getQuote("BASE");
fail( "Expected BaseFault_Exception but no fault was thrown ");
}catch(BaseFault_Exception e){
BaseFault_Exception fault = (BaseFault_Exception) e;
BaseFault faultInfo = fault.getFaultInfo();
assertTrue(faultInfo != null);
assertTrue(faultInfo.getA() == 400);
} catch (Exception e) {
fail("Wrong exception thrown. Expected BaseFault_Exception but received " + e.getClass());
}
}
/**
* Tests that throwing of DerivedFault1_Exception
*/
public void testFaultsService7(){
Exception exception = null;
try{
FaultsServicePortType proxy = getProxy();
// the invoke will throw an exception, if the test is performed right
float total = proxy.getQuote("DF1");
fail( "Expected DerivedFault1_Exception but no fault was thrown");
}catch(DerivedFault1_Exception e){
DerivedFault1_Exception fault = (DerivedFault1_Exception) e;
DerivedFault1 faultInfo = fault.getFaultInfo();
assertTrue(faultInfo != null);
assertTrue(faultInfo.getA() == 100);
assertTrue(faultInfo.getB().equals("DF1"));
} catch (Exception e) {
fail("Wrong exception thrown. Expected DerivedFault1_Exception but received " + e.getClass());
}
}
/**
* Tests that throwing of DerivedFault1_Exception
*/
public void testFaultsService8(){
Exception exception = null;
try{
FaultsServicePortType proxy = getProxy();
// the invoke will throw an exception, if the test is performed right
float total = proxy.getQuote("DF2");
fail( "Expected DerivedFault2_Exception but no fault was thrown ");
}catch(DerivedFault2_Exception e){
DerivedFault2_Exception fault = (DerivedFault2_Exception) e;
DerivedFault2 faultInfo = fault.getFaultInfo();
assertTrue(faultInfo != null);
assertTrue(faultInfo.getA() == 200);
assertTrue(faultInfo.getB().equals("DF2"));
assertTrue(faultInfo.getC() == 80.0F);
} catch (Exception e) {
fail("Wrong exception thrown. Expected DerivedFault1_Exception but received " + e.getClass());
}
}
/**
* Tests that that SOAPFaultException is thrown
*/
public void testFaultsService9a(){
Exception exception = null;
try{
FaultsServicePortType proxy = getProxy();
// the invoke will throw an exception, if the test is performed right
int total = proxy.throwFault(2, "SOAPFaultException", 2); // "SOAPFaultException" will cause service to throw SOAPFaultException
}catch(SOAPFaultException e){
// Okay
exception = e;
} catch (Exception e) {
fail("Did not get a SOAPFaultException");
}
TestLogger.logger.debug("----------------------------------");
assertNotNull(exception);
SOAPFaultException sfe = (SOAPFaultException) exception;
SOAPFault soapFault = sfe.getFault();
assertTrue(soapFault != null);
assertTrue(soapFault.getFaultString().equals("hello world"));
assertTrue(soapFault.getFaultActor().equals("actor"));
assertTrue(soapFault.getDetail() == null);
}
/**
* Tests that that SOAPFaultException is thrown
*/
public void testFaultsService9b(){
Exception exception = null;
try{
FaultsServicePortType proxy = getProxy();
// the invoke will throw an exception, if the test is performed right
int total = proxy.throwFault(2, "SOAPFaultException2", 2); // "SOAPFaultException" will cause service to throw SOAPFaultException
}catch(SOAPFaultException e){
// Okay
exception = e;
} catch (Exception e) {
fail("Did not get a SOAPFaultException");
}
TestLogger.logger.debug("----------------------------------");
assertNotNull(exception);
SOAPFaultException sfe = (SOAPFaultException) exception;
SOAPFault soapFault = sfe.getFault();
assertTrue(soapFault != null);
assertTrue(soapFault.getFaultString().equals("hello world2"));
assertTrue(soapFault.getFaultActor().equals("actor2"));
assertTrue(soapFault.getDetail() != null);
DetailEntry de = (DetailEntry) soapFault.getDetail().getDetailEntries().next();
assertTrue(de != null);
assertTrue(de.getNamespaceURI().equals("urn://sample"));
assertTrue(de.getLocalName().equals("detailEntry"));
assertTrue(de.getValue().equals("Texas"));
}
/**
* Tests that that SOAPFaultException (NPE) is thrown
*/
public void testFaultsService10(){
Exception exception = null;
try{
FaultsServicePortType proxy = getProxy();
// the invoke will throw an exception, if the test is performed right
int total = proxy.throwFault(2, "NPE", 2); // "NPE" will cause service to throw NPE System Exception
}catch(SOAPFaultException e){
// Okay
exception = e;
} catch (Exception e) {
fail("Did not get a SOAPFaultException");
}
TestLogger.logger.debug("----------------------------------");
assertNotNull(exception);
SOAPFaultException sfe = (SOAPFaultException) exception;
SOAPFault soapFault = sfe.getFault();
assertTrue(soapFault != null);
assertTrue(soapFault.getFaultString().equals("java.lang.NullPointerException"));
}
/**
* Tests that that SOAPFaultException (NPE) is thrown
*/
public void testFaultsService10a(){
Exception exception = null;
try{
FaultsServicePortType proxy = getProxy();
// the invoke will throw an exception, if the test is performed right
int total = proxy.throwFault(2, "NPE2", 2); // "NPE" will cause service to throw NPE System Exception
}catch(SOAPFaultException e){
// Okay
exception = e;
} catch (Exception e) {
fail("Did not get a SOAPFaultException");
}
TestLogger.logger.debug("----------------------------------");
assertNotNull(exception);
SOAPFaultException sfe = (SOAPFaultException) exception;
SOAPFault soapFault = sfe.getFault();
assertTrue(soapFault != null);
assertTrue(soapFault.getFaultString().equals("Null Pointer Exception occurred"));
}
/**
* Tests that that SOAPFaultException (for WebServiceException) is thrown
*/
public void testFaultsService11(){
Exception exception = null;
try{
FaultsServicePortType proxy = getProxy();
// the invoke will throw an exception, if the test is performed right
int total = proxy.throwFault(2, "WSE", 2); // "WSE" will cause service to throw WebServiceException System Exception
}catch(SOAPFaultException e){
// Okay...on the client a SOAPFaultException should be thrown
exception = e;
} catch (Exception e) {
fail("Did not get a SOAPFaultException");
}
TestLogger.logger.debug("----------------------------------");
assertNotNull(exception);
SOAPFaultException sfe = (SOAPFaultException) exception;
SOAPFault soapFault = sfe.getFault();
assertTrue(soapFault != null);
assertTrue(soapFault.getFaultString().equals("This is a WebServiceException"));
}
/**
* Tests Resource injection
*/
public void testResourceInjection() throws Exception {
FaultsServicePortType proxy = getProxy();
float total = proxy.getQuote("INJECTION");
// If resource injection occurred properly, then the a value of 1234567 is expected
assertTrue("Resource Injection Failed", total == 1234567);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?