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.common.utils.Utils.*;
20
21 import org.apache.juneau.*;
22 import org.apache.juneau.rest.matcher.*;
23 import org.apache.juneau.rest.mock.*;
24 import org.junit.jupiter.api.*;
25
26 import jakarta.servlet.http.*;
27
28 class RestOp_Matchers_Test extends TestBase {
29
30
31
32
33
34 @Rest
35 public static class A {
36 @RestOp(path="/one", matchers=A1.class)
37 public String a() {
38 return "OK-1a";
39 }
40 @RestGet(path="/one", matchers=A2.class)
41 public String b() {
42 return "OK-1b";
43 }
44 @RestGet(path="/one")
45 public String c() {
46 return "OK-1c";
47 }
48 @RestOp(path="/two")
49 public String d() {
50 return "OK-2a";
51 }
52 @RestGet(path="/two", matchers={A1.class, A2.class})
53 public String e() {
54 return "OK-2b";
55 }
56
57 public static class A1 extends RestMatcher {
58 @Override
59 public boolean matches(HttpServletRequest req) {
60 return emptyIfNull(req.getQueryString()).contains("t1=1");
61 }
62 }
63 public static class A2 extends RestMatcher {
64 @Override
65 public boolean matches(HttpServletRequest req) {
66 return emptyIfNull(req.getQueryString()).contains("t2=2");
67 }
68 }
69 }
70
71 @Test void a01_overlapping() throws Exception {
72 var a = MockRestClient.build(A.class);
73 a.get("/one?t1=1").run().assertContent("OK-1a");
74 a.get("/one?t2=2").run().assertContent("OK-1b");
75 a.get("/one").run().assertContent("OK-1c");
76 a.get("/two?t1=1").run().assertContent("OK-2b");
77 a.get("/two?t2=2").run().assertContent("OK-2b");
78 a.get("/two?t1=1&t2=2").run().assertContent("OK-2b");
79 a.get("/two?tx=x").run().assertContent("OK-2a");
80 }
81 }