1 16 17 package test.functional; 18 19 import junit.framework.TestCase; 20 import org.apache.axis.AxisProperties; 21 import org.apache.axis.client.AdminClient; 22 import org.apache.axis.utils.NetworkUtils; 23 24 import javax.xml.namespace.QName ; 25 import javax.xml.rpc.Service ; 26 import javax.xml.rpc.ServiceFactory ; 27 import javax.xml.rpc.Stub ; 28 import java.net.URL ; 29 import java.util.Date ; 30 31 public class TestAutoTypes extends TestCase { 32 33 protected void setUp() throws java.lang.Exception { 34 AxisProperties.setProperty("axis.doAutoTypes", "true"); 35 String [] args = {"test/functional/auto-deploy.wsdd"}; 36 AdminClient.main(args); 37 } 38 39 protected void tearDown() throws java.lang.Exception { 40 AxisProperties.setProperty("axis.doAutoTypes", "false"); 41 String [] args = {"test/functional/auto-undeploy.wsdd"}; 42 AdminClient.main(args); 43 } 44 45 private IAutoTypes getSimpleProxy() throws Exception { 46 String thisHost = NetworkUtils.getLocalHostname(); 47 String thisPort = System.getProperty("test.functional.ServicePort", 48 "8080"); 49 50 String wsdlLocation = "http://" + thisHost + ":" + thisPort + 52 "/jws/AutoTypesTest.jws?wsdl"; 53 URL urlWsdl = new URL (wsdlLocation); 54 String nameSpaceUri = "http://" + thisHost + ":" + thisPort + 55 "/jws/AutoTypesTest.jws"; 56 String serviceName = "AutoTypesTestService"; 57 String portName = "AutoTypesTest"; 58 ServiceFactory serviceFactory = ServiceFactory.newInstance(); 59 Service service = serviceFactory.createService(urlWsdl, new 60 QName (nameSpaceUri, serviceName)); 61 Stub stub = (Stub ) service.getPort(new 62 QName (nameSpaceUri, portName), IAutoTypes.class); 63 IAutoTypes myProxy = (IAutoTypes) stub; 64 return myProxy; 65 } 66 67 public static void main(String [] args) throws Exception { 68 junit.textui.TestRunner.run(TestAutoTypes.class); 69 } 70 71 public void testPing() throws Exception { 72 IAutoTypes test = getSimpleProxy(); 73 String ret = test.ping(); 74 assertEquals("echoed string incorrect IntValue", "Pong", ret); 75 } 76 77 public void testGetBean() throws Exception { 78 getSimpleProxy().getBean(); 79 } 80 81 public void testSetBean() throws Exception { 82 getSimpleProxy().setBean(new SimpleBean()); 83 } 84 85 public void testEchoBean() throws Exception { 86 SimpleBean in = new SimpleBean(); 87 in.setIntValue(42); 88 SimpleBean out = getSimpleProxy().echoBean(in); 89 assertEquals("echoed bean incorrect IntValue", 42, out.getIntValue()); 90 } 91 92 public void testEchoBeanArray() throws Exception { 93 SimpleBean[] beans = (SimpleBean[]) getSimpleProxy().echoBeanArray(new SimpleBean[]{ 94 new SimpleBean(), new SimpleBean(), 95 new SimpleBean(), new SimpleBean(), new SimpleBean(), 96 new SimpleBean()}); 97 assertEquals("expected array of SimpleBean", SimpleBean[].class, beans 98 .getClass()); 99 assertEquals("expected array of SimpleBean of length 6", 6, 100 beans.length); 101 } 102 103 public void testGetBeanArray() throws Exception { 104 SimpleBean[] beans = (SimpleBean[]) getSimpleProxy().getBeanArray(6); 105 assertEquals("expected array of SimpleBean", SimpleBean[].class, beans 106 .getClass()); 107 assertEquals("expected array of SimpleBean of length 6", 6, 108 beans.length); 109 } 110 111 public void testSetBeanArray() throws Exception { 112 SimpleBean[] beans = new SimpleBean[]{new SimpleBean(), 113 new SimpleBean(), 114 new SimpleBean(), 115 new SimpleBean(), 116 new SimpleBean(), 117 new SimpleBean()}; 118 getSimpleProxy().setBeanArray(beans); 119 } 120 121 public void testGetNestedBean() throws Throwable { 122 NestedBean result = getSimpleProxy().getNestedBean(); 123 assertNotNull("StartDate is not null ", result.getStartDate()); 124 assertEquals("Test String is correct", 125 "some test string " + result.getStartDate(), 126 result.getTestString()); assertEquals("Result Array Correct length ", 3, 128 result.getSimpleBeanList().length); assertEquals("Result Array[0] Correct", 1, 130 result.getSimpleBeanList()[0].getIntValue()); assertEquals("Result Array[1] Correct", 2, 132 result.getSimpleBeanList()[1].getIntValue()); assertEquals("Result Array[2] Correct", 3, 134 result.getSimpleBeanList()[2].getIntValue()); } 136 137 public void testSetNestedBean() throws Throwable { 138 NestedBean result = new NestedBean(); 139 result.setStartDate(new Date ()); 140 result.setTestString("some test string " + result.getStartDate()); SimpleBean[] sba = new SimpleBean[3]; 142 sba[0] = new SimpleBean(); 143 sba[1] = new SimpleBean(); 144 sba[2] = new SimpleBean(); 145 sba[0].setIntValue(1); 146 sba[1].setIntValue(2); 147 sba[2].setIntValue(3); 148 result.setSimpleBeanList(sba); 149 getSimpleProxy().setNestedBean(result); 150 } 151 152 public void testEchoNestedBean() throws Throwable { 153 NestedBean result = new NestedBean(); 154 result.setStartDate(new Date ()); 155 result.setTestString("some test string " + result.getStartDate()); SimpleBean[] sba = new SimpleBean[3]; 157 sba[0] = new SimpleBean(); 158 sba[1] = new SimpleBean(); 159 sba[2] = new SimpleBean(); 160 sba[0].setIntValue(1); 161 sba[1].setIntValue(2); 162 sba[2].setIntValue(3); 163 result.setSimpleBeanList(sba); 164 getSimpleProxy().echoNestedBean(result); 165 } 166 } 167 | Popular Tags |