Some tests.

This commit is contained in:
marcins78@gmail.com
2012-03-05 04:14:44 +00:00
parent 0205407e28
commit dfc69488d7
8 changed files with 128 additions and 60 deletions

View File

@@ -444,4 +444,44 @@ public class IndividualCardAtTest extends AbstractAtTest {
AwaitingDecision decision = _userFeedback.getAwaitingDecision(P1); AwaitingDecision decision = _userFeedback.getAwaitingDecision(P1);
assertEquals(AwaitingDecisionType.MULTIPLE_CHOICE, decision.getDecisionType()); assertEquals(AwaitingDecisionType.MULTIPLE_CHOICE, decision.getDecisionType());
} }
@Test
public void fordOfBruinenReduce() throws DecisionResultInvalidException {
initializeSimplestGame();
skipMulligans();
// End fellowship
playerDecided(P1, "");
// End shadow
playerDecided(P2, "");
PhysicalCardImpl ford = new PhysicalCardImpl(101, "1_338", P2, _library.getLotroCardBlueprint("1_338"));
ford.setSiteNumber(3);
_game.getGameState().addCardToZone(_game, ford, Zone.ADVENTURE_PATH);
// End regroup
playerDecided(P1, "");
playerDecided(P2, "");
// Decide to move
playerDecided(P1, getMultipleDecisionIndex(_userFeedback.getAwaitingDecision(P1), "Yes"));
// End shadow
playerDecided(P2, "");
// End regroup
playerDecided(P1, "");
playerDecided(P2, "");
// P2 Turn
PhysicalCardImpl attea = new PhysicalCardImpl(102, "1_229", P1, _library.getLotroCardBlueprint("1_229"));
_game.getGameState().addCardToZone(_game, attea, Zone.HAND);
// End fellowship
playerDecided(P2, "");
assertEquals(8, _game.getModifiersQuerying().getTwilightCost(_game.getGameState(), attea, false));
}
} }

View File

