1.1 --- a/webidor/src/test/java/cz/xelfi/quoridor/webidor/resources/ChatTest.java Sun Nov 08 10:21:46 2009 +0100
1.2 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/resources/ChatTest.java Sun Sep 12 00:06:44 2010 +0200
1.3 @@ -26,6 +26,8 @@
1.4
1.5 package cz.xelfi.quoridor.webidor.resources;
1.6
1.7 +import com.sun.jersey.test.framework.WebAppDescriptor;
1.8 +import com.sun.jersey.test.framework.AppDescriptor;
1.9 import com.sun.jersey.test.framework.JerseyTest;
1.10 import cz.xelfi.quoridor.Board;
1.11 import cz.xelfi.quoridor.Move;
1.12 @@ -55,21 +57,21 @@
1.13 }
1.14 private File dir;
1.15
1.16 - public ChatTest() throws Exception {
1.17 - super("cz.xelfi.quoridor.webidor.resources");
1.18 - }
1.19 -
1.20 @Override
1.21 - public void setUp() throws Exception {
1.22 - dir = File.createTempFile("quoridor", ".dir");
1.23 - dir.delete();
1.24 - System.setProperty("quoridor.dir", dir.getPath());
1.25 - dir.mkdirs();
1.26 - File passwd = new File(dir, "passwd");
1.27 - FileOutputStream os = new FileOutputStream(passwd);
1.28 - os.write("Jarda=heslo\nJirka=pesko\n".getBytes("UTF-8"));
1.29 - os.close();
1.30 - super.setUp();
1.31 + protected AppDescriptor configure() {
1.32 + try {
1.33 + dir = File.createTempFile("quoridor", ".dir");
1.34 + dir.delete();
1.35 + System.setProperty("quoridor.dir", dir.getPath());
1.36 + dir.mkdirs();
1.37 + File passwd = new File(dir, "passwd");
1.38 + FileOutputStream os = new FileOutputStream(passwd);
1.39 + os.write("Jarda=heslo\nJirka=pesko\n".getBytes("UTF-8"));
1.40 + os.close();
1.41 + } catch (Exception ex) {
1.42 + throw new IllegalStateException(ex);
1.43 + }
1.44 + return new WebAppDescriptor.Builder("cz.xelfi.quoridor.webidor.resources").build();
1.45 }
1.46
1.47 @Override
1.48 @@ -92,17 +94,17 @@
1.49 }
1.50
1.51 @Test public void testCreateAGame() throws Exception {
1.52 - String logJarda = webResource.path("login").
1.53 + String logJarda = resource().path("login").
1.54 queryParam("name", "Jarda").
1.55 queryParam("password", "heslo").
1.56 accept(MediaType.TEXT_PLAIN).
1.57 put(String.class);
1.58 - String logJirka = webResource.path("login").
1.59 + String logJirka = resource().path("login").
1.60 queryParam("name", "Jirka").
1.61 queryParam("password", "pesko").
1.62 accept(MediaType.TEXT_PLAIN).
1.63 put(String.class);
1.64 - GameId s = webResource.path("games").queryParam("loginID", logJarda).
1.65 + GameId s = resource().path("games").queryParam("loginID", logJarda).
1.66 queryParam("white", "Jarda")
1.67 .queryParam("black", "Jirka").post(GameId.class);
1.68
1.69 @@ -116,21 +118,21 @@
1.70 ResourceBundle b = ResourceBundle.getBundle("cz/xelfi/quoridor/webidor/TestBundle");
1.71 String comment = b.getString("COMMENT");
1.72
1.73 - GameId s1 = webResource.path("games/" + s.getId()).
1.74 + GameId s1 = resource().path("games/" + s.getId()).
1.75 queryParam("loginID", logJarda).
1.76 queryParam("player", "Jarda").queryParam("move", "N").put(GameId.class);
1.77
1.78 - GameId comment1 = webResource.path("games/" + s.getId()).
1.79 + GameId comment1 = resource().path("games/" + s.getId()).
1.80 queryParam("loginID", logJarda).
1.81 queryParam("player", "Jarda").queryParam("comment", "I like this game!").put(GameId.class);
1.82 assertEquals("One comment in the game", 1, comment1.getComments());
1.83
1.84 - GameId comment2 = webResource.path("games/" + s.getId()).
1.85 + GameId comment2 = resource().path("games/" + s.getId()).
1.86 queryParam("loginID", logJirka).
1.87 queryParam("player", "Jirka").queryParam("comment", comment).put(GameId.class);
1.88 assertEquals("Snd comment in the game", 2, comment2.getComments());
1.89
1.90 - GameId s2 = webResource.path("games/" + s.getId()).
1.91 + GameId s2 = resource().path("games/" + s.getId()).
1.92 queryParam("loginID", logJirka).
1.93 queryParam("player", "Jirka").queryParam("move", "S").put(GameId.class);
1.94 assertNotNull("Successful move", s2);
1.95 @@ -191,8 +193,8 @@
1.96
1.97 assertEquals("Newly written file remains the same", sss1, readFile(tmp).replaceAll("@.*:", "date"));
1.98
1.99 - String sGame = webResource.path("games").path(s.getId()).accept(MediaType.TEXT_XML).get(String.class);
1.100 - Game readGame = webResource.path("games").path(s.getId()).accept(MediaType.TEXT_XML).get(Game.class);
1.101 + String sGame = resource().path("games").path(s.getId()).accept(MediaType.TEXT_XML).get(String.class);
1.102 + Game readGame = resource().path("games").path(s.getId()).accept(MediaType.TEXT_XML).get(Game.class);
1.103 assertNotNull("Game really returned", readGame);
1.104
1.105 assertEquals(Move.NORTH, readGame.getMoves().get(0).getMove());