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