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();
}
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();
}
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();
}
Aggregations