1.1 --- a/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java Sat Sep 12 10:02:07 2009 +0200
1.2 +++ b/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java Sun Sep 13 16:48:54 2009 +0200
1.3 @@ -38,6 +38,7 @@
1.4 import java.util.Locale;
1.5 import java.util.concurrent.Callable;
1.6 import javax.ws.rs.core.Cookie;
1.7 +import javax.ws.rs.core.MediaType;
1.8 import javax.ws.rs.core.MultivaluedMap;
1.9 import org.junit.AfterClass;
1.10 import org.junit.Before;
1.11 @@ -68,7 +69,7 @@
1.12
1.13 File passwd = new File(dir, "passwd");
1.14 FileOutputStream os = new FileOutputStream(passwd);
1.15 - os.write("test=pes\n".getBytes("UTF-8"));
1.16 + os.write("test=pes\nJarda=darda\n".getBytes("UTF-8"));
1.17 os.close();
1.18 }
1.19
1.20 @@ -111,6 +112,13 @@
1.21 }
1.22
1.23 @Test public void testGetIndexPage() throws Exception {
1.24 + String logJarda = webResource.path("api/login").
1.25 + queryParam("name", "Jarda").
1.26 + queryParam("password", "darda").
1.27 + accept(MediaType.TEXT_PLAIN).
1.28 + put(String.class);
1.29 + assertNotNull("Logged in OK", logJarda);
1.30 +
1.31 String res = webResource.accept("text/html").get(String.class);
1.32 if (res.indexOf("Quoridor") == -1) {
1.33 fail("Wrong index.html:\n" + res);
1.34 @@ -124,7 +132,7 @@
1.35 if (res.toLowerCase().indexOf("error") != -1) {
1.36 fail("There was an error:\n" + res);
1.37 }
1.38 - res = webResource.cookie(Cookie.valueOf("login=jarda")).accept("text/html").get(String.class);
1.39 + res = webResource.cookie(Cookie.valueOf("login=" + logJarda)).accept("text/html").get(String.class);
1.40 if (res.indexOf("action=\"/games/create\"") == -1) {
1.41 fail(res);
1.42 }
1.43 @@ -146,10 +154,15 @@
1.44
1.45
1.46 @Test public void testCreateGameWrongUsers() throws Exception {
1.47 + String logTest = webResource.path("api/login").
1.48 + queryParam("name", "test").
1.49 + queryParam("password", "pes").
1.50 + accept(MediaType.TEXT_PLAIN).
1.51 + put(String.class);
1.52 ClientResponse res = webResource.path("games/create").
1.53 queryParam("white", "unknown1").
1.54 queryParam("black", "unknown2").
1.55 - cookie(Cookie.valueOf("login=test")).
1.56 + cookie(Cookie.valueOf("login=" + logTest)).
1.57 accept("text/html").
1.58 get(ClientResponse.class);
1.59 final String txt = res.getEntity(String.class);
1.60 @@ -160,10 +173,15 @@
1.61 }
1.62
1.63 @Test public void testCreateGameOK() throws Exception {
1.64 + String logTest = webResource.path("api/login").
1.65 + queryParam("name", "test").
1.66 + queryParam("password", "pes").
1.67 + accept(MediaType.TEXT_PLAIN).
1.68 + put(String.class);
1.69 ClientResponse res = webResource.path("games/create").
1.70 queryParam("white", "unknown1").
1.71 queryParam("black", "test").
1.72 - cookie(Cookie.valueOf("login=test")).
1.73 + cookie(Cookie.valueOf("login=" + logTest)).
1.74 accept("text/html").
1.75 get(ClientResponse.class);
1.76