Adding test of the different methods to block a player from the server.
This commit is contained in:
@@ -36,6 +36,7 @@ import org.junit.runners.Suite;
|
||||
CreateRankingGameTest.class,
|
||||
StartNormalGameTest.class,
|
||||
RunNormalGameTest.class,
|
||||
BlockedPlayerTest.class,
|
||||
RunRankingGameTest.class
|
||||
})
|
||||
public class AllTests {
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package pokerth_test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import pokerth_protocol.AnnounceMessage;
|
||||
import pokerth_protocol.AuthenticatedLogin;
|
||||
import pokerth_protocol.InitMessage;
|
||||
import pokerth_protocol.PokerTHMessage;
|
||||
import pokerth_protocol.Version;
|
||||
import pokerth_protocol.AnnounceMessage.AnnounceMessageSequenceType.ServerTypeEnumType;
|
||||
import pokerth_protocol.ErrorMessage.ErrorMessageSequenceType.ErrorReasonEnumType;
|
||||
import pokerth_protocol.InitMessage.InitMessageSequenceType;
|
||||
import pokerth_protocol.InitMessage.InitMessageSequenceType.LoginChoiceType;
|
||||
|
||||
|
||||
public class BlockedPlayerTest extends TestBase {
|
||||
|
||||
void verifyLoginBlocked() throws Exception {
|
||||
PokerTHMessage msg = receiveMessage(sock);
|
||||
AnnounceMessage announce = msg.getAnnounceMessage();
|
||||
assertTrue(announce.getValue().getServerType().getValue() == ServerTypeEnumType.EnumType.serverTypeInternetAuth);
|
||||
|
||||
ScramSha1 scramAuth = new ScramSha1();
|
||||
|
||||
// Send challenge.
|
||||
Version requestedVersion = new Version();
|
||||
requestedVersion.setMajor(PROTOCOL_VERSION_MAJOR);
|
||||
requestedVersion.setMinor(PROTOCOL_VERSION_MINOR);
|
||||
AuthenticatedLogin authLogin = new AuthenticatedLogin();
|
||||
authLogin.setClientUserData(scramAuth.executeStep1("test1").getBytes());
|
||||
LoginChoiceType loginType = new LoginChoiceType();
|
||||
loginType.selectAuthenticatedLogin(authLogin);
|
||||
InitMessageSequenceType msgType = new InitMessageSequenceType();
|
||||
msgType.setBuildId(0L);
|
||||
msgType.setLogin(loginType);
|
||||
msgType.setRequestedVersion(requestedVersion);
|
||||
InitMessage init = new InitMessage();
|
||||
init.setValue(msgType);
|
||||
msg = new PokerTHMessage();
|
||||
msg.selectInitMessage(init);
|
||||
sendMessage(msg, sock);
|
||||
|
||||
msg = receiveMessage(sock);
|
||||
assertTrue(msg.isErrorMessageSelected());
|
||||
assertEquals(ErrorReasonEnumType.EnumType.errorBlockedByServer, msg.getErrorMessage().getValue().getErrorReason().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRunRankingGame() throws Exception {
|
||||
|
||||
Statement dbStatement = dbConn.createStatement();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET valid = 0 WHERE username = 'test1'");
|
||||
verifyLoginBlocked();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET valid = 1 WHERE username = 'test1'");
|
||||
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
|
||||
dbStatement.executeUpdate("UPDATE player_login SET valid = 2 WHERE username = 'test1'");
|
||||
verifyLoginBlocked();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET valid = 1 WHERE username = 'test1'");
|
||||
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
|
||||
dbStatement.executeUpdate("UPDATE player_login SET valid = 4 WHERE username = 'test1'");
|
||||
verifyLoginBlocked();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET valid = 1 WHERE username = 'test1'");
|
||||
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
|
||||
dbStatement.executeUpdate("UPDATE player_login SET aktivator = 0 WHERE username = 'test1'");
|
||||
verifyLoginBlocked();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET aktivator = 1 WHERE username = 'test1'");
|
||||
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
|
||||
dbStatement.executeUpdate("UPDATE player_login SET aktivator = 2 WHERE username = 'test1'");
|
||||
verifyLoginBlocked();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET aktivator = 1 WHERE username = 'test1'");
|
||||
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
|
||||
dbStatement.executeUpdate("UPDATE player_login SET aktivator = 4 WHERE username = 'test1'");
|
||||
verifyLoginBlocked();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET aktivator = 1 WHERE username = 'test1'");
|
||||
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
|
||||
userInit(sock, "test1", "test1");
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,6 @@
|
||||
package pokerth_test;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
@@ -34,49 +32,12 @@ import pokerth_protocol.*;
|
||||
import pokerth_protocol.NetGameInfo.EndRaiseModeEnumType;
|
||||
import pokerth_protocol.NetGameInfo.NetGameTypeEnumType;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
import java.io.File;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import pokerth_protocol.MyActionRequestMessage.MyActionRequestMessageSequenceType;
|
||||
import pokerth_protocol.StartEventAckMessage.StartEventAckMessageSequenceType;
|
||||
|
||||
|
||||
public class RunRankingGameTest extends TestBase {
|
||||
|
||||
Connection dbConn;
|
||||
|
||||
@Before
|
||||
public void dbInit() throws Exception {
|
||||
String configFileName = System.getProperty("user.home") + "/.pokerth/config.xml";
|
||||
File file = new File(configFileName);
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
Document doc = db.parse(file);
|
||||
doc.getDocumentElement().normalize();
|
||||
Element configNode = (Element)doc.getElementsByTagName("Configuration").item(0);
|
||||
|
||||
Element dbAddressNode = (Element)configNode.getElementsByTagName("DBServerAddress").item(0);
|
||||
String dbAddress = dbAddressNode.getAttribute("value");
|
||||
|
||||
Element dbUserNode = (Element)configNode.getElementsByTagName("DBServerUser").item(0);
|
||||
String dbUser = dbUserNode.getAttribute("value");
|
||||
|
||||
Element dbPasswordNode = (Element)configNode.getElementsByTagName("DBServerPassword").item(0);
|
||||
String dbPassword = dbPasswordNode.getAttribute("value");
|
||||
|
||||
Element dbNameNode = (Element)configNode.getElementsByTagName("DBServerDatabaseName").item(0);
|
||||
String dbName = dbNameNode.getAttribute("value");
|
||||
|
||||
final String dbUrl = "jdbc:mysql://" + dbAddress + ":3306/" + dbName;
|
||||
Class.forName("com.mysql.jdbc.Driver").newInstance ();
|
||||
dbConn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRunRankingGame() throws Exception {
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ import static org.junit.Assert.*;
|
||||
import org.bn.*;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import pokerth_protocol.*;
|
||||
import pokerth_protocol.AnnounceMessage.AnnounceMessageSequenceType.ServerTypeEnumType;
|
||||
@@ -36,8 +38,13 @@ import pokerth_protocol.NetGameInfo.RaiseIntervalModeChoiceType;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
public abstract class TestBase {
|
||||
|
||||
public final int PROTOCOL_VERSION_MAJOR = 2;
|
||||
@@ -50,6 +57,39 @@ public abstract class TestBase {
|
||||
protected IEncoder<PokerTHMessage> encoder;
|
||||
protected IDecoder decoder;
|
||||
protected Socket sock;
|
||||
protected Connection dbConn;
|
||||
|
||||
@Before
|
||||
public void dbInit() throws Exception {
|
||||
String configFileName = System.getProperty("user.home") + "/.pokerth/config.xml";
|
||||
File file = new File(configFileName);
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
Document doc = db.parse(file);
|
||||
doc.getDocumentElement().normalize();
|
||||
Element configNode = (Element)doc.getElementsByTagName("Configuration").item(0);
|
||||
|
||||
Element dbAddressNode = (Element)configNode.getElementsByTagName("DBServerAddress").item(0);
|
||||
String dbAddress = dbAddressNode.getAttribute("value");
|
||||
|
||||
Element dbUserNode = (Element)configNode.getElementsByTagName("DBServerUser").item(0);
|
||||
String dbUser = dbUserNode.getAttribute("value");
|
||||
|
||||
Element dbPasswordNode = (Element)configNode.getElementsByTagName("DBServerPassword").item(0);
|
||||
String dbPassword = dbPasswordNode.getAttribute("value");
|
||||
|
||||
Element dbNameNode = (Element)configNode.getElementsByTagName("DBServerDatabaseName").item(0);
|
||||
String dbName = dbNameNode.getAttribute("value");
|
||||
|
||||
final String dbUrl = "jdbc:mysql://" + dbAddress + ":3306/" + dbName;
|
||||
Class.forName("com.mysql.jdbc.Driver").newInstance ();
|
||||
dbConn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
|
||||
}
|
||||
|
||||
@After
|
||||
public void dbClose() throws Exception {
|
||||
dbConn.close();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user