1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.rest.client;
18
19 import static org.apache.juneau.TestUtils.*;
20 import static org.junit.jupiter.api.Assertions.*;
21
22 import java.io.*;
23
24 import org.apache.http.entity.*;
25 import org.apache.juneau.*;
26 import org.apache.juneau.marshaller.*;
27 import org.apache.juneau.parser.*;
28 import org.apache.juneau.rest.annotation.*;
29 import org.apache.juneau.rest.mock.*;
30 import org.apache.juneau.rest.servlet.*;
31 import org.junit.jupiter.api.*;
32
33 class RestCallException_Test extends TestBase {
34
35 public static class ABean {
36 public int f;
37 static ABean get() {
38 var x = new ABean();
39 x.f = 1;
40 return x;
41 }
42 @Override
43 public String toString() {
44 return Json5.of(this);
45 }
46 }
47
48 @Rest
49 public static class A extends BasicRestObject {
50 @RestPost
51 public InputStream echo(InputStream is) {
52 return is;
53 }
54 }
55
56 @Test void a01_basic() throws Exception {
57 try {
58 client().build().get().run();
59 fail();
60 } catch (RestCallException e) {
61 assertEquals(404, e.getResponseCode());
62 assertNull(e.getCause());
63 }
64
65 try {
66 client().build().post("/echo",new StringEntity("{f:")).run().getContent().as(ABean.class);
67 fail();
68 } catch (RestCallException e) {
69 assertThrowable(Exception.class, "Could not find '}'", e.getCause(ParseException.class));
70 }
71
72 var e = new RestCallException(null, null, null);
73 assertNotNull(e.getThrown());
74 assertFalse(e.getThrown().isPresent());
75 assertEquals(0, e.getResponseCode());
76 }
77
78
79
80
81
82 private static RestClient.Builder client() {
83 return MockRestClient.create(A.class).json5().noTrace();
84 }
85 }