mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 12:02:01 -08:00
Tests: added checks for errors on card loading (see #4402)
This commit is contained in:
parent
a63f87da2c
commit
7c2511355e
2 changed files with 33 additions and 9 deletions
|
|
@ -29,10 +29,12 @@ import org.mage.test.serverside.base.CardTestAPI;
|
||||||
import org.mage.test.serverside.base.MageTestPlayerBase;
|
import org.mage.test.serverside.base.MageTestPlayerBase;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API for test initialization and asserting the test results.
|
* API for test initialization and asserting the test results.
|
||||||
|
|
@ -61,11 +63,6 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
||||||
UNKNOWN
|
UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
|
||||||
// CardScanner.scanned = true;
|
|
||||||
CardScanner.scan();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default game initialization params for red player (that plays with
|
* Default game initialization params for red player (that plays with
|
||||||
* Mountains)
|
* Mountains)
|
||||||
|
|
@ -111,6 +108,17 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
||||||
addCard(Zone.LIBRARY, playerB, "Plains", 10);
|
addCard(Zone.LIBRARY, playerB, "Plains", 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void checkDatabase() {
|
||||||
|
// load all cards to db from class list
|
||||||
|
ArrayList<String> errorsList = new ArrayList<>();
|
||||||
|
CardScanner.scan(errorsList);
|
||||||
|
|
||||||
|
if (errorsList.size() > 0) {
|
||||||
|
Assert.fail("Found errors on card loading: " + '\n' + errorsList.stream().collect(Collectors.joining("\n")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void reset() throws GameException, FileNotFoundException {
|
public void reset() throws GameException, FileNotFoundException {
|
||||||
if (currentGame != null) {
|
if (currentGame != null) {
|
||||||
|
|
|
||||||
|
|
@ -43,16 +43,23 @@ public final class CardScanner {
|
||||||
private static final Logger logger = Logger.getLogger(CardScanner.class);
|
private static final Logger logger = Logger.getLogger(CardScanner.class);
|
||||||
|
|
||||||
public static void scan() {
|
public static void scan() {
|
||||||
|
scan(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void scan(List<String> errorsList) {
|
||||||
if (scanned) {
|
if (scanned) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
scanned = true;
|
scanned = true;
|
||||||
|
|
||||||
List<CardInfo> cardsToAdd = new ArrayList<>();
|
List<CardInfo> cardsToAdd = new ArrayList<>();
|
||||||
|
int setsUpdatedCount = 0;
|
||||||
|
int setsAddedCount = 0;
|
||||||
|
|
||||||
for (ExpansionSet set : Sets.getInstance().values()) {
|
for (ExpansionSet set : Sets.getInstance().values()) {
|
||||||
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(set.getCode());
|
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(set.getCode());
|
||||||
if (expansionInfo == null) {
|
if (expansionInfo == null) {
|
||||||
|
setsAddedCount += 1;
|
||||||
ExpansionRepository.instance.add(new ExpansionInfo(set));
|
ExpansionRepository.instance.add(new ExpansionInfo(set));
|
||||||
} else if (!expansionInfo.name.equals(set.getName())
|
} else if (!expansionInfo.name.equals(set.getName())
|
||||||
|| !expansionInfo.code.equals(set.getCode())
|
|| !expansionInfo.code.equals(set.getCode())
|
||||||
|
|
@ -61,17 +68,26 @@ public final class CardScanner {
|
||||||
|| expansionInfo.type != set.getSetType()
|
|| expansionInfo.type != set.getSetType()
|
||||||
|| expansionInfo.boosters != set.hasBoosters()
|
|| expansionInfo.boosters != set.hasBoosters()
|
||||||
|| expansionInfo.basicLands != set.hasBasicLands()) {
|
|| expansionInfo.basicLands != set.hasBasicLands()) {
|
||||||
|
setsUpdatedCount += 1;
|
||||||
ExpansionRepository.instance.update(expansionInfo);
|
ExpansionRepository.instance.update(expansionInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExpansionRepository.instance.setContentVersion(ExpansionRepository.instance.getContentVersionConstant());
|
ExpansionRepository.instance.setContentVersion(ExpansionRepository.instance.getContentVersionConstant());
|
||||||
|
|
||||||
|
if (setsAddedCount > 0) {
|
||||||
|
logger.info("DB: need to add " + setsUpdatedCount + " new sets");
|
||||||
|
}
|
||||||
|
if (setsUpdatedCount > 0) {
|
||||||
|
logger.info("DB: need to update " + setsUpdatedCount + " sets");
|
||||||
|
}
|
||||||
|
|
||||||
for (ExpansionSet set : Sets.getInstance().values()) {
|
for (ExpansionSet set : Sets.getInstance().values()) {
|
||||||
for (ExpansionSet.SetCardInfo setInfo : set.getSetCardInfo()) {
|
for (ExpansionSet.SetCardInfo setInfo : set.getSetCardInfo()) {
|
||||||
if (CardRepository.instance.findCard(set.getCode(), setInfo.getCardNumber()) == null) {
|
if (CardRepository.instance.findCard(set.getCode(), setInfo.getCardNumber()) == null) {
|
||||||
Card card = CardImpl.createCard(setInfo.getCardClass(),
|
Card card = CardImpl.createCard(
|
||||||
new CardSetInfo(setInfo.getName(), set.getCode(), setInfo.getCardNumber(),
|
setInfo.getCardClass(),
|
||||||
setInfo.getRarity(), setInfo.getGraphicInfo()));
|
new CardSetInfo(setInfo.getName(), set.getCode(), setInfo.getCardNumber(), setInfo.getRarity(), setInfo.getGraphicInfo()),
|
||||||
|
errorsList);
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
cardsToAdd.add(new CardInfo(card));
|
cardsToAdd.add(new CardInfo(card));
|
||||||
if (card instanceof SplitCard) {
|
if (card instanceof SplitCard) {
|
||||||
|
|
@ -85,7 +101,7 @@ public final class CardScanner {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cardsToAdd.isEmpty()) {
|
if (!cardsToAdd.isEmpty()) {
|
||||||
logger.info("Cards need storing in DB: " + cardsToAdd.size());
|
logger.info("DB: need to add " + cardsToAdd.size() + " new cards");
|
||||||
CardRepository.instance.addCards(cardsToAdd);
|
CardRepository.instance.addCards(cardsToAdd);
|
||||||
}
|
}
|
||||||
CardRepository.instance.setContentVersion(CardRepository.instance.getContentVersionConstant());
|
CardRepository.instance.setContentVersion(CardRepository.instance.getContentVersionConstant());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue