# HG changeset patch # User Jaroslav Tulach # Date 1255894407 -7200 # Node ID eba04a2569d0fe8d525025fbe3ee22453dabf35f # Parent ac8fff40babc63d9f86902ff95acd04aeb61abaa Can list just games with certain status diff -r ac8fff40babc -r eba04a2569d0 webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Sun Oct 18 20:55:21 2009 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Sun Oct 18 21:33:27 2009 +0200 @@ -34,8 +34,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -181,10 +179,14 @@ @GET @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_XML }) - public List listGames() { + public List listGames( + @DefaultValue("") @QueryParam("status") String status + ) { List arr = new ArrayList(games.size()); for (Game g : games) { - arr.add(g.getId()); + if (status.length() == 0 || g.getId().getStatus().toString().equals(status)) { + arr.add(g.getId()); + } } Collections.sort(arr, GameId.NEWEST_FIRST); return arr; diff -r ac8fff40babc -r eba04a2569d0 webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java --- a/webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java Sun Oct 18 20:55:21 2009 +0200 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java Sun Oct 18 21:33:27 2009 +0200 @@ -26,10 +26,12 @@ package cz.xelfi.quoridor.webidor; +import com.sun.jersey.api.client.GenericType; import com.sun.jersey.test.framework.JerseyTest; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.util.List; import javax.ws.rs.core.MediaType; import org.junit.Test; import static org.junit.Assert.*; @@ -115,6 +117,11 @@ .queryParam("loginID", logJirka) .queryParam("player", "Jirka").queryParam("move", "SS").put(GameId.class); + + GenericType> gType = new GenericType>() {}; + List nothing = webResource.path("games/").queryParam("status", "blackWon").accept(MediaType.TEXT_XML).get(gType); + assertTrue("Nothing has been finished yet: " + nothing, nothing.isEmpty()); + for (int i = 0; i < 3; i++) { webResource.path("games/" + s.getId()) .queryParam("loginID", logJarda) @@ -124,8 +131,14 @@ .queryParam("player", "Jirka").queryParam("move", "S").put(GameId.class); } + Game end = webResource.path("games/" + s.getId()).accept(MediaType.TEXT_XML).get(Game.class); assertEquals("BlackWins", GameStatus.blackWon, end.getId().getStatus()); + + List something = webResource.path("games/").queryParam("status", "blackWon").accept(MediaType.TEXT_XML).get(gType); + + assertEquals("One game finished: " + something, 1, something.size()); + assertEquals("Id is OK", end.getId().getId(), something.get(0).getId()); } @Test public void testResignAGame() throws Exception {