test: broken sql connection + more adequate logging levels
This commit is contained in:
parent
72c2c5ed12
commit
d95a9e844a
5 changed files with 60 additions and 12 deletions
|
@ -25,7 +25,6 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class NickoBukkit extends JavaPlugin {
|
||||
private static NickoBukkit plugin;
|
||||
|
@ -66,7 +65,7 @@ public class NickoBukkit extends JavaPlugin {
|
|||
|
||||
if (!dataStore.getStorage().getProvider().init()) {
|
||||
dataStore.getStorage().setError(true);
|
||||
getLogger().warning("Failed to open persistence, data will NOT be saved!");
|
||||
getLogger().severe("Failed to open persistence, data will NOT be saved!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +77,7 @@ public class NickoBukkit extends JavaPlugin {
|
|||
|
||||
getLogger().info("Loading internals...");
|
||||
if (getInternals() == null) {
|
||||
getLogger().log(Level.SEVERE, "Nicko could not find a valid implementation for this server version. Is your server supported?");
|
||||
getLogger().severe("Nicko could not find a valid implementation for this server version. Is your server supported?");
|
||||
dataStore.getStorage().setError(true);
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
@ -87,7 +86,7 @@ public class NickoBukkit extends JavaPlugin {
|
|||
getLogger().info("Loading persistence...");
|
||||
if (!dataStore.getStorage().getProvider().init()) {
|
||||
dataStore.getStorage().setError(true);
|
||||
getLogger().warning("Failed to open persistence, data will NOT be saved!");
|
||||
getLogger().severe("Failed to open persistence, data will NOT be saved!");
|
||||
}
|
||||
|
||||
mojangAPI = new MojangAPI(this);
|
||||
|
@ -97,7 +96,7 @@ public class NickoBukkit extends JavaPlugin {
|
|||
if (localeFileManager.dumpFromLocale(Locale.ENGLISH)) {
|
||||
getLogger().info("Successfully loaded custom language file.");
|
||||
} else {
|
||||
getLogger().warning("Failed to load custom language file!");
|
||||
getLogger().severe("Failed to load custom language file!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,7 +134,7 @@ public class NickoBukkit extends JavaPlugin {
|
|||
dataStore.removeAllNames();
|
||||
dataStore.saveAll();
|
||||
if (!dataStore.getStorage().getProvider().close()) {
|
||||
getLogger().warning("Failed to close persistence!");
|
||||
getLogger().severe("Failed to close persistence!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,10 +15,10 @@ public class BungeeCordSupport {
|
|||
final Server server = instance.getServer();
|
||||
final YamlConfiguration config = server.spigot().getConfig();
|
||||
if (config.getConfigurationSection("settings").getBoolean("bungeecord") && instance.getNickoConfig().isBungeecordSupport()) {
|
||||
instance.getLogger().severe("Hummm. Your server is hooked to BungeeCord, but it seems");
|
||||
instance.getLogger().severe("that BungeeCord support is not enabled inside Nicko.");
|
||||
instance.getLogger().severe("If this is intentional, you can safely ignore this message.");
|
||||
instance.getLogger().severe("Otherwise, you can enable BungeeCord support inside Nicko's configuration file.");
|
||||
instance.getLogger().warning("Hummm. Your server is hooked to BungeeCord, but it seems");
|
||||
instance.getLogger().warning("that BungeeCord support is not enabled inside Nicko.");
|
||||
instance.getLogger().warning("If this is intentional, you can safely ignore this message.");
|
||||
instance.getLogger().warning("Otherwise, you can enable BungeeCord support inside Nicko's configuration file.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public class SQLStorage extends Storage {
|
|||
statement.executeUpdate();
|
||||
return new ActionResult<>();
|
||||
} catch (SQLException e) {
|
||||
instance.getLogger().warning("Unable to store player. (%s)".formatted(e.getMessage()));
|
||||
instance.getLogger().warning("Couldn't send SQL Request: " + e.getMessage());
|
||||
return new ActionResult<>(I18NDict.Error.SQL_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public class SQLStorageProvider implements StorageProvider {
|
|||
createTable();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
instance.getLogger().severe("Couldn't establish a connection to the MySQL database: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package net.artelnatif.nicko.test.storage;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.config.NickoConfiguration;
|
||||
import net.artelnatif.nicko.disguise.ActionResult;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.i18n.Locale;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
public class BrokenSQLTest {
|
||||
private static ServerMock server;
|
||||
private static NickoBukkit plugin;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final NickoConfiguration config = new NickoConfiguration(null);
|
||||
config.setLocalStorage(false);
|
||||
config.setBungeecordSupport(false);
|
||||
config.setSQLAddress("127.0.0.1");
|
||||
config.setSQLUsername("root");
|
||||
config.setSQLPassword("INVALID_PASSWORD");
|
||||
|
||||
server = MockBukkit.mock();
|
||||
plugin = MockBukkit.load(NickoBukkit.class, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Fail to create Tables")
|
||||
public void createSQLTables() {
|
||||
Assertions.assertTrue(plugin.getDataStore().getStorage().isError());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Store Player Via SQL")
|
||||
public void storePlayer() {
|
||||
final PlayerMock playerMock = server.addPlayer();
|
||||
final NickoProfile profile = new NickoProfile("Notch", "Notch", Locale.ENGLISH, true);
|
||||
final ActionResult<Void> storeAction = plugin.getDataStore().getStorage().store(playerMock.getUniqueId(), profile);
|
||||
Assertions.assertFalse(storeAction.isError());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void shutdown() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue