Adding support for 'permission.games' to allow special roles to enlist all the available games
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * The contents of this file are subject to the terms of either the GNU
5 * General Public License Version 2 only ("GPL") or the Common
6 * Development and Distribution License("CDDL") (collectively, the
7 * "License"). You may not use this file except in compliance with the
8 * License. You can obtain a copy of the License at
9 * http://www.netbeans.org/cddl-gplv2.html
10 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
11 * specific language governing permissions and limitations under the
12 * License. When distributing the software, include this License Header
13 * Notice in each file and include the License file at
14 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
15 * particular file as subject to the "Classpath" exception as provided
16 * by Sun in the GPL Version 2 section of the License file that
17 * accompanied this code. If applicable, add the following below the
18 * License Header, with the fields enclosed by brackets [] replaced by
19 * your own identifying information:
20 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Portions Copyrighted 2009 Jaroslav Tulach
27 package cz.xelfi.quoridor.webidor;
29 import com.sun.jersey.api.client.GenericType;
30 import java.util.List;
31 import com.sun.jersey.api.client.UniformInterfaceException;
32 import com.sun.jersey.test.framework.JerseyTest;
34 import java.io.FileOutputStream;
35 import java.io.IOException;
36 import java.util.Properties;
37 import javax.ws.rs.core.MediaType;
38 import org.junit.Test;
39 import static org.junit.Assert.*;
43 * @author Jaroslav Tulach <jtulach@netbeans.org>
45 public class AllGamesTest extends JerseyTest {
47 System.setProperty("JERSEY_HTTP_PORT", "45420");
52 public AllGamesTest() throws Exception {
53 super("cz.xelfi.quoridor.webidor.resources");
57 public void setUp() throws Exception {
58 dir = File.createTempFile("quoridor", ".dir");
60 System.setProperty("quoridor.dir", dir.getPath());
62 File passwd = new File(dir, "passwd");
63 FileOutputStream os = new FileOutputStream(passwd);
64 os.write("Jarda=heslo\nJirka=pesko\nJan=pan\n".getBytes("UTF-8"));
70 public void tearDown() throws Exception {
74 static void deleteRec(File dir) throws IOException {
78 File[] arr = dir.listFiles();
86 @Test public void testListGames() throws Exception {
87 File usersDir = new File(dir, "users");
89 File fJarda = new File(usersDir, "Jarda");
91 Properties p = new Properties();
92 p.setProperty("email", "jar@da.cz");
93 p.setProperty("permission.games", "true");
94 p.store(new FileOutputStream(fJarda), "");
96 File fJirka = new File(usersDir, "Jirka");
98 Properties p = new Properties();
99 p.setProperty("email", "jir@ka.cz");
100 p.store(new FileOutputStream(fJirka), "");
102 File fJan = new File(usersDir, "Jan");
104 Properties p = new Properties();
105 p.setProperty("email", "j@an.cz");
106 p.store(new FileOutputStream(fJan), "");
109 String logRoot = webResource.path("login").
110 queryParam("name", "Jarda").
111 queryParam("password", "heslo").
112 accept(MediaType.TEXT_PLAIN).
114 String logJirka = webResource.path("login").
115 queryParam("name", "Jirka").
116 queryParam("password", "pesko").
117 accept(MediaType.TEXT_PLAIN).
119 String logJan = webResource.path("login").
120 queryParam("name", "Jan").
121 queryParam("password", "pan").
122 accept(MediaType.TEXT_PLAIN).
125 GameId s = webResource.path("games").queryParam("white", "Jan")
126 .queryParam("loginID", logJan)
127 .queryParam("black", "Jirka").post(GameId.class);
128 webResource.path("games/" + s.getId())
129 .queryParam("loginID", logJan)
130 .queryParam("player", "Jan").queryParam("move", "RESIGN").put(GameId.class);
132 GenericType<List<GameId>> gType = new GenericType<List<GameId>>() {};
133 List<GameId> all = webResource.path("games/").queryParam("loginID", logRoot).accept(MediaType.TEXT_XML).get(gType);
134 boolean found = false;
135 for (GameId id : all) {
136 if (id.getId().equals(s.getId())) {
141 assertTrue("List of games shall contai all games: " + all, found);
143 Game end = webResource.path("games/" + s.getId()).queryParam("loginID", logRoot).accept(MediaType.TEXT_XML).get(Game.class);
144 assertEquals("One can see status of games with priviledges", GameStatus.blackWon, end.getId().getStatus());