jtulach@35
|
1 |
/*
|
jtulach@35
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
jtulach@35
|
3 |
*
|
jtulach@35
|
4 |
* The contents of this file are subject to the terms of either the GNU
|
jtulach@35
|
5 |
* General Public License Version 2 only ("GPL") or the Common
|
jtulach@35
|
6 |
* Development and Distribution License("CDDL") (collectively, the
|
jtulach@35
|
7 |
* "License"). You may not use this file except in compliance with the
|
jtulach@35
|
8 |
* License. You can obtain a copy of the License at
|
jtulach@35
|
9 |
* http://www.netbeans.org/cddl-gplv2.html
|
jtulach@35
|
10 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
jtulach@35
|
11 |
* specific language governing permissions and limitations under the
|
jtulach@35
|
12 |
* License. When distributing the software, include this License Header
|
jtulach@35
|
13 |
* Notice in each file and include the License file at
|
jtulach@35
|
14 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
|
jtulach@35
|
15 |
* particular file as subject to the "Classpath" exception as provided
|
jtulach@35
|
16 |
* by Sun in the GPL Version 2 section of the License file that
|
jtulach@35
|
17 |
* accompanied this code. If applicable, add the following below the
|
jtulach@35
|
18 |
* License Header, with the fields enclosed by brackets [] replaced by
|
jtulach@35
|
19 |
* your own identifying information:
|
jtulach@35
|
20 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
jtulach@35
|
21 |
*
|
jtulach@35
|
22 |
* Contributor(s):
|
jtulach@35
|
23 |
*
|
jtulach@35
|
24 |
* Portions Copyrighted 2009 Jaroslav Tulach
|
jtulach@35
|
25 |
*/
|
jtulach@35
|
26 |
|
jtulach@35
|
27 |
package cz.xelfi.quoridor.webidor;
|
jtulach@35
|
28 |
|
jtulach@35
|
29 |
import com.sun.jersey.api.client.GenericType;
|
jtulach@35
|
30 |
import com.sun.jersey.api.client.UniformInterfaceException;
|
jtulach@35
|
31 |
import com.sun.jersey.core.header.MediaTypes;
|
jtulach@35
|
32 |
import com.sun.jersey.test.framework.JerseyTest;
|
jtulach@35
|
33 |
import java.util.List;
|
jtulach@35
|
34 |
import org.junit.Test;
|
jtulach@35
|
35 |
import static org.junit.Assert.*;
|
jtulach@35
|
36 |
|
jtulach@35
|
37 |
/**
|
jtulach@35
|
38 |
*
|
jtulach@35
|
39 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jtulach@35
|
40 |
*/
|
jtulach@35
|
41 |
public class QuoridorTest extends JerseyTest {
|
jtulach@35
|
42 |
|
jtulach@35
|
43 |
public QuoridorTest() throws Exception {
|
jtulach@35
|
44 |
super("cz.xelfi.quoridor.webidor.resources");
|
jtulach@35
|
45 |
}
|
jtulach@35
|
46 |
|
jtulach@35
|
47 |
/**
|
jtulach@35
|
48 |
* Test if a WADL document is available at the relative path
|
jtulach@35
|
49 |
* "application.wadl".
|
jtulach@35
|
50 |
*/
|
jtulach@35
|
51 |
@Test public void testApplicationWadl() {
|
jtulach@35
|
52 |
String serviceWadl = webResource.path("application.wadl").
|
jtulach@35
|
53 |
accept(MediaTypes.WADL).get(String.class);
|
jtulach@35
|
54 |
assertTrue(serviceWadl.length() > 0);
|
jtulach@35
|
55 |
}
|
jtulach@35
|
56 |
|
jtulach@35
|
57 |
@Test public void testCreateAGame() {
|
jtulach@35
|
58 |
Game s = webResource.path("games").queryParam("white", "Jarda")
|
jtulach@35
|
59 |
.queryParam("black", "Jirka").post(Game.class);
|
jtulach@35
|
60 |
|
jtulach@35
|
61 |
String msg = webResource.path("games").get(String.class);
|
jtulach@35
|
62 |
//List<Game> games = webResource.path("games").get(new GenericType<List<Game>>() {});
|
jtulach@35
|
63 |
|
jtulach@35
|
64 |
GenericType<List<Game>> gType = new GenericType<List<Game>>() {};
|
jtulach@35
|
65 |
|
jtulach@35
|
66 |
List<Game> games = webResource.path("games").accept("application/json").get(gType);
|
jtulach@35
|
67 |
assertEquals("One game", 1, games.size());
|
jtulach@35
|
68 |
assertEquals("Same white", "Jarda", games.get(0).getWhite());
|
jtulach@35
|
69 |
assertEquals("Same black", "Jirka", games.get(0).getBlack());
|
jtulach@35
|
70 |
|
jtulach@35
|
71 |
Game s1 = webResource.path("games/" + s.getId()).queryParam("player", "Jarda").queryParam("move", "N").put(Game.class);
|
jtulach@35
|
72 |
try {
|
jtulach@35
|
73 |
Game s2 = webResource.path("games/" + s.getId()).queryParam("player", "Jarda").queryParam("move", "N").put(Game.class);
|
jtulach@35
|
74 |
fail("Not Jarda's turn, previous call shall fail");
|
jtulach@35
|
75 |
} catch (UniformInterfaceException ex) {
|
jtulach@35
|
76 |
// OK
|
jtulach@35
|
77 |
}
|
jtulach@35
|
78 |
try {
|
jtulach@35
|
79 |
Game s2 = webResource.path("games/" + s.getId()).queryParam("player", "Jirka").queryParam("move", "NONSENCE").put(Game.class);
|
jtulach@35
|
80 |
fail("Invalid move");
|
jtulach@35
|
81 |
} catch (UniformInterfaceException ex) {
|
jtulach@35
|
82 |
// OK
|
jtulach@35
|
83 |
}
|
jtulach@35
|
84 |
Game s2 = webResource.path("games/" + s.getId()).queryParam("player", "Jirka").queryParam("move", "S").put(Game.class);
|
jtulach@35
|
85 |
assertNotNull("Successful move", s2);
|
jtulach@35
|
86 |
}
|
jtulach@35
|
87 |
|
jtulach@35
|
88 |
}
|