diff --git a/pom.xml b/pom.xml index 4f37f2aaef6c006c1cdabb857ae7787128d71766..a1fe802d25b92f3c95961e9719ba2f9c6b28a779 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,13 @@ <scope>test</scope> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-junit-jupiter</artifactId> + <version>5.8.0</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> @@ -75,6 +82,12 @@ <artifactId>gson</artifactId> <version>2.10.1</version> </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>RELEASE</version> + <scope>test</scope> + </dependency> </dependencies> diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/AzureDB.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/AzureDB.java index b138e76967b758555477fbde0c736ff98e2f7690..f75e8d1d4f322ef6b6c6302549337ea8b2a550b4 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/AzureDB.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/AzureDB.java @@ -1,35 +1,30 @@ package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Utilities.CryptoUtils; import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.CryptoException; import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.SQLException; -import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Utilities.CryptoUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; +import java.sql.*; import java.util.ArrayList; -public class AzureDB implements ISQLDataBase { +/*this class is only here for showcasing the interchangeability of the DBMS. AzureDB could be used as fallback database when primary database is unreachable*/ - /*this class is only here for showcasing the interchangeability of the DBMS*/ +public class AzureDB implements ISQLDataBase { private static String user=""; private static String password=""; private static String[] parts= new String[2]; - static File encryptedFile = new File("src\\main\\resources\\database\\AzureDB_logindetails"); - private static final Logger log = LogManager.getLogger(OracleDB.class); public static void getLoginData() throws CryptoException { parts = CryptoUtils.decrypt(encryptedFile); user = parts[0]; password = parts[1]; - log.info("AzureDB_logindetails: user: " + user + " password: " + password); + //log.info("AzureDB_logindetails: user: " + user + " password: " + password); } @Override @@ -37,18 +32,17 @@ public class AzureDB implements ISQLDataBase { try { getLoginData(); String url = "jdbc:sqlserver://battlearena.database.windows.net;encrypt=true;user=" + user + ";password=" + password + ";databaseName=battleArena;"; - - log.info("Connecting to the database!"); Connection connection = DriverManager.getConnection(url); - log.info("Database connection test" + connection.getCatalog()); - + //log.info("Database connection test" + connection.getCatalog()); connection.setAutoCommit(true); + log.info("Connecting to SQL database ..."); + return connection; } catch(Exception e){ log.error(e); - throw new SQLException("SQL Connection Error! " + e.getMessage()); + throw new SQLException("SQL connection error! " + e.getMessage()); } } @@ -59,20 +53,20 @@ public class AzureDB implements ISQLDataBase { String sql = "SELECT * FROM CoreMaps"; PreparedStatement stmt = connection.prepareStatement(sql); - log.info("Sending SQL statement"); + log.info("Sending SQL statement."); ResultSet rs = stmt.executeQuery(); while(rs.next()){ newMaps.add(new MapData(rs.getString("map_id"), rs.getString("map_name"), rs.getInt("map_width"), rs.getInt("map_height"), rs.getString("map_data"))); } - log.info("SQL query successful"); rs.close(); stmt.close(); + log.info("Core-Maps retrieved successfully from SQL server!"); return newMaps; } catch(Exception e){ log.error(e); - throw new SQLException("Error retrieving Coremaps! " + e.getMessage()); + throw new SQLException("Error retrieving Core-Maps from SQL server! " + e.getMessage()); } } @@ -83,7 +77,7 @@ public class AzureDB implements ISQLDataBase { String sql = "SELECT map_id, map_name, map_width, map_height, map_downloads FROM communitymaps"; PreparedStatement stmt = connection.prepareStatement(sql); - log.info("Sending SQL statement"); + log.info("Sending SQL statement."); ResultSet rs = stmt.executeQuery(); while(rs.next()){ @@ -91,12 +85,39 @@ public class AzureDB implements ISQLDataBase { } rs.close(); stmt.close(); - log.info("Community map names retrieved successfully"); + log.info("Community-Map names retrieved successfully from SQL server!"); return tempList; } catch(Exception e){ log.error(e); - throw new SQLException("Error retrieving community map names! " + e.getMessage()); + throw new SQLException("Error retrieving Community-Map names from SQL server! " + e.getMessage()); + } + } + + @Override + public PlayerStatistics getStatistics(String playerName) throws SQLException { + try(Connection connection = connect()) { + String sql = "SELECT games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time FROM players WHERE player_name = ?"; + PreparedStatement stmt = connection.prepareStatement(sql); + stmt.setString(1, playerName); + + log.info("Sending SQL statement."); + ResultSet rs = stmt.executeQuery(); + if(rs.next() == false){ //if no data matches + throw new SQLException("No match on SQL database!"); + } + PlayerStatistics stats = new PlayerStatistics(0, 0, 0, 0, 0, 0); + while(rs.next()) { + stats = new PlayerStatistics(rs.getInt("games_won"), rs.getInt("games_lost"), rs.getInt("kills"), rs.getInt("deaths"), rs.getInt("blocks_destroyed"), rs.getInt("ingame_time")); + } + rs.close(); + stmt.close(); + log.info("Player statistics retrieved successfully from SQL server!"); + return stats; + } + catch(Exception e){ + log.error(e); + throw new SQLException("Error retrieving player statistics from SQL server! " + e.getMessage()); } } @@ -107,151 +128,143 @@ public class AzureDB implements ISQLDataBase { PreparedStatement stmt = connection.prepareStatement(sql); stmt.setString(1, mapID); - log.info("Sending SQL statement"); + log.info("Sending SQL statement."); ResultSet rs = stmt.executeQuery(); MapData mapChosen = new MapData("", "",0,0, ""); if(rs.next() == false){ //if no data matches - throw new SQLException("No match on Database"); + throw new SQLException("No match on SQL database!"); } while(rs.next()) { mapChosen = new MapData(rs.getString("map_id"), rs.getString("map_name"), rs.getInt("map_width"), rs.getInt("map_height"), rs.getString("map_data")); } rs.close(); stmt.close(); - log.info("Community map retrieved successfully"); + log.info("Community-Map retrieved successfully from SQL server!"); String sql2 = "UPDATE communitymaps SET map_downloads = map_downloads + 1 WHERE map_id = ?"; PreparedStatement stmt2 = connection.prepareStatement(sql2); stmt2.setString(1, mapID); stmt2.executeQuery(); - log.info("Sending SQL statement to update Download-Counter"); + log.info("Sending SQL statement to update Download-Counter for downloaded map."); stmt2.close(); return mapChosen; } catch(Exception e){ log.error(e); - throw new SQLException("Error retrieving community map! " + e.getMessage()); + throw new SQLException("Error retrieving Community-Map from SQL server! " + e.getMessage()); } } @Override - public void uploadCommunityMap(MapData map) throws SQLException { + public String checkCredentials(String playerName) throws SQLException { try(Connection connection = connect()) { - String sql = "INSERT INTO communitymaps (map_id, map_name, map_width, map_height, map_data) VALUES (?, ?, ?, ?, ?)"; + String sql = "SELECT player_pw FROM players WHERE player_name = ?"; PreparedStatement stmt = connection.prepareStatement(sql); - stmt.setString(1, map.getMapID()); - stmt.setString(2, map.getMapName()); - stmt.setInt(3, map.getMapWidth()); - stmt.setInt(4, map.getMapHeight()); - stmt.setString(5, map.getMapData()); + stmt.setString(1, playerName); - log.info("Sending SQL statement"); - stmt.executeQuery(); + log.info("Sending SQL statement."); + ResultSet rs = stmt.executeQuery(); + String password = ""; + while(rs.next()) { + password = rs.getString("player_pw"); + } + rs.close(); stmt.close(); - log.info("Community Map uploaded successfully"); + log.info("Player credentials retrieved successfully from SQL server!"); + return password; } catch(Exception e){ log.error(e); - throw new SQLException("Error uploading created community map! " + e.getMessage()); + throw new SQLException("Error retrieving retrieving player credentials from SQL server! " + e.getMessage()); } } @Override - public void createPlayer(String playerName, String playerPW) throws SQLException { + public void uploadCommunityMap(MapData map) throws SQLException { try(Connection connection = connect()) { - String sql = "INSERT INTO players (player_name, player_pw, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time) VALUES (?, ?, 0, 0, 0, 0, 0, 0)"; + String sql = "INSERT INTO communitymaps (map_id, map_name, map_width, map_height, map_data, map_downloads) VALUES (?, ?, ?, ?, ?, 0)"; PreparedStatement stmt = connection.prepareStatement(sql); - stmt.setString(1, playerName); - stmt.setString(2, playerPW); + stmt.setString(1, map.getMapID()); + stmt.setString(2, map.getMapName()); + stmt.setInt(3, map.getMapWidth()); + stmt.setInt(4, map.getMapHeight()); + stmt.setString(5, map.getMapData()); - log.info("Sending SQL statement"); + log.info("Sending SQL statement."); stmt.executeQuery(); stmt.close(); - log.info("Online account created successfully"); + log.info("Community-Map uploaded successfully to SQL server!"); } catch(Exception e){ log.error(e); - throw new SQLException("Error creating online account! " + e.getMessage()); + throw new SQLException("Error uploading created Community-Map to SQL server! " + e.getMessage()); } } @Override - public String checkCredentials(String playerName) throws SQLException { + public void createPlayer(String playerName, String playerPW) throws SQLException { try(Connection connection = connect()) { - String sql = "SELECT player_pw FROM players WHERE player_name = ?"; + String sql = "INSERT INTO players (player_name, player_pw, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time) VALUES (?, ?, 0, 0, 0, 0, 0, 0)"; PreparedStatement stmt = connection.prepareStatement(sql); stmt.setString(1, playerName); + stmt.setString(2, playerPW); - log.info("Sending SQL statement"); - ResultSet rs = stmt.executeQuery(); + log.info("Sending SQL statement."); + stmt.executeQuery(); - String password = ""; - while(rs.next()) { - password = rs.getString("player_pw"); - } - rs.close(); stmt.close(); - log.info("Player credentials retrieved successfully"); - return password; + log.info("Online account created successfully on SQL server!"); } catch(Exception e){ log.error(e); - throw new SQLException("Error retrieving retrieving player credentials! " + e.getMessage()); + throw new SQLException("Error creating online account on SQL server! " + e.getMessage()); } } @Override - public PlayerStatistics getStatistics(String playerName) throws SQLException { + public void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws SQLException { try(Connection connection = connect()) { - String sql = "SELECT games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time FROM players WHERE player_name = ?"; + String sql = "UPDATE players SET games_won = ?, games_lost = ?, kills = ?, deaths = ?, blocks_destroyed = ?, ingame_time = ? WHERE player_name = ?"; PreparedStatement stmt = connection.prepareStatement(sql); - stmt.setString(1, playerName); + stmt.setInt(1, stats.getGamesWon()); + stmt.setInt(2, stats.getGamesLost()); + stmt.setInt(3, stats.getKills()); + stmt.setInt(4, stats.getDeaths()); + stmt.setInt(5, stats.getBlocksDestroyed()); + stmt.setInt(6, stats.getGameTime()); + stmt.setString(7, account.getPlayerName()); + + log.info("Sending SQL statement."); + stmt.executeQuery(); - log.info("Sending SQL statement"); - ResultSet rs = stmt.executeQuery(); - if(rs.next() == false){ //if no data matches - throw new SQLException("No match on Database"); - } - PlayerStatistics stats = new PlayerStatistics(0, 0, 0, 0, 0, 0); - while(rs.next()) { - stats = new PlayerStatistics(rs.getInt("games_won"), rs.getInt("games_lost"), rs.getInt("kills"), rs.getInt("deaths"), rs.getInt("blocks_destroyed"), rs.getInt("ingame_time")); - } - rs.close(); stmt.close(); - log.info("Player statistics retrieved successfully"); - return stats; + log.info("Player statistics updated successfully on SQL server!"); } catch(Exception e){ log.error(e); - throw new SQLException("Error retrieving player statistics! " + e.getMessage()); + throw new SQLException("Error updating player statistics on SQL server! " + e.getMessage()); } } @Override - public void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws SQLException { + public void resetPlayerStats(PlayerAccount account) throws SQLException{ //verification of player credentials necessary beforehand (use methode "verifyAccountData" in "Persistence.java) try(Connection connection = connect()) { - String sql = "UPDATE players SET games_won = ?, games_lost = ?, kills = ?, deaths = ?, blocks_destroyed = ?, ingame_time = ? WHERE player_name = ?"; + String sql = "UPDATE players SET games_won = 0, games_lost = 0, kills = 0, deaths = 0, blocks_destroyed = 0, ingame_time = 0 WHERE player_name = ?"; PreparedStatement stmt = connection.prepareStatement(sql); - stmt.setInt(1, stats.getGamesWon()); - stmt.setInt(2, stats.getGamesLost()); - stmt.setInt(3, stats.getKills()); - stmt.setInt(4, stats.getDeaths()); - stmt.setInt(5, stats.getBlocksDestroyed()); - stmt.setInt(6, stats.getGameTime()); - stmt.setString(7, account.getPlayerName()); + stmt.setString(1, account.getPlayerName()); - log.info("Sending SQL statement"); + log.info("Sending SQL statement."); stmt.executeQuery(); stmt.close(); - log.info("Player statistics updated successfully"); + log.info("Player statistics reset successfully on SQL server!"); } catch(Exception e){ log.error(e); - throw new SQLException("Error updating player statistics! " + e.getMessage()); + throw new SQLException("Error resetting player statistics on SQL server! " + e.getMessage()); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/GsonHandler.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/GsonHandler.java index b330be1f110d65125e9dfb9b413adcac5c90a10e..308b553a68422590c8a0619baa336e91ee513bb2 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/GsonHandler.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/GsonHandler.java @@ -37,12 +37,18 @@ public class GsonHandler { } try (FileReader reader = new FileReader(filePath)) { ArrayList<MapData> maps = gson.fromJson(reader, mapDataType); - log.info("GSON - Maps successfully loaded from JSON"); + log.info("GSON - Maps successfully loaded from JSON!"); return maps; } catch (Exception e) { log.info(e); - log.info("GSON - Loading maps from JSON failed"); - throw new GSONException("Error loading maps!"); + if(type == MapType.COREMAP){ + log.info("GSON - Loading Core-Maps from JSON failed!"); + throw new GSONException("Loading Core-Maps from JSON failed!"); + } + else{ + log.info("GSON - Loading Community-Maps from JSON failed!"); + throw new GSONException("Loading Community-Maps from JSON failed!"); + } } } @@ -56,80 +62,86 @@ public class GsonHandler { } try (FileWriter writer = new FileWriter(filePath)) { gson.toJson(maps, writer); - log.info("GSON - Maps successfully saved to JSON"); + log.info("GSON - Maps successfully saved to JSON!"); } catch (Exception e) { log.info(e); - log.info("GSON - Saving maps to JSON failed"); - throw new GSONException("Error saving maps!"); + if(type == MapType.COREMAP){ + log.info("GSON - Saving Core-Maps to JSON failed!"); + throw new GSONException("Saving Core-Maps to JSON failed!"); + } + else{ + log.info("GSON - Saving Community-Maps to JSON failed!"); + throw new GSONException("Saving Community-Maps to JSON failed!"); + } } } public PlayerStatistics loadStats() throws GSONException { try (FileReader reader = new FileReader(filePathPlayerStats)) { PlayerStatistics stats = gson.fromJson(reader, playerStatsType); - log.info("GSON - Player statistics successfully loaded from JSON"); + log.info("GSON - Player statistics successfully loaded from JSON!"); return stats; } catch (Exception e) { log.info(e); - log.info("GSON - Loading player statistics from JSON failed"); - throw new GSONException("Error loading player statistics!"); + log.info("GSON - Loading player statistics from JSON failed!"); + throw new GSONException("Loading player statistics from JSON failed!"); } } public void saveStats(PlayerStatistics stats) throws GSONException { try (FileWriter writer = new FileWriter(filePathPlayerStats)) { gson.toJson(stats, writer); - log.info("GSON - Player statistics successfully saved to JSON"); + log.info("GSON - Player statistics successfully saved to JSON!"); } catch (Exception e) { log.info(e); - log.info("GSON - Saving player statistics to JSON failed"); - throw new GSONException("Error saving player statistics!"); + log.info("GSON - Saving player statistics to JSON failed!"); + throw new GSONException("Saving player statistics to JSON failed!"); } } public AppSettings loadSettings() throws GSONException { try (FileReader reader = new FileReader(filePathSettings)) { AppSettings settings = gson.fromJson(reader, settingsType); - log.info("GSON - Settings successfully loaded from JSON"); + log.info("GSON - Settings successfully loaded from JSON!"); return settings; } catch (Exception e) { log.info(e); - log.info("GSON - Loading settings from JSON failed"); - throw new GSONException("Error Loading settings!"); + log.info("GSON - Loading settings from JSON failed!"); + throw new GSONException("Loading settings from JSON failed!"); } } public void saveSettings(AppSettings settings) throws GSONException { try (FileWriter writer = new FileWriter(filePathSettings)) { gson.toJson(settings, writer); - log.info("GSON - Settings successfully saved to JSON"); + log.info("GSON - Settings successfully saved to JSON!"); } catch (Exception e) { log.info(e); - log.info("GSON - Saving settings to JSON failed"); - throw new GSONException("Error saving settings!"); + log.info("GSON - Saving settings to JSON failed!"); + throw new GSONException("Saving settings to JSON failed!"); } } public PlayerAccount loadAccount() throws GSONException { try (FileReader reader = new FileReader(filePathPlayerAccount)) { PlayerAccount account = gson.fromJson(reader, accountType); - log.info("GSON - Player account information successfully loaded from JSON"); + log.info("GSON - Player account information successfully loaded from JSON!"); return account; } catch (Exception e) { log.info(e); - log.info("GSON - Loading player account information from JSON failed"); - throw new GSONException("Error loading player account information!"); + log.info("GSON - Loading player account information from JSON failed!"); + throw new GSONException("Loading player account information from JSON failed!"); } } public void saveAccount(PlayerAccount account) throws GSONException { try (FileWriter writer = new FileWriter(filePathPlayerAccount)) { gson.toJson(account, writer); - log.info("GSON - Player account information successfully saved to JSON"); + log.info("GSON - Player account information successfully saved to JSON!"); } catch (Exception e) { log.info(e); - log.info("GSON - Saving player account information to JSON failed"); - throw new GSONException("Error loading player account information!"); + log.info("GSON - Saving player account information to JSON failed!"); + throw new GSONException("Saving player account information to JSON failed!"); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/ISQLDataBase.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/ISQLDataBase.java index dd7bb2f0eb72ddd6eac0a59ce72e0654f522a3ab..7a169c9b21d76b2a7eba64b8899dbb5e397b22cb 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/ISQLDataBase.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/ISQLDataBase.java @@ -19,5 +19,6 @@ public interface ISQLDataBase { String checkCredentials(String playerName) throws SQLException; PlayerStatistics getStatistics(String playerName) throws SQLException; void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws SQLException; + void resetPlayerStats(PlayerAccount account) throws SQLException; } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/OracleDB.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/OracleDB.java index 070e42d3bbd2fcbed93881fea80a7e5aac077733..856fe24df247e972c4ed074ddddce4fd1f71a1ce 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/OracleDB.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/OracleDB.java @@ -12,18 +12,14 @@ import java.util.ArrayList; import oracle.jdbc.pool.OracleDataSource; - public class OracleDB implements ISQLDataBase { + private static String user=""; private static String password=""; private static String[] parts= new String[2]; - static File encryptedFile = new File("src\\main\\resources\\database\\OracleDB_logindetails"); - - //static File encryptedFile = new File("src\\main\\resources\\database\\document.encrypted"); - //static File decryptedFile = new File("src\\main\\resources\\database\\document.decrypted"); - private static final Logger log = LogManager.getLogger(OracleDB.class); + public static void getLoginData() throws CryptoException { parts = CryptoUtils.decrypt(encryptedFile); user = parts[0]; @@ -41,7 +37,7 @@ public class OracleDB implements ISQLDataBase { ods.setPassword(password); Connection conn = ods.getConnection(); - log.info("Connecting to the database!"); + log.info("Connecting to SQL database ..."); return conn; } @@ -58,20 +54,20 @@ public class OracleDB implements ISQLDataBase { String sql = "SELECT * FROM battlearenadata.coremaps"; PreparedStatement stmt = connection.prepareStatement(sql); - log.info("Sending SQL statement"); + log.info("Sending SQL statement."); ResultSet rs = stmt.executeQuery(); while(rs.next()){ - newMaps.add(new MapData(rs.getString("map_id"), rs.getString("map_name"), rs.getInt("map_width"), rs.getInt("map_height"), rs.getString("map_data"))); + newMaps.add(new MapData(rs.getString("map_id"), rs.getString("map_name"), rs.getInt("map_width"), rs.getInt("map_height"), rs.getString("map_data"))); } rs.close(); stmt.close(); - log.info("Coremaps retrieved successfully"); + log.info("Core-Maps retrieved successfully from SQL server!"); return newMaps; } catch(Exception e){ log.error(e); - throw new SQLException("Error retrieving coremaps! " + e.getMessage()); + throw new SQLException("Error retrieving Core-Maps from SQL server! " + e.getMessage()); } } @@ -82,7 +78,7 @@ public class OracleDB implements ISQLDataBase { String sql = "SELECT map_id, map_name, map_width, map_height, map_downloads FROM battlearenadata.communitymaps"; PreparedStatement stmt = connection.prepareStatement(sql); - log.info("Sending SQL statement"); + log.info("Sending SQL statement."); ResultSet rs = stmt.executeQuery(); while(rs.next()){ @@ -90,12 +86,39 @@ public class OracleDB implements ISQLDataBase { } rs.close(); stmt.close(); - log.info("Community map names retrieved successfully"); + log.info("Community-Map names retrieved successfully from SQL server!"); return tempList; } catch(Exception e){ log.error(e); - throw new SQLException("Error retrieving community map names! " + e.getMessage()); + throw new SQLException("Error retrieving Community-Map names from SQL server! " + e.getMessage()); + } + } + + @Override + public PlayerStatistics getStatistics(String playerName) throws SQLException { + try(Connection connection = connect()) { + String sql = "SELECT games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time FROM battlearenadata.players WHERE player_name = ?"; + PreparedStatement stmt = connection.prepareStatement(sql); + stmt.setString(1, playerName); + + log.info("Sending SQL statement."); + ResultSet rs = stmt.executeQuery(); + if(rs.next() == false){ //if no data matches + throw new SQLException("No match on SQL database!"); + } + PlayerStatistics stats = new PlayerStatistics(0, 0, 0, 0, 0, 0); + while(rs.next()) { + stats = new PlayerStatistics(rs.getInt("games_won"), rs.getInt("games_lost"), rs.getInt("kills"), rs.getInt("deaths"), rs.getInt("blocks_destroyed"), rs.getInt("ingame_time")); + } + rs.close(); + stmt.close(); + log.info("Player statistics retrieved successfully from SQL server!"); + return stats; + } + catch(Exception e){ + log.error(e); + throw new SQLException("Error retrieving player statistics from SQL server! " + e.getMessage()); } } @@ -106,151 +129,143 @@ public class OracleDB implements ISQLDataBase { PreparedStatement stmt = connection.prepareStatement(sql); stmt.setString(1, mapID); - log.info("Sending SQL statement"); + log.info("Sending SQL statement."); ResultSet rs = stmt.executeQuery(); MapData mapChosen = new MapData("", "",0,0, ""); if(rs.next() == false){ //if no data matches - throw new SQLException("No match on Database"); + throw new SQLException("No match on SQL database!"); } while(rs.next()) { mapChosen = new MapData(rs.getString("map_id"), rs.getString("map_name"), rs.getInt("map_width"), rs.getInt("map_height"), rs.getString("map_data")); } rs.close(); stmt.close(); - log.info("Community map retrieved successfully"); + log.info("Community-Map retrieved successfully from SQL server!"); String sql2 = "UPDATE battlearenadata.communitymaps SET map_downloads = map_downloads + 1 WHERE map_id = ?"; PreparedStatement stmt2 = connection.prepareStatement(sql2); stmt2.setString(1, mapID); stmt2.executeQuery(); - log.info("Sending SQL statement to update Download-Counter"); + log.info("Sending SQL statement to update Download-Counter for downloaded map!"); stmt2.close(); return mapChosen; } catch(Exception e){ - log.error(e.getMessage()); - throw new SQLException("Error retrieving community map! " + e.getMessage()); + log.error(e); + throw new SQLException("Error retrieving Community-Map from SQL server! " + e.getMessage()); } } @Override - public void uploadCommunityMap(MapData map) throws SQLException { + public String checkCredentials(String playerName) throws SQLException { try(Connection connection = connect()) { - String sql = "INSERT INTO battlearenadata.communitymaps (map_id, map_name, map_width, map_height, map_data) VALUES (?, ?, ?, ?, ?)"; + String sql = "SELECT player_pw FROM battlearenadata.players WHERE player_name = ?"; PreparedStatement stmt = connection.prepareStatement(sql); - stmt.setString(1, map.getMapID()); - stmt.setString(2, map.getMapName()); - stmt.setInt(3, map.getMapWidth()); - stmt.setInt(4, map.getMapHeight()); - stmt.setString(5, map.getMapData()); + stmt.setString(1, playerName); - log.info("Sending SQL statement"); - stmt.executeQuery(); + log.info("Sending SQL statement."); + ResultSet rs = stmt.executeQuery(); + String password = ""; + while(rs.next()) { + password = rs.getString("player_pw"); + } + rs.close(); stmt.close(); - log.info("Community Map uploaded successfully"); + log.info("Player credentials retrieved successfully from SQL server!"); + return password; } catch(Exception e){ log.error(e); - throw new SQLException("Error uploading created community map! " + e.getMessage()); + throw new SQLException("Error retrieving retrieving player credentials from SQL server! " + e.getMessage()); } } @Override - public void createPlayer(String playerName, String playerPW) throws SQLException { + public void uploadCommunityMap(MapData map) throws SQLException { try(Connection connection = connect()) { - String sql = "INSERT INTO battlearenadata.players (player_name, player_pw, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time) VALUES (?, ?, 0, 0, 0, 0, 0, 0)"; + String sql = "INSERT INTO battlearenadata.communitymaps (map_id, map_name, map_width, map_height, map_data, map_downloads) VALUES (?, ?, ?, ?, ?, 0)"; PreparedStatement stmt = connection.prepareStatement(sql); - stmt.setString(1, playerName); - stmt.setString(2, playerPW); + stmt.setString(1, map.getMapID()); + stmt.setString(2, map.getMapName()); + stmt.setInt(3, map.getMapWidth()); + stmt.setInt(4, map.getMapHeight()); + stmt.setString(5, map.getMapData()); - log.info("Sending SQL statement"); + log.info("Sending SQL statement."); stmt.executeQuery(); stmt.close(); - log.info("Online account created successfully"); + log.info("Community-Map uploaded successfully to SQL server!"); } catch(Exception e){ log.error(e); - throw new SQLException("Error creating online account! " + e.getMessage()); + throw new SQLException("Error uploading created Community-Map to SQL server! " + e.getMessage()); } } @Override - public String checkCredentials(String playerName) throws SQLException { + public void createPlayer(String playerName, String playerPW) throws SQLException { try(Connection connection = connect()) { - String sql = "SELECT player_pw FROM battlearenadata.players WHERE player_name = ?"; + String sql = "INSERT INTO battlearenadata.players (player_name, player_pw, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time) VALUES (?, ?, 0, 0, 0, 0, 0, 0)"; PreparedStatement stmt = connection.prepareStatement(sql); stmt.setString(1, playerName); + stmt.setString(2, playerPW); - log.info("Sending SQL statement"); - ResultSet rs = stmt.executeQuery(); + log.info("Sending SQL statement."); + stmt.executeQuery(); - String password = ""; - while(rs.next()) { - password = rs.getString("player_pw"); - } - rs.close(); stmt.close(); - log.info("Player credentials retrieved successfully"); - return password; + log.info("Online account created successfully on SQL server!"); } catch(Exception e){ log.error(e); - throw new SQLException("Error retrieving retrieving player credentials! " + e.getMessage()); + throw new SQLException("Error creating online account on SQL server! " + e.getMessage()); } } @Override - public PlayerStatistics getStatistics(String playerName) throws SQLException { + public void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws SQLException { try(Connection connection = connect()) { - String sql = "SELECT games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time FROM battlearenadata.players WHERE player_name = ?"; + String sql = "UPDATE battlearenadata.players SET games_won = ?, games_lost = ?, kills = ?, deaths = ?, blocks_destroyed = ?, ingame_time = ? WHERE player_name = ?"; PreparedStatement stmt = connection.prepareStatement(sql); - stmt.setString(1, playerName); + stmt.setInt(1, stats.getGamesWon()); + stmt.setInt(2, stats.getGamesLost()); + stmt.setInt(3, stats.getKills()); + stmt.setInt(4, stats.getDeaths()); + stmt.setInt(5, stats.getBlocksDestroyed()); + stmt.setInt(6, stats.getGameTime()); + stmt.setString(7, account.getPlayerName()); + + log.info("Sending SQL statement."); + stmt.executeQuery(); - log.info("Sending SQL statement"); - ResultSet rs = stmt.executeQuery(); - if(rs.next() == false){ //if no data matches - throw new SQLException("No match on database"); - } - PlayerStatistics stats = new PlayerStatistics(0, 0, 0, 0, 0, 0); - while(rs.next()) { - stats = new PlayerStatistics(rs.getInt("games_won"), rs.getInt("games_lost"), rs.getInt("kills"), rs.getInt("deaths"), rs.getInt("blocks_destroyed"), rs.getInt("ingame_time")); - } - rs.close(); stmt.close(); - log.info("Player statistics retrieved successfully"); - return stats; + log.info("Player statistics updated successfully on SQL server!"); } catch(Exception e){ log.error(e); - throw new SQLException("Error retrieving player statistics! " + e.getMessage()); + throw new SQLException("Error updating player statistics on SQL server! " + e.getMessage()); } } @Override - public void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws SQLException { + public void resetPlayerStats(PlayerAccount account) throws SQLException{ //verification of player credentials necessary beforehand (use methode "verifyAccountData" in "Persistence.java) try(Connection connection = connect()) { - String sql = "UPDATE battlearenadata.players SET games_won = ?, games_lost = ?, kills = ?, deaths = ?, blocks_destroyed = ?, ingame_time = ? WHERE player_name = ?"; + String sql = "UPDATE battlearenadata.players SET games_won = 0, games_lost = 0, kills = 0, deaths = 0, blocks_destroyed = 0, ingame_time = 0 WHERE player_name = ?"; PreparedStatement stmt = connection.prepareStatement(sql); - stmt.setInt(1, stats.getGamesWon()); - stmt.setInt(2, stats.getGamesLost()); - stmt.setInt(3, stats.getKills()); - stmt.setInt(4, stats.getDeaths()); - stmt.setInt(5, stats.getBlocksDestroyed()); - stmt.setInt(6, stats.getGameTime()); - stmt.setString(7, account.getPlayerName()); + stmt.setString(1, account.getPlayerName()); - log.info("Sending SQL statement"); + log.info("Sending SQL statement."); stmt.executeQuery(); stmt.close(); - log.info("Player statistics updated successfully"); + log.info("Player statistics reset successfully on SQL server!"); } catch(Exception e){ log.error(e); - throw new SQLException("Error updating player statistics! " + e.getMessage()); + throw new SQLException("Error resetting player statistics on SQL server! " + e.getMessage()); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java index d8dd5bf0303003f3ab525b04a8b2ea6db4588403..f2fcc0591e906e7642e85e8f01b4b808fae080c2 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java @@ -16,12 +16,15 @@ public class Persistence { private static final Logger log = LogManager.getLogger(Persistence.class); private static final Persistence persistenceSingleton = new Persistence(); private final GsonHandler gsonHandler = new GsonHandler(); - protected OracleDB db = new OracleDB(); //evtl. Methoden von OracleDB static machen und von GSON Handler - protected ArrayList<MapData> coreMaps; - protected ArrayList<MapData> communityMaps; - protected PlayerStatistics statistics; - protected PlayerAccount account; + protected OracleDB db = new OracleDB(); //evtl. Methoden von OracleDB static machen und von GSON Handler ; "protected" for testing purposes to showcase Mockito tests + private ArrayList<MapData> coreMaps; + private ArrayList<MapData> communityMaps; + private PlayerStatistics statistics; + private PlayerAccount account; private AppSettings settings; + //protected ArrayList<String> coreMapsListLocal; //for drop-down list -- kommt eigentlich eher in RuntimeInfo + //protected ArrayList<String> communityMapsListLocal; //for drop-down list -- kommt eigentlich eher in RuntimeInfo + protected ArrayList<MapInfo> communityMapsListRemote; //for community map browser @@ -31,10 +34,70 @@ public class Persistence { return persistenceSingleton; } + public ArrayList<MapData> getCoreMaps() { + return coreMaps; + } + + public ArrayList<MapData> getCommunityMaps() { + return communityMaps; + } + + public PlayerStatistics getStatistics() { + return statistics; + } + + public PlayerAccount getAccount() { + return account; + } + + public AppSettings getSettings() { + return settings; + } + + public ArrayList<MapInfo> getCommunityMapsListRemote() { + return communityMapsListRemote; + } + + public void loadPlayerAccount() throws DatabaseException { + try { + gsonHandler.loadAccount(); + log.info("Player account successfully loaded!"); + } + catch(Exception e){ + log.error(e); + throw new DatabaseException("Loading player account data from local storage failed!"); + } + } + + public void loadPlayerStatistics() throws DatabaseException { + try { + if (account.getAccountType() == AccountType.LOCAL) { + statistics = gsonHandler.loadStats(); + } else { + statistics = db.getStatistics(account.getPlayerName()); + } + log.info("Player statistics successfully loaded!"); + } + catch(SQLException e){ + log.error(e); + if(e.getMessage().contains("ORA-17868") | e.getMessage().contains("ORA-01017")){ + throw new DatabaseException("No connection to SQL server!"); + } + else{ + throw new DatabaseException("Unknown Database Error. Retrieving statistics from SQL server failed!"); + } + } + catch(GSONException e){ + log.error(e); + throw new DatabaseException(e.getMessage()); + } + } + public void loadCoreMaps() throws DatabaseException { try { coreMaps = gsonHandler.loadMaps(MapType.COREMAP); - log.info("Core-Maps successfully loaded from file"); + log.info("Core-Maps successfully loaded from file!"); + //createCoreMapsList(); } catch(Exception e){ log.error(e); @@ -45,7 +108,8 @@ public class Persistence { public void loadCommunityMaps() throws DatabaseException { try { communityMaps = gsonHandler.loadMaps(MapType.COMMUNITYMAP); - log.info("Community-Maps successfully loaded from file"); + log.info("Community-Maps successfully loaded from file!"); + //createLocalCommunityMapsList(); } catch(Exception e){ log.error(e); @@ -53,11 +117,23 @@ public class Persistence { } } + public void loadSettings() throws DatabaseException { + try { + settings = gsonHandler.loadSettings(); + log.info("Application settings successfully loaded from file!"); + } + catch(Exception e){ + log.error(e); + throw new DatabaseException("Loading settings from local storage failed!"); + } + } + public void updateCoreMaps() throws DatabaseException { try { coreMaps = db.getCoreMaps(); gsonHandler.saveMaps(coreMaps, MapType.COREMAP); - log.info("Maps successfully updated from SQL-Server"); + //createCoreMapsList(); + log.info("Core-Maps successfully updated from SQL-Server!"); } catch(Exception e){ log.error(e); @@ -79,6 +155,7 @@ public class Persistence { try { communityMaps.add(db.getCommunityMapByID(mapID)); gsonHandler.saveMaps(communityMaps, MapType.COMMUNITYMAP); + //createLocalCommunityMapsList(); log.info("Community Map successfully retrieved from SQL-Server!"); } catch(Exception e){ @@ -86,7 +163,7 @@ public class Persistence { if(e.getMessage().contains("ORA-17868") | e.getMessage().contains("ORA-01017")){ throw new DatabaseException("No connection to SQL server!"); } - else if(e.getMessage().equals("No match on Database")){ + else if(e.getMessage().equals("No match on Database!")){ throw new DatabaseException("No map existing for mapID: " + mapID); } else{ @@ -95,6 +172,39 @@ public class Persistence { } } + public String getGameMap(String mapSelected, boolean choseCoremaps) throws DatabaseException{ + + String mapID = mapSelected.substring(mapSelected.indexOf("(") + 1, mapSelected.length() - 1); + if (choseCoremaps) { + for (int index = 0; index < coreMaps.size(); index++) { + if (coreMaps.get(index).getMapID().equals(mapID)) { + return coreMaps.get(index).getMapID(); + } + } + } else { + for (int index = 0; index < communityMaps.size(); index++) { + if (communityMaps.get(index).getMapID().equals(mapID)) { + return coreMaps.get(index).getMapID(); + } + } + } + throw new DatabaseException("Database error - Map not found!"); + } + + public void savePlayerStatistics() throws DatabaseException{ //on shutdown of game + try { + if (account.getAccountType() == AccountType.LOCAL) { + gsonHandler.saveStats(statistics); + } else if (account.getAccountType() == AccountType.ONLINE) { + db.updatePlayerStats(statistics, account); + } + log.info("Statistics successfully saved!"); + } + catch(Exception e){ + log.error(e); + } + } + public void saveCreatedMapLocally(MapData map) throws DatabaseException { try { for(int i = 0; communityMaps.size() > i; i++){ @@ -104,7 +214,8 @@ public class Persistence { } communityMaps.add(map); gsonHandler.saveMaps(communityMaps, MapType.COMMUNITYMAP); - log.info("Newly created map stored successfully in JSON"); + //createLocalCommunityMapsList(); + log.info("Newly created map stored successfully in JSON!"); } catch(Exception e){ log.error(e); @@ -136,15 +247,18 @@ public class Persistence { } } - public void loadSettings() throws DatabaseException { - try { - settings = gsonHandler.loadSettings(); - log.info("Application settings successfully loaded from file"); + public void updatePlayerStatistics(int kills, int deaths, int gameTime, int blocksDestroyed, boolean gameWon) throws DatabaseException{ //after game round + statistics.addKills(kills); + statistics.addDeaths(deaths); + statistics.addGameTime(gameTime); + statistics.addBlocksDestroyed(blocksDestroyed); + if(gameWon){ + statistics.addGamesWon(); } - catch(Exception e){ - log.error(e); - throw new DatabaseException("Loading settings from local storage failed!"); + else{ + statistics.addGamesLost(); } + log.info("Statistics successfully updated!"); } public void createAccount(String playerName, String password, AccountType type) throws DatabaseException { @@ -163,6 +277,7 @@ public class Persistence { throw new DatabaseException("Corrupted Account-Type. Please restart game."); } gsonHandler.saveAccount(account); + log.info("Player account successfully created!"); } catch(ParserException e){ log.error(e); @@ -186,25 +301,41 @@ public class Persistence { } } - public void loadPlayerAccount() throws DatabaseException { + public void createRemoteCommunityMapsList(){ //for Map-Browser try { - gsonHandler.loadAccount(); + communityMapsListRemote = db.getCommunityMapsList(); + log.info("MapList successfully retrieved from server!"); + //log.info(communityMapsListRemote.get(0).getMapName()); //for testing purposes } catch(Exception e){ log.error(e); - throw new DatabaseException("Loading player account data from local storage failed!"); } } + //kommen beide eigentlich eher in die RuntimeInfo +/* public void createCoreMapsList(){ //for dropdown list in "create" scene + coreMapsListLocal = new ArrayList<String>(); + for(int i = 0; i < coreMaps.size(); i++){ + coreMapsListLocal.add(coreMaps.get(i).getMapName() + " (" + coreMaps.get(i).getMapID() + ")"); + } + } + + public void createLocalCommunityMapsList(){ //for dropdown list in "create" scene + communityMapsListLocal = new ArrayList<String>(); + for (int i = 0; i < communityMaps.size(); i++) { + communityMapsListLocal.add(communityMaps.get(i).getMapName() + " (" + communityMaps.get(i).getMapID() + ")"); + } + }*/ + public void verifyPlayerAccount() throws DatabaseException { try { if (account.getAccountType() == AccountType.NONE) { - throw new DatabaseException("Must create playerAccount first"); + throw new DatabaseException("Must create playerAccount first!"); } else if (account.getAccountType() == AccountType.LOCAL) { Parser.usernameValid(account.getPlayerName()); } else if (account.getAccountType() == AccountType.ONLINE) { Parser.usernameValid(account.getPlayerName()); - Parser.sha1HashValid(account.getAccountPassword()); + Parser.sha1HexHashValid(account.getAccountPassword()); if (!(account.getAccountPassword().equals(db.checkCredentials(account.getPlayerName())))){ throw new DatabaseException("Locally stored password does not match online password. Please reenter credentials!"); } @@ -212,6 +343,7 @@ public class Persistence { else{ throw new DatabaseException("AccountType invalid - accountData corrupted! Please create new Account or login with existing!"); } + log.info("Player account successfully verified!"); } catch(ParserException e){ log.error(e); @@ -222,7 +354,7 @@ public class Persistence { if(e.getMessage().contains("ORA-17868") | e.getMessage().contains("ORA-01017")){ throw new DatabaseException("No connection to SQL server! Do you want to continue without tracking statistics?"); } - else if(e.getMessage().contains("No match on Database")){ + else if(e.getMessage().contains("No match on SQL database!")){ throw new DatabaseException("No entry for player name " + account.getPlayerName() + " on SQL server. Please create account or login with different username!"); } else{ @@ -235,48 +367,83 @@ public class Persistence { } } - public void loadPlayerStatistics() throws DatabaseException { + public void verifyCoreMaps() throws DatabaseException{ try { - if (account.getAccountType() == AccountType.LOCAL) { - statistics = gsonHandler.loadStats(); - } else { - statistics = db.getStatistics(account.getPlayerName()); - } - } - catch(SQLException e){ - log.error(e); - if(e.getMessage().contains("ORA-17868") | e.getMessage().contains("ORA-01017")){ - throw new DatabaseException("No connection to SQL server!"); - } - else{ - throw new DatabaseException("Unknown Database Error. Retrieving statistics from SQL server failed!"); + for (int i = 0; coreMaps.size() > i; i++) { + Parser.mapDataValid(coreMaps.get(i).getMapData()); + Parser.mapNameValid(coreMaps.get(i).getMapName()); + Parser.sha1HexHashValid(coreMaps.get(i).getMapID()); + if(!HashGenerator.hashAndHex(coreMaps.get(i).getMapData()).equals(coreMaps.get(i).getMapID())){ + throw new DatabaseException("mapData Hash does not match mapID!"); + } } + log.info("Core-Maps data is valid!"); } - catch(GSONException e){ + catch(Exception e){ log.error(e); throw new DatabaseException(e.getMessage()); } } - public void updatePlayerStatistics(int kills, int deaths, int gameTime, boolean gameWon){ //after game round - statistics.setKills(statistics.getKills() + kills); - statistics.setDeaths(statistics.getDeaths() + deaths); - statistics.setGameTime(statistics.getGameTime() + gameTime); - if(gameWon){ - statistics.setGamesWon(statistics.getGamesWon() + 1); + public void verifyCommunityMaps() throws DatabaseException{ + try { + for (int i = 0; communityMaps.size() > i; i++) { + Parser.mapDataValid(communityMaps.get(i).getMapData()); + Parser.mapNameValid(communityMaps.get(i).getMapName()); + Parser.sha1HexHashValid(communityMaps.get(i).getMapID()); + if(!HashGenerator.hashAndHex(communityMaps.get(i).getMapData()).equals(communityMaps.get(i).getMapID())){ + throw new DatabaseException("mapData Hash does not match mapID!"); + } + } + log.info("Community-Maps data is valid!"); } - else{ - statistics.setGamesWon(statistics.getGamesLost() + 1); + catch(Exception e){ + log.error(e); + throw new DatabaseException(e.getMessage()); } } - public void savePlayerStatistics(){ //on shutdown of game + public void resetPlayerStatistics() throws DatabaseException{ try { + verifyPlayerAccount(); if (account.getAccountType() == AccountType.LOCAL) { + statistics = new PlayerStatistics(0, 0, 0, 0, 0, 0); gsonHandler.saveStats(statistics); } else if (account.getAccountType() == AccountType.ONLINE) { - db.updatePlayerStats(statistics, account); + db.resetPlayerStats(account); + statistics = new PlayerStatistics(0, 0, 0, 0, 0, 0); } + log.info("Player statistics successfully reset on local storage!"); + } + catch(Exception e){ + log.error(e); + } + } + + public void resetSettings(){ + //implement me (user can click button to reset settings to default values) + } + + public void resetCoreMaps(){ + try { + coreMaps = new ArrayList<MapData>(); + coreMaps.add(new MapData("09a02b54d05b5b7ebc29a4383ca12d3dda846b72", "Arena1", 18, 18, "12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + coreMaps.add(new MapData("0ab15557ab6dc4be60dfe6a9b0288bac3036bd97", "Arena2", 18, 18, "12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + gsonHandler.saveMaps(coreMaps, MapType.COREMAP); + log.info("Core maps successfully reset on local storage!"); + } + catch(Exception e){ + log.error(e); + } + } + + public void resetCommunityMaps(){ + try { + communityMaps = new ArrayList<MapData>(); + communityMaps.add(new MapData("fbf44184867512faecc195ae75ca55d5ab7bad2d", "Arena3", 18, 18, "12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 8 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + communityMaps.add(new MapData("1c23b362fd666c5fb7ed60ca611b17246424e49f", "Arena4", 18, 18, "12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 8 4 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + gsonHandler.saveMaps(communityMaps, MapType.COMMUNITYMAP); + log.info("Community maps successfully reset on local storage!"); } catch(Exception e){ log.error(e); diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PlayerStatistics.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PlayerStatistics.java index 532324238dd5b1b7a19c8de5a0555bc3e2c83fba..41a54e7e0c69f7a86c324929286748643f5c2221 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PlayerStatistics.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PlayerStatistics.java @@ -11,7 +11,7 @@ public class PlayerStatistics { private int kills = 0; private int deaths = 0; private int blocksDestroyed = 0; - private int gameTime = 0; + private int gameTime = 0; //in seconds public PlayerStatistics(int gamesLost, int gamesWon, int kills, int deaths, int blocksDestroyed, int gameTime) { this.gamesLost = gamesLost; @@ -27,48 +27,48 @@ public class PlayerStatistics { return gamesLost; } - public void setGamesLost(int gamesLost) { - this.gamesLost = gamesLost; + protected void addGamesLost() { + gamesLost = gamesLost + 1; } public int getGamesWon() { return gamesWon; } - public void setGamesWon(int gamesWon) { - this.gamesWon = gamesWon; + protected void addGamesWon() { + gamesWon = gamesWon + 1; } public int getKills() { return kills; } - public void setKills(int kills) { - this.kills = kills; + protected void addKills(int kills) { + this.kills = this.kills + kills; } public int getDeaths() { return deaths; } - public void setDeaths(int deaths) { - this.deaths = deaths; + protected void addDeaths(int deaths) { + this.deaths = this.deaths + deaths; } public int getBlocksDestroyed() { return blocksDestroyed; } - public void setBlocksDestroyed(int blocksDestroyed) { - this.blocksDestroyed = blocksDestroyed; + protected void addBlocksDestroyed(int blocksDestroyed) { + this.blocksDestroyed = this.blocksDestroyed + blocksDestroyed; } public int getGameTime() { return gameTime; } - public void setGameTime(int gameTime) { - this.gameTime = gameTime; + protected void addGameTime(int gameTime) { + this.gameTime = this.gameTime + gameTime; } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/RuntimeInfo.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/RuntimeInfo.java index 641449a5164e3aaa72e5aef97324569ec1c7b3c2..12c229b24a282a87678b4831f74e0177b3ab6131 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/RuntimeInfo.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/RuntimeInfo.java @@ -13,9 +13,6 @@ public class RuntimeInfo { private static final Logger log = LogManager.getLogger(RuntimeInfo.class); private static final RuntimeInfo runtimeInfoSingleton = new RuntimeInfo(); private final Persistence persistenceInst = Persistence.getInstance(); - protected ArrayList<String> coreMapsListLocal; //for drop-down list - protected ArrayList<String> communityMapsListLocal; //for drop-down list - protected ArrayList<MapInfo> communityMapsListRemote; //for community map browser protected String mapDataGame; protected boolean offlineMode; //if Account-Type is online but no SQL connection: start game without stats tracking @@ -43,47 +40,17 @@ public class RuntimeInfo { } public void setGameMap(String mapSelected, boolean choseCoremaps){ - String mapID = mapSelected.substring(mapSelected.indexOf("(") + 1, mapSelected.length() - 1); - - if(choseCoremaps) { - for (int index = 0; index < persistenceInst.coreMaps.size(); index++) { - if (persistenceInst.coreMaps.get(index).getMapID().equals(mapID)) { - mapDataGame = persistenceInst.coreMaps.get(index).getMapID(); - } - } - } - else { - for (int index = 0; index < persistenceInst.communityMaps.size(); index++) { - if (persistenceInst.communityMaps.get(index).getMapID().equals(mapID)) { - mapDataGame = persistenceInst.coreMaps.get(index).getMapID(); - } - } - } - } - - public void createCoreMapsList(){ //for dropdown list in "create" scene - coreMapsListLocal = new ArrayList<String>(); - for(int i = 0; i < persistenceInst.coreMaps.size(); i++){ - coreMapsListLocal.add(persistenceInst.coreMaps.get(i).getMapName() + " (" + persistenceInst.coreMaps.get(i).getMapID() + ")"); - } - } - - public void createLocalCommunityMapsList(){ //for dropdown list in "create" scene - communityMapsListLocal = new ArrayList<String>(); - for (int i = 0; i < persistenceInst.communityMaps.size(); i++) { - communityMapsListLocal.add(persistenceInst.communityMaps.get(i).getMapName() + " (" + persistenceInst.communityMaps.get(i).getMapID() + ")"); - } - } - - public void createRemoteCommunityMapsList(){ //for Map-Browser try { - communityMapsListRemote = persistenceInst.db.getCommunityMapsList(); - log.info("MapList successfully retrieved from server!"); - //log.info(communityMapsListRemote.get(0).getMapName()); //for testing purposes + mapDataGame = persistenceInst.getGameMap(mapSelected, choseCoremaps); } catch(Exception e){ log.error(e); } } + + public int gameTimeInHours(){ + return persistenceInst.getStatistics().getGameTime() / 3600; + } + } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/Parser.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/Parser.java index 4ccec6fc0d9eb8956792cdcc5290cbc1455dae10..a98f5bc2a3e7a345b72ba6633b7e328733e02212 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/Parser.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/Parser.java @@ -1,6 +1,7 @@ package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Utilities; import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.ParserException; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.PlayerStatistics; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -17,12 +18,14 @@ public class Parser { */ public static void usernameValid(String username) throws ParserException { + int minUsernameLength = 4; + int maxUsernameLength = 40; - if(username.length() < 4){ - throw new ParserException("Username too short! Min length is 4 characters."); + if(username.length() < minUsernameLength){ + throw new ParserException("Username too short! Min length is " + minUsernameLength + " characters."); } - if(username.length() > 40){ - throw new ParserException("Username too long! Max length is 40 characters."); + if(username.length() > maxUsernameLength){ + throw new ParserException("Username too long! Max length is " + maxUsernameLength + " characters."); } Pattern pat = Pattern.compile("[^a-z0-9_-]", Pattern.CASE_INSENSITIVE); @@ -34,12 +37,14 @@ public class Parser { } public static void passwordValid(String password) throws ParserException { + int minPasswordLength = 4; + int maxPasswordLength = 40; - if(password.length() < 4){ - throw new ParserException("Password too short! Min length is 4 characters."); + if(password.length() < minPasswordLength){ + throw new ParserException("Password too short! Min length is " + minPasswordLength + " characters."); } - if(password.length() > 40){ - throw new ParserException("Password too long! Max length is 40 characters."); + if(password.length() > maxPasswordLength){ + throw new ParserException("Password too long! Max length is " + maxPasswordLength + " characters."); } Pattern pat = Pattern.compile("[^a-z0-9_-]", Pattern.CASE_INSENSITIVE); @@ -51,12 +56,14 @@ public class Parser { } public static void mapNameValid(String mapName) throws ParserException { + int minMapNameLength = 4; + int maxMapNameLength = 30; - if(mapName.length() < 4){ - throw new ParserException("Map-Name too short! Min length is 4 characters."); + if(mapName.length() < minMapNameLength){ + throw new ParserException("Map-Name too short! Min length is " + minMapNameLength + " characters."); } - if(mapName.length() > 30){ - throw new ParserException("Map-Name too long! Max length is 30 characters."); + if(mapName.length() > maxMapNameLength){ + throw new ParserException("Map-Name too long! Max length is " + maxMapNameLength + " characters."); } Pattern pat = Pattern.compile("[^a-z0-9_-]", Pattern.CASE_INSENSITIVE); @@ -67,10 +74,11 @@ public class Parser { } } - public static void sha1HashValid(String mapID) throws ParserException { + public static void sha1HexHashValid(String mapID) throws ParserException { + int hashLength = 40; - if(!(mapID.length() == 40)){ - throw new ParserException("Map-ID length not correct. Must have length of 40 characters!"); + if(mapID.length() != hashLength){ + throw new ParserException("Map-ID length not correct. Must have length of " + hashLength + " characters!"); } Pattern pat = Pattern.compile("[^a-f0-9]"); //maybe make case-insensitive -> letters can be uppercase and still be valid hex number @@ -83,111 +91,262 @@ public class Parser { public static void ipAddressValid(String address) throws ParserException { + int addressMinLength = 7; + int addressMaxLength = 15; + int addressLength = address.length(); + int octetMinDecValue = 0; + int octetMaxDecValue = 255; + if(address.equals("localhost")){ return; } - if(address.length() > 15){ - throw new ParserException("IP-Address too long. Must have length of 15 characters including octet dividers (.) !"); + if(addressLength > addressMaxLength){ + throw new ParserException("IP-Address too long. Must have maximum length of " + addressMaxLength + " characters including octet dividers (.) !"); } - if(address.length() < 7){ - throw new ParserException("IP-Address too short. Must have length of 7 characters including octet dividers (.) !"); + if(addressLength < addressMinLength){ + throw new ParserException("IP-Address too short. Must have minimum length of " + addressMinLength + " characters including octet dividers (.) !"); } - if(address.charAt(0) == '.' | address.charAt(address.length()-1) == '.'){ + if(address.charAt(0) == '.' | address.charAt(addressLength - 1) == '.'){ throw new ParserException("IP-Address must not start nor end with octet dividers (.) !"); } int counter = 0; - for(int i = 0; address.length() > i ; i++){ + for(int i = 0; addressLength > i ; i++){ if(address.charAt(i) == '.'){ counter++; } } - if(!(counter == 3)){ + if(counter != 3){ throw new ParserException("IP-Address must contain exactly 3 octet dividers (.) !"); } - Pattern pat = Pattern.compile("[^0-9]"); - for(int i = 0; address.length() > i ; i++){ - if(!(address.charAt(i) == '.')){ - Matcher mat = pat.matcher(address.substring(i, i+1)); - boolean result = mat.find(); - if(result){ - throw new ParserException("IP address does not consist out of numbers 0-9 and separators (.))!"); - } + for(int i = 0; addressLength > i ; i++){ + if(address.charAt(i) == '.' && address.charAt(i + 1) == '.'){ + throw new ParserException("IP-Address must not contain two or more consecutive dividers (.) without number in between!"); + } + } + + Pattern pat = Pattern.compile("[^0-9.]"); + for(int i = 0; addressLength > i ; i++){ + Matcher mat = pat.matcher(address.substring(i, i+1)); + boolean result = mat.find(); + if(result){ + throw new ParserException("IP address must consist out of numbers 0-9 and separators (.) !"); } } counter = 0; - int[] positions = new int[5]; + int[] positions = new int[4]; positions[0] = 0; - positions[4] = address.length(); - for(int i = 0; address.length() > i ; i++){ + for(int i = 0; addressLength > i ; i++){ if(address.charAt(i) == '.'){ counter++; - positions[counter] = i; + positions[counter] = i + 1; } } - for(int i = 0; 4 > i; i++){ - if(Integer.parseInt(address.substring(positions[i], positions[i+1])) > 255){ - throw new ParserException("Octets of IP-address must not exceed 255!"); + for(int i = 0; positions.length > i; i++){ + if(positions.length - 1 > i) { + if (Integer.parseInt(address.substring(positions[i], positions[i + 1] - 1)) > octetMaxDecValue) { + throw new ParserException("Octets of IP-address must not exceed 255!"); + } } - if(i < 3) { - positions[i + 1] = positions[i + 1] + 1; + else{ + if (Integer.parseInt(address.substring(positions[i], addressLength)) > octetMaxDecValue) { + throw new ParserException("Octets of IP-address must not exceed 255!"); + } } } } public static void mapDataValid(String mapData) throws ParserException { - if(!(mapData.length() == 647)){ - throw new ParserException("Map-Data corrupted - must have length of 647 chars including spaces!"); + //values could be handed to method (Instance of MapData Class) + int actualMapDataLength = mapData.length(); + int mapWidth = 18; //Tiles + int mapHeight = 18; //Tiles + int spacesAmount = (mapHeight * mapWidth) - 1; //space used as separator + int totalTilesAmount = mapHeight * mapWidth; + int borderTilesAmount = (2 * mapWidth) + (2 * (mapHeight - 2)); + int spawnTilesAmount = 4; + int fieldTilesAmount = totalTilesAmount - borderTilesAmount - spawnTilesAmount; + int maxTileNumberDigits = 2; //Tile-Numbers are max 2 digits: 10 to 29 + int minTileNumberDigits = 1; //Tile-Numbers are min 1 digit: 0 to 9 + int minTileNumber = 0; + int maxTileNumber = 29; + int walkableTileMinNumber = 0; + int walkableTileMaxNumber = 9; + int indestructibleTileMinNumber = 10; + int indestructibleTileMaxNumber = 19; + int destructibleTileMinNumber = 20; + int destructibleTileMaxNumber = 29; + int maxMapDataLength = spacesAmount + borderTilesAmount * Integer.toString(indestructibleTileMaxNumber).length() + spawnTilesAmount * Integer.toString(walkableTileMaxNumber).length() + fieldTilesAmount * Integer.toString(destructibleTileMaxNumber).length(); //"Integer.toString(destructibleTileMaxNumber).length()" results in number of digits of destructibleTileMaxNumber + int minMapDataLength = spacesAmount + borderTilesAmount * Integer.toString(indestructibleTileMinNumber).length() + spawnTilesAmount * Integer.toString(walkableTileMinNumber).length() + fieldTilesAmount * Integer.toString(walkableTileMinNumber).length(); + + if(actualMapDataLength > maxMapDataLength){ + throw new ParserException("Map-Data corrupted - mapData String must not exceed length of " + maxMapDataLength + " chars including spaces for " + mapWidth + "x" + mapHeight + " Tiles map!"); } - for(int i = 1; i < 647; i = i + 2){ - if(!(mapData.charAt(i) == ' ')){ - throw new ParserException("Map-Data corrupted - must use space every other character!"); + if(actualMapDataLength < minMapDataLength){ + throw new ParserException("Map-Data corrupted - minimum length of mapData String must be " + minMapDataLength + " chars including spaces for " + mapWidth + "x" + mapHeight + " Tiles map!"); + } + + if(mapData.charAt(0) == ' ' | mapData.charAt(actualMapDataLength - 1) == ' '){ + throw new ParserException("Map-Data corrupted - must not start nor end with space!"); + } + + for(int i = 0; actualMapDataLength > i ; i++){ + if(mapData.charAt(i) == ' ' && mapData.charAt(i + 1) == ' '){ + throw new ParserException("Map-Data corrupted - must not contain two or more consecutive spaces without number in between!"); + } + } + + int counter = 0; + for(int i = 0; i < actualMapDataLength; i++){ + if((mapData.charAt(i) == ' ')){ + counter++; + } + } + if(counter != spacesAmount){ + throw new ParserException("Map-Data corrupted - number of spaces must be " + spacesAmount + "!"); + } + + Pattern pat = Pattern.compile("[^0-9 ]"); + for(int i = 0; actualMapDataLength > i ; i++){ + Matcher mat = pat.matcher(mapData.substring(i, i+1)); + boolean result = mat.find(); + if(result){ + throw new ParserException("Map-Data corrupted - must consist out of numbers 0-9 and space as separator!"); + } + } + + counter = 0; + int[] positions = new int[totalTilesAmount]; + positions[0] = 0; + for(int i = 0; actualMapDataLength > i ; i++){ + if(mapData.charAt(i) == ' '){ + counter++; + positions[counter] = i + 1; + } + } + for(int i = 0; positions.length > i; i++){ + if(positions.length - 1 > i) { + if (Integer.parseInt(mapData.substring(positions[i], positions[i + 1] - 1)) > maxTileNumber | Integer.parseInt(mapData.substring(positions[i], positions[i + 1] - 1)) < minTileNumber) { + throw new ParserException("Map-Data corrupted - Tile number must be between " + minTileNumber + " and " + maxTileNumber + "!"); + } + } + else{ + if (Integer.parseInt(mapData.substring(positions[i], actualMapDataLength)) > maxTileNumber | Integer.parseInt(mapData.substring(positions[i], actualMapDataLength)) < minTileNumber) { + throw new ParserException("Map-Data corrupted - Tile number must be between " + minTileNumber + " and " + maxTileNumber + "!"); + } } } - for(int i = 0; i < 647; i = i + 2){ - if((Integer.parseInt(mapData.substring(i, i+1)) > 4) | (Integer.parseInt(mapData.substring(i, i+1)) <= 0)){ - throw new ParserException("Map-Data corrupted - Tile number must be between 1 and 4!"); + //Alternative code for checking if tile number is between minTileNumber and maxTileNumber: + + /* + String combinedNumbers = ""; + for(int i = 0; i < actualMapDataLength - 1; i++){ + if(mapData.charAt(i+1) == ' '){ + combinedNumbers = combinedNumbers + mapData.charAt(i); + if((Integer.parseInt(combinedNumbers) > maxTileNumber) | (Integer.parseInt(combinedNumbers) < minTileNumber)){ + throw new ParserException("Map-Data corrupted - Tile number must be between " + minTileNumber + " and " + maxTileNumber + "!"); + } + combinedNumbers = ""; + if(i < actualMapDataLength - 1){ + i++; + } + } + else if(i >= actualMapDataLength - 2){ + combinedNumbers = combinedNumbers + mapData.charAt(i) + mapData.charAt(i+1); + if((Integer.parseInt(combinedNumbers) > maxTileNumber) | (Integer.parseInt(combinedNumbers) < minTileNumber)){ + throw new ParserException("Map-Data corrupted - Tile number must be between " + minTileNumber + " and " + maxTileNumber + "!"); + } + } + else{ + combinedNumbers = combinedNumbers + mapData.charAt(i); } } + */ - for(int i = 0; i < 18; i = i + 2){ - if(!(Integer.parseInt(mapData.substring(i, i+1)) == 3)){ + //corner Tiles included + for(int i = 0; i < mapWidth; i++){ + if(Integer.parseInt(mapData.substring(positions[i], positions[i+1] - 1)) > indestructibleTileMaxNumber | Integer.parseInt(mapData.substring(positions[i], positions[i+1] - 1)) < indestructibleTileMinNumber){ throw new ParserException("Map-Data corrupted - Top-Line must be border tiles!"); } } - for(int i = 628; i < 647; i = i + 2){ - if(!(Integer.parseInt(mapData.substring(i, i+1)) == 3)){ - throw new ParserException("Map-Data corrupted - Bottom-Line must be border tiles!"); + //corner Tiles included + for(int i = positions.length - mapWidth; i < positions.length; i++){ + if(positions.length - 1 > i) { + if (Integer.parseInt(mapData.substring(positions[i], positions[i + 1] - 1)) > indestructibleTileMaxNumber | Integer.parseInt(mapData.substring(positions[i], positions[i + 1] - 1)) < indestructibleTileMinNumber) { + throw new ParserException("Map-Data corrupted - Bottom-Line must be border tiles!"); + } + } + else{ + if (Integer.parseInt(mapData.substring(positions[i], actualMapDataLength)) > indestructibleTileMaxNumber | Integer.parseInt(mapData.substring(positions[i], actualMapDataLength)) < indestructibleTileMinNumber) { + throw new ParserException("Map-Data corrupted - Bottom-Line must be border tiles!"); + } } } - for(int i = 0; i < 647; i = i + 2){ - if(i % 36 == 0 && !(Integer.parseInt(mapData.substring(i, i+1)) == 3)){ + //corner Tiles excluded + for(int i = mapWidth; i < positions.length - mapWidth; i = i + mapWidth){ + if(i % mapWidth == 0 && Integer.parseInt(mapData.substring(positions[i], positions[i + 1] - 1)) > indestructibleTileMaxNumber | Integer.parseInt(mapData.substring(positions[i], positions[i + 1] - 1)) < indestructibleTileMinNumber){ throw new ParserException("Map-Data corrupted - Left Edge must be border tiles!"); } } - for(int i = 2; i < 647; i = i + 2){ - if(i % 36 == 0 && !(Integer.parseInt(mapData.substring(i-2, i-1)) == 3)){ + //corner Tiles excluded + for(int i = mapWidth - 1; i < positions.length - mapWidth; i = i + mapWidth){ + if((i + 1) % mapWidth == 0 && Integer.parseInt(mapData.substring(positions[i], positions[i + 1] - 1)) > indestructibleTileMaxNumber | Integer.parseInt(mapData.substring(positions[i], positions[i + 1] - 1)) < indestructibleTileMinNumber){ throw new ParserException("Map-Data corrupted - Right Edge must be border tiles!"); } } - if(!(Integer.parseInt(mapData.substring(38, 39)) == 1) | !(Integer.parseInt(mapData.substring(68, 69)) == 1)){ - throw new ParserException("Map-Data corrupted - Player spawn must use walkable tile!"); + if(Integer.parseInt(mapData.substring(positions[mapWidth + 1], positions[mapWidth + 2] - 1)) < walkableTileMinNumber | Integer.parseInt(mapData.substring(positions[mapWidth + 1], positions[mapWidth + 2] - 1)) > walkableTileMaxNumber){ + throw new ParserException("Map-Data corrupted - Player spawn top left must use walkable tile!"); + } + + if(Integer.parseInt(mapData.substring(positions[(mapWidth*2) - 2], positions[(mapWidth*2) - 1] - 1)) < walkableTileMinNumber | Integer.parseInt(mapData.substring(positions[(mapWidth*2) - 2], positions[(mapWidth*2) - 1] - 1)) > walkableTileMaxNumber){ + throw new ParserException("Map-Data corrupted - Player spawn top right must use walkable tile!"); + } + + if(Integer.parseInt(mapData.substring(positions[positions.length - (mapWidth*2) + 1], positions[positions.length - (mapWidth*2) + 2] - 1)) < walkableTileMinNumber | Integer.parseInt(mapData.substring(positions[positions.length - (mapWidth*2) + 1], positions[positions.length - (mapWidth*2) + 2] - 1)) > walkableTileMaxNumber) { + throw new ParserException("Map-Data corrupted - Player spawn bottom left must use walkable tile!"); + } + + if(Integer.parseInt(mapData.substring(positions[positions.length - mapWidth - 2], positions[positions.length - mapWidth - 1] - 1)) < walkableTileMinNumber | Integer.parseInt(mapData.substring(positions[positions.length - mapWidth - 2], positions[positions.length - mapWidth - 1] - 1)) > walkableTileMaxNumber){ + throw new ParserException("Map-Data corrupted - Player spawn bottom right must use walkable tile!"); + } + } + + public static void playerStatsValid(PlayerStatistics stats) throws ParserException{ + + if(stats.getGamesLost() < 0){ + throw new ParserException("Player statistics data corrupted - Minimum value for lost games is 0!"); + } + + if(stats.getGamesWon() < 0){ + throw new ParserException("Player statistics data corrupted - Minimum value for won games is 0!"); + } + + if(stats.getKills() < 0){ + throw new ParserException("Player statistics data corrupted - Minimum value for kills is 0!"); + } + + if(stats.getDeaths() < 0){ + throw new ParserException("Player statistics data corrupted - Minimum value for deaths is 0!"); + } + + if(stats.getBlocksDestroyed() < 0){ + throw new ParserException("Player statistics data corrupted - Minimum value for destroyed blocks is 0!"); } - if(!(Integer.parseInt(mapData.substring(578, 579)) == 1) | !(Integer.parseInt(mapData.substring(608, 609)) == 1)){ - throw new ParserException("Map-Data corrupted - Player spawn must use walkable tile!"); + if(stats.getGameTime() < 0){ + throw new ParserException("Player statistics data corrupted - Minimum value for ingame time is 0 seconds!"); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_AzureDB.sql b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_AzureDB.sql index 64e90f19dee42b333ff193b2041cbe3e29723604..3ee29cb25e3cc97a8a8f53e352dd1f90ff5a5707 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_AzureDB.sql +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_AzureDB.sql @@ -11,14 +11,14 @@ CREATE TABLE coremaps( map_name VARCHAR(30) NOT NULL, map_width INTEGER NOT NULL, map_height INTEGER NOT NULL, - map_data VARCHAR(1682) NOT NULL UNIQUE); --allows for map size up to 29x29 + map_data VARCHAR(1082) NOT NULL UNIQUE); --allows for map size up to 19x19 (when using double digit numbers for tiles) CREATE TABLE communitymaps( map_id CHAR(40) NOT NULL UNIQUE, --SHA1 hash is 40 chars length in hex map_name VARCHAR(30) NOT NULL, map_width INTEGER NOT NULL, map_height INTEGER NOT NULL, - map_data VARCHAR(1682) NOT NULL UNIQUE, --allows for map size up to 29x29 + map_data VARCHAR(1082) NOT NULL UNIQUE, --allows for map size up to 19x19 (when using double digit numbers for tiles) map_downloads INTEGER NOT NULL); CREATE TABLE players( @@ -33,25 +33,33 @@ CREATE TABLE players( INSERT INTO coremaps (map_id, map_name, map_width, map_height, map_data) -VALUES ('72e1c81687463ab159b4cb8d935e347a26d7fe40', +VALUES ('09a02b54d05b5b7ebc29a4383ca12d3dda846b72', 'Arena1', 18, 18, - '3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3'); + '12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12'); INSERT INTO coremaps (map_id, map_name, map_width, map_height, map_data) -VALUES ('f7e1fc56cefbacacb9ba403220476f3ac258de06', +VALUES ('0ab15557ab6dc4be60dfe6a9b0288bac3036bd97', 'Arena2', 18, 18, - '3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 1 1 1 1 1 1 1 3 1 1 3 3 1 1 1 1 1 3 1 3 3 3 1 1 1 3 1 1 3 3 1 1 1 1 1 3 1 1 1 1 1 1 1 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3'); + '12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12'); INSERT INTO communitymaps (map_id, map_name, map_width, map_height, map_data, map_downloads) -VALUES ('c8ce8e85e4a9b99e4fa956e2486e55df73b2cf08', - 'Arena1', +VALUES ('fbf44184867512faecc195ae75ca55d5ab7bad2d', + 'Arena3', + 18, + 18, + '12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 8 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12', + 0); + +INSERT INTO communitymaps (map_id, map_name, map_width, map_height, map_data, map_downloads) +VALUES ('1c23b362fd666c5fb7ed60ca611b17246424e49f', + 'Arena4', 18, 18, - '3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 3 3 3 3 1 1 1 1 1 1 1 3 3 1 1 1 1 1 3 3 3 3 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3', + '12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 8 4 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12', 0); INSERT INTO players (player_name, player_pw, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time) diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_Oracle.sql b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_Oracle.sql index af8c0ca3e9ee71ca652b85f47c5ad018fa79725e..2e1959bf86f5d739a14878f45ae62ca8b2d04344 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_Oracle.sql +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Scripts/DDL_Script_Oracle.sql @@ -17,14 +17,14 @@ CREATE TABLE battlearenadata.coremaps( map_name VARCHAR(30) NOT NULL, map_width INTEGER NOT NULL, map_height INTEGER NOT NULL, - map_data VARCHAR(1682) NOT NULL UNIQUE); --allows for map size up to 29x29 + map_data VARCHAR(1082) NOT NULL UNIQUE); --allows for map size up to 19x19 (when using double digit numbers for tiles) CREATE TABLE battlearenadata.communitymaps( map_id CHAR(40) NOT NULL UNIQUE, --SHA1 hash is 40 chars length in hex map_name VARCHAR(30) NOT NULL, map_width INTEGER NOT NULL, map_height INTEGER NOT NULL, - map_data VARCHAR(1682) NOT NULL UNIQUE, --allows for map size up to 29x29 + map_data VARCHAR(1082) NOT NULL UNIQUE, --allows for map size up to 19x19 (when using double digit numbers for tiles) map_downloads INTEGER NOT NULL); CREATE TABLE battlearenadata.players( @@ -42,25 +42,33 @@ ALTER USER battlearenadata QUOTA 500M ON communitymaps; ALTER USER battlearenadata QUOTA 500M ON players; INSERT INTO battlearenadata.coremaps (map_id, map_name, map_width, map_height, map_data) -VALUES ('72e1c81687463ab159b4cb8d935e347a26d7fe40', +VALUES ('09a02b54d05b5b7ebc29a4383ca12d3dda846b72', 'Arena1', 18, 18, - '3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3'); + '12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12'); INSERT INTO battlearenadata.coremaps (map_id, map_name, map_width, map_height, map_data) -VALUES ('f7e1fc56cefbacacb9ba403220476f3ac258de06', +VALUES ('0ab15557ab6dc4be60dfe6a9b0288bac3036bd97', 'Arena2', 18, 18, - '3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 1 1 1 1 1 1 1 3 1 1 3 3 1 1 1 1 1 3 1 3 3 3 1 1 1 3 1 1 3 3 1 1 1 1 1 3 1 1 1 1 1 1 1 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3'); + '12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12'); INSERT INTO battlearenadata.communitymaps (map_id, map_name, map_width, map_height, map_data, map_downloads) -VALUES ('c8ce8e85e4a9b99e4fa956e2486e55df73b2cf08', - 'Arena1', +VALUES ('fbf44184867512faecc195ae75ca55d5ab7bad2d', + 'Arena3', + 18, + 18, + '12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 8 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12', + 0); + +INSERT INTO battlearenadata.communitymaps (map_id, map_name, map_width, map_height, map_data, map_downloads) +VALUES ('1c23b362fd666c5fb7ed60ca611b17246424e49f', + 'Arena4', 18, 18, - '3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 3 3 3 3 1 1 1 1 1 1 1 3 3 1 1 1 1 1 3 3 3 3 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3', + '12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 8 4 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12', 0); INSERT INTO battlearenadata.players (player_name, player_pw, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time) diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml index 6fb857169bf3b818c95f9a1a9ada8ad3b39b0d58..9a77de28c30d210dadfd85f28a594d9e5621d9c8 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -16,6 +16,7 @@ </Logger> <Root level="info"> <AppenderRef ref="STDOUT"/> + <AppenderRef ref="A1"/> </Root> </Loggers> </Configuration> \ No newline at end of file diff --git a/src/main/resources/maps/communityMaps.json b/src/main/resources/maps/communityMaps.json index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..9c99ec44154627bf856e8eff30053efa9d624f9f 100644 --- a/src/main/resources/maps/communityMaps.json +++ b/src/main/resources/maps/communityMaps.json @@ -0,0 +1,16 @@ +[ + { + "mapID": "fbf44184867512faecc195ae75ca55d5ab7bad2d", + "mapName": "Arena3", + "mapWidth": 18, + "mapHeight": 18, + "mapData": "12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 8 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12" + }, + { + "mapID": "1c23b362fd666c5fb7ed60ca611b17246424e49f", + "mapName": "Arena4", + "mapWidth": 18, + "mapHeight": 18, + "mapData": "12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 8 4 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12" + } +] \ No newline at end of file diff --git a/src/main/resources/maps/coreMaps.json b/src/main/resources/maps/coreMaps.json index 84828ae2b407d2ff4b089fdb479656a518e3a688..ba63b040f5afc06edf39a660e0cd815b3bb7963b 100644 --- a/src/main/resources/maps/coreMaps.json +++ b/src/main/resources/maps/coreMaps.json @@ -1,16 +1,16 @@ [ { - "mapID": "a593cafd1d061f0f463a2d2051bf4718aaaf5c48", + "mapID": "09a02b54d05b5b7ebc29a4383ca12d3dda846b72", "mapName": "Arena1", "mapWidth": 18, "mapHeight": 18, - "mapData": "4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 2 1 1 1 1 1 2 2 2 1 1 1 1 2 1 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 1 2 3 4 1 1 1 2 2 4 1 3 3 3 1 1 1 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 2 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 1 3 4 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 1 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 1 1 4 3 3 1 3 3 3 3 3 1 2 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3" + "mapData": "12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12" }, { - "mapID": "e559d8fbb53b333f5839cb3c6c0c515395afe344", + "mapID": "0ab15557ab6dc4be60dfe6a9b0288bac3036bd97", "mapName": "Arena2", "mapWidth": 18, "mapHeight": 18, - "mapData": "4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 2 4 2 1 1 1 1 1 2 2 2 1 1 1 1 2 3 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 1 2 3 4 1 1 1 2 2 4 1 3 3 3 1 1 1 3 2 2 3 4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 2 1 3 4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 1 3 4 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 1 1 3 4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 1 1 4 3 3 1 3 3 3 3 3 1 2 3 4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3" + "mapData": "12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12" } ] \ No newline at end of file diff --git a/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PersistenceTest.java b/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PersistenceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..79b599da6c201b66ffe5d1c21293f44b9ee244e4 --- /dev/null +++ b/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PersistenceTest.java @@ -0,0 +1,48 @@ +package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes; + +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.DatabaseException; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.SQLException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class PersistenceTest { + + private static final Logger log = LogManager.getLogger(PersistenceTest.class); + Persistence persistenceSingleton; + + OracleDB inst = new OracleDB(); + + @Before + public void setup() throws SQLException { + persistenceSingleton = Persistence.getInstance(); + persistenceSingleton.db = inst; + ArrayList<MapData> maps = new ArrayList<MapData>(); + maps.add(new MapData("09a02b54d05b5b7ebc29a4383ca12d3dda846b72", "Arena1", 18, 18, "12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + maps.add(new MapData("0ab15557ab6dc4be60dfe6a9b0288bac3036bd97", "Arena2", 18, 18, "12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + when(inst.getCoreMaps()).thenReturn(maps); + } + + @Test + void updateCoreMaps() throws RuntimeException, DatabaseException { + persistenceSingleton.updateCoreMaps(); + assertEquals("09a02b54d05b5b7ebc29a4383ca12d3dda846b72", persistenceSingleton.getCoreMaps().get(0).getMapID()); + assertEquals("0ab15557ab6dc4be60dfe6a9b0288bac3036bd97", persistenceSingleton.getCoreMaps().get(1).getMapID()); + } + + @Test + void loadPlayerStatistics() { + } + + + + +} \ No newline at end of file diff --git a/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/ParserTest.java b/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/ParserTest.java index 62f0b705af1053613a39adfe2a296fc69099dd98..0ffdfca98e607df423dd54c2abcc281146e293b4 100644 --- a/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/ParserTest.java +++ b/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/ParserTest.java @@ -1,6 +1,7 @@ package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Utilities; import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.ParserException; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.PlayerStatistics; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -8,21 +9,20 @@ import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; class ParserTest { - @ParameterizedTest @ValueSource(strings = {"Player1", "Player2", - "HelloWorld"}) + "0123456789012345678901234567890123456789"}) void usernameValid(String test){ assertDoesNotThrow(() -> Parser.usernameValid(test)); } @Test - void usernameValidException() { - ParserException testMe = assertThrows(ParserException.class, () -> Parser.usernameValid("hi")); + void usernameInvalid() { + ParserException testMe = assertThrows(ParserException.class, () -> Parser.usernameValid("lol")); assertTrue(testMe.getMessage().contains("Username too short! Min length is 4 characters.")); - testMe = assertThrows(ParserException.class, () -> Parser.usernameValid("jiaodjidsfjoisjdiofjsiofjidosfijsodfjisdfjoi")); + testMe = assertThrows(ParserException.class, () -> Parser.usernameValid("01234567890123456789012345678901234567890")); assertTrue(testMe.getMessage().contains("Username too long! Max length is 40 characters.")); testMe = assertThrows(ParserException.class, () -> Parser.usernameValid("SELECT * FROM")); @@ -32,17 +32,17 @@ class ParserTest { @ParameterizedTest @ValueSource(strings = {"pw123456", "Passwort", - "lololol"}) + "0123456789012345678901234567890123456789"}) void passwordValid(String test){ assertDoesNotThrow(() -> Parser.passwordValid(test)); } @Test - void passwordValidException() { - ParserException testMe = assertThrows(ParserException.class, () -> Parser.passwordValid("hi")); + void passwordInvalid() { + ParserException testMe = assertThrows(ParserException.class, () -> Parser.passwordValid("lol")); assertTrue(testMe.getMessage().contains("Password too short! Min length is 4 characters.")); - testMe = assertThrows(ParserException.class, () -> Parser.passwordValid("jiaodjidsfjoisjdiofjsiofjidosfijsodfjisdfjoi")); + testMe = assertThrows(ParserException.class, () -> Parser.passwordValid("01234567890123456789012345678901234567890")); assertTrue(testMe.getMessage().contains("Password too long! Max length is 40 characters.")); testMe = assertThrows(ParserException.class, () -> Parser.passwordValid("SELECT * FROM")); @@ -50,7 +50,7 @@ class ParserTest { } @ParameterizedTest - @ValueSource(strings = {"Map_1", + @ValueSource(strings = {"012345678901234567890123456789", "de_dust", "Ziba-Tower"}) void mapNameValid(String test){ @@ -58,11 +58,11 @@ class ParserTest { } @Test - void mapNameValidException() { - ParserException testMe = assertThrows(ParserException.class, () -> Parser.mapNameValid("hi")); + void mapNameInvalid() { + ParserException testMe = assertThrows(ParserException.class, () -> Parser.mapNameValid("lol")); assertTrue(testMe.getMessage().contains("Map-Name too short! Min length is 4 characters.")); - testMe = assertThrows(ParserException.class, () -> Parser.mapNameValid("jiaodjidsfjoisjdiofjsiofjidosfijsodfjisdfjoi")); + testMe = assertThrows(ParserException.class, () -> Parser.mapNameValid("0123456789012345678901234567890")); assertTrue(testMe.getMessage().contains("Map-Name too long! Max length is 30 characters.")); testMe = assertThrows(ParserException.class, () -> Parser.mapNameValid("SELECT * FROM")); @@ -74,16 +74,19 @@ class ParserTest { "e559d8fbb53b333f5839cb3c6c0c515395afe344", "a593cafd1d061f0f463a2d2051bf4718aaaf5c48"}) void mapIDValid(String test){ - assertDoesNotThrow(() -> Parser.sha1HashValid(test)); + assertDoesNotThrow(() -> Parser.sha1HexHashValid(test)); } @Test - void mapIDValidException() { + void mapIDInvalid() { + + ParserException testMe = assertThrows(ParserException.class, () -> Parser.sha1HexHashValid("01234567890123456789012345678901234567890")); + assertTrue(testMe.getMessage().contains("Map-ID length not correct. Must have length of 40 characters!")); - ParserException testMe = assertThrows(ParserException.class, () -> Parser.sha1HashValid("jiaodjidsfjoisjdiofjsiofjidosfijsodfjisdfjoi")); + testMe = assertThrows(ParserException.class, () -> Parser.sha1HexHashValid("012345678901234567890123456789012345678")); assertTrue(testMe.getMessage().contains("Map-ID length not correct. Must have length of 40 characters!")); - testMe = assertThrows(ParserException.class, () -> Parser.sha1HashValid("XYZ3cafd1d061f0f463a2d2051bf4718aaaf5c48")); + testMe = assertThrows(ParserException.class, () -> Parser.sha1HexHashValid("XYZ3cafd1d061f0f463a2d2051bf4718aaaf5c48")); assertTrue(testMe.getMessage().contains("Forbidden characters used! Map ID only consists out of letters a-f and/or numbers 0-9!")); } @@ -97,70 +100,155 @@ class ParserTest { } @Test - void ipAddressValidException() { + void ipAddressInvalid() { - ParserException testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("255.255.255.255.255.255")); - assertTrue(testMe.getMessage().contains("IP-Address too long. Must have length of 15 characters including octet dividers (.) !")); + ParserException testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("255.255.255.2555")); + assertTrue(testMe.getMessage().contains("IP-Address too long. Must have maximum length of 15 characters including octet dividers (.) !")); - testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("0.0.0")); - assertTrue(testMe.getMessage().contains("IP-Address too short. Must have length of 7 characters including octet dividers (.) !")); + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("0.0.12")); + assertTrue(testMe.getMessage().contains("IP-Address too short. Must have minimum length of 7 characters including octet dividers (.) !")); + + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid(".25.255.25")); + assertTrue(testMe.getMessage().contains("IP-Address must not start nor end with octet dividers (.) !")); - testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid(".25.255.25.")); + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("25.255.25.")); assertTrue(testMe.getMessage().contains("IP-Address must not start nor end with octet dividers (.) !")); testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("12.3.0.12.12")); assertTrue(testMe.getMessage().contains("IP-Address must contain exactly 3 octet dividers (.) !")); - testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("255.ff.12.12")); - assertTrue(testMe.getMessage().contains("IP address does not consist out of numbers 0-9 and separators (.))!")); + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("12.12..2")); + assertTrue(testMe.getMessage().contains("IP-Address must not contain two or more consecutive dividers (.) without number in between!")); + + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("f1.12.12.12")); + assertTrue(testMe.getMessage().contains("IP address must consist out of numbers 0-9 and separators (.) !")); + + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("12.12.12.1f")); + assertTrue(testMe.getMessage().contains("IP address must consist out of numbers 0-9 and separators (.) !")); + + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("256.12.12.12")); + assertTrue(testMe.getMessage().contains("Octets of IP-address must not exceed 255!")); + + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("12.12.12.256")); + assertTrue(testMe.getMessage().contains("Octets of IP-address must not exceed 255!")); + + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("2500.12.12.12")); + assertTrue(testMe.getMessage().contains("Octets of IP-address must not exceed 255!")); - testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("2555.800.12.12")); + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("12.12.12.2500")); assertTrue(testMe.getMessage().contains("Octets of IP-address must not exceed 255!")); } @ParameterizedTest - @ValueSource(strings = {"3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", - "3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 1 1 1 1 1 1 1 3 1 1 3 3 1 1 1 1 1 3 1 3 3 3 1 1 1 3 1 1 3 3 1 1 1 1 1 3 1 1 1 1 1 1 1 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 1 1 1 3 3 3 1 3 3 3 3 3 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", - "3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 3 3 3 3 1 1 1 1 1 1 1 3 3 1 1 1 1 1 3 3 3 3 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3"}) + @ValueSource(strings = {"12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12", + "12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 5 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12", + "12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 8 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12"}) void mapDataValid(String test){ assertDoesNotThrow(() -> Parser.mapDataValid(test)); } @Test - void mapDataValidException() { - ParserException testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("hi")); - assertTrue(testMe.getMessage().contains("Map-Data corrupted - must have length of 647 chars including spaces!")); + void mapDataInvalid() { + ParserException testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - mapData String must not exceed length of 967 chars including spaces for 18x18 Tiles map!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("1 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 8 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - minimum length of mapData String must be 715 chars including spaces for 18x18 Tiles map!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid(" 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - must not start nor end with space!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 ")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - must not start nor end with space!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 11 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - must not contain two or more consecutive spaces without number in between!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 11 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - must not contain two or more consecutive spaces without number in between!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 13")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - number of spaces must be 323!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("10 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - number of spaces must be 323!")); - testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3a3a3a3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); - assertTrue(testMe.getMessage().contains("Map-Data corrupted - must use space every other character!")); + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("a2 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - must consist out of numbers 0-9 and space as separator!")); - testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 8 9 7 7 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); - assertTrue(testMe.getMessage().contains("Map-Data corrupted - Tile number must be between 1 and 4!")); + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1d")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - must consist out of numbers 0-9 and space as separator!")); - testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("42 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - Tile number must be between 0 and 29!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 42")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - Tile number must be between 0 and 29!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("22 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); assertTrue(testMe.getMessage().contains("Map-Data corrupted - Top-Line must be border tiles!")); - testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 1 1 1 1 1 3 3 3 3 3 3")); + //don't forget to reach minimum length with test String! Otherwise, wrong Exception will be thrown! + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 5 12 1 1 1 1 1 12 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - Top-Line must be border tiles!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 22")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - Bottom-Line must be border tiles!")); + + //don't forget to reach minimum length with test String! Otherwise, wrong Exception will be thrown! + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 12 1 1 1 1 1 1 1 1 12 8 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); assertTrue(testMe.getMessage().contains("Map-Data corrupted - Bottom-Line must be border tiles!")); - testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 22 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - Left Edge must be border tiles!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 22 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); assertTrue(testMe.getMessage().contains("Map-Data corrupted - Left Edge must be border tiles!")); - testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 22 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - Right Edge must be border tiles!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 22 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); assertTrue(testMe.getMessage().contains("Map-Data corrupted - Right Edge must be border tiles!")); - testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); - assertTrue(testMe.getMessage().contains("Map-Data corrupted - Player spawn must use walkable tile!")); + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 25 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - Player spawn top left must use walkable tile!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - Player spawn top right must use walkable tile!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 25 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - Player spawn bottom left must use walkable tile!")); + + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 12 12 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 12")); + assertTrue(testMe.getMessage().contains("Map-Data corrupted - Player spawn bottom right must use walkable tile!")); + } + + @Test + void statsValid(){ + PlayerStatistics stats = new PlayerStatistics(0, 0, 0, 0, 0, 0); + assertDoesNotThrow(() -> Parser.playerStatsValid(stats)); + } + + @Test + void statsInvalid(){ + ParserException testMe = assertThrows(ParserException.class, () -> Parser.playerStatsValid(new PlayerStatistics(-1, 0, 0, 0, 0, 0))); + assertTrue(testMe.getMessage().contains("Player statistics data corrupted - Minimum value for lost games is 0!")); + + testMe = assertThrows(ParserException.class, () -> Parser.playerStatsValid(new PlayerStatistics(0, -1, 0, 0, 0, 0))); + assertTrue(testMe.getMessage().contains("Player statistics data corrupted - Minimum value for won games is 0!")); - testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); - assertTrue(testMe.getMessage().contains("Map-Data corrupted - Player spawn must use walkable tile!")); + testMe = assertThrows(ParserException.class, () -> Parser.playerStatsValid(new PlayerStatistics(0, 0, -1, 0, 0, 0))); + assertTrue(testMe.getMessage().contains("Player statistics data corrupted - Minimum value for kills is 0!")); - testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); - assertTrue(testMe.getMessage().contains("Map-Data corrupted - Player spawn must use walkable tile!")); + testMe = assertThrows(ParserException.class, () -> Parser.playerStatsValid(new PlayerStatistics(0, 0, 0, -1, 0, 0))); + assertTrue(testMe.getMessage().contains("Player statistics data corrupted - Minimum value for deaths is 0!")); - testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); - assertTrue(testMe.getMessage().contains("Map-Data corrupted - Player spawn must use walkable tile!")); + testMe = assertThrows(ParserException.class, () -> Parser.playerStatsValid(new PlayerStatistics(0, 0, 0, 0, -1, 0))); + assertTrue(testMe.getMessage().contains("Player statistics data corrupted - Minimum value for destroyed blocks is 0!")); + testMe = assertThrows(ParserException.class, () -> Parser.playerStatsValid(new PlayerStatistics(0, 0, 0, 0, 0, -1))); + assertTrue(testMe.getMessage().contains("Player statistics data corrupted - Minimum value for ingame time is 0 seconds!")); } } \ No newline at end of file