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");
46 System.setProperty("quoridor.dir", dir.getPath());
50 public void tearDown() throws Exception {
54 static void deleteRec(File dir) throws IOException {
58 File[] arr = dir.listFiles();
67 @Test public void testCreateAGame() throws Exception {
68 File f = new File(dir, "x");
69 f.getParentFile().mkdirs();
70 FileOutputStream os = new FileOutputStream(f);
71 os.write("# white: W\n# black: B\n# status: IN_PROGRESS\nN S\n\n".getBytes("UTF-8"));
76 long middle = f.lastModified();
80 Games games = new Games(dir, new Quoridor());
81 Game g = games.getBoardInfo("", "x", -1);
82 assertNotNull("Game found", g);
83 assertNotNull("Board found", g.getBoard());
84 assertEquals("List of moves has two", 2, g.getMoves().size());
86 assertEquals("Last move is last touch of the file", middle, g.getId().getModified());
89 @Test public void testLoadGameWithComments() throws Exception {
90 File f = new File(dir, "x");
91 f.getParentFile().mkdirs();
92 FileOutputStream os = new FileOutputStream(f);
93 os.write("# white: W\n# black: B\n# status: IN_PROGRESS\nN #good move\n... S # ok move\n\n".getBytes("UTF-8"));
98 long middle = f.lastModified();
102 Games games = new Games(dir, new Quoridor());
103 Game g = games.getBoardInfo("", "x", -1);
104 assertNotNull("Game found", g);
105 assertNotNull("Board found", g.getBoard());
106 assertEquals("List of moves has two", 2, g.getMoves().size());
108 assertEquals("Last move is last touch of the file", middle, g.getId().getModified());
111 @Test public void testLoadGameWithInternationalComments() throws Exception {
112 File f = new File(dir, "x");
113 f.getParentFile().mkdirs();
114 FileOutputStream os = new FileOutputStream(f);
115 ResourceBundle b = ResourceBundle.getBundle("cz/xelfi/quoridor/webidor/TestBundle");
116 String comment = b.getString("COMMENT");
117 os.write(("# white: W\n# black: B\n# status: IN_PROGRESS\nN\n#" +
118 comment + "\n... S # ok move\n\n").getBytes("UTF-8"));
123 long middle = f.lastModified();
127 Games games = new Games(dir, new Quoridor());
128 Game g = games.getBoardInfo("", "x", -1);
129 assertNotNull("Game found", g);
130 assertNotNull("Board found", g.getBoard());
131 assertEquals("List of moves has two", 2, g.getMoves().size());
132 String commentRead = g.getMoves().get(0).getComments().get(0).getComment();
133 assertEquals(comment, commentRead);
135 assertEquals("Last move is last touch of the file", middle, g.getId().getModified());