Reputation: 34061
I build a controller in spark java, but do not know how to test it.
The controller class:
public class PdfController {
public PdfController(final Pdf pdf) {
post("/", (req, res) -> {
InputStream stream = new ByteArrayInputStream(req.bodyAsBytes());
PdfState state = pdf.validate(stream);
res.type("application/json");
return JsonUtil.toJson(state);
});
}
}
I build the test boilerplate
public class PdfControllerTest {
@BeforeClass
public static void beforeClass() {
PdfInspector.main(null);
}
@Test(groups = {"fast"})
public void IsPdfContentRequestValid_StreamValidPdfContent_ExpectJsonSuccess() {
}
@AfterClass
public static void afterClass() {
Spark.stop();
}
}
But do not know how to write a test method.
How to write an integration test in spark java?
Upvotes: 0
Views: 81
Reputation: 86
Download POSTMAN from chrome web store and make changes in your code so that your code could accept data... and also use "maven install" from eclipse to build your project, javaspark framework will call embedded jetty server and will run on that server...
TRY "localhost:4567/" to access your page from POSTMAN and do send some JSON or other input to that code...
Upvotes: 1