1 16 package test.properties; 17 18 import junit.framework.TestCase; 19 import org.apache.axis.client.Call; 20 import org.apache.axis.client.Service; 21 import org.apache.axis.configuration.BasicClientConfig; 22 import org.apache.axis.configuration.BasicServerConfig; 23 import org.apache.axis.configuration.SimpleProvider; 24 import org.apache.axis.handlers.soap.SOAPService; 25 import org.apache.axis.providers.java.RPCProvider; 26 import org.apache.axis.server.AxisServer; 27 import org.apache.axis.transport.local.LocalTransport; 28 29 37 public class TestScopedProperties extends TestCase { 38 public static final String PROP_NAME = "test.property"; 39 public static final String CLIENT_VALUE = "client-side property value!"; 40 public static final String SERVER_VALUE = "this is the server side value"; 41 public static final String OVERRIDE_NAME = "override.property"; 42 public static final String OVERRIDE_VALUE = "The REAL value!"; 43 44 private SOAPService service; 45 private PropertyHandler serverHandler = new PropertyHandler(); 46 private SimpleProvider config; 47 private AxisServer server; 48 49 public TestScopedProperties(String s) { 50 super(s); 51 } 52 53 61 protected void setUp() throws Exception { 62 config = new BasicServerConfig(); 63 server = new AxisServer(config); 64 65 69 RPCProvider provider = new RPCProvider(); 70 service = new SOAPService(serverHandler, provider, null); 71 service.setOption("className", PropertyHandler.class.getName()); 72 service.setOption("allowedMethods", "*"); 73 74 service.setOption(PROP_NAME, SERVER_VALUE); 76 77 service.setOption(OVERRIDE_NAME, SERVER_VALUE); 81 82 config.deployService("service", service); 83 } 84 85 93 public void testScopedProperties() throws Exception { 94 BasicClientConfig config = new BasicClientConfig(); 95 PropertyHandler clientHandler = new PropertyHandler(); 96 SOAPService clientService = new SOAPService(clientHandler, null, null); 97 config.deployService("service", clientService); 98 99 Service s = new Service(config); 100 Call call = new Call(s); 101 102 call.setProperty(PROP_NAME, CLIENT_VALUE); 105 106 LocalTransport transport = new LocalTransport(server); 107 transport.setRemoteService("service"); 108 call.setTransport(transport); 109 110 String result = (String )call.invoke("service", 112 "testScopedProperty", 113 new Object [] { }); 114 115 assertEquals("Returned scoped property wasn't correct", 116 SERVER_VALUE, 117 result); 118 119 assertEquals("Client-side scoped property wasn't correct", 122 CLIENT_VALUE, 123 clientHandler.getPropVal()); 124 assertEquals("Server-side scoped property wasn't correct", 125 SERVER_VALUE, 126 serverHandler.getPropVal()); 127 } 128 129 135 public void testMessageContextOverride() throws Exception { 136 Call call = new Call(new Service()); 139 140 LocalTransport transport = new LocalTransport(server); 141 transport.setRemoteService("service"); 142 call.setTransport(transport); 143 144 String result = (String )call.invoke("service", 146 "testOverrideProperty", 147 new Object [] { }); 148 assertEquals("Overriden property value didn't match", 149 OVERRIDE_VALUE, 150 result); 151 } 152 153 161 public void testFullClientScopes() throws Exception { 162 Call call = new Call(new Service()); 163 PropertyHandler clientHandler = new PropertyHandler(); 164 SOAPService clientService = new SOAPService(clientHandler, null, null); 165 166 call.setSOAPService(clientService); 167 168 call.setProperty(PROP_NAME, CLIENT_VALUE); 171 172 LocalTransport transport = new LocalTransport(server); 173 transport.setRemoteService("service"); 174 call.setTransport(transport); 175 176 call.invoke("testOverrideProperty", new Object [] { }); 178 assertEquals("Client-side scoped property from Call wasn't correct", 179 CLIENT_VALUE, 180 clientHandler.getPropVal()); 181 182 clientService.setOption(PROP_NAME, OVERRIDE_VALUE); 185 186 call.invoke("testOverrideProperty", new Object [] { }); 188 assertEquals("Client-side scoped property from service wasn't correct", 189 OVERRIDE_VALUE, 190 clientHandler.getPropVal()); 191 } 192 } 193 | Popular Tags |