fix(sql): mockbukkit is the issue
This commit is contained in:
parent
3a7da4b3d6
commit
7d07834bf7
3 changed files with 25 additions and 29 deletions
|
@ -7,9 +7,10 @@ import xyz.atnrch.nicko.i18n.Locale;
|
||||||
import xyz.atnrch.nicko.profile.NickoProfile;
|
import xyz.atnrch.nicko.profile.NickoProfile;
|
||||||
import xyz.atnrch.nicko.storage.Storage;
|
import xyz.atnrch.nicko.storage.Storage;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.sql.Connection;
|
||||||
import java.nio.ByteBuffer;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.*;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
@ -54,7 +55,7 @@ public class SQLStorage extends Storage {
|
||||||
if (connection == null) return false;
|
if (connection == null) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String sql = "SELECT * FROM nicko.DATA WHERE uuid = ?";
|
final String sql = "SELECT uuid FROM nicko.DATA WHERE uuid = ?";
|
||||||
|
|
||||||
final PreparedStatement statement = connection.prepareStatement(sql);
|
final PreparedStatement statement = connection.prepareStatement(sql);
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
|
@ -71,6 +72,7 @@ public class SQLStorage extends Storage {
|
||||||
public Optional<NickoProfile> retrieve(UUID uuid) {
|
public Optional<NickoProfile> retrieve(UUID uuid) {
|
||||||
final Connection connection = getProvider().getConnection();
|
final Connection connection = getProvider().getConnection();
|
||||||
if (connection == null) return Optional.empty();
|
if (connection == null) return Optional.empty();
|
||||||
|
if (!isStored(uuid)) return Optional.empty();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String sql = "SELECT * FROM nicko.DATA WHERE uuid = ?";
|
final String sql = "SELECT * FROM nicko.DATA WHERE uuid = ?";
|
||||||
|
@ -89,6 +91,9 @@ public class SQLStorage extends Storage {
|
||||||
locale = resultSet.getString("locale");
|
locale = resultSet.getString("locale");
|
||||||
bungeecord = resultSet.getBoolean("bungeecord");
|
bungeecord = resultSet.getBoolean("bungeecord");
|
||||||
}
|
}
|
||||||
|
System.out.println("name = " + name);
|
||||||
|
System.out.println("skin = " + skin);
|
||||||
|
System.out.println("locale = " + locale);
|
||||||
|
|
||||||
final NickoProfile profile = new NickoProfile(name, skin, Locale.fromCode(locale), bungeecord);
|
final NickoProfile profile = new NickoProfile(name, skin, Locale.fromCode(locale), bungeecord);
|
||||||
return Optional.of(profile);
|
return Optional.of(profile);
|
||||||
|
@ -104,7 +109,7 @@ public class SQLStorage extends Storage {
|
||||||
if (connection == null) return ActionResult.error(I18NDict.Error.SQL_ERROR);
|
if (connection == null) return ActionResult.error(I18NDict.Error.SQL_ERROR);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String sql = "DELETE FROM nicko.DATA WHERE uuid = ? LIMIT 1";
|
final String sql = "DELETE FROM nicko.DATA WHERE uuid = ?";
|
||||||
final PreparedStatement statement = connection.prepareStatement(sql);
|
final PreparedStatement statement = connection.prepareStatement(sql);
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
int rows = statement.executeUpdate();
|
int rows = statement.executeUpdate();
|
||||||
|
@ -136,12 +141,4 @@ public class SQLStorage extends Storage {
|
||||||
statement.setString(5, uuid.toString());
|
statement.setString(5, uuid.toString());
|
||||||
return statement;
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ByteArrayInputStream uuidToBin(UUID uuid) {
|
|
||||||
byte[] bytes = new byte[16];
|
|
||||||
ByteBuffer.wrap(bytes)
|
|
||||||
.putLong(uuid.getMostSignificantBits())
|
|
||||||
.putLong(uuid.getLeastSignificantBits());
|
|
||||||
return new ByteArrayInputStream(bytes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class SQLStorageProvider implements StorageProvider {
|
||||||
"skin varchar(16)," +
|
"skin varchar(16)," +
|
||||||
"locale char(2) NOT NULL," +
|
"locale char(2) NOT NULL," +
|
||||||
"bungeecord boolean NOT NULL," +
|
"bungeecord boolean NOT NULL," +
|
||||||
"PRIMARY KEY (UUID))";
|
"PRIMARY KEY (uuid))";
|
||||||
query = query.replace("%s", schemaName);
|
query = query.replace("%s", schemaName);
|
||||||
|
|
||||||
final PreparedStatement statement = connection.prepareStatement(query);
|
final PreparedStatement statement = connection.prepareStatement(query);
|
||||||
|
|
|
@ -1,27 +1,24 @@
|
||||||
package xyz.atnrch.nicko.test.storage;
|
package xyz.atnrch.nicko.test.storage;
|
||||||
|
|
||||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||||
import be.seeseemelk.mockbukkit.ServerMock;
|
|
||||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
import xyz.atnrch.nicko.NickoBukkit;
|
import xyz.atnrch.nicko.NickoBukkit;
|
||||||
|
import xyz.atnrch.nicko.appearance.ActionResult;
|
||||||
import xyz.atnrch.nicko.config.Configuration;
|
import xyz.atnrch.nicko.config.Configuration;
|
||||||
import xyz.atnrch.nicko.config.DataSourceConfiguration;
|
import xyz.atnrch.nicko.config.DataSourceConfiguration;
|
||||||
import xyz.atnrch.nicko.appearance.ActionResult;
|
|
||||||
import xyz.atnrch.nicko.profile.NickoProfile;
|
|
||||||
import xyz.atnrch.nicko.i18n.Locale;
|
import xyz.atnrch.nicko.i18n.Locale;
|
||||||
|
import xyz.atnrch.nicko.profile.NickoProfile;
|
||||||
import xyz.atnrch.nicko.storage.PlayerDataStore;
|
import xyz.atnrch.nicko.storage.PlayerDataStore;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
public class SQLStorageTest {
|
public class SQLStorageTest {
|
||||||
private static ServerMock server;
|
|
||||||
private static NickoBukkit plugin;
|
|
||||||
private static PlayerMock player;
|
|
||||||
private static PlayerDataStore dataStore;
|
private static PlayerDataStore dataStore;
|
||||||
|
private static UUID uuid;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
|
@ -30,10 +27,12 @@ public class SQLStorageTest {
|
||||||
DataSourceConfiguration.REDIS_EMPTY,
|
DataSourceConfiguration.REDIS_EMPTY,
|
||||||
"",
|
"",
|
||||||
false);
|
false);
|
||||||
server = MockBukkit.mock();
|
|
||||||
plugin = MockBukkit.load(NickoBukkit.class, config);
|
MockBukkit.mock();
|
||||||
|
|
||||||
|
final NickoBukkit plugin = MockBukkit.load(NickoBukkit.class, config);
|
||||||
dataStore = plugin.getDataStore();
|
dataStore = plugin.getDataStore();
|
||||||
player = server.addPlayer();
|
uuid = UUID.randomUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -47,7 +46,7 @@ public class SQLStorageTest {
|
||||||
@DisplayName("Store empty profile")
|
@DisplayName("Store empty profile")
|
||||||
@Order(2)
|
@Order(2)
|
||||||
public void storeEmptyProfile() {
|
public void storeEmptyProfile() {
|
||||||
final Optional<NickoProfile> optionalProfile = dataStore.getData(player.getUniqueId());
|
final Optional<NickoProfile> optionalProfile = dataStore.getData(uuid);
|
||||||
assertTrue(optionalProfile.isPresent());
|
assertTrue(optionalProfile.isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +54,7 @@ public class SQLStorageTest {
|
||||||
@DisplayName("Update profile")
|
@DisplayName("Update profile")
|
||||||
@Order(3)
|
@Order(3)
|
||||||
public void updateProfile() {
|
public void updateProfile() {
|
||||||
final Optional<NickoProfile> optionalProfile = dataStore.getData(player.getUniqueId());
|
final Optional<NickoProfile> optionalProfile = dataStore.getData(uuid);
|
||||||
final NickoProfile profile = optionalProfile.get();
|
final NickoProfile profile = optionalProfile.get();
|
||||||
assertNull(profile.getName());
|
assertNull(profile.getName());
|
||||||
assertNull(profile.getSkin());
|
assertNull(profile.getSkin());
|
||||||
|
@ -67,7 +66,7 @@ public class SQLStorageTest {
|
||||||
profile.setLocale(Locale.FRENCH);
|
profile.setLocale(Locale.FRENCH);
|
||||||
profile.setBungeecordTransfer(false);
|
profile.setBungeecordTransfer(false);
|
||||||
|
|
||||||
final ActionResult result = dataStore.saveData(player);
|
final ActionResult result = dataStore.getStorage().store(uuid, profile);
|
||||||
assertFalse(result.isError());
|
assertFalse(result.isError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +74,7 @@ public class SQLStorageTest {
|
||||||
@DisplayName("Get updated profile")
|
@DisplayName("Get updated profile")
|
||||||
@Order(4)
|
@Order(4)
|
||||||
public void hasProfileBeenUpdated() {
|
public void hasProfileBeenUpdated() {
|
||||||
final Optional<NickoProfile> profile = dataStore.getData(player.getUniqueId());
|
final Optional<NickoProfile> profile = dataStore.getData(uuid);
|
||||||
assertTrue(profile.isPresent());
|
assertTrue(profile.isPresent());
|
||||||
|
|
||||||
final NickoProfile updatedProfile = profile.get();
|
final NickoProfile updatedProfile = profile.get();
|
||||||
|
@ -89,7 +88,7 @@ public class SQLStorageTest {
|
||||||
@DisplayName("Delete profile")
|
@DisplayName("Delete profile")
|
||||||
@Order(5)
|
@Order(5)
|
||||||
public void deleteProfile() {
|
public void deleteProfile() {
|
||||||
final ActionResult sqlDelete = dataStore.getStorage().delete(player.getUniqueId());
|
final ActionResult sqlDelete = dataStore.getStorage().delete(uuid);
|
||||||
assertFalse(sqlDelete.isError());
|
assertFalse(sqlDelete.isError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue