|
| 1 | +package io.jooby.i2352; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | + |
| 5 | +import io.jooby.junit.ServerTest; |
| 6 | +import io.jooby.junit.ServerTestRunner; |
| 7 | +import okhttp3.MultipartBody; |
| 8 | + |
| 9 | +public class Issue2352 { |
| 10 | + @ServerTest |
| 11 | + public void shouldNotIgnoreAnnotationOnParam(ServerTestRunner runner) { |
| 12 | + runner.define(app -> { |
| 13 | + app.mvc(new C2352()); |
| 14 | + app.error((ctx, cause, code) -> { |
| 15 | + ctx.send(cause.getMessage()); |
| 16 | + }); |
| 17 | + }).ready(http -> { |
| 18 | + |
| 19 | + String name = getClass().getSimpleName(); |
| 20 | + http.post("/2352/nonnull", new MultipartBody.Builder() |
| 21 | + .setType(MultipartBody.FORM) |
| 22 | + .addFormDataPart("noname", name) |
| 23 | + .build(), rsp -> { |
| 24 | + assertEquals(400, rsp.code()); |
| 25 | + assertEquals("Missing value: 'name'", rsp.body().string()); |
| 26 | + }); |
| 27 | + |
| 28 | + http.post("/2352/nonnull", new MultipartBody.Builder() |
| 29 | + .setType(MultipartBody.FORM) |
| 30 | + .addFormDataPart("name", name) |
| 31 | + .build(), rsp -> { |
| 32 | + assertEquals(name, rsp.body().string()); |
| 33 | + }); |
| 34 | + |
| 35 | + http.post("/2352/nullable", new MultipartBody.Builder() |
| 36 | + .setType(MultipartBody.FORM) |
| 37 | + .addFormDataPart("noname", name) |
| 38 | + .build(), rsp -> { |
| 39 | + assertEquals(200, rsp.code()); |
| 40 | + assertEquals("null", rsp.body().string()); |
| 41 | + }); |
| 42 | + }); |
| 43 | + } |
| 44 | +} |
0 commit comments