Search in sources :

Example 1 with ZippedObjectImpl

use of mage.remote.traffic.ZippedObjectImpl in project mage by magefree.

the class SerializationTest method test_Game.

@Test
public void test_Game() {
    addCard(Zone.BATTLEFIELD, playerA, "Grizzly Bears", 1);
    setStopAt(1, PhaseStep.END_TURN);
    execute();
    GameView gameView = getGameView(playerA);
    Object compressed = CompressUtil.compress(gameView);
    Assert.assertTrue("Must be zip", compressed instanceof ZippedObjectImpl);
    GameView uncompressed = (GameView) CompressUtil.decompress(compressed);
    Assert.assertEquals("Must be same", 1, uncompressed.getPlayers().get(0).getBattlefield().size());
}
Also used : ZippedObjectImpl(mage.remote.traffic.ZippedObjectImpl) GameView(mage.view.GameView) Test(org.junit.Test)

Example 2 with ZippedObjectImpl

use of mage.remote.traffic.ZippedObjectImpl in project mage by magefree.

the class SerializationTest method test_PermanentImpl_Simple.

@Test
public void test_PermanentImpl_Simple() {
    CardInfo cardInfo = CardRepository.instance.findCard("Balduvian Bears");
    Card newCard = cardInfo.getCard();
    Card permCard = CardUtil.getDefaultCardSideForBattlefield(currentGame, newCard);
    PermanentImpl permanent = new PermanentCard(permCard, playerA.getId(), currentGame);
    currentGame.addPermanent(permanent, 0);
    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());
}
Also used : CardInfo(mage.cards.repository.CardInfo) PermanentImpl(mage.game.permanent.PermanentImpl) ZippedObjectImpl(mage.remote.traffic.ZippedObjectImpl) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard) Test(org.junit.Test)

Example 3 with ZippedObjectImpl

use of mage.remote.traffic.ZippedObjectImpl in project mage by magefree.

the class SerializationTest method test_PermanentImpl_MarkedDamageInfo.

@Test
public void test_PermanentImpl_MarkedDamageInfo() {
    CardInfo cardInfo = CardRepository.instance.findCard("Balduvian Bears");
    Card newCard = cardInfo.getCard();
    Card permCard = CardUtil.getDefaultCardSideForBattlefield(currentGame, newCard);
    PermanentImpl permanent = new PermanentCard(permCard, playerA.getId(), currentGame);
    currentGame.addPermanent(permanent, 0);
    // mark damage from infected ability
    permanent.addAbility(InfectAbility.getInstance(), null, currentGame);
    permanent.markDamage(1, permanent.getId(), null, 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));
}
Also used : CardInfo(mage.cards.repository.CardInfo) PermanentImpl(mage.game.permanent.PermanentImpl) ZippedObjectImpl(mage.remote.traffic.ZippedObjectImpl) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard) Test(org.junit.Test)

Example 4 with ZippedObjectImpl

use of mage.remote.traffic.ZippedObjectImpl in project mage by magefree.

the class SerializationTest method processSingleCard.

private void processSingleCard(CardInfo cardInfo) {
    // compress each card's part
    Card newCard = cardInfo.getCard();
    CardUtil.getObjectPartsAsObjects(newCard).stream().map(Card.class::cast).forEach(card -> {
        Card testCard = CardUtil.getDefaultCardSideForBattlefield(currentGame, newCard);
        Card testPermanent = null;
        if (!testCard.isInstantOrSorcery()) {
            testPermanent = new PermanentCard(testCard, playerA.getId(), currentGame);
        }
        // card
        {
            Object compressed = CompressUtil.compress(testCard);
            Assert.assertTrue("Must be zip", compressed instanceof ZippedObjectImpl);
            Card uncompressed = (Card) CompressUtil.decompress(compressed);
            Assert.assertEquals("Must be same", testCard.getName(), uncompressed.getName());
        }
        // permanent
        if (testPermanent != null) {
            Object compressed = CompressUtil.compress(testPermanent);
            Assert.assertTrue("Must be zip", compressed instanceof ZippedObjectImpl);
            Card uncompressed = (Card) CompressUtil.decompress(compressed);
            Assert.assertEquals("Must be same", testPermanent.getName(), uncompressed.getName());
        }
    });
}
Also used : ZippedObjectImpl(mage.remote.traffic.ZippedObjectImpl) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard)

Example 5 with ZippedObjectImpl

use of mage.remote.traffic.ZippedObjectImpl in project mage by magefree.

the class SerializationTest method test_LondonMulligan.

@Test
public void test_LondonMulligan() {
    LondonMulligan mulligan = new LondonMulligan(15);
    Object compressed = CompressUtil.compress(mulligan);
    Assert.assertTrue("Must be zip", compressed instanceof ZippedObjectImpl);
    LondonMulligan uncompressed = (LondonMulligan) CompressUtil.decompress(compressed);
    Assert.assertEquals("Must be same", mulligan.getFreeMulligans(), uncompressed.getFreeMulligans());
}
Also used : ZippedObjectImpl(mage.remote.traffic.ZippedObjectImpl) LondonMulligan(mage.game.mulligan.LondonMulligan) Test(org.junit.Test)

Aggregations

ZippedObjectImpl (mage.remote.traffic.ZippedObjectImpl)5 Test (org.junit.Test)4 Card (mage.cards.Card)3 PermanentCard (mage.game.permanent.PermanentCard)3 CardInfo (mage.cards.repository.CardInfo)2 PermanentImpl (mage.game.permanent.PermanentImpl)2 LondonMulligan (mage.game.mulligan.LondonMulligan)1 GameView (mage.view.GameView)1