author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Sun, 30 Aug 2009 14:56:32 +0200 | |
changeset 50 | 1cce50d16bb5 |
child 51 | 8358ef0d29d7 |
permissions | -rw-r--r-- |
jaroslav@50 | 1 |
/* |
jaroslav@50 | 2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
jaroslav@50 | 3 |
* |
jaroslav@50 | 4 |
* The contents of this file are subject to the terms of either the GNU |
jaroslav@50 | 5 |
* General Public License Version 2 only ("GPL") or the Common |
jaroslav@50 | 6 |
* Development and Distribution License("CDDL") (collectively, the |
jaroslav@50 | 7 |
* "License"). You may not use this file except in compliance with the |
jaroslav@50 | 8 |
* License. You can obtain a copy of the License at |
jaroslav@50 | 9 |
* http://www.netbeans.org/cddl-gplv2.html |
jaroslav@50 | 10 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
jaroslav@50 | 11 |
* specific language governing permissions and limitations under the |
jaroslav@50 | 12 |
* License. When distributing the software, include this License Header |
jaroslav@50 | 13 |
* Notice in each file and include the License file at |
jaroslav@50 | 14 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this |
jaroslav@50 | 15 |
* particular file as subject to the "Classpath" exception as provided |
jaroslav@50 | 16 |
* by Sun in the GPL Version 2 section of the License file that |
jaroslav@50 | 17 |
* accompanied this code. If applicable, add the following below the |
jaroslav@50 | 18 |
* License Header, with the fields enclosed by brackets [] replaced by |
jaroslav@50 | 19 |
* your own identifying information: |
jaroslav@50 | 20 |
* "Portions Copyrighted [year] [name of copyright owner]" |
jaroslav@50 | 21 |
* |
jaroslav@50 | 22 |
* Contributor(s): |
jaroslav@50 | 23 |
* |
jaroslav@50 | 24 |
* Portions Copyrighted 2009 Jaroslav Tulach |
jaroslav@50 | 25 |
*/ |
jaroslav@50 | 26 |
|
jaroslav@50 | 27 |
package cz.xelfi.quoridor.freemarkerdor; |
jaroslav@50 | 28 |
|
jaroslav@50 | 29 |
import com.sun.jersey.api.client.Client; |
jaroslav@50 | 30 |
import com.sun.jersey.api.client.WebResource; |
jaroslav@50 | 31 |
import com.sun.jersey.core.header.MediaTypes; |
jaroslav@50 | 32 |
import java.io.File; |
jaroslav@50 | 33 |
import java.io.IOException; |
jaroslav@50 | 34 |
import java.net.URI; |
jaroslav@50 | 35 |
import java.util.concurrent.Callable; |
jaroslav@50 | 36 |
import org.junit.After; |
jaroslav@50 | 37 |
import org.junit.Before; |
jaroslav@50 | 38 |
import org.junit.Test; |
jaroslav@50 | 39 |
import static org.junit.Assert.*; |
jaroslav@50 | 40 |
|
jaroslav@50 | 41 |
/** |
jaroslav@50 | 42 |
* |
jaroslav@50 | 43 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
jaroslav@50 | 44 |
*/ |
jaroslav@50 | 45 |
public class UITest extends Object { |
jaroslav@50 | 46 |
private File dir; |
jaroslav@50 | 47 |
private Callable<Void> stop; |
jaroslav@50 | 48 |
private WebResource webResource; |
jaroslav@50 | 49 |
|
jaroslav@50 | 50 |
public UITest() throws Exception { |
jaroslav@50 | 51 |
} |
jaroslav@50 | 52 |
|
jaroslav@50 | 53 |
@Before |
jaroslav@50 | 54 |
public void setUp() throws Exception { |
jaroslav@50 | 55 |
dir = File.createTempFile("quoridor", ".dir"); |
jaroslav@50 | 56 |
dir.delete(); |
jaroslav@50 | 57 |
System.setProperty("quoridor.dir", dir.getPath()); |
jaroslav@50 | 58 |
stop = UI.startServers(); |
jaroslav@50 | 59 |
|
jaroslav@50 | 60 |
Client client = new Client(); |
jaroslav@50 | 61 |
webResource = client.resource(new URI("http://localhost:9997/")); |
jaroslav@50 | 62 |
} |
jaroslav@50 | 63 |
|
jaroslav@50 | 64 |
@After |
jaroslav@50 | 65 |
public void tearDown() throws Exception { |
jaroslav@50 | 66 |
deleteRec(dir); |
jaroslav@50 | 67 |
if (stop != null) { |
jaroslav@50 | 68 |
stop.call(); |
jaroslav@50 | 69 |
} |
jaroslav@50 | 70 |
} |
jaroslav@50 | 71 |
|
jaroslav@50 | 72 |
static void deleteRec(File dir) throws IOException { |
jaroslav@50 | 73 |
if (dir == null) { |
jaroslav@50 | 74 |
return; |
jaroslav@50 | 75 |
} |
jaroslav@50 | 76 |
File[] arr = dir.listFiles(); |
jaroslav@50 | 77 |
if (arr != null) { |
jaroslav@50 | 78 |
for (File f : arr) { |
jaroslav@50 | 79 |
deleteRec(f); |
jaroslav@50 | 80 |
} |
jaroslav@50 | 81 |
} |
jaroslav@50 | 82 |
dir.delete(); |
jaroslav@50 | 83 |
} |
jaroslav@50 | 84 |
|
jaroslav@50 | 85 |
/** |
jaroslav@50 | 86 |
* Test if a WADL document is available at the relative path |
jaroslav@50 | 87 |
* "application.wadl". |
jaroslav@50 | 88 |
*/ |
jaroslav@50 | 89 |
@Test public void testApplicationWadl() { |
jaroslav@50 | 90 |
String serviceWadl = webResource.path("application.wadl"). |
jaroslav@50 | 91 |
accept(MediaTypes.WADL).get(String.class); |
jaroslav@50 | 92 |
assertTrue(serviceWadl.length() > 0); |
jaroslav@50 | 93 |
} |
jaroslav@50 | 94 |
|
jaroslav@50 | 95 |
@Test public void testGetIndexPage() throws Exception { |
jaroslav@50 | 96 |
String res = webResource.accept("text/html").get(String.class); |
jaroslav@50 | 97 |
if (res.indexOf("Quoridor") == -1) { |
jaroslav@50 | 98 |
fail("Wrong index.html:\n" + res); |
jaroslav@50 | 99 |
} |
jaroslav@50 | 100 |
} |
jaroslav@50 | 101 |
|
jaroslav@50 | 102 |
} |