141142143144145146147148149150151
.expect() .statusCode(200) .when() .post("/"); Beer beer = RestAssured.expect() .statusCode(200) .when() .get("/Westmalle") .andReturn() .body()
162163164165166167168169170171172
running(testServer(PORT), new Runnable() { @Override public void run() { Beer beer = RestAssured.given() .contentType(ContentType.JSON) .content("{\"name\":\"Westmale\"}") .expect() .statusCode(200) .when()
1516171819202122232425
return ok(Json.toJson(Beer.getAll())); } public static Result get(String name) { Beer beer = Beer.getByName(name); Result result; if (beer == null) { result = notFound();
333435363738394041424344
@BodyParser.Of(BodyParser.Json.class) public static Result create() { JsonNode json = request().body().asJson(); Beer beer = Json.fromJson(json, Beer.class); beer.save(); return ok(Json.toJson(beer)); }
4546474849505152535455
@BodyParser.Of(BodyParser.Json.class) public static Result update(String name) { JsonNode json = request().body().asJson(); Beer beer = Json.fromJson(json, Beer.class); beer.update(); return ok(Json.toJson(beer)); }
54555657585960616263646566676869707172
return ok(Json.toJson(beer)); } public static Result delete(String name) { Beer beer = Beer.getByName(name); Result result; if (beer == null) { result = notFound(); } else { beer.delete(); result = noContent(); } return result; }