soapfaulttest.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 940 行 · 第 1/3 页
JAVA
940 行
assertNotNull(faultSubCodes);
}
public void testAppendFaultSubCode() throws Exception {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault sf = body.addFault();
QName expected1 = new QName("http://example.com", "myfault1", "flt1");
QName expected2 = new QName("http://example.com", "myfault2", "flt2");
boolean found1 = false;
boolean found2 = false;
//Appending fault Subcode
sf.appendFaultSubcode(expected1);
//Appending a second fault Subcode
sf.appendFaultSubcode(expected2);
//Getting FaultSubCodes from SOAPFault
Iterator i = sf.getFaultSubcodes();
int j = 0;
while (i.hasNext()) {
Object o = i.next();
if (o != null && o instanceof QName) {
QName actual = (QName)o;
if (actual.equals(expected1)) {
if (!found1) {
found1 = true;
//System.out.println("Subcode= '"+actual+"'");
} else {
//System.out.println("Received a duplicate Subcode :'"+actual+"'");
}
} else if (actual.equals(expected2)) {
if (!found2) {
found2 = true;
//System.out.println("Subcode= '"+actual+"'");
} else {
//System.out.println("Received a duplicate Subcode :'"+actual+"'");
}
}
}
j++;
}
if (j < 1) {
fail("No Subcode was returned");
}
if (j > 2) {
fail("More than two Subcodes were returned");
}
if (!found1) {
fail("The following Subcode was not received: '" + expected1 + "'");
}
if (!found2) {
fail("The following Subcode was not received: '" + expected2 + "'");
}
}
public void _testGetFaultReasonTexts() {
try {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
soapFault.addFaultReasonText("myReason", new Locale("en"));
soapFault.addFaultReasonText("de-myReason", new Locale("de"));
soapFault.addFaultReasonText("si-myReason", new Locale("si"));
soapMessage.saveChanges();
Iterator reasonTexts = soapFault.getFaultReasonTexts();
while (reasonTexts.hasNext()) {
String reasonText = (String)reasonTexts.next();
assertNotNull(reasonText);
}
} catch (Exception e) {
fail("Unexpected Exception : " + e);
}
}
public void _testAddFaultReasonText1() {
try {
MessageFactory fac = MessageFactory.newInstance();
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
soapFault.addFaultReasonText("myReason", Locale.ENGLISH);
soapMessage.saveChanges();
} catch (SOAPException e) {
fail("Unexpected Exception Occurred : " + e);
}
}
public void testAddFaultReasonText2() {
try {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
soapFault.addFaultReasonText("myReason", new Locale("en"));
soapFault.addFaultReasonText("de-myReason", new Locale("de"));
soapFault.addFaultReasonText("si-myReason", new Locale("si"));
soapMessage.saveChanges();
} catch (SOAPException e) {
fail("Unexpected Exception Occurred : " + e);
}
}
public void testAddFaultReasonText3() {
try {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPFault sf = body.addFault();
String expected = "Its my fault again";
boolean found = false;
sf.addFaultReasonText("Its my fault", Locale.ENGLISH);
sf.addFaultReasonText(expected, Locale.ENGLISH);
Iterator i = sf.getFaultReasonTexts();
int j = 0;
while (i.hasNext()) {
Object o = i.next();
if (o != null && o instanceof String) {
String actual = (String)o;
if (actual.equals(expected)) {
if (!found) {
found = true;
}
}
}
j++;
}
if (j < 1) {
fail("No reason text was returned");
}
if (j > 1) {
fail("More than one reason text was returned");
}
if (!found) {
fail("The following Reason text was not received: '" + expected + "'");
}
} catch (SOAPException e) {
fail("Unexpected Exception Occurred : " + e);
}
}
public void testAddFaultReasonText4() throws Exception {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPFault sf = body.addFault();
String expected1 = "Its my fault";
String expected2 = "Its my fault again";
boolean found1 = false;
boolean found2 = false;
sf.addFaultReasonText(expected1, Locale.UK);
sf.addFaultReasonText(expected2, Locale.ENGLISH);
Iterator i = sf.getFaultReasonTexts();
int j = 0;
while (i.hasNext()) {
Object o = i.next();
if (o != null && o instanceof String) {
String actual = (String)o;
if (actual.equals(expected1)) {
if (!found1) {
found1 = true;
}
} else if (actual.equals(expected2)) {
if (!found2) {
found2 = true;
}
}
}
j++;
}
if (j < 1) {
fail("No reason text was returned");
}
if (j > 2) {
fail("More than two reason texts were returned");
}
if (!found1) {
fail("The following Reason text was not received: '" + expected1 + "'");
}
if (!found2) {
fail("The following Reason text was not received: '" + expected2 + "'");
}
}
public void testSetFaultRole() {
try {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
soapFault.setFaultRole("test");
soapMessage.saveChanges();
} catch (SOAPException e) {
fail("Unexpected Exception Occurred : " + e);
}
}
public void testSetFaultNode() {
try {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
soapFault.setFaultNode("test");
soapMessage.saveChanges();
} catch (SOAPException e) {
fail("Unexpected Exception Occurred : " + e);
}
}
public void _testGetFaultReasonText() {
try {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
soapFault.addFaultReasonText("myReason", new Locale("en"));
soapFault.addFaultReasonText("de-myReason", new Locale("de"));
soapFault.addFaultReasonText("si-myReason", new Locale("si"));
soapMessage.saveChanges();
String faultReasonText = soapFault.getFaultReasonText(new Locale("si"));
assertNotNull(faultReasonText);
faultReasonText = soapFault.getFaultReasonText(new Locale("ja"));
assertNull(faultReasonText);
} catch (Exception e) {
fail("Unexpected Exception : " + e);
}
}
public void _testGetFaultCodeAsQName() {
try {
//MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
MessageFactory fac = MessageFactory.newInstance();
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
SOAPBody body = envelope.getBody();
SOAPFault soapFault = body.addFault();
soapFault.addFaultReasonText("myReason", new Locale("en"));
soapFault.setFaultCode("mycode");
soapMessage.saveChanges();
QName qname = soapFault.getFaultCodeAsQName();
assertNotNull(qname);
} catch (Exception e) {
fail("Unexpected Exception : " + e);
}
}
public void testHasDetail() {
try {
MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
//MessageFactory fac = MessageFactory.newInstance();
SOAPMessage soapMessage = fac.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?