protected static String allocatePort(Class<?> cls) { return TestUtil.getPortNumber(cls); } protected static String allocatePort(Class<?> cls, int count) {
public static String getNewPortNumber(String name) { return getNewPortNumber(name, name); }
protected void updateAddressPort(Object o, String port) throws NumberFormatException, MalformedURLException { TestUtil.updateAddressPort(o, port); }
public static String getNewPortNumber(String fullName, String simpleName) { removeNames(fullName, simpleName); return getPortNumber(fullName, simpleName); } public static String getPortNumber(String fullName, String simpleName) {
protected void setAddress(Object o, String address) { TestUtil.setAddress(o, address); }
public static boolean deleteDir(File dir) { if (dir.isDirectory()) { String[] children = dir.list(); if (children != null) { for (int i = 0; i < children.length; i++) { boolean success = deleteDir(new File(dir, children[i])); if (!success) { return false; } } } } // The directory is now empty so delete it return dir.delete(); }
public static String getPortNumber(String fullName, String simpleName) { String p = ports.getProperty("testutil.ports." + fullName); if (p == null) { p = System.getProperty("testutil.ports." + fullName); if (p != null) { ports.setProperty("testutil.ports." + fullName, p); ports.setProperty("testutil.ports." + simpleName, p); } } while (p == null) { int pn = portNum++; try { //make sure the port can be opened. Something MIGHT be running on it. ServerSocket sock = new ServerSocket(pn); sock.close(); p = Integer.toString(pn); LOG.fine("Setting port for " + fullName + " to " + p); } catch (IOException ex) { // } } applyNames(fullName, simpleName, p); return p; }
for (Map.Entry<Object, Object> entry : TestUtil.getAllPorts().entrySet()) { cmd.add("-D" + entry.getKey() + "=" + entry.getValue());
public static void updateAddressPort(Object o, int port) throws MalformedURLException { String address = null; if (o instanceof BindingProvider) { address = ((BindingProvider)o).getRequestContext() .get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY).toString(); } else if (o instanceof Client) { Client c = (Client)o; address = c.getEndpoint().getEndpointInfo().getAddress(); } if (address != null && address.startsWith("http")) { // http and https are ok URL url = new URL(address); url = new URL(url.getProtocol(), url.getHost(), port, url.getFile()); setAddress(o, url.toString()); } //maybe simple frontend proxy? }
protected static String allocatePort(String s) { return TestUtil.getPortNumber(s); } protected static String allocatePort(Class<?> cls) {
public static String getNewPortNumber(Class<?> cls, int count) { return getNewPortNumber(cls.getName() + "." + count, cls.getSimpleName() + "." + count); } public static String getNewPortNumber(String name) {
public static void updateAddressPort(Object o, String port) throws NumberFormatException, MalformedURLException { updateAddressPort(o, Integer.parseInt(port)); }
@Test public void testNoAuth() throws Exception { URL wsdl = getClass().getResource("../greeting.wsdl"); assertNotNull("WSDL is null", wsdl); SOAPService service = new SOAPService(wsdl, serviceName); assertNotNull("Service is null", service); Greeter mortimer = service.getPort(mortimerQ, Greeter.class); assertNotNull("Port is null", mortimer); TestUtil.setAddress(mortimer, "http://localhost:" + PORT + "/digestauth/greeter"); try { String answer = mortimer.sayHi(); Assert.fail("Unexpected reply (" + answer + "). Should throw exception"); } catch (Exception e) { Throwable cause = e.getCause(); assertEquals(HTTPException.class, cause.getClass()); HTTPException he = (HTTPException)cause; assertEquals(401, he.getResponseCode()); } }
protected static String allocatePort(Class<?> cls) { return TestUtil.getPortNumber(cls); } protected static String allocatePort(Class<?> cls, int i) {
public static String getNewPortNumber(Class<?> cls) { return getNewPortNumber(cls.getName(), cls.getSimpleName()); } public static String getNewPortNumber(Class<?> cls, int count) {
@org.junit.Test public void testKerberosViaCustomTokenAction() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = KerberosTokenTest.class.getResource("client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = KerberosTokenTest.class.getResource("DoubleItKerberos.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, "DoubleItKerberosTransportActionPort"); DoubleItPortType kerberosPort = service.getPort(portQName, DoubleItPortType.class); TestUtil.updateAddressPort(kerberosPort, PORT2); Assert.assertEquals(50, kerberosPort.doubleIt(25)); ((java.io.Closeable)kerberosPort).close(); bus.shutdown(true); } }
@Test public void testDigestAuth() throws Exception { URL wsdl = getClass().getResource("../greeting.wsdl"); assertNotNull("WSDL is null", wsdl); SOAPService service = new SOAPService(wsdl, serviceName); assertNotNull("Service is null", service); Greeter mortimer = service.getPort(mortimerQ, Greeter.class); assertNotNull("Port is null", mortimer); TestUtil.setAddress(mortimer, "http://localhost:" + PORT + "/digestauth/greeter"); Client client = ClientProxy.getClient(mortimer); HTTPConduit http = (HTTPConduit) client.getConduit(); AuthorizationPolicy authPolicy = new AuthorizationPolicy(); authPolicy.setAuthorizationType("Digest"); authPolicy.setUserName("foo"); authPolicy.setPassword("bar"); http.setAuthorization(authPolicy); String answer = mortimer.sayHi(); assertEquals("Unexpected answer: " + answer, "Hi", answer); }
public static String getPortNumber(String name) { return getPortNumber(name, name); }
public static void resetPortMap() { PORTMAP.clear(); for (int x = 0; x < 9; x++) { PORTMAP.put("PORT" + x, TestUtil.getNewPortNumber(BusServer.class, x)); } } public static String getPort(int x) {
private void runKerberosTest(String portName, boolean streaming, String portNumber) throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = SpnegoTokenTest.class.getResource("client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = SpnegoTokenTest.class.getResource("DoubleItSpnego.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, portName); DoubleItPortType kerberosPort = service.getPort(portQName, DoubleItPortType.class); TestUtil.updateAddressPort(kerberosPort, portNumber); if (streaming) { SecurityTestUtil.enableStreaming(kerberosPort); } Assert.assertEquals(50, kerberosPort.doubleIt(25)); ((java.io.Closeable)kerberosPort).close(); bus.shutdown(true); } }