2 * Quoridor server and related libraries
3 * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://www.gnu.org/licenses/.
19 package cz.xelfi.quoridor.webidor;
21 import cz.xelfi.quoridor.webidor.resources.Games;
22 import cz.xelfi.quoridor.webidor.resources.Quoridor;
24 import java.io.FileOutputStream;
25 import java.io.IOException;
26 import java.util.ResourceBundle;
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import static org.junit.Assert.*;
34 * @author Jaroslav Tulach <jtulach@netbeans.org>
36 public class GamesTest extends Object {
38 System.setProperty("JERSEY_HTTP_PORT", "33436");
43 public void setUp() throws Exception {
44 dir = File.createTempFile("quoridor", ".dir");
47 System.setProperty("quoridor.dir", dir.getPath());
51 public void tearDown() throws Exception {
55 static void deleteRec(File dir) throws IOException {
59 File[] arr = dir.listFiles();
68 @Test public void testCreateAGame() throws Exception {
69 File f = new File(new File(dir, "games"), "x");
70 f.getParentFile().mkdirs();
71 FileOutputStream os = new FileOutputStream(f);
72 os.write("# white: W\n# black: B\n# status: IN_PROGRESS\nN S\n\n".getBytes("UTF-8"));
77 long middle = f.lastModified();
81 Games games = new Games(f.getParentFile(), new Quoridor());
82 Game g = games.getBoardInfo("", "x", -1);
83 assertNotNull("Game found", g);
84 assertNotNull("Board found", g.getBoard());
85 assertEquals("List of moves has two", 2, g.getMoves().size());
87 assertEquals("Last move is last touch of the file", middle, g.getId().getModified());
90 @Test public void testLoadGameWithComments() throws Exception {
91 File f = new File(new File(dir, "games"), "x");
92 f.getParentFile().mkdirs();
93 FileOutputStream os = new FileOutputStream(f);
94 os.write("# white: W\n# black: B\n# status: IN_PROGRESS\nN #good move\n... S # ok move\n\n".getBytes("UTF-8"));
99 long middle = f.lastModified();
103 Games games = new Games(f.getParentFile(), new Quoridor());
104 Game g = games.getBoardInfo("", "x", -1);
105 assertNotNull("Game found", g);
106 assertNotNull("Board found", g.getBoard());
107 assertEquals("List of moves has two", 2, g.getMoves().size());
109 assertEquals("Last move is last touch of the file", middle, g.getId().getModified());
112 @Test public void testLoadGameWithInternationalComments() throws Exception {
113 File f = new File(new File(dir, "games"), "x");
114 f.getParentFile().mkdirs();
115 FileOutputStream os = new FileOutputStream(f);
116 ResourceBundle b = ResourceBundle.getBundle("cz/xelfi/quoridor/webidor/TestBundle");
117 String comment = b.getString("COMMENT");
118 os.write(("# white: W\n# black: B\n# status: IN_PROGRESS\nN\n#" +
119 comment + "\n... S # ok move\n\n").getBytes("UTF-8"));
124 long middle = f.lastModified();
128 Games games = new Games(f.getParentFile(), new Quoridor());
129 Game g = games.getBoardInfo("", "x", -1);
130 assertNotNull("Game found", g);
131 assertNotNull("Board found", g.getBoard());
132 assertEquals("List of moves has two", 2, g.getMoves().size());
133 String commentRead = g.getMoves().get(0).getComments().get(0).getComment();
134 assertEquals(comment, commentRead);
136 assertEquals("Last move is last touch of the file", middle, g.getId().getModified());