@@ -13,9 +13,13 @@ import com.gempukku.lotro.logic.actions.RequiredTriggerAction;
import com.gempukku.lotro.logic.decisions.AwaitingDecision; import com.gempukku.lotro.logic.decisions.AwaitingDecision;
import com.gempukku.lotro.logic.decisions.AwaitingDecisionType; import com.gempukku.lotro.logic.decisions.AwaitingDecisionType;
import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException; import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException;
import com.gempukku.lotro.logic.modifiers.Modifier;
import com.gempukku.lotro.logic.modifiers.ModifierFlag;
import com.gempukku.lotro.logic.modifiers.SpecialFlagModifier;
import com.gempukku.lotro.logic.timing.EffectResult; import com.gempukku.lotro.logic.timing.EffectResult;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import org.junit.Test; import org.junit.Test;
@@ -244,4 +248,67 @@ public class TimingAtTest extends AbstractAtTest {
assertEquals(1, moveFrom.get()); assertEquals(1, moveFrom.get());
assertEquals(1, moveTo.get()); assertEquals(1, moveTo.get());
} }
@Test
public void movementSiteAffecting() throws DecisionResultInvalidException {
initializeSimplestGame();
skipMulligans();
PhysicalCardImpl moveFromSite = new PhysicalCardImpl(100, "0_1234", P1,
new AbstractSite("Blah", Block.FELLOWSHIP, 1, 0, LotroCardBlueprint.Direction.LEFT) {
@Override
public Modifier getAlwaysOnModifier(PhysicalCard self) {
return new SpecialFlagModifier(self, ModifierFlag.RING_TEXT_INACTIVE);
}
});
moveFromSite.setSiteNumber(1);
PhysicalCardImpl moveToSite = new PhysicalCardImpl(100, "0_1235", P1,
new AbstractSite("Blah", Block.FELLOWSHIP, 2, 0, LotroCardBlueprint.Direction.LEFT) {
@Override
public Modifier getAlwaysOnModifier(PhysicalCard self) {
return new SpecialFlagModifier(self, ModifierFlag.CANT_PREVENT_WOUNDS);
}
});
moveToSite.setSiteNumber(2);
_game.getGameState().removeCardsFromZone(P1, Collections.singleton(_game.getGameState().getCurrentSite()));
_game.getGameState().addCardToZone(_game, moveFromSite, Zone.ADVENTURE_PATH);
_game.getGameState().addCardToZone(_game, moveToSite, Zone.ADVENTURE_PATH);
assertTrue(_game.getModifiersQuerying().hasFlagActive(_game.getGameState(), ModifierFlag.RING_TEXT_INACTIVE));
assertFalse(_game.getModifiersQuerying().hasFlagActive(_game.getGameState(), ModifierFlag.CANT_PREVENT_WOUNDS));
// End fellowship phase
playerDecided(P1, "");
// End shadow phase
playerDecided(P2, "");
assertFalse(_game.getModifiersQuerying().hasFlagActive(_game.getGameState(), ModifierFlag.RING_TEXT_INACTIVE));
assertTrue(_game.getModifiersQuerying().hasFlagActive(_game.getGameState(), ModifierFlag.CANT_PREVENT_WOUNDS));
// Pass in Regroup phase
assertEquals(Phase.REGROUP, _game.getGameState().getCurrentPhase());
playerDecided(P1, "");
assertEquals(Phase.REGROUP, _game.getGameState().getCurrentPhase());
playerDecided(P2, "");
// Decide not to move
assertEquals(Phase.REGROUP, _game.getGameState().getCurrentPhase());
playerDecided(P1, getMultipleDecisionIndex(_userFeedback.getAwaitingDecision(P1), "No"));
// Fellowship of player2
assertTrue(_game.getModifiersQuerying().hasFlagActive(_game.getGameState(), ModifierFlag.RING_TEXT_INACTIVE));
assertFalse(_game.getModifiersQuerying().hasFlagActive(_game.getGameState(), ModifierFlag.CANT_PREVENT_WOUNDS));
// End fellowship phase
playerDecided(P2, "");
// End shadow phase
playerDecided(P1, "");
assertFalse(_game.getModifiersQuerying().hasFlagActive(_game.getGameState(), ModifierFlag.RING_TEXT_INACTIVE));
assertTrue(_game.getModifiersQuerying().hasFlagActive(_game.getGameState(), ModifierFlag.CANT_PREVENT_WOUNDS));
}
} }

View File

@@ -3,7 +3,6 @@ package com.gempukku.lotro.server;
import com.gempukku.lotro.collection.CollectionsManager; import com.gempukku.lotro.collection.CollectionsManager;
import com.gempukku.lotro.db.DeckDAO; import com.gempukku.lotro.db.DeckDAO;
import com.gempukku.lotro.db.LeagueDAO; import com.gempukku.lotro.db.LeagueDAO;
import com.gempukku.lotro.db.LeagueSerieDAO;
import com.gempukku.lotro.db.vo.CollectionType; import com.gempukku.lotro.db.vo.CollectionType;
import com.gempukku.lotro.game.*; import com.gempukku.lotro.game.*;
import com.gempukku.lotro.hall.HallServer; import com.gempukku.lotro.hall.HallServer;
@@ -31,8 +30,6 @@ public class AdminResource extends AbstractResource {
@Context @Context
private LeagueDAO _leagueDao; private LeagueDAO _leagueDao;
@Context @Context
private LeagueSerieDAO _leagueSeasonDao;
@Context
private LotroCardBlueprintLibrary _library; private LotroCardBlueprintLibrary _library;
@Context @Context
private HallServer _hallServer; private HallServer _hallServer;
@@ -103,25 +100,6 @@ public class AdminResource extends AbstractResource {
return "OK"; return "OK";
} }
@Path("/addLeagueSeason")
@POST
public String addLeagueSeason(
@FormParam("leagueType") String leagueType,
@FormParam("type") String type,
@FormParam("format") String format,
@FormParam("product") String product,
@FormParam("start") int start,
@FormParam("end") int end,
@FormParam("maxMatches") int maxMatches,
@Context HttpServletRequest request) throws Exception {
validateAdmin(request);
_leagueSeasonDao.addSerie(leagueType, type, format, product, start, end, maxMatches);
return "OK";
}
@Path("/addItems") @Path("/addItems")
@POST @POST
public String addItems( public String addItems(
@@ -201,6 +179,6 @@ public class AdminResource extends AbstractResource {
if (collectionType.equals("permanent")) if (collectionType.equals("permanent"))
return new CollectionType("permanent", "My cards"); return new CollectionType("permanent", "My cards");
return _leagueService.getLeagueByType(collectionType).getCollectionType(); return _leagueService.getCollectionTypeByCode(collectionType);
} }
} }

