diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/performance/SerializationTest.java b/Mage.Tests/src/test/java/org/mage/test/serverside/performance/SerializationTest.java new file mode 100644 index 0000000000..b3739a9383 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/performance/SerializationTest.java @@ -0,0 +1,53 @@ +package org.mage.test.serverside.performance; + +import mage.abilities.keyword.InfectAbility; +import mage.cards.repository.CardInfo; +import mage.cards.repository.CardRepository; +import mage.counters.CounterType; +import mage.game.permanent.PermanentCard; +import mage.game.permanent.PermanentImpl; +import mage.remote.traffic.ZippedObjectImpl; +import mage.utils.CompressUtil; +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * @author JayDi85 + */ +public class SerializationTest extends CardTestPlayerBase { + + @Test + public void test_PermanentImpl_Simple() { + CardInfo cardInfo = CardRepository.instance.findCard("Balduvian Bears"); + PermanentImpl permanent = new PermanentCard(cardInfo.getCard(), playerA.getId(), currentGame); + currentGame.addPermanent(permanent); + + Object compressed = CompressUtil.compress(permanent); + Assert.assertTrue("Must be zip", compressed instanceof ZippedObjectImpl); + PermanentImpl uncompressed = (PermanentImpl) CompressUtil.decompress(compressed); + Assert.assertEquals("Must be same", permanent.getName(), uncompressed.getName()); + } + + @Test + public void test_PermanentImpl_MarkedDamageInfo() { + CardInfo cardInfo = CardRepository.instance.findCard("Balduvian Bears"); + PermanentImpl permanent = new PermanentCard(cardInfo.getCard(), playerA.getId(), currentGame); + currentGame.addPermanent(permanent); + + // mark damage from infected ability + permanent.addAbility(InfectAbility.getInstance(), currentGame); + permanent.markDamage(1, permanent.getId(), currentGame, false, false); + + // test compress (it uses default java serialization) + Object compressed = CompressUtil.compress(permanent); + Assert.assertTrue("Must be zip", compressed instanceof ZippedObjectImpl); + PermanentImpl uncompressed = (PermanentImpl) CompressUtil.decompress(compressed); + Assert.assertEquals("Must be same", permanent.getName(), uncompressed.getName()); + + // ensure that it was marked damage + permanent.applyDamage(currentGame); + Assert.assertEquals("Must get infected counter", 1, permanent.getCounters(currentGame).getCount(CounterType.M1M1)); + } + +} diff --git a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java index 6cd06ee66b..1a13d26a71 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java @@ -37,6 +37,7 @@ import mage.util.GameLog; import mage.util.ThreadLocalStringBuilder; import org.apache.log4j.Logger; +import java.io.Serializable; import java.util.*; /** @@ -46,7 +47,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { private static final Logger logger = Logger.getLogger(PermanentImpl.class); - static class MarkedDamageInfo { + static class MarkedDamageInfo implements Serializable { public MarkedDamageInfo(Counter counter, MageObject sourceObject) { this.counter = counter;