mirror of
https://github.com/correl/mage.git
synced 2024-11-28 19:19:55 +00:00
Removed using bdd tests because of weird behaeve framework.
This commit is contained in:
parent
0ce1f50734
commit
ddf1866d6e
6 changed files with 0 additions and 296 deletions
|
@ -88,11 +88,6 @@
|
|||
<version>${project.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jbehave</groupId>
|
||||
<artifactId>jbehave-core</artifactId>
|
||||
<version>3.2-beta-1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<pluginRepositories>
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
package mage.server.bdd;
|
||||
|
||||
import org.jbehave.core.configuration.Configuration;
|
||||
import org.jbehave.core.configuration.MostUsefulConfiguration;
|
||||
import org.jbehave.core.embedder.Embedder;
|
||||
import org.jbehave.core.io.CodeLocations;
|
||||
import org.jbehave.core.io.LoadFromRelativeFile;
|
||||
import org.jbehave.core.io.StoryResourceNotFound;
|
||||
import org.jbehave.core.reporters.StoryReporterBuilder;
|
||||
import org.jbehave.core.steps.CandidateSteps;
|
||||
import org.jbehave.core.steps.InstanceStepsFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains configuration for working with steps and stories in Mage.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class MageEmbedder extends Embedder {
|
||||
|
||||
/**
|
||||
* We meed to extend LoadFromRelativeFile because of bug in replacing slashes
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
private class MageStoryFilePath extends LoadFromRelativeFile {
|
||||
|
||||
private final StoryFilePath[] traversals;
|
||||
private final URL location;
|
||||
|
||||
public MageStoryFilePath(URL location, StoryFilePath... traversals) {
|
||||
super(location, traversals);
|
||||
this.location = location;
|
||||
this.traversals = traversals;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String loadResourceAsText(String resourcePath) {
|
||||
List<String> traversalPaths = new ArrayList<String>();
|
||||
String locationPath = new File(location.getFile()).getAbsolutePath();
|
||||
|
||||
String filePath = locationPath.replace("target\\test-classes", "src/test/java") + "/" + resourcePath;
|
||||
File file = new File(filePath);
|
||||
if (file.exists()) {
|
||||
return loadContent(filePath);
|
||||
}
|
||||
|
||||
throw new StoryResourceNotFound(resourcePath, traversalPaths);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration configuration() {
|
||||
Class<?> embedderClass = this.getClass();
|
||||
URL codeLocation = CodeLocations.codeLocationFromClass(embedderClass);
|
||||
Configuration configuration = new MostUsefulConfiguration()
|
||||
.useStoryLoader(new MageStoryFilePath(codeLocation, LoadFromRelativeFile.mavenModuleTestStoryFilePath("src/test/java") ))
|
||||
.useStoryReporterBuilder(new StoryReporterBuilder()
|
||||
.withCodeLocation(codeLocation)
|
||||
.withDefaultFormats());
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CandidateSteps> candidateSteps() {
|
||||
return new InstanceStepsFactory(configuration(), new MageSteps()).createCandidateSteps();
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package mage.server.bdd;
|
||||
|
||||
import org.jbehave.core.annotations.Given;
|
||||
import org.jbehave.core.annotations.Then;
|
||||
import org.jbehave.core.annotations.When;
|
||||
|
||||
/**
|
||||
* Defines Mage BDD steps.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class MageSteps {
|
||||
|
||||
@Given("I'm in the game")
|
||||
public void inTheGame() {
|
||||
System.out.println("In the game");
|
||||
}
|
||||
|
||||
@Given("I have an \"$card\" card")
|
||||
public void hasACard(String card) {
|
||||
System.out.println("card: " + card);
|
||||
}
|
||||
|
||||
@Given("phase is $own \"$phase\"")
|
||||
public void hasPhase(String own, String phase) {
|
||||
System.out.println("phase is: " + own + " -> " + phase);
|
||||
}
|
||||
|
||||
@When("I splay \"$card\"")
|
||||
public void playCard(String card) {
|
||||
System.out.println("play a card: " + card);
|
||||
}
|
||||
|
||||
@Then("there is an \"$card\" on $zone")
|
||||
public void playCard(String card, String zone) {
|
||||
System.out.println("checking: " + card + ", zone=" + zone);
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package mage.server.bdd;
|
||||
|
||||
import org.jbehave.core.io.StoryFinder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
/**
|
||||
* Runs Mage stories (tests)
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class MageStoryRunner {
|
||||
public static void main(String[] argv) throws Throwable {
|
||||
MageEmbedder embedder = new MageEmbedder();
|
||||
List<String> storyPaths = (new StoryFinder()).findPaths("src/test/java", asList("stories/land.story"), null);
|
||||
System.out.println("Found stories count: " + storyPaths.size());
|
||||
embedder.runStoriesAsPaths(storyPaths);
|
||||
}
|
||||
}
|
|
@ -1,152 +0,0 @@
|
|||
package mage.server.bdd;
|
||||
|
||||
import mage.interfaces.MageException;
|
||||
import mage.interfaces.Server;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.interfaces.callback.CallbackClient;
|
||||
import mage.interfaces.callback.CallbackClientDaemon;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.Main;
|
||||
import mage.sets.Sets;
|
||||
import mage.util.Logging;
|
||||
import mage.view.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Proof of concept of running game from tests.\
|
||||
* Will be removed later when BDD is finished.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class StoryRunPOC {
|
||||
|
||||
private static Logger logger = Logging.getLogger(StoryRunPOC.class.getName());
|
||||
|
||||
private static UUID sessionId;
|
||||
private static Server server;
|
||||
private static String userName;
|
||||
private static ServerState serverState;
|
||||
private static CallbackClientDaemon callbackDaemon;
|
||||
private static UUID gameId;
|
||||
private static UUID playerId;
|
||||
private static CardView cardPlayed;
|
||||
|
||||
@Test
|
||||
public void testEmpty() {
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] argv) throws Exception {
|
||||
String[] args = new String[] {"-testMode=true"};
|
||||
Main.main(args);
|
||||
connect("player", "localhost", 17171);
|
||||
UUID roomId = server.getMainRoomId();
|
||||
|
||||
List<String> playerTypes = new ArrayList<String>();
|
||||
playerTypes.add("Human");
|
||||
playerTypes.add("Computer - default");
|
||||
TableView table = server.createTable(sessionId, roomId, "Two Player Duel", "Limited", playerTypes, null, null);
|
||||
System.out.println("Cards in the deck: " + Sets.loadDeck("UW Control.dck").getCards().size());
|
||||
server.joinTable(sessionId, roomId, table.getTableId(), "Human", Sets.loadDeck("UW Control.dck"));
|
||||
server.joinTable(sessionId, roomId, table.getTableId(), "Computer", Sets.loadDeck("UW Control.dck"));
|
||||
server.startGame(sessionId, roomId, table.getTableId());
|
||||
}
|
||||
|
||||
public static void connect(String userName, String serverName, int port) {
|
||||
try {
|
||||
System.setSecurityManager(null);
|
||||
Registry reg = LocateRegistry.getRegistry(serverName, port);
|
||||
server = (Server) reg.lookup("mage-server");
|
||||
sessionId = server.registerClient(userName, UUID.randomUUID());
|
||||
CallbackClient client = new CallbackClient(){
|
||||
@Override
|
||||
public void processCallback(ClientCallback callback) {
|
||||
logger.info("IN >> " + callback.getMessageId() + " - " + callback.getMethod());
|
||||
try {
|
||||
if (callback.getMethod().equals("startGame")) {
|
||||
UUID[] data = (UUID[]) callback.getData();
|
||||
gameId = data[0];
|
||||
playerId = data[1];
|
||||
server.joinGame(gameId, sessionId);
|
||||
} else if (callback.getMethod().equals("gameInit")) {
|
||||
server.ack("gameInit", sessionId);
|
||||
} else if (callback.getMethod().equals("gameAsk")) {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
logger.info("ASK >> " + message.getMessage());
|
||||
if (message.getMessage().equals("Do you want to take a mulligan?")) {
|
||||
server.sendPlayerBoolean(gameId, sessionId, false);
|
||||
}
|
||||
} else if (callback.getMethod().equals("gameTarget")) {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
logger.info("TARGET >> " + message.getMessage() + " >> " + message.getTargets());
|
||||
if (message.getMessage().equals("Select a starting player")) {
|
||||
logger.info(" Sending >> " + playerId);
|
||||
server.sendPlayerUUID(gameId, sessionId, playerId);
|
||||
}
|
||||
} else if (callback.getMethod().equals("gameSelect")) {
|
||||
GameClientMessage message = (GameClientMessage) callback.getData();
|
||||
logger.info("SELECT >> " + message.getMessage());
|
||||
if (!message.getMessage().startsWith("Precombat Main - play spells and sorceries.")) {
|
||||
server.sendPlayerBoolean(gameId, sessionId, false);
|
||||
} else {
|
||||
if (cardPlayed == null) {
|
||||
CardsView cards = message.getGameView().getHand();
|
||||
CardView landToPlay = null;
|
||||
for (CardView card : cards.values()) {
|
||||
//System.out.println(card.getName());
|
||||
if (card.getName().equals("Plains") || card.getName().equals("Island")) {
|
||||
landToPlay = card;
|
||||
}
|
||||
}
|
||||
if (landToPlay != null) {
|
||||
logger.info("Playing " + landToPlay);
|
||||
server.sendPlayerUUID(gameId, sessionId, landToPlay.getId());
|
||||
cardPlayed = landToPlay;
|
||||
} else {
|
||||
logger.warning("Couldn't find land to play");
|
||||
}
|
||||
} else {
|
||||
logger.info("Checking battlefield...");
|
||||
boolean foundPlayer = false;
|
||||
boolean foundLand = false;
|
||||
for (PlayerView player: message.getGameView().getPlayers()) {
|
||||
if (player.getPlayerId().equals(playerId)) {
|
||||
foundPlayer = true;
|
||||
for (PermanentView permanent : player.getBattlefield().values()) {
|
||||
if (permanent.getId().equals(cardPlayed.getId())) {
|
||||
foundLand = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
logger.info(" found player: " + foundPlayer);
|
||||
logger.info(" found land: " + foundLand);
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info(e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
callbackDaemon = new CallbackClientDaemon(sessionId, client, server);
|
||||
serverState = server.getServerState();
|
||||
} catch (MageException ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
} catch (RemoteException ex) {
|
||||
logger.log(Level.SEVERE, "Unable to connect to server - ", ex);
|
||||
} catch (NotBoundException ex) {
|
||||
logger.log(Level.SEVERE, "Unable to connect to server - ", ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
Scenario: player plays Land on his main phase
|
||||
|
||||
Given I'm in the game
|
||||
And I have an "Island" card
|
||||
And phase is my "Precombat Main"
|
||||
When I play "Island"
|
||||
Then there is an "Island" on battlefield
|
Loading…
Reference in a new issue