01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.config.schema.setup.sources;
05:
06: import com.tc.util.Assert;
07:
08: import java.io.BufferedWriter;
09: 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(
28: new OutputStreamWriter(socket
29: .getOutputStream()));
30: response.write("connected to server");
31: sleep(5000);
32: response.write("\n");
33: response.flush();
34: socket.close();
35: } catch (Exception e) {
36: // not implemented
37: }
38: }
39: };
40: t.start();
41: this .configSrc = new URLConfigurationSource("http://"
42: + server.getInetAddress().getHostAddress() + ":"
43: + server.getLocalPort());
44: }
45:
46: public void testGetInputStreamFailure() throws Exception {
47: try {
48: configSrc.getInputStream(1);
49: throw Assert.failure("Connection should have timed out");
50: } catch (SocketTimeoutException e) {
51: // pass
52: }
53: }
54:
55: public void tearDown() throws Exception {
56: server.close();
57: }
58: }
|