1 4 package com.tc.config.schema.setup.sources; 5 6 import com.tc.util.Assert; 7 8 import java.io.BufferedWriter ; 9 import java.io.OutputStreamWriter ; 10 import java.net.ServerSocket ; 11 import java.net.Socket ; 12 import java.net.SocketTimeoutException ; 13 14 import junit.framework.TestCase; 15 16 public class URLConfigurationSourceTest extends TestCase { 17 18 private URLConfigurationSource configSrc; 19 private ServerSocket server; 20 21 public void setUp() throws Exception { 22 this.server = new ServerSocket (0); 23 Thread t = new Thread () { 24 public void run() { 25 try { 26 Socket socket = server.accept(); 27 BufferedWriter response = new BufferedWriter (new OutputStreamWriter (socket.getOutputStream())); 28 response.write("connected to server"); 29 sleep(5000); 30 response.write("\n"); 31 response.flush(); 32 socket.close(); 33 } catch (Exception e) { 34 } 36 } 37 }; 38 t.start(); 39 this.configSrc = new URLConfigurationSource("http://" + server.getInetAddress().getHostAddress() + ":" 40 + server.getLocalPort()); 41 } 42 43 public void testGetInputStreamFailure() throws Exception { 44 try { 45 configSrc.getInputStream(1); 46 throw Assert.failure("Connection should have timed out"); 47 } catch (SocketTimeoutException e) { 48 } 50 } 51 52 public void tearDown() throws Exception { 53 server.close(); 54 } 55 } 56 | Popular Tags |