Search in sources :

Example 6 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class DistributedFilesPersistenceHandlerTest method shouldHandleReadErrorGracefully.

@Test
public void shouldHandleReadErrorGracefully() throws IOException {
    // given
    // assumption
    File invalidFile = new File(playerDataFolder, "seg16-4-limbo.json");
    assertThat(invalidFile.exists(), equalTo(false));
    Files.write("not valid json".getBytes(), invalidFile);
    // when
    LimboPlayer result = persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UNKNOWN_UUID));
    // then
    assertThat(result, nullValue());
}
Also used : LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) File(java.io.File) Test(org.junit.Test)

Example 7 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class DistributedFilesPersistenceHandlerTest method shouldAddPlayer.

@Test
public void shouldAddPlayer() {
    // given
    Player uuidToAdd1 = mockPlayerWithUuid(UNKNOWN_UUID);
    Location location1 = new Location(mockWorldWithName("1world"), 120, 60, -80, 0.42345f, 120.32f);
    LimboPlayer limbo1 = new LimboPlayer(location1, false, "group-1", true, 0.1f, 0.2f);
    Player uuidToAdd2 = mockPlayerWithUuid(UNKNOWN_UUID2);
    Location location2 = new Location(mockWorldWithName("2world"), -40, 20, 33, 4.235f, 8.32299f);
    LimboPlayer limbo2 = new LimboPlayer(location2, true, "", false, 0.0f, 0.25f);
    // when
    persistenceHandler.saveLimboPlayer(uuidToAdd1, limbo1);
    persistenceHandler.saveLimboPlayer(uuidToAdd2, limbo2);
    // then
    LimboPlayer addedPlayer1 = persistenceHandler.getLimboPlayer(uuidToAdd1);
    assertThat(addedPlayer1, isLimbo(limbo1));
    assertThat(addedPlayer1, hasLocation(location1));
    LimboPlayer addedPlayer2 = persistenceHandler.getLimboPlayer(uuidToAdd2);
    assertThat(addedPlayer2, isLimbo(limbo2));
    assertThat(addedPlayer2, hasLocation(location2));
    assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(MIGRATED_UUID)), MIGRATED_LIMBO_MATCHER);
    assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UUID_FAB69)), FAB69_MATCHER);
    assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UUID_STAFF)), STAFF_MATCHER);
    assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UUID_8C679)), SC679_MATCHER);
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Location(org.bukkit.Location) LimboPlayerMatchers.hasLocation(fr.xephi.authme.data.limbo.LimboPlayerMatchers.hasLocation) Test(org.junit.Test)

Example 8 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class IndividualFilesPersistenceHandlerTest method shouldReadDataFromFile.

@Test
public void shouldReadDataFromFile() {
    // given
    Player player = mock(Player.class);
    given(player.getUniqueId()).willReturn(SAMPLE_UUID);
    World world = mock(World.class);
    given(bukkitService.getWorld("nether")).willReturn(world);
    // when
    LimboPlayer data = handler.getLimboPlayer(player);
    // then
    assertThat(data, not(nullValue()));
    assertThat(data.isOperator(), equalTo(true));
    assertThat(data.isCanFly(), equalTo(true));
    assertThat(data.getWalkSpeed(), equalTo(0.2f));
    assertThat(data.getFlySpeed(), equalTo(0.1f));
    assertThat(data.getGroup(), equalTo("players"));
    Location location = data.getLocation();
    assertThat(location.getX(), equalTo(-113.219));
    assertThat(location.getY(), equalTo(72.0));
    assertThat(location.getZ(), equalTo(130.637));
    assertThat(location.getWorld(), equalTo(world));
    assertThat(location.getPitch(), equalTo(24.15f));
    assertThat(location.getYaw(), equalTo(-292.484f));
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) World(org.bukkit.World) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Location(org.bukkit.Location) Test(org.junit.Test)

Example 9 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class LimboPersistenceTest method shouldHandleExceptionWhenGettingLimbo.

@Test
public void shouldHandleExceptionWhenGettingLimbo() {
    // given
    Player player = mock(Player.class);
    Logger logger = TestHelper.setupLogger();
    LimboPersistenceHandler handler = getHandler();
    doThrow(IllegalAccessException.class).when(handler).getLimboPlayer(player);
    // when
    LimboPlayer result = limboPersistence.getLimboPlayer(player);
    // then
    assertThat(result, nullValue());
    verify(logger).warning(argThat(containsString("[IllegalAccessException]")));
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Logger(java.util.logging.Logger) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Test(org.junit.Test)

Example 10 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class LimboPersistenceTest method shouldHandleExceptionWhenSavingLimbo.

@Test
public void shouldHandleExceptionWhenSavingLimbo() {
    // given
    Player player = mock(Player.class);
    LimboPlayer limbo = mock(LimboPlayer.class);
    Logger logger = TestHelper.setupLogger();
    LimboPersistenceHandler handler = getHandler();
    doThrow(IllegalStateException.class).when(handler).saveLimboPlayer(player, limbo);
    // when
    limboPersistence.saveLimboPlayer(player, limbo);
    // then
    verify(logger).warning(argThat(containsString("[IllegalStateException]")));
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Logger(java.util.logging.Logger) Test(org.junit.Test)

Aggregations

LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)25 Test (org.junit.Test)17 Player (org.bukkit.entity.Player)16 Location (org.bukkit.Location)10 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)9 File (java.io.File)7 World (org.bukkit.World)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 LimboService (fr.xephi.authme.data.limbo.LimboService)2 Logger (java.util.logging.Logger)2 JsonObject (com.google.gson.JsonObject)1 DebugSectionUtils.applyToLimboPlayersMap (fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.applyToLimboPlayersMap)1 DebugSectionUtils.formatLocation (fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.formatLocation)1 LimboPlayerMatchers.hasLocation (fr.xephi.authme.data.limbo.LimboPlayerMatchers.hasLocation)1 LimboPersistence (fr.xephi.authme.data.limbo.persistence.LimboPersistence)1 LoginEvent (fr.xephi.authme.events.LoginEvent)1 DebugSectionPermissions (fr.xephi.authme.permission.DebugSectionPermissions)1 PermissionNode (fr.xephi.authme.permission.PermissionNode)1 PermissionsManager (fr.xephi.authme.permission.PermissionsManager)1