package server1; import static org.junit.Assert.*; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; //import org.junit.Before; import org.junit.BeforeClass; import org.junit.AfterClass; import org.junit.Test; public class Proovitestid{ static ServerSocket ss; Socket sc1, sc2; static ChatServer server; InputStream is1, is2; OutputStream os1, os2; static final int PORT=3001; @BeforeClass public static void alusta() throws Exception { ss=new ServerSocket(PORT); ss.setSoTimeout(4000); server=new ChatServer(ss); } @AfterClass public static void lopeta() throws Exception{ // System.out.println("suleb serverit"); ss.close(); // System.out.println("Server suletud"); } @Test public void test() { assertEquals(5, 3+2); } public void yhenduseLoomine() throws IOException{ sc1=new Socket("localhost", PORT); sc1.setSoTimeout(2000); is1=sc1.getInputStream(); sc2=new Socket("localhost", PORT); sc2.setSoTimeout(2000); os2=sc2.getOutputStream(); } @Test public void viieBaidiKirjutamine() throws IOException{ yhenduseLoomine(); for(int i=0; i<5; i++){ os2.write(37+i); } os2.close(); for(int i=0; i<5; i++){ assertEquals(37+i, is1.read()); } sc1.close(); sc2.close(); } @Test public void kahelKorralKirjutamine() throws IOException{ viieBaidiKirjutamine(); viieBaidiKirjutamine(); } }