1.1 --- a/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java Sat Nov 27 09:10:44 2010 +0100
1.2 +++ b/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java Sat Nov 27 17:32:47 2010 +0100
1.3 @@ -17,6 +17,8 @@
1.4 */
1.5 package cz.xelfi.quoridor.freemarkerdor;
1.6
1.7 +import java.util.Collection;
1.8 +import java.util.Arrays;
1.9 import com.sun.jersey.api.client.Client;
1.10 import com.sun.jersey.api.client.ClientResponse;
1.11 import com.sun.jersey.api.client.WebResource;
1.12 @@ -29,6 +31,7 @@
1.13 import java.io.IOException;
1.14 import java.io.InputStream;
1.15 import java.net.URI;
1.16 +import java.util.HashSet;
1.17 import java.util.Locale;
1.18 import java.util.concurrent.Callable;
1.19 import java.util.regex.Matcher;
1.20 @@ -194,8 +197,8 @@
1.21 }
1.22
1.23 @Test public void testCreateGameOK() throws Exception {
1.24 - int origGames = new File(dir, "games").list().length;
1.25 -
1.26 + Collection<String> origGamesNames= Arrays.asList(new File(dir, "games").list());
1.27 + int origGames = origGamesNames.size();
1.28
1.29 String logTest = apiResource.path("login").
1.30 queryParam("name", "test").
1.31 @@ -217,14 +220,24 @@
1.32 final String txt = res.getEntity(String.class);
1.33 assertEquals("OK\n" + txt, ClientResponse.Status.OK, res.getClientResponseStatus());
1.34
1.35 - String[] games = new File(dir, "games").list();
1.36 - assertEquals("One new game", origGames + 1, games.length);
1.37 -
1.38 - if (txt.indexOf(games[0]) == -1) {
1.39 - fail(games[0] + " expected inside of:\n" + txt);
1.40 +
1.41 + String myGame;
1.42 + {
1.43 + String[] games = new File(dir, "games").list();
1.44 + assertEquals("One new game", origGames + 1, games.length);
1.45 +
1.46 + HashSet<String> newNames = new HashSet<String>();
1.47 + newNames.addAll(Arrays.asList(games));
1.48 + newNames.removeAll(origGamesNames);
1.49 + assertEquals("Just one name left: " + newNames, 1, newNames.size());
1.50 + myGame = newNames.iterator().next();
1.51 }
1.52
1.53 - ClientResponse page = webResource.path("games/" + games[0]).
1.54 + if (txt.indexOf(myGame) == -1) {
1.55 + fail(myGame + " expected inside of:\n" + txt);
1.56 + }
1.57 +
1.58 + ClientResponse page = webResource.path("games/" + myGame).
1.59 cookie(Cookie.valueOf("login=" + logJarda)).
1.60 get(ClientResponse.class);
1.61 String ptxt = page.getEntity(String.class);
1.62 @@ -237,7 +250,7 @@
1.63 InputStream img1 = webResource.path(m.group(1)).get(InputStream.class);
1.64 assertNotNull("image found", img1);
1.65
1.66 - ClientResponse move = apiResource.path("games/" + games[0]).
1.67 + ClientResponse move = apiResource.path("games/" + myGame).
1.68 queryParam("loginID", logJarda).
1.69 queryParam("player", "Jarda").queryParam("move", "N").put(ClientResponse.class);
1.70 assertEquals("Move OK:\n" + move.getEntity(String.class), ClientResponse.Status.OK, move.getClientResponseStatus());
1.71 @@ -245,7 +258,7 @@
1.72 InputStream img2 = webResource.path(m.group(1)).get(InputStream.class);
1.73 assertNotNull("image found", img2);
1.74
1.75 - ClientResponse page2 = webResource.path("games/" + games[0]).
1.76 + ClientResponse page2 = webResource.path("games/" + myGame).
1.77 cookie(Cookie.valueOf("login=" + logJarda)).
1.78 get(ClientResponse.class);
1.79 String ptxt2 = page2.getEntity(String.class);