001package csheets.core.ext.share;
002
003import static org.junit.Assert.*;
004
005import java.net.InetAddress;
006import java.util.*;
007
008import org.junit.Test;
009
010import csheets.ext.share.core.*;
011
012/**
013 * Tests the discover function
014 * 
015 * @author Andre
016 * 
017 */
018public class DiscoverTest implements Observer {
019
020        /**
021         * Test the discover function of the application
022         */
023        @Test
024        public void testDiscover() {
025                try {
026                        // local ip
027                        InetAddress ip = InetAddress.getLocalHost();
028                        int port = 5000;
029
030                        // start the server broadcast messages
031                        ServerDiscover.getInstance().findClients(port, this);
032                        List<Connections> list = ClientDiscover.getInstance().findServers(
033                                        this);
034                        // get the first resulted
035                        Connections resulted = list.get(0);
036
037                        Thread.sleep(100);
038
039                        assertEquals(ip, resulted.getIP());
040                        assertEquals(port, resulted.getPort());
041                } catch (Exception e) {
042                        fail("Exception Error!");
043                }
044        }
045
046        @Override
047        public void update(Observable o, Object arg) {
048                fail("Exception Error!");
049        }
050
051}