|
| 1 | +/* |
| 2 | + * Jooby https://jooby.io |
| 3 | + * Apache License Version 2.0 https://jooby.io/LICENSE.txt |
| 4 | + * Copyright 2014 Edgar Espina |
| 5 | + */ |
| 6 | +package io.jooby.i3400; |
| 7 | + |
| 8 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 9 | + |
| 10 | +import io.jooby.Jooby; |
| 11 | +import io.jooby.jackson.JacksonModule; |
| 12 | +import io.jooby.junit.ServerTest; |
| 13 | +import io.jooby.junit.ServerTestRunner; |
| 14 | +import okhttp3.MediaType; |
| 15 | +import okhttp3.RequestBody; |
| 16 | + |
| 17 | +public class Issue3400 { |
| 18 | + |
| 19 | + static class AppA extends Jooby { |
| 20 | + { |
| 21 | + post("/pets", ctx -> ctx.body(Pet3400.class)); |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + @ServerTest |
| 26 | + public void shouldShareDecodersOnMountedResources(ServerTestRunner runner) { |
| 27 | + runner |
| 28 | + .define( |
| 29 | + app -> { |
| 30 | + app.install(new JacksonModule()); |
| 31 | + app.mount(new AppA()); |
| 32 | + }) |
| 33 | + .ready( |
| 34 | + http -> { |
| 35 | + http.post( |
| 36 | + "/pets", |
| 37 | + RequestBody.create( |
| 38 | + "{\"id\": 1, \"name\": \"Cheddar\"}", MediaType.parse("application/json")), |
| 39 | + rsp -> { |
| 40 | + assertEquals("{\"id\":1,\"name\":\"Cheddar\"}", rsp.body().string()); |
| 41 | + assertEquals("application/json;charset=UTF-8", rsp.header("Content-Type")); |
| 42 | + }); |
| 43 | + }); |
| 44 | + } |
| 45 | + |
| 46 | + @ServerTest |
| 47 | + public void shouldShareDecodersOnInstalledResources(ServerTestRunner runner) { |
| 48 | + runner |
| 49 | + .define( |
| 50 | + app -> { |
| 51 | + app.install(new JacksonModule()); |
| 52 | + app.install(AppA::new); |
| 53 | + }) |
| 54 | + .ready( |
| 55 | + http -> { |
| 56 | + http.post( |
| 57 | + "/pets", |
| 58 | + RequestBody.create( |
| 59 | + "{\"id\": 1, \"name\": \"Cheddar\"}", MediaType.parse("application/json")), |
| 60 | + rsp -> { |
| 61 | + assertEquals("{\"id\":1,\"name\":\"Cheddar\"}", rsp.body().string()); |
| 62 | + assertEquals("application/json;charset=UTF-8", rsp.header("Content-Type")); |
| 63 | + }); |
| 64 | + }); |
| 65 | + } |
| 66 | +} |
0 commit comments