use of spark.util.SparkTestUtil in project spark by perwendel.
the class StaticFilesTest 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();
}
use of spark.util.SparkTestUtil in project spark by perwendel.
the class StaticFilesTestExternal method setup.
@BeforeClass
public static void setup() throws IOException {
testUtil = new SparkTestUtil(4567);
String directoryRoot = System.getProperty("java.io.tmpdir") + "sparkish";
new File(directoryRoot).mkdirs();
tmpExternalFile1 = new File(directoryRoot, EXTERNAL_FILE_NAME_HTML);
FileWriter writer = new FileWriter(tmpExternalFile1);
writer.write(CONTENT_OF_EXTERNAL_FILE);
writer.flush();
writer.close();
File root = new File(directoryRoot);
folderOutsideStaticFiles = new File(root.getAbsolutePath() + "/../dumpsterstuff");
folderOutsideStaticFiles.mkdirs();
String newFilePath = root.getAbsolutePath() + "/../dumpsterstuff/Spark.class";
tmpExternalFile2 = new File(newFilePath);
tmpExternalFile2.createNewFile();
staticFiles.externalLocation(directoryRoot);
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();
}
use of spark.util.SparkTestUtil in project spark by perwendel.
the class BodyAvailabilityTest method setup.
@BeforeClass
public static void setup() {
LOGGER.debug("setup()");
testUtil = new SparkTestUtil(4567);
beforeBody = null;
routeBody = null;
afterBody = null;
before("/hello", (req, res) -> {
LOGGER.debug("before-req.body() = " + req.body());
beforeBody = req.body();
});
post("/hello", (req, res) -> {
LOGGER.debug("get-req.body() = " + req.body());
routeBody = req.body();
return req.body();
});
after("/hello", (req, res) -> {
LOGGER.debug("after-before-req.body() = " + req.body());
afterBody = req.body();
});
Spark.awaitInitialization();
}
use of spark.util.SparkTestUtil in project spark by perwendel.
the class ResponseWrapperDelegationTest method setup.
@BeforeClass
public static void setup() throws IOException {
testUtil = new SparkTestUtil(4567);
get("/204", (q, a) -> {
a.status(204);
return "";
});
after("/204", (q, a) -> {
if (a.status() == 204) {
a.status(200);
a.body("ok");
}
});
get("/json", (q, a) -> {
a.type("application/json");
return "{\"status\": \"ok\"}";
});
after("/json", (q, a) -> {
if ("application/json".equalsIgnoreCase(a.type())) {
a.type("text/plain");
}
});
exception(Exception.class, (exception, q, a) -> {
exception.printStackTrace();
});
Spark.awaitInitialization();
}
use of spark.util.SparkTestUtil in project spark by perwendel.
the class ServicePortIntegrationTest method testGetPort_withRandomPort.
@Test
public void testGetPort_withRandomPort() throws Exception {
int actualPort = service.port();
LOGGER.info("got port ");
SparkTestUtil testUtil = new SparkTestUtil(actualPort);
SparkTestUtil.UrlResponse response = testUtil.doMethod("GET", "/hi", null);
Assert.assertEquals(200, response.status);
Assert.assertEquals("Hello World!", response.body);
}
Aggregations