freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java
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--
Test to verify that we are able to read the main page
     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     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]"
    21  *
    22  * Contributor(s):
    23  *
    24  * Portions Copyrighted 2009 Jaroslav Tulach
    25  */
    26 
    27 package cz.xelfi.quoridor.freemarkerdor;
    28 
    29 import com.sun.jersey.api.client.Client;
    30 import com.sun.jersey.api.client.WebResource;
    31 import com.sun.jersey.core.header.MediaTypes;
    32 import java.io.File;
    33 import java.io.IOException;
    34 import java.net.URI;
    35 import java.util.concurrent.Callable;
    36 import org.junit.After;
    37 import org.junit.Before;
    38 import org.junit.Test;
    39 import static org.junit.Assert.*;
    40 
    41 /**
    42  *
    43  * @author Jaroslav Tulach <jtulach@netbeans.org>
    44  */
    45 public class UITest extends Object {
    46     private File dir;
    47     private Callable<Void> stop;
    48     private WebResource webResource;
    49 
    50     public UITest() throws Exception {
    51     }
    52 
    53     @Before
    54     public void setUp() throws Exception {
    55         dir = File.createTempFile("quoridor", ".dir");
    56         dir.delete();
    57         System.setProperty("quoridor.dir", dir.getPath());
    58         stop = UI.startServers();
    59 
    60         Client client = new Client();
    61         webResource = client.resource(new URI("http://localhost:9997/"));
    62     }
    63 
    64     @After
    65     public void tearDown() throws Exception {
    66         deleteRec(dir);
    67         if (stop != null) {
    68             stop.call();
    69         }
    70     }
    71 
    72     static void deleteRec(File dir) throws IOException {
    73         if (dir == null) {
    74             return;
    75         }
    76         File[] arr = dir.listFiles();
    77         if (arr != null) {
    78             for (File f : arr) {
    79                 deleteRec(f);
    80             }
    81         }
    82         dir.delete();
    83     }
    84 
    85     /**
    86      * Test if a WADL document is available at the relative path
    87      * "application.wadl".
    88      */
    89     @Test public void testApplicationWadl() {
    90         String serviceWadl = webResource.path("application.wadl").
    91                 accept(MediaTypes.WADL).get(String.class);
    92         assertTrue(serviceWadl.length() > 0);
    93     }
    94 
    95     @Test public void testGetIndexPage() throws Exception {
    96         String res = webResource.accept("text/html").get(String.class);
    97         if (res.indexOf("Quoridor") == -1) {
    98             fail("Wrong index.html:\n" + res);
    99         }
   100     }
   101 
   102 }