package pdp.scrabble.test.multiplayer;
import java.net.MalformedURLException;
import java.rmi.NoSuchObjectException;
import java.rmi.RemoteException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.fail;
import pdp.scrabble.Game;
import pdp.scrabble.Language;
import pdp.scrabble.multiplayer.Client;
import pdp.scrabble.multiplayer.Server;
import static pdp.scrabble.Factory.FACTORY;
public class ServerTest {
private static final String LANG = "English";
private static final Game GAME = FACTORY.createGame(Language.init(LANG), null);
public ServerTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
GAME.create();
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void ServerTester() throws RemoteException {
Server server = FACTORY.createServer(1099, LANG);
Client client = FACTORY.createClient(null, "test");
//Connect client to server
try {
server.connect(null, client);
System.out.println("Connect client to server");
}
catch (RemoteException ex) {
fail("RemoteException was not expected");
}
catch (NullPointerException ex) {
System.out.println("Can't connect");
}
//Disconnect client
try {
server.disconnect(0);
System.out.println("Disconnecting client");
}
catch (RemoteException ex) {
fail("RemoteException was not expected");
}
//Try to connect null Client
try {
server.connect(null, null);
}
catch (RemoteException ex) {
fail("RemoteException was not expected");
}
catch (NullPointerException ex) {
System.out.println("Can't connect null client");
}
//Change player turn with no clients
try {
server.endTurnMulti();
fail("Change turn with null client was not expected");
}
catch (NullPointerException ex){
System.out.println("Can't change turn with null client");
}
// End existing server
try {
server.endServer();
System.out.println("Ending server");
}
catch (MalformedURLException ex) {
fail("MalformedURLException xas not expected");
}
//try to end server already ended
try {
server.endServer();
fail("Can't end a null server");
}
catch (MalformedURLException ex) {
fail("MalformedURLException not expected");
}
catch (NoSuchObjectException ex) {
System.out.println("NoSuchObjectException : Null can't be ended");
}
}
}