001package csheets.core.ext.share; 002 003import static org.junit.Assert.*; 004 005import java.util.*; 006 007import org.junit.*; 008 009import csheets.core.*; 010import csheets.ext.share.core.*; 011 012/** 013 * Test the connectivity of the spreadsheet 014 * 015 * @author Andre 016 * 017 */ 018public class SendReceiveTest implements Observer { 019 020 private static Workbook workbook; 021 private static Spreadsheet sheet; 022 023 /** 024 * Create a new workbook for the program 025 * 026 * @throws Exception 027 * any Exception can occur 028 */ 029 @BeforeClass 030 public static void setUpClass() throws Exception { 031 032 /** create a new instance of workbook */ 033 workbook = new Workbook(3); 034 035 /** Change to the first spreadsheet */ 036 sheet = workbook.getSpreadsheet(0); 037 038 } 039 040 /** 041 * Method that will test the connectivity 042 */ 043 @Test 044 public void testConnection() { 045 046 try { 047 String password = "test"; 048 049 // Initializes cells 050 Cell cellOri = sheet.getCell(new Address(1, 1)); 051 cellOri.setContent("56"); 052 Cell[][] cells = new Cell[1][1]; 053 cells[0][0] = cellOri; 054 Cell cellFim = sheet.getCell(new Address(0, 0)); 055 056 // Create a new instance of server and client 057 Server svr = Server.getInstance(); 058 Client cli = new Client(); 059 String props = "wr"; 060 061 // Start client and server 062 svr.startServer(50000, cells, 063 Validate.encrypt(password.getBytes()), props, this); 064 cli.startClient("localhost", 50000, cellFim, 065 Validate.encrypt(password.getBytes()), this); 066 067 // To wait to the system transmition 068 Thread.sleep(1000); 069 070 assertEquals(cellOri.getContent(), cellFim.getContent()); 071 } catch (Exception e) { 072 fail("Exception Error!"); 073 } 074 } 075 076 @Override 077 public void update(Observable o, Object arg) { 078 fail("Exception Error!"); 079 } 080}