1 16 package test.wsdl.choice; 17 18 import java.util.Date ; 19 import java.util.Calendar ; 20 21 import org.apache.axis.types.URI; 22 import org.apache.axis.encoding.ser.CalendarSerializer; 23 24 import junit.framework.TestCase; 25 import junit.framework.AssertionFailedError; 26 27 import org.apache.axis.client.AdminClient; 28 import org.apache.axis.components.logger.LogFactory; 29 import org.apache.axis.message.MessageElement; 30 import org.apache.axis.message.Text; 31 import org.apache.axis.utils.Options; 32 import org.apache.commons.logging.Log; 33 import org.apache.log4j.Logger; 34 35 import javax.xml.namespace.QName ; 36 import java.io.FileInputStream ; 37 import java.io.FileNotFoundException ; 38 import java.io.InputStream ; 39 import java.util.Calendar ; 40 41 public class ChoiceServiceTestCase extends TestCase { 42 43 public ChoiceServiceTestCase(String name) { 44 super(name); 45 } 46 47 public void testSerialization() throws Exception { 48 ChoiceServiceSoap binding; 49 try { 50 ChoiceServiceLocator locator = new ChoiceServiceLocator(); 51 binding = locator.getChoiceServiceSoap(); 52 deployServer(); 53 } 54 catch (javax.xml.rpc.ServiceException jre) { 55 throw new AssertionFailedError("JAX-RPC ServiceException caught: " + jre); 56 } 57 catch (Exception e) { 58 throw new AssertionFailedError("Binding initialization Exception caught: " + e); 59 } 60 assertTrue("binding is null", binding != null); 61 62 FaultPropertyType fp1; 63 FaultPropertyType fp2; 64 Record1 r1; 65 Record2 r2; 66 67 FaultType f1 = new FaultType(); 69 f1.setDescription("foo"); 70 f1.setCommand("bar"); 71 72 fp1 = new FaultPropertyType(); 73 fp1.setFault1(f1); 74 75 r1 = new Record1(); 76 r1.setElem(fp1); 77 78 r2 = binding.get(r1); 79 80 assertTrue(r2 != null); 81 82 fp2 = r2.getElem(); 83 84 assertTrue(fp2 != null); 85 86 assertTrue(fp2.getFault1() != null); 87 assertTrue(fp2.getFault1() instanceof FaultType); 88 assertEquals("foo", 89 ((FaultType)fp2.getFault1()).getDescription()); 90 assertEquals("bar", 91 ((FaultType)fp2.getFault1()).getCommand()); 92 93 StagingFaultType f2 = new StagingFaultType(); 95 f2.setDescription("foo1"); 96 f2.setCommand("bar1"); 97 f2.setAttribute("moo"); 98 99 fp1 = new FaultPropertyType(); 100 fp1.setFault2(f2); 101 102 r1 = new Record1(); 103 r1.setElem(fp1); 104 105 r2 = binding.get(r1); 106 107 assertTrue(r2 != null); 108 109 fp2 = r2.getElem(); 110 111 assertTrue(fp2 != null); 112 113 assertTrue(fp2.getFault2() != null); 114 assertTrue(fp2.getFault2() instanceof StagingFaultType); 115 assertEquals("foo1", 116 ((FaultType)fp2.getFault2()).getDescription()); 117 assertEquals("bar1", 118 ((FaultType)fp2.getFault2()).getCommand()); 119 assertEquals("moo", 120 ((StagingFaultType)fp2.getFault2()).getAttribute()); 121 122 } 123 124 public void testChoiceSerialization() throws Exception { 125 ChoiceServiceSoap binding; 126 try { 127 ChoiceServiceLocator locator = new ChoiceServiceLocator(); 128 binding = locator.getChoiceServiceSoap(); 129 deployServer(); 130 } 131 catch (javax.xml.rpc.ServiceException jre) { 132 throw new AssertionFailedError("JAX-RPC ServiceException caught: " + jre); 133 } 134 catch (Exception e) { 135 throw new AssertionFailedError("Binding initialization Exception caught: " + e); 136 } 137 assertTrue("binding is null", binding != null); 138 139 FaultPropertyType fp1; 140 Record1 r1; 141 Record2 r2; 142 143 FaultType f1 = new FaultType(); 145 f1.setDescription("foo"); 146 f1.setCommand("bar"); 147 148 fp1 = new FaultPropertyType(); 149 fp1.setFault1(f1); 150 151 r1 = new Record1(); 152 r1.setElem(fp1); 153 154 r2 = binding.get(r1); 155 assertTrue(r2 != null); 156 157 StagingFaultType f2 = new StagingFaultType(); 159 f2.setDescription("foo1"); 160 f2.setCommand("bar1"); 161 f2.setAttribute("moo"); 162 163 fp1 = new FaultPropertyType(); 164 fp1.setFault2(f2); 165 166 r1 = new Record1(); 167 r1.setElem(fp1); 168 169 r2 = binding.get(r1); 170 assertTrue(r2 != null); 171 } 172 173 174 private void deployServer() { 175 final String INPUT_FILE = "server-deploy.wsdd"; 176 177 InputStream is = getClass().getResourceAsStream(INPUT_FILE); 178 if (is == null) { 179 try { 181 is = new FileInputStream (INPUT_FILE); 182 } catch (FileNotFoundException e) { 183 is = null; 184 } 185 } 186 assertNotNull("Unable to find " + INPUT_FILE + ". Make sure it is on the classpath or in the current directory.", is); 187 AdminClient admin = new AdminClient(); 188 try { 189 Options opts = new Options( null ); 190 opts.setDefaultURL("http://localhost:8080/axis/services/AdminService"); 191 admin.process(opts, is); 192 } catch (Exception e) { 193 assertTrue("Unable to deploy " + INPUT_FILE + ". ERROR: " + e, false); 194 } 195 } 196 197 } 198 | Popular Tags |