Search in sources :

Example 16 with SparkTestUtil

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

the class GenericSecureIntegrationTest method setup.

@BeforeClass
public static void setup() {
    testUtil = new SparkTestUtil(4567);
    // note that the keystore stuff is retrieved from SparkTestUtil which
    // respects JVM params for keystore, password
    // but offers a default included store if not.
    Spark.secure(SparkTestUtil.getKeyStoreLocation(), SparkTestUtil.getKeystorePassword(), null, null);
    before("/protected/*", (request, response) -> {
        halt(401, "Go Away!");
    });
    get("/hi", (request, response) -> "Hello World!");
    get("/ip", (request, response) -> request.ip());
    get("/:param", (request, response) -> "echo: " + request.params(":param"));
    get("/paramwithmaj/:paramWithMaj", (request, response) -> "echo: " + request.params(":paramWithMaj"));
    get("/", (request, response) -> "Hello Root!");
    post("/poster", (request, response) -> {
        String body = request.body();
        // created
        response.status(201);
        return "Body was: " + body;
    });
    patch("/patcher", (request, response) -> {
        String body = request.body();
        response.status(200);
        return "Body was: " + body;
    });
    after("/hi", (request, response) -> {
        response.header("after", "foobar");
    });
    Spark.awaitInitialization();
}
Also used : SparkTestUtil(spark.util.SparkTestUtil) BeforeClass(org.junit.BeforeClass)

Example 17 with SparkTestUtil

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

the class RedirectTest method setup.

@BeforeClass
public static void setup() throws IOException {
    testUtil = new SparkTestUtil(4567);
    // don't set the others to be able to verify affect of Redirect.Status
    testUtil.setFollowRedirectStrategy(301, 302);
    get("/hello", (request, response) -> REDIRECTED);
    redirect.get("/hi", "/hello");
    redirect.post("/hi", "/hello");
    redirect.put("/hi", "/hello");
    redirect.delete("/hi", "/hello");
    redirect.any("/any", "/hello");
    redirect.get("/hiagain", "/hello", Redirect.Status.USE_PROXY);
    redirect.post("/hiagain", "/hello", Redirect.Status.USE_PROXY);
    redirect.put("/hiagain", "/hello", Redirect.Status.USE_PROXY);
    redirect.delete("/hiagain", "/hello", Redirect.Status.USE_PROXY);
    redirect.any("/anyagain", "/hello", Redirect.Status.USE_PROXY);
    Spark.awaitInitialization();
}
Also used : SparkTestUtil(spark.util.SparkTestUtil) BeforeClass(org.junit.BeforeClass)

Example 18 with SparkTestUtil

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

the class DisableMimeGuessingTest 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"));
    staticFiles.disableMimeTypeGuessing();
    get("/hello", (q, a) -> FO_SHIZZY);
    get("/*", (q, a) -> {
        throw new NotFoundException();
    });
    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)

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