1 package test.soap12; 2 3 import junit.framework.TestCase; 4 import org.apache.axis.AxisFault; 5 import org.apache.axis.Constants; 6 import org.apache.axis.Message; 7 import org.apache.axis.MessageContext; 8 import org.apache.axis.message.RPCElement; 9 import org.apache.axis.message.RPCParam; 10 import org.apache.axis.message.SOAPEnvelope; 11 import org.apache.axis.server.AxisServer; 12 import org.apache.axis.utils.Messages; 13 14 import java.util.Vector ; 15 16 20 public class TestHrefs extends TestCase { 21 22 private String HEAD; 23 private String HEADERT; 24 private String BODYT; 25 26 public TestHrefs(String name) { 27 this(name, Constants.URI_DEFAULT_SCHEMA_XSI, 28 Constants.URI_DEFAULT_SCHEMA_XSD); 29 } 30 31 public TestHrefs(String name, String NS_XSI, String NS_XSD) { 32 super(name); 33 34 HEAD = 35 "<?xml version=\"1.0\"?>\n" + 36 "<soap:Envelope " + 37 "xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" " + 38 "xmlns:soapenc=\"http://www.w3.org/2003/05/soap-encoding\" " + 39 "xmlns:xsi=\"" + NS_XSI + "\" " + 40 "xmlns:xsd=\"" + NS_XSD + "\">\n" + 41 "<soap:Header>\n"; 42 43 HEADERT = "</soap:Header>\n" + 44 "<soap:Body>\n" + 45 "<methodResult xmlns=\"http://tempuri.org/\">\n"; 46 47 BODYT = "</methodResult>\n" + 48 "</soap:Body>\n" + 49 "</soap:Envelope>\n"; 50 } 51 52 private void deserialize(String data, Object expected, int pos) 53 throws Exception 54 { 55 Message message = new Message(data); 56 MessageContext context = new MessageContext(new AxisServer()); 57 message.setMessageContext(context); 58 context.setProperty(Constants.MC_NO_OPERATION_OK, Boolean.TRUE); 59 60 SOAPEnvelope envelope = (SOAPEnvelope)message.getSOAPEnvelope(); 61 assertNotNull("SOAP envelope should not be null", envelope); 62 63 RPCElement body = (RPCElement)envelope.getFirstBody(); 64 assertNotNull("SOAP body should not be null", body); 65 66 Vector arglist = body.getParams(); 67 assertNotNull("arglist", arglist); 68 assertTrue("SOAP param.size()<=0 {Should be > 0}", arglist.size()>0); 69 70 RPCParam param = (RPCParam) arglist.get(pos); 71 assertNotNull("SOAP param should not be null", param); 72 73 Object result = param.getObjectValue(); 74 assertEquals("Expected result not received", expected, result); 75 } 76 77 public void testStringReference1() throws Exception { 78 String result = HEAD + HEADERT + 79 "<result root=\"0\" id=\"1\" xsi:type=\"xsd:string\">abc</result>" + 80 "<reference ref=\"#1\"/>\n" + 81 BODYT; 82 deserialize(result, "abc", 1); 83 } 84 85 public void testIntReference1() throws Exception { 86 String result = HEAD + HEADERT + 87 "<result root=\"0\" id=\"1\" xsi:type=\"xsd:int\">567</result>" + 88 "<reference ref=\"#1\"/>\n" + 89 BODYT; 90 deserialize(result, new Integer (567), 1); 91 } 92 93 public void testStringReferenceInHeader() throws Exception { 94 String result = HEAD + 95 "<result root=\"0\" id=\"1\" xsi:type=\"xsd:string\">abc</result>" + 96 HEADERT + 97 "<reference ref=\"#1\"/>\n" + 98 BODYT; 99 deserialize(result, "abc", 0); 100 } 101 102 public void testIDANDHREF() throws Exception { 103 String result = HEAD + 104 HEADERT + 105 "<result root=\"0\" ref=\"#1\" id=\"1\" xsi:type=\"xsd:string\">abc</result>" + 106 BODYT; 107 try { 108 deserialize(result, "abc", 0); 109 } catch (AxisFault af) { 110 assertTrue(af.getFaultString().indexOf(Messages.getMessage("noIDandHREFonSameElement")) != -1 && 111 Constants.FAULT_SOAP12_SENDER.equals(af.getFaultCode())); 112 return; 113 } 114 fail("Didn't got the expected fault"); 115 116 } 117 118 119 } | Popular Tags |