*/
@Test
public void testTemporaryBan() throws Throwable {
DBTransaction transaction = TransactionPool.get().beginWork();
try {
AccountDAO accountDAO = DAORegister.get().get(AccountDAO.class);
CharacterDAO characterDAO = DAORegister.get().get(CharacterDAO.class);
Player player = PlayerTestHelper.createPlayer("bobby");
Player admin = PlayerTestHelper.createPlayer("admin");
RPAction action = new RPAction();
action.put("type", "ban");
action.put("target", player.getName());
action.put("hours", 1);
action.put("reason", "We want to test the temporary bans");
if (!accountDAO.hasPlayer(transaction, player.getName())) {
accountDAO.addPlayer(transaction, player.getName(), new byte[0], "schnubbel");
}
accountDAO.setAccountStatus(transaction, player.getName(), "active");
if (!accountDAO.hasPlayer(transaction, admin.getName())) {
accountDAO.addPlayer(transaction, admin.getName(), new byte[0], "schnubbel");
}
// we do a character check now. Made the the character name and the account name the same
if (!characterDAO.hasCharacter(transaction, player.getName(), player.getName())) {
characterDAO.addCharacter(transaction, player.getName(), player.getName(), player);
}
accountDAO.setAccountStatus(transaction, admin.getName(), "active");
assertEquals("active", accountDAO.getAccountStatus(transaction, player.getName()));
assertEquals("active", accountDAO.getAccountStatus(transaction, admin.getName()));
TransactionPool.get().commit(transaction);
assertFalse(CommandCenter.execute(admin , action));
admin.clearEvents();
admin.setAdminLevel(5000);
assertTrue(CommandCenter.execute(admin , action));
transaction = TransactionPool.get().beginWork();
System.out.println(admin.events().get(0).toString());
assertEquals("active", accountDAO.getAccountStatus(transaction, player.getName()));
assertEquals("active", accountDAO.getAccountStatus(transaction, admin.getName()));
assertFalse(admin.events().isEmpty());
assertThat(admin.events().get(0).toString(), containsString("RPEvent private_text with Attributes of Class(private_text): "));
// not sure of a good way to reliably test the timestamping
assertThat(admin.events().get(0).toString(), containsString("[text=You have banned account bobby (character: bobby) until "));
assertThat(admin.events().get(0).toString(), containsString("for: We want to test the temporary bans"));