Search in sources :

Example 11 with SparkTestUtil

use of spark.util.SparkTestUtil in project spark by perwendel.

the class GzipTest method testGet.

/**
 * Used to verify that "normal" functionality works after static files mapping
 */
private static void testGet() throws Exception {
    SparkTestUtil testUtil = new SparkTestUtil(4567);
    SparkTestUtil.UrlResponse response = testUtil.doMethod("GET", "/hello", "");
    Assert.assertEquals(200, response.status);
    Assert.assertTrue(response.body.contains(GzipExample.FO_SHIZZY));
}
Also used : SparkTestUtil(spark.util.SparkTestUtil)

Example 12 with SparkTestUtil

use of spark.util.SparkTestUtil in project spark by perwendel.

the class StaticFilesMemberTest method setup.

@BeforeClass
public static void setup() throws IOException {
    testUtil = new SparkTestUtil(4567);
    tmpExternalFile = new File(System.getProperty("java.io.tmpdir"), EXTERNAL_FILE_NAME_HTML);
    FileWriter writer = new FileWriter(tmpExternalFile);
    writer.write(CONTENT_OF_EXTERNAL_FILE);
    writer.flush();
    writer.close();
    staticFiles.location("/public");
    staticFiles.externalLocation(System.getProperty("java.io.tmpdir"));
    get("/hello", (q, a) -> FO_SHIZZY);
    get("/*", (q, a) -> {
        throw new NotFoundException();
    });
    exception(NotFoundException.class, (e, request, response) -> {
        response.status(404);
        response.body(NOT_FOUND_BRO);
    });
    Spark.awaitInitialization();
}
Also used : FileWriter(java.io.FileWriter) NotFoundException(spark.examples.exception.NotFoundException) SparkTestUtil(spark.util.SparkTestUtil) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 13 with SparkTestUtil

use of spark.util.SparkTestUtil in project spark by perwendel.

the class CustomErrorPagesTest method setup.

@BeforeClass
public static void setup() throws IOException {
    testUtil = new SparkTestUtil(4567);
    get("/hello", (q, a) -> HELLO_WORLD);
    get("/raiseinternal", (q, a) -> {
        throw new Exception("");
    });
    notFound(CUSTOM_NOT_FOUND);
    internalServerError((request, response) -> {
        if (request.queryParams(QUERY_PARAM_KEY) != null) {
            throw new Exception();
        }
        response.type(APPLICATION_JSON);
        return CUSTOM_INTERNAL;
    });
    Spark.awaitInitialization();
}
Also used : SparkTestUtil(spark.util.SparkTestUtil) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 14 with SparkTestUtil

use of spark.util.SparkTestUtil in project spark by perwendel.

the class ResponseBodyTest method setup.

@BeforeClass
public static void setup() throws IOException {
    http = new SparkTestUtil(4567);
    get(HELLO, (q, a) -> HELLO_WORLD);
    after(HELLO, (q, a) -> {
        String body = a.body();
        assertEquals(HELLO_WORLD, body);
    });
    get(SPECIAL, (q, a) -> {
        a.body(XIDXUS);
        return "";
    });
    after(SPECIAL, (q, a) -> {
        String body = a.body();
        assertEquals(XIDXUS, body);
    });
    get(PORAKATIKAOKAO, (q, a) -> {
        a.body(GALLUS_SCANDALUM);
        return null;
    });
    after(PORAKATIKAOKAO, (q, a) -> {
        String body = a.body();
        assertEquals(GALLUS_SCANDALUM, body);
    });
    get(MAXIME, (q, a) -> {
        a.body(XIDXUS);
        return $11AB;
    });
    after(MAXIME, (q, a) -> {
        String body = a.body();
        assertEquals($11AB, body);
    });
    Spark.awaitInitialization();
}
Also used : SparkTestUtil(spark.util.SparkTestUtil) BeforeClass(org.junit.BeforeClass)

Example 15 with SparkTestUtil

use of spark.util.SparkTestUtil in project spark by perwendel.

the class FilterTest method setup.

@BeforeClass
public static void setup() throws IOException {
    testUtil = new SparkTestUtil(4567);
    before("/justfilter", (q, a) -> System.out.println("Filter matched"));
    awaitInitialization();
}
Also used : SparkTestUtil(spark.util.SparkTestUtil) BeforeClass(org.junit.BeforeClass)

Aggregations

SparkTestUtil (spark.util.SparkTestUtil)18 BeforeClass (org.junit.BeforeClass)16 File (java.io.File)5 FileWriter (java.io.FileWriter)5 NotFoundException (spark.examples.exception.NotFoundException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Server (org.eclipse.jetty.server.Server)1 ServerConnector (org.eclipse.jetty.server.ServerConnector)1 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)1 Test (org.junit.Test)1 JWGmeligMeylingException (spark.examples.exception.JWGmeligMeylingException)1 SubclassOfBaseException (spark.examples.exception.SubclassOfBaseException)1