View File

@@ -11,6 +11,7 @@ import com.gempukku.lotro.game.CardCollection;
import com.gempukku.lotro.game.LotroCardBlueprintLibrary; import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
import com.gempukku.lotro.game.LotroServer; import com.gempukku.lotro.game.LotroServer;
import com.gempukku.lotro.game.Player; import com.gempukku.lotro.game.Player;
import com.gempukku.lotro.league.LeagueSerieData;
import com.gempukku.lotro.league.LeagueService; import com.gempukku.lotro.league.LeagueService;
import com.gempukku.lotro.packs.PacksStorage; import com.gempukku.lotro.packs.PacksStorage;
import com.sun.jersey.spi.resource.Singleton; import com.sun.jersey.spi.resource.Singleton;
@@ -76,11 +77,10 @@ public class CollectionResource extends AbstractResource {
@Context HttpServletResponse response) throws ParserConfigurationException { @Context HttpServletResponse response) throws ParserConfigurationException {
Player resourceOwner = getResourceOwnerSafely(request, participantId); Player resourceOwner = getResourceOwnerSafely(request, participantId);
final League league = _leagueService.getLeagueByType(collectionType);
if (league != null)
_leagueService.ensurePlayerIsInLeague(resourceOwner, league);
CardCollection collection = getCollection(resourceOwner, collectionType); CardCollection collection = getCollection(resourceOwner, collectionType);
if (collection == null && !collectionType.equals("default") && !collectionType.equals("permanent"))
collection = _leagueService.ensurePlayerHasCollection(resourceOwner, collectionType);
if (collection == null) if (collection == null)
sendError(Response.Status.NOT_FOUND); sendError(Response.Status.NOT_FOUND);
@@ -145,10 +145,14 @@ public class CollectionResource extends AbstractResource {
Element collectionsElem = doc.createElement("collections"); Element collectionsElem = doc.createElement("collections");
for (League league : _leagueService.getActiveLeagues()) { for (League league : _leagueService.getActiveLeagues()) {
Element collectionElem = doc.createElement("collection"); LeagueSerieData serie = _leagueService.getCurrentLeagueSerie(league);
collectionElem.setAttribute("type", league.getType()); if (serie.isLimited()) {
collectionElem.setAttribute("name", league.getName()); CollectionType collectionType = serie.getCollectionType();
collectionsElem.appendChild(collectionElem); Element collectionElem = doc.createElement("collection");
collectionElem.setAttribute("type", collectionType.getCode());
collectionElem.setAttribute("name", collectionType.getFullName());
collectionsElem.appendChild(collectionElem);
}
} }
doc.appendChild(collectionsElem); doc.appendChild(collectionsElem);
@@ -215,6 +219,6 @@ public class CollectionResource extends AbstractResource {
if (collectionType.equals("permanent")) if (collectionType.equals("permanent"))
return new CollectionType("permanent", "My cards"); return new CollectionType("permanent", "My cards");
return _leagueService.getLeagueByType(collectionType).getCollectionType(); return _leagueService.getCollectionTypeByCode(collectionType);
} }
} }

View File

@@ -19,7 +19,6 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
private Injectable<GameHistoryDAO> _gameHistoryDAOInjectable; private Injectable<GameHistoryDAO> _gameHistoryDAOInjectable;
private Injectable<LeagueDAO> _leagueDaoInjectable; private Injectable<LeagueDAO> _leagueDaoInjectable;
private Injectable<LeagueSerieDAO> _leagueSeasonDAOInjectable;
private Injectable<LeagueMatchDAO> _leagueMatchDAOInjectable; private Injectable<LeagueMatchDAO> _leagueMatchDAOInjectable;
private Injectable<LeaguePointsDAO> _leaguePointsDAOInjectable; private Injectable<LeaguePointsDAO> _leaguePointsDAOInjectable;
@@ -43,8 +42,6 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
return getGameHistoryDaoSafely(); return getGameHistoryDaoSafely();
else if (type.equals(LeagueDAO.class)) else if (type.equals(LeagueDAO.class))
return getLeagueDaoSafely(); return getLeagueDaoSafely();
else if (type.equals(LeagueSerieDAO.class))
return getLeagueSeasonDaoSafely();
else if (type.equals(LeagueMatchDAO.class)) else if (type.equals(LeagueMatchDAO.class))
return getLeagueMatchDaoSafely(); return getLeagueMatchDaoSafely();
else if (type.equals(LeaguePointsDAO.class)) else if (type.equals(LeaguePointsDAO.class))
@@ -78,19 +75,6 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
return _leagueMatchDAOInjectable; return _leagueMatchDAOInjectable;
} }
private synchronized Injectable<LeagueSerieDAO> getLeagueSeasonDaoSafely() {
if (_leagueSeasonDAOInjectable == null) {
final LeagueSerieDAO leagueSeasonDao = new LeagueSerieDAO(_dbAccess);
_leagueSeasonDAOInjectable = new Injectable<LeagueSerieDAO>() {
@Override
public LeagueSerieDAO getValue() {
return leagueSeasonDao;
}
};
}
return _leagueSeasonDAOInjectable;
}
private synchronized Injectable<LeagueDAO> getLeagueDaoSafely() { private synchronized Injectable<LeagueDAO> getLeagueDaoSafely() {
if (_leagueDaoInjectable == null) { if (_leagueDaoInjectable == null) {
final LeagueDAO leagueDao = new LeagueDAO(_dbAccess, _collectionSerializer); final LeagueDAO leagueDao = new LeagueDAO(_dbAccess, _collectionSerializer);

View File

@@ -1,12 +1,12 @@
package com.gempukku.lotro.server; package com.gempukku.lotro.server;
import com.gempukku.lotro.db.vo.League; import com.gempukku.lotro.db.vo.League;
import com.gempukku.lotro.db.vo.LeagueSerie;
import com.gempukku.lotro.game.LotroFormat; import com.gempukku.lotro.game.LotroFormat;
import com.gempukku.lotro.game.Player; import com.gempukku.lotro.game.Player;
import com.gempukku.lotro.hall.HallException; import com.gempukku.lotro.hall.HallException;
import com.gempukku.lotro.hall.HallInfoVisitor; import com.gempukku.lotro.hall.HallInfoVisitor;
import com.gempukku.lotro.hall.HallServer; import com.gempukku.lotro.hall.HallServer;
import com.gempukku.lotro.league.LeagueSerieData;
import com.gempukku.lotro.league.LeagueService; import com.gempukku.lotro.league.LeagueService;
import com.sun.jersey.spi.resource.Singleton; import com.sun.jersey.spi.resource.Singleton;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@@ -57,7 +57,7 @@ public class HallResource extends AbstractResource {
hall.appendChild(formatElem); hall.appendChild(formatElem);
} }
for (League league : _leagueService.getActiveLeagues()) { for (League league : _leagueService.getActiveLeagues()) {
final LeagueSerie currentLeagueSerie = _leagueService.getCurrentLeagueSerie(league); final LeagueSerieData currentLeagueSerie = _leagueService.getCurrentLeagueSerie(league);
if (currentLeagueSerie != null) { if (currentLeagueSerie != null) {
Element formatElem = doc.createElement("format"); Element formatElem = doc.createElement("format");
formatElem.setAttribute("type", league.getType()); formatElem.setAttribute("type", league.getType());

View File

@@ -1,9 +1,8 @@
package com.gempukku.lotro.server; package com.gempukku.lotro.server;
import com.gempukku.lotro.db.LeagueDAO; import com.gempukku.lotro.db.LeagueDAO;
import com.gempukku.lotro.db.LeagueSerieDAO;
import com.gempukku.lotro.db.vo.League; import com.gempukku.lotro.db.vo.League;
import com.gempukku.lotro.db.vo.LeagueSerie; import com.gempukku.lotro.league.LeagueSerieData;
import com.gempukku.lotro.league.LeagueService; import com.gempukku.lotro.league.LeagueService;
import com.gempukku.lotro.league.LeagueStanding; import com.gempukku.lotro.league.LeagueStanding;
import com.sun.jersey.spi.resource.Singleton; import com.sun.jersey.spi.resource.Singleton;
@@ -26,8 +25,6 @@ public class LeagueResource extends AbstractResource {
private LeagueDAO _leagueDao; private LeagueDAO _leagueDao;
@Context @Context
private LeagueService _leagueService; private LeagueService _leagueService;
@Context
private LeagueSerieDAO _leagueSerieDao;
@GET @GET
public Document getLeagueInformation() throws ParserConfigurationException { public Document getLeagueInformation() throws ParserConfigurationException {
@@ -44,10 +41,10 @@ public class LeagueResource extends AbstractResource {
leagueElem.setAttribute("start", String.valueOf(league.getStart())); leagueElem.setAttribute("start", String.valueOf(league.getStart()));
leagueElem.setAttribute("end", String.valueOf(league.getEnd())); leagueElem.setAttribute("end", String.valueOf(league.getEnd()));
List<LeagueSerie> series = _leagueSerieDao.getSeriesForLeague(league); List<LeagueSerieData> series = league.getLeagueData().getSeries();
for (LeagueSerie serie : series) { for (LeagueSerieData serie : series) {
Element serieElem = doc.createElement("serie"); Element serieElem = doc.createElement("serie");
serieElem.setAttribute("type", serie.getType()); serieElem.setAttribute("type", serie.getName());
serieElem.setAttribute("maxMatches", String.valueOf(serie.getMaxMatches())); serieElem.setAttribute("maxMatches", String.valueOf(serie.getMaxMatches()));
serieElem.setAttribute("start", String.valueOf(serie.getStart())); serieElem.setAttribute("start", String.valueOf(serie.getStart()));
serieElem.setAttribute("end", String.valueOf(serie.getEnd())); serieElem.setAttribute("end", String.valueOf(serie.getEnd()));

View File

@@ -37,8 +37,6 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
@Context @Context
private LeagueDAO _leagueDao; private LeagueDAO _leagueDao;
@Context @Context
private LeagueSerieDAO _leagueSeasonDao;
@Context
private LeagueMatchDAO _leagueMatchDao; private LeagueMatchDAO _leagueMatchDao;
@Context @Context
private LeaguePointsDAO _leaguePointsDao; private LeaguePointsDAO _leaguePointsDao;
@@ -68,7 +66,7 @@ public class ServerProvider implements InjectableProvider<Context, Type> {
private synchronized Injectable<LeagueService> getLeagueServiceInjectable() { private synchronized Injectable<LeagueService> getLeagueServiceInjectable() {
if (_leagueServerInjectable == null) { if (_leagueServerInjectable == null) {
final LeagueService leagueService = new LeagueService(_leagueDao, _leagueSeasonDao, _leaguePointsDao, _leagueMatchDao, getCollectionsManagerInjectable().getValue()); final LeagueService leagueService = new LeagueService(_leagueDao, _leaguePointsDao, _leagueMatchDao, getCollectionsManagerInjectable().getValue());
_leagueServerInjectable = new Injectable<LeagueService>() { _leagueServerInjectable = new Injectable<LeagueService>() {
@Override @Override
public LeagueService getValue() { public LeagueService getValue() {