1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.rest.annotation;
18
19 import static org.apache.juneau.commons.utils.CollectionUtils.*;
20 import static org.apache.juneau.commons.utils.StringUtils.*;
21
22 import org.apache.juneau.*;
23 import org.apache.juneau.encoders.*;
24 import org.apache.juneau.http.annotation.*;
25 import org.apache.juneau.http.header.*;
26 import org.apache.juneau.rest.mock.*;
27 import org.junit.jupiter.api.*;
28
29 class Rest_Encoders_Test extends TestBase {
30
31
32
33
34
35 public static class MyEncoder extends GzipEncoder {
36 @Override
37 public String[] getCodings() {
38 return a("mycoding");
39 }
40 }
41
42
43
44
45
46 @Rest
47 public static class A {
48 @RestOp
49 public String put(@Content String in) {
50 return in;
51 }
52 }
53
54 @Test void a01_noCompression() throws Exception {
55 var a = MockRestClient.buildLax(A.class);
56 a.put("/", "foo").run().assertContent("foo");
57 a.put("/", "foo").header(ContentEncoding.of("")).run().assertContent("foo");
58 a.put("/", "foo").header(ContentEncoding.of("identity")).run().assertContent("foo");
59 a.put("?noTrace=true", compress("foo")).header(ContentEncoding.of("mycoding")).run()
60 .assertStatus(415)
61 .assertContent().isContains(
62 "Unsupported encoding in request header 'Content-Encoding': 'mycoding'",
63 "Supported codings: ['identity']"
64 );
65 }
66
67
68
69
70
71 @Rest(encoders=MyEncoder.class)
72 public static class B {
73 @RestOp
74 public String put(@Content String in) {
75 return in;
76 }
77 }
78
79 @Test void b01_withCompression() throws Exception {
80 var b = MockRestClient.build(B.class);
81 b.put("/", "foo")
82 .run()
83 .assertContent("foo");
84 b.put("/", "foo")
85 .header(ContentEncoding.of(""))
86 .run()
87 .assertContent("foo");
88 b.put("/", "foo")
89 .header(ContentEncoding.of("identity"))
90 .run()
91 .assertContent("foo");
92 }
93